Skip to content

Commit

Permalink
test: Add test for EVALSHA command (#222)
Browse files Browse the repository at this point in the history
  • Loading branch information
uki00a authored Apr 11, 2021
1 parent 1c989e6 commit 0a0a70c
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 10 deletions.
10 changes: 0 additions & 10 deletions tests/general_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,6 @@ suite.test("exists", async () => {
});
});

suite.test("eval", async () => {
const raw = await client.eval(
"return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}",
["1", "2"],
["3", "4"],
);
assert(Array.isArray(raw));
assertEquals(raw, ["1", "2", "3", "4"]);
});

suite.test("parse basic URL", () => {
const options = parseURL("redis://127.0.0.1:7003");
assertEquals(options.hostname, "127.0.0.1");
Expand Down
57 changes: 57 additions & 0 deletions tests/script_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { connect, Redis } from "../mod.ts";
import { delay } from "../vendor/https/deno.land/std/async/mod.ts";
import {
assert,
assertEquals,
} from "../vendor/https/deno.land/std/testing/asserts.ts";
import {
newClient,
nextPort,
startRedis,
stopRedis,
TestSuite,
} from "./test_util.ts";

const suite = new TestSuite("script");
const port = nextPort();
const server = await startRedis({ port });
const client = await newClient({ hostname: "127.0.0.1", port });

suite.afterAll(() => {
stopRedis(server);
client.close();
});

suite.afterEach(async () => {
await client.flushdb();
});

suite.test("eval", async () => {
const raw = await client.eval(
"return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}",
["1", "2"],
["3", "4"],
);
assert(Array.isArray(raw));
assertEquals(raw, ["1", "2", "3", "4"]);
});

suite.test("evalsha", async () => {
const hash = await client.scriptLoad(
`return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}`,
);
try {
assertEquals(
await client.scriptExists(hash),
[1],
);

const result = await client.evalsha(hash, ["a", "b"], ["1", "2"]);
assert(Array.isArray(result));
assertEquals(result, ["a", "b", "1", "2"]);
} finally {
await client.scriptFlush();
}
});

suite.runTests();

0 comments on commit 0a0a70c

Please sign in to comment.