Skip to content

Commit 36e82ef

Browse files
Merge pull request #117 from RedisInsight/main
a new release candidate
2 parents 32af41b + 19e7664 commit 36e82ef

File tree

197 files changed

+4450
-1814
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

197 files changed

+4450
-1814
lines changed

package.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,12 @@
7575
"\\.(jpg|jpeg|png|ico|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/redisinsight/__mocks__/fileMock.js",
7676
"\\.(css|less|sass|scss)$": "identity-obj-proxy",
7777
"uiSrc/(.*)": "<rootDir>/redisinsight/ui/src/$1",
78-
"monaco-editor": "<rootDir>/redisinsight/__mocks__/monacoMock.js"
78+
"monaco-editor": "<rootDir>/redisinsight/__mocks__/monacoMock.js",
79+
"unified": "<rootDir>/redisinsight/__mocks__/unified.js",
80+
"remark-parse": "<rootDir>/redisinsight/__mocks__/remarkParse.js",
81+
"remark-rehype": "<rootDir>/redisinsight/__mocks__/remarkRehype.js",
82+
"rehype-stringify": "<rootDir>/redisinsight/__mocks__/rehypeStringify.js",
83+
"unist-util-visit": "<rootDir>/redisinsight/__mocks__/unistUtilsVisit.js"
7984
},
8085
"setupFilesAfterEnv": [
8186
"<rootDir>/redisinsight/ui/src/setup-tests.ts"
@@ -243,7 +248,12 @@
243248
"react-redux": "^7.2.2",
244249
"react-jsx-parser": "^1.28.4",
245250
"react-router-dom": "^5.2.0",
246-
"react-virtualized": "^9.22.2"
251+
"react-virtualized": "^9.22.2",
252+
"remark-parse": "^10.0.1",
253+
"remark-rehype": "^10.0.1",
254+
"rehype-stringify": "^9.0.2",
255+
"unified": "^10.1.1",
256+
"unist-util-visit": "^4.1.0"
247257
},
248258
"devEngines": {
249259
"node": ">=14.x <16",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default jest.fn()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default jest.fn()

redisinsight/__mocks__/remarkRehype.js

Whitespace-only changes.

redisinsight/__mocks__/unified.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const unified = jest.fn()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const visit = jest.fn();

redisinsight/api/src/modules/cli/dto/cli.dto.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ export enum ClusterNodeRole {
2727
Slave = 'SLAVE',
2828
}
2929

30+
class ClusterNode extends EndpointDto {
31+
@ApiPropertyOptional({
32+
description: 'Cluster node slot.',
33+
type: Number,
34+
example: 0,
35+
})
36+
slot?: number;
37+
}
38+
3039
export class CreateCliClientDto {
3140
@ApiPropertyOptional({
3241
type: String,
@@ -51,7 +60,7 @@ export class SendCommandDto {
5160

5261
@ApiPropertyOptional({
5362
description: 'Define output format',
54-
default: CliOutputFormatterTypes.Text,
63+
default: CliOutputFormatterTypes.Raw,
5564
enum: CliOutputFormatterTypes,
5665
})
5766
@IsOptional()
@@ -123,10 +132,10 @@ export class SendClusterCommandResponse {
123132
response: any;
124133

125134
@ApiPropertyOptional({
126-
type: () => EndpointDto,
135+
type: () => ClusterNode,
127136
description: 'Redis Cluster Node info',
128137
})
129-
node?: EndpointDto;
138+
node?: ClusterNode;
130139

131140
@ApiProperty({
132141
description: 'Redis CLI command execution status',

redisinsight/api/src/modules/cli/services/cli-business/cli-business.service.spec.ts

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const mockENotFoundMessage = 'ENOTFOUND some message';
5555
const mockMemoryUsageCommand = 'memory usage key';
5656
const mockGetEscapedKeyCommand = 'get "\\\\key';
5757
const mockServerInfoCommand = 'info server';
58-
const mockIntegerResponse = '(integer) 5';
58+
const mockIntegerResponse = 5;
5959

6060
describe('CliBusinessService', () => {
6161
let service: CliBusinessService;
@@ -197,9 +197,9 @@ describe('CliBusinessService', () => {
197197
});
198198

199199
describe('sendCommand', () => {
200-
it('should successfully execute command and return text response', async () => {
200+
it('should successfully execute command (RAW format)', async () => {
201201
const dto: SendCommandDto = { command: mockMemoryUsageCommand };
202-
const formatSpy = jest.spyOn(textFormatter, 'format');
202+
const formatSpy = jest.spyOn(rawFormatter, 'format');
203203
const mockResult: SendCommandResponse = {
204204
response: mockIntegerResponse,
205205
status: CommandExecutionStatus.Success,
@@ -551,11 +551,42 @@ describe('CliBusinessService', () => {
551551
);
552552
});
553553

554-
it('should successfully execute command for single node with redirection', async () => {
554+
it('should successfully execute command for single node with redirection (RAW format)', async () => {
555+
const command = 'set foo bar';
556+
const mockResult: SendClusterCommandResponse = {
557+
response: 'OK',
558+
node: { ...mockNode, port: 7002, slot: 7008 },
559+
status: CommandExecutionStatus.Success,
560+
};
561+
cliTool.execCommandForNode
562+
.mockResolvedValueOnce({
563+
response: mockRedisMovedError.message,
564+
error: mockRedisMovedError,
565+
status: CommandExecutionStatus.Fail,
566+
})
567+
.mockResolvedValueOnce({
568+
response: 'OK',
569+
host: '127.0.0.1',
570+
port: 7002,
571+
status: CommandExecutionStatus.Success,
572+
});
573+
574+
const result = await service.sendCommandForSingleNode(
575+
mockClientOptions,
576+
command,
577+
ClusterNodeRole.All,
578+
nodeOptions,
579+
CliOutputFormatterTypes.Raw,
580+
);
581+
582+
expect(cliTool.execCommandForNode).toHaveBeenCalledTimes(2);
583+
expect(result).toEqual(mockResult);
584+
});
585+
it('should successfully execute command for single node with redirection (Text format)', async () => {
555586
const command = 'set foo bar';
556587
const mockResult: SendClusterCommandResponse = {
557588
response: '-> Redirected to slot [7008] located at 127.0.0.1:7002\nOK',
558-
node: { ...mockNode, port: 7002 },
589+
node: { ...mockNode, port: 7002, slot: 7008 },
559590
status: CommandExecutionStatus.Success,
560591
};
561592
cliTool.execCommandForNode
@@ -576,6 +607,7 @@ describe('CliBusinessService', () => {
576607
command,
577608
ClusterNodeRole.All,
578609
nodeOptions,
610+
CliOutputFormatterTypes.Text,
579611
);
580612

581613
expect(cliTool.execCommandForNode).toHaveBeenCalledTimes(2);

redisinsight/api/src/modules/cli/services/cli-business/cli-business.service.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ export class CliBusinessService {
142142
this.logger.log('Executing redis CLI command.');
143143
const { command: commandLine } = dto;
144144
let namespace = AppTool.CLI.toString();
145-
const outputFormat = dto.outputFormat || CliOutputFormatterTypes.Text;
145+
const outputFormat = dto.outputFormat || CliOutputFormatterTypes.Raw;
146146
try {
147147
const formatter = this.outputFormatterManager.getStrategy(outputFormat);
148148
const [command, ...args] = splitCliCommandLine(commandLine);
@@ -216,7 +216,7 @@ export class CliBusinessService {
216216
clientOptions: IFindRedisClientInstanceByOptions,
217217
commandLine: string,
218218
role: ClusterNodeRole,
219-
outputFormat: CliOutputFormatterTypes = CliOutputFormatterTypes.Text,
219+
outputFormat: CliOutputFormatterTypes = CliOutputFormatterTypes.Raw,
220220
): Promise<SendClusterCommandResponse[]> {
221221
let namespace = AppTool.CLI.toString();
222222
this.logger.log(`Executing redis.cluster CLI command for [${role}] nodes.`);
@@ -278,7 +278,7 @@ export class CliBusinessService {
278278
commandLine: string,
279279
role: ClusterNodeRole,
280280
nodeOptions: ClusterSingleNodeOptions,
281-
outputFormat: CliOutputFormatterTypes = CliOutputFormatterTypes.Text,
281+
outputFormat: CliOutputFormatterTypes = CliOutputFormatterTypes.Raw,
282282
): Promise<SendClusterCommandResponse> {
283283
this.logger.log(`Executing redis.cluster CLI command for single node ${JSON.stringify(nodeOptions)}`);
284284
try {
@@ -306,6 +306,7 @@ export class CliBusinessService {
306306
replyEncoding,
307307
);
308308
result.response = formatter.format(result.response, { slot, address });
309+
result.slot = parseInt(slot, 10);
309310
} else {
310311
result.response = formatter.format(result.response);
311312
}
@@ -316,9 +317,9 @@ export class CliBusinessService {
316317
{ command, outputFormat },
317318
);
318319
const {
319-
host, port, error, ...rest
320+
host, port, error, slot, ...rest
320321
} = result;
321-
return { ...rest, node: { host, port } };
322+
return { ...rest, node: { host, port, slot } };
322323
} catch (error) {
323324
this.logger.error('Failed to execute redis.cluster CLI command.', error);
324325

redisinsight/api/src/modules/cli/services/cli-business/output-formatter/output-formatter-manager.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class TestFormatterStrategy implements IOutputFormatterStrategy {
1111
return '';
1212
}
1313
}
14-
const strategyName = CliOutputFormatterTypes.Text;
14+
const strategyName = CliOutputFormatterTypes.Raw;
1515
const testStrategy = new TestFormatterStrategy();
1616

1717
describe('OutputFormatterManager', () => {

0 commit comments

Comments
 (0)