Skip to content

Commit 4f52f5b

Browse files
Merge pull request #86 from RedisInsight/feature/RI_1697_Send_requst_between_switch_visualizations
#RI-1697
2 parents cadd93d + 69ee489 commit 4f52f5b

File tree

28 files changed

+279
-102
lines changed

28 files changed

+279
-102
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class SendCommandDto {
5151

5252
@ApiPropertyOptional({
5353
description: 'Define output format',
54-
default: CliOutputFormatterTypes.Text,
54+
default: CliOutputFormatterTypes.Raw,
5555
enum: CliOutputFormatterTypes,
5656
})
5757
@IsOptional()

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

Lines changed: 36 additions & 4 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,7 +551,38 @@ 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 },
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',
@@ -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: 3 additions & 3 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 {

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', () => {

redisinsight/api/test/api/cli/POST-instance-id-cli-uuid-send_cluster_command.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ describe('POST /instance/:instanceId/cli/:uuid/send-cluster-command', () => {
8585
name: 'Should create string',
8686
data: {
8787
command: `set ${constants.TEST_STRING_KEY_1} ${constants.TEST_STRING_VALUE_1}`,
88+
outputFormat: 'TEXT',
8889
role: 'ALL',
8990
},
9091
responseSchema,
@@ -99,6 +100,7 @@ describe('POST /instance/:instanceId/cli/:uuid/send-cluster-command', () => {
99100
name: 'Should get string',
100101
data: {
101102
command: `get ${constants.TEST_STRING_KEY_1}`,
103+
outputFormat: 'TEXT',
102104
role: 'ALL',
103105
},
104106
responseSchema,
@@ -111,6 +113,7 @@ describe('POST /instance/:instanceId/cli/:uuid/send-cluster-command', () => {
111113
name: 'Should remove string',
112114
data: {
113115
command: `del ${constants.TEST_STRING_KEY_1}`,
116+
outputFormat: 'TEXT',
114117
role: 'ALL',
115118
},
116119
responseSchema,
@@ -134,6 +137,7 @@ describe('POST /instance/:instanceId/cli/:uuid/send-cluster-command', () => {
134137
name: 'Should create string',
135138
data: {
136139
command: `set ${constants.TEST_STRING_KEY_1} ${constants.TEST_STRING_VALUE_1}`,
140+
outputFormat: 'TEXT',
137141
role: 'ALL',
138142
nodeOptions
139143
},
@@ -152,6 +156,7 @@ describe('POST /instance/:instanceId/cli/:uuid/send-cluster-command', () => {
152156
name: 'Should get string',
153157
data: {
154158
command: `get ${constants.TEST_STRING_KEY_1}`,
159+
outputFormat: 'TEXT',
155160
role: 'ALL',
156161
nodeOptions
157162
},
@@ -165,6 +170,7 @@ describe('POST /instance/:instanceId/cli/:uuid/send-cluster-command', () => {
165170
name: 'Should remove string',
166171
data: {
167172
command: `del ${constants.TEST_STRING_KEY_1}`,
173+
outputFormat: 'TEXT',
168174
role: 'ALL',
169175
nodeOptions
170176
},
@@ -259,6 +265,7 @@ describe('POST /instance/:instanceId/cli/:uuid/send-cluster-command', () => {
259265
name: `Should create string with redirection if needed (${node.host}:${node.port})`,
260266
data: {
261267
command: `set ${constants.TEST_STRING_KEY_1} ${node.host}`,
268+
outputFormat: 'TEXT',
262269
role: 'ALL',
263270
nodeOptions: {
264271
host: node.host,

0 commit comments

Comments
 (0)