diff options
author | Bert Belder <bertbelder@gmail.com> | 2020-08-18 14:07:57 +0200 |
---|---|---|
committer | Bert Belder <bertbelder@gmail.com> | 2020-08-18 20:50:52 +0200 |
commit | f6e9150b33168ab8c5e48238860e2c3f3bf625f3 (patch) | |
tree | 8dd1c3767cf340f51e8bca0d9cc30bed2750954d /cli/tests/unit/dispatch_json_test.ts | |
parent | b308a774e81d7d18dfc2122459632f9ba9ae1eb8 (diff) |
Async op dispatcher support with 'stateful_json_op_(a)sync()' (#7095)
Closes: #7020
Diffstat (limited to 'cli/tests/unit/dispatch_json_test.ts')
-rw-r--r-- | cli/tests/unit/dispatch_json_test.ts | 47 |
1 files changed, 40 insertions, 7 deletions
diff --git a/cli/tests/unit/dispatch_json_test.ts b/cli/tests/unit/dispatch_json_test.ts index e10a50361..e5200aa5b 100644 --- a/cli/tests/unit/dispatch_json_test.ts +++ b/cli/tests/unit/dispatch_json_test.ts @@ -1,4 +1,9 @@ -import { assert, unitTest, assertMatch, unreachable } from "./test_util.ts"; +import { + assertStrictEquals, + unitTest, + assertMatch, + unreachable, +} from "./test_util.ts"; const openErrorStackPattern = new RegExp( `^.* @@ -28,10 +33,38 @@ declare global { } unitTest(function malformedJsonControlBuffer(): void { - const opId = Deno.core.ops()["op_open"]; - const res = Deno.core.send(opId, new Uint8Array([1, 2, 3, 4, 5])); - const resText = new TextDecoder().decode(res); - const resJson = JSON.parse(resText); - assert(!resJson.ok); - assert(resJson.err); + const opId = Deno.core.ops()["op_open_sync"]; + const argsBuf = new Uint8Array([1, 2, 3, 4, 5]); + const resBuf = Deno.core.send(opId, argsBuf); + const resText = new TextDecoder().decode(resBuf); + const resObj = JSON.parse(resText); + assertStrictEquals(resObj.ok, undefined); + assertStrictEquals(resObj.err.kind, "TypeError"); + assertMatch(resObj.err.message, /\bexpected value\b/); +}); + +unitTest(function invalidPromiseId(): void { + const opId = Deno.core.ops()["op_open_async"]; + const argsObj = { + promiseId: "1. NEIN!", + path: "/tmp/P.I.S.C.I.X/yeah", + mode: 0o666, + options: { + read: true, + write: true, + create: true, + truncate: false, + append: false, + createNew: false, + }, + }; + const argsText = JSON.stringify(argsObj); + const argsBuf = new TextEncoder().encode(argsText); + const resBuf = Deno.core.send(opId, argsBuf); + const resText = new TextDecoder().decode(resBuf); + const resObj = JSON.parse(resText); + console.error(resText); + assertStrictEquals(resObj.ok, undefined); + assertStrictEquals(resObj.err.kind, "TypeError"); + assertMatch(resObj.err.message, /\bpromiseId\b/); }); |