Skip to content

Commit 3d8caee

Browse files
[CAE-342] Minor refactor
1 parent 9633d9f commit 3d8caee

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

packages/client/lib/sentinel/index.spec.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { strict as assert } from 'node:assert';
22
import { setTimeout } from 'node:timers/promises';
3-
import testUtils, { GLOBAL } from '../test-utils';
3+
import testUtils, { GLOBAL, MATH_FUNCTION } from '../test-utils';
44
import { RESP_TYPES } from '../RESP/decoder';
55
import { WatchError } from "../errors";
6-
import { MATH_FUNCTION } from '../commands/FUNCTION_LOAD.spec';
76
import { RedisSentinelConfig, SentinelFramework } from "./test-util";
87
import { RedisSentinelEvent, RedisSentinelType, RedisSentinelClientType, RedisNode } from "./types";
9-
import { RedisModules, RedisFunctions, RedisScripts, RespVersions, TypeMapping } from '../RESP/types';
8+
import { RedisModules, RedisFunctions, RedisScripts, RespVersions, TypeMapping, NumberReply } from '../RESP/types';
109
import { promisify } from 'node:util';
1110
import { exec } from 'node:child_process';
1211
const execAsync = promisify(exec);
@@ -417,7 +416,7 @@ describe('legacy tests', () => {
417416
})
418417

419418
describe('Sentinel Client', function () {
420-
let sentinel: RedisSentinelType< RedisModules, RedisFunctions, RedisScripts, RespVersions, TypeMapping> | undefined;
419+
let sentinel: RedisSentinelType<RedisModules, RedisFunctions, RedisScripts, RespVersions, TypeMapping> | undefined;
421420

422421
beforeEach(async function () {
423422
this.timeout(0);

packages/client/lib/test-utils.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { setTimeout } from 'node:timers/promises';
44
import { CredentialsProvider } from './authx';
55
import { Command, NumberReply } from './RESP/types';
66
import { BasicCommandParser, CommandParser } from './client/parser';
7-
import { MATH_FUNCTION } from './commands/FUNCTION_LOAD.spec';
87
import { defineScript } from './lua-script';
98
import RedisBloomModules from '@redis/bloom';
109
const utils = TestUtils.createFromConfig({
@@ -56,6 +55,33 @@ const SQUARE_SCRIPT = defineScript({
5655
transformReply: undefined as unknown as () => NumberReply
5756
});
5857

58+
export const MATH_FUNCTION = {
59+
name: 'math',
60+
engine: 'LUA',
61+
code:
62+
`#!LUA name=math
63+
redis.register_function {
64+
function_name = "square",
65+
callback = function(keys, args)
66+
local number = redis.call('GET', keys[1])
67+
return number * number
68+
end,
69+
flags = { "no-writes" }
70+
}`,
71+
library: {
72+
square: {
73+
NAME: 'square',
74+
IS_READ_ONLY: true,
75+
NUMBER_OF_KEYS: 1,
76+
FIRST_KEY_INDEX: 0,
77+
parseCommand(parser: CommandParser, key: string) {
78+
parser.pushKey(key);
79+
},
80+
transformReply: undefined as unknown as () => NumberReply
81+
}
82+
}
83+
};
84+
5985
export const GLOBAL = {
6086
SERVERS: {
6187
OPEN: {
@@ -122,7 +148,7 @@ export const GLOBAL = {
122148
password: undefined,
123149
functions: {
124150
math: MATH_FUNCTION.library,
125-
}
151+
},
126152
},
127153
WITH_MODULE: {
128154
serverArguments: [...DEBUG_MODE_ARGS],

0 commit comments

Comments
 (0)