You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-17 19:41:06 +03:00
fix tests
This commit is contained in:
@@ -44,17 +44,17 @@ export function transformReply(rawReply: Array<any>): XInfoStreamReply {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'first-entry':
|
case 'first-entry':
|
||||||
parsedReply.firstEntry = {
|
parsedReply.firstEntry = rawReply[i + 1] ? {
|
||||||
id: rawReply[i + 1][0],
|
id: rawReply[i + 1][0],
|
||||||
message: transformReplyTuples(rawReply[i + 1][1])
|
message: transformReplyTuples(rawReply[i + 1][1])
|
||||||
};
|
} : null;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'last-entry':
|
case 'last-entry':
|
||||||
parsedReply.lastEntry = {
|
parsedReply.lastEntry = rawReply[i + 1] ? {
|
||||||
id: rawReply[i + 1][0],
|
id: rawReply[i + 1][0],
|
||||||
message: transformReplyTuples(rawReply[i + 1][1])
|
message: transformReplyTuples(rawReply[i + 1][1])
|
||||||
};
|
} : null;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -14,24 +14,37 @@ import { Context as MochaContext } from 'mocha';
|
|||||||
|
|
||||||
type RedisVersion = [major: number, minor: number, patch: number];
|
type RedisVersion = [major: number, minor: number, patch: number];
|
||||||
|
|
||||||
type PartialRedisVersion = RedisVersion | [major: number, minor: number] | [major: number] | undefined;
|
type PartialRedisVersion = RedisVersion | [major: number, minor: number] | [major: number];
|
||||||
|
|
||||||
const REDIS_VERSION = execSync('redis-server -v')
|
const REDIS_PATH = which.sync('redis-server'),
|
||||||
.toString()
|
REDIS_VERSION = getRedisVersion();
|
||||||
.split('.', 3)
|
|
||||||
.map(Number) as RedisVersion;
|
|
||||||
|
|
||||||
export function isRedisVersionGreaterThan(minimumVersion: PartialRedisVersion): boolean {
|
function getRedisVersion(): RedisVersion {
|
||||||
|
const raw = execSync(`${REDIS_PATH} -v`).toString(),
|
||||||
|
indexOfVersion = raw.indexOf('v=');
|
||||||
|
|
||||||
|
if (indexOfVersion === -1) {
|
||||||
|
throw new Error('Unknown redis version');
|
||||||
|
}
|
||||||
|
|
||||||
|
const start = indexOfVersion + 2;
|
||||||
|
return raw.substring(
|
||||||
|
start,
|
||||||
|
raw.indexOf(' ', start)
|
||||||
|
).split('.', 3).map(Number) as RedisVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isRedisVersionGreaterThan(minimumVersion: PartialRedisVersion | undefined): boolean {
|
||||||
if (minimumVersion === undefined) return true;
|
if (minimumVersion === undefined) return true;
|
||||||
|
|
||||||
const lastIndex = minimumVersion.length - 1;
|
const lastIndex = minimumVersion.length - 1;
|
||||||
for (let i = 0; i < lastIndex; i++) {
|
for (let i = 0; i < lastIndex; i++) {
|
||||||
if (minimumVersion[i] > REDIS_VERSION[i]) {
|
if (REDIS_VERSION[i] > minimumVersion[i]) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return minimumVersion[lastIndex] >= REDIS_VERSION[lastIndex];
|
return REDIS_VERSION[lastIndex] >= minimumVersion[lastIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum TestRedisServers {
|
export enum TestRedisServers {
|
||||||
@@ -47,9 +60,6 @@ export enum TestRedisClusters {
|
|||||||
|
|
||||||
export const TEST_REDIS_CLUSTERES: Record<TestRedisClusters, Array<RedisSocketOptions>> = <any>{};
|
export const TEST_REDIS_CLUSTERES: Record<TestRedisClusters, Array<RedisSocketOptions>> = <any>{};
|
||||||
|
|
||||||
|
|
||||||
const REDIS_PATH = which.sync('redis-server');
|
|
||||||
|
|
||||||
let port = 6379;
|
let port = 6379;
|
||||||
|
|
||||||
interface SpawnRedisServerResult {
|
interface SpawnRedisServerResult {
|
||||||
@@ -219,6 +229,10 @@ async function spawnPasswordServer(): Promise<void> {
|
|||||||
port: await spawnGlobalRedisServer(['--requirepass', 'password']),
|
port: await spawnGlobalRedisServer(['--requirepass', 'password']),
|
||||||
password: 'password'
|
password: 'password'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (isRedisVersionGreaterThan([6])) {
|
||||||
|
TEST_REDIS_SERVERS[TestRedisServers.PASSWORD].username = 'default';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function spawnOpenCluster(): Promise<void> {
|
async function spawnOpenCluster(): Promise<void> {
|
||||||
@@ -241,18 +255,18 @@ interface RedisTestOptions {
|
|||||||
minimumRedisVersion?: PartialRedisVersion;
|
minimumRedisVersion?: PartialRedisVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function handleMinimumRedisVersion(mochaContext: MochaContext, minimumRedisVersion: PartialRedisVersion): boolean {
|
export function handleMinimumRedisVersion(mochaContext: MochaContext, minimumVersion: PartialRedisVersion | undefined): boolean {
|
||||||
if (isRedisVersionGreaterThan(minimumRedisVersion)) {
|
if (isRedisVersionGreaterThan(minimumVersion)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
mochaContext.skip();
|
mochaContext.skip();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
export function describeHandleMinimumRedisVersion(minimumVersion: PartialRedisVersion): void {
|
||||||
}
|
|
||||||
|
|
||||||
export function describeHandleMinimumRedisVersion(minimumRedisVersion: PartialRedisVersion): void {
|
|
||||||
before(function () {
|
before(function () {
|
||||||
handleMinimumRedisVersion(this, minimumRedisVersion);
|
handleMinimumRedisVersion(this, minimumVersion);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -263,7 +277,7 @@ export function itWithClient(
|
|||||||
options?: RedisTestOptions
|
options?: RedisTestOptions
|
||||||
): void {
|
): void {
|
||||||
it(title, async function () {
|
it(title, async function () {
|
||||||
handleMinimumRedisVersion(this, options?.minimumRedisVersion);
|
if (handleMinimumRedisVersion(this, options?.minimumRedisVersion)) return;
|
||||||
|
|
||||||
const client = RedisClient.create({
|
const client = RedisClient.create({
|
||||||
socket: TEST_REDIS_SERVERS[type]
|
socket: TEST_REDIS_SERVERS[type]
|
||||||
@@ -288,7 +302,7 @@ export function itWithCluster(
|
|||||||
options?: RedisTestOptions
|
options?: RedisTestOptions
|
||||||
): void {
|
): void {
|
||||||
it(title, async function () {
|
it(title, async function () {
|
||||||
handleMinimumRedisVersion(this, options?.minimumRedisVersion);
|
if (handleMinimumRedisVersion(this, options?.minimumRedisVersion)) return;
|
||||||
|
|
||||||
const cluster = RedisCluster.create({
|
const cluster = RedisCluster.create({
|
||||||
rootNodes: TEST_REDIS_CLUSTERES[type]
|
rootNodes: TEST_REDIS_CLUSTERES[type]
|
||||||
|
Reference in New Issue
Block a user