Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion redisinsight/api/src/modules/cli/dto/cli.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class SendCommandDto {

@ApiPropertyOptional({
description: 'Define output format',
default: CliOutputFormatterTypes.Text,
default: CliOutputFormatterTypes.Raw,
enum: CliOutputFormatterTypes,
})
@IsOptional()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const mockENotFoundMessage = 'ENOTFOUND some message';
const mockMemoryUsageCommand = 'memory usage key';
const mockGetEscapedKeyCommand = 'get "\\\\key';
const mockServerInfoCommand = 'info server';
const mockIntegerResponse = '(integer) 5';
const mockIntegerResponse = 5;

describe('CliBusinessService', () => {
let service: CliBusinessService;
Expand Down Expand Up @@ -197,9 +197,9 @@ describe('CliBusinessService', () => {
});

describe('sendCommand', () => {
it('should successfully execute command and return text response', async () => {
it('should successfully execute command (RAW format)', async () => {
const dto: SendCommandDto = { command: mockMemoryUsageCommand };
const formatSpy = jest.spyOn(textFormatter, 'format');
const formatSpy = jest.spyOn(rawFormatter, 'format');
const mockResult: SendCommandResponse = {
response: mockIntegerResponse,
status: CommandExecutionStatus.Success,
Expand Down Expand Up @@ -551,7 +551,38 @@ describe('CliBusinessService', () => {
);
});

it('should successfully execute command for single node with redirection', async () => {
it('should successfully execute command for single node with redirection (RAW format)', async () => {
const command = 'set foo bar';
const mockResult: SendClusterCommandResponse = {
response: 'OK',
node: { ...mockNode, port: 7002 },
status: CommandExecutionStatus.Success,
};
cliTool.execCommandForNode
.mockResolvedValueOnce({
response: mockRedisMovedError.message,
error: mockRedisMovedError,
status: CommandExecutionStatus.Fail,
})
.mockResolvedValueOnce({
response: 'OK',
host: '127.0.0.1',
port: 7002,
status: CommandExecutionStatus.Success,
});

const result = await service.sendCommandForSingleNode(
mockClientOptions,
command,
ClusterNodeRole.All,
nodeOptions,
CliOutputFormatterTypes.Raw,
);

expect(cliTool.execCommandForNode).toHaveBeenCalledTimes(2);
expect(result).toEqual(mockResult);
});
it('should successfully execute command for single node with redirection (Text format)', async () => {
const command = 'set foo bar';
const mockResult: SendClusterCommandResponse = {
response: '-> Redirected to slot [7008] located at 127.0.0.1:7002\nOK',
Expand All @@ -576,6 +607,7 @@ describe('CliBusinessService', () => {
command,
ClusterNodeRole.All,
nodeOptions,
CliOutputFormatterTypes.Text,
);

expect(cliTool.execCommandForNode).toHaveBeenCalledTimes(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export class CliBusinessService {
this.logger.log('Executing redis CLI command.');
const { command: commandLine } = dto;
let namespace = AppTool.CLI.toString();
const outputFormat = dto.outputFormat || CliOutputFormatterTypes.Text;
const outputFormat = dto.outputFormat || CliOutputFormatterTypes.Raw;
try {
const formatter = this.outputFormatterManager.getStrategy(outputFormat);
const [command, ...args] = splitCliCommandLine(commandLine);
Expand Down Expand Up @@ -216,7 +216,7 @@ export class CliBusinessService {
clientOptions: IFindRedisClientInstanceByOptions,
commandLine: string,
role: ClusterNodeRole,
outputFormat: CliOutputFormatterTypes = CliOutputFormatterTypes.Text,
outputFormat: CliOutputFormatterTypes = CliOutputFormatterTypes.Raw,
): Promise<SendClusterCommandResponse[]> {
let namespace = AppTool.CLI.toString();
this.logger.log(`Executing redis.cluster CLI command for [${role}] nodes.`);
Expand Down Expand Up @@ -278,7 +278,7 @@ export class CliBusinessService {
commandLine: string,
role: ClusterNodeRole,
nodeOptions: ClusterSingleNodeOptions,
outputFormat: CliOutputFormatterTypes = CliOutputFormatterTypes.Text,
outputFormat: CliOutputFormatterTypes = CliOutputFormatterTypes.Raw,
): Promise<SendClusterCommandResponse> {
this.logger.log(`Executing redis.cluster CLI command for single node ${JSON.stringify(nodeOptions)}`);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class TestFormatterStrategy implements IOutputFormatterStrategy {
return '';
}
}
const strategyName = CliOutputFormatterTypes.Text;
const strategyName = CliOutputFormatterTypes.Raw;
const testStrategy = new TestFormatterStrategy();

describe('OutputFormatterManager', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ describe('POST /instance/:instanceId/cli/:uuid/send-cluster-command', () => {
name: 'Should create string',
data: {
command: `set ${constants.TEST_STRING_KEY_1} ${constants.TEST_STRING_VALUE_1}`,
outputFormat: 'TEXT',
role: 'ALL',
},
responseSchema,
Expand All @@ -99,6 +100,7 @@ describe('POST /instance/:instanceId/cli/:uuid/send-cluster-command', () => {
name: 'Should get string',
data: {
command: `get ${constants.TEST_STRING_KEY_1}`,
outputFormat: 'TEXT',
role: 'ALL',
},
responseSchema,
Expand All @@ -111,6 +113,7 @@ describe('POST /instance/:instanceId/cli/:uuid/send-cluster-command', () => {
name: 'Should remove string',
data: {
command: `del ${constants.TEST_STRING_KEY_1}`,
outputFormat: 'TEXT',
role: 'ALL',
},
responseSchema,
Expand All @@ -134,6 +137,7 @@ describe('POST /instance/:instanceId/cli/:uuid/send-cluster-command', () => {
name: 'Should create string',
data: {
command: `set ${constants.TEST_STRING_KEY_1} ${constants.TEST_STRING_VALUE_1}`,
outputFormat: 'TEXT',
role: 'ALL',
nodeOptions
},
Expand All @@ -152,6 +156,7 @@ describe('POST /instance/:instanceId/cli/:uuid/send-cluster-command', () => {
name: 'Should get string',
data: {
command: `get ${constants.TEST_STRING_KEY_1}`,
outputFormat: 'TEXT',
role: 'ALL',
nodeOptions
},
Expand All @@ -165,6 +170,7 @@ describe('POST /instance/:instanceId/cli/:uuid/send-cluster-command', () => {
name: 'Should remove string',
data: {
command: `del ${constants.TEST_STRING_KEY_1}`,
outputFormat: 'TEXT',
role: 'ALL',
nodeOptions
},
Expand Down Expand Up @@ -259,6 +265,7 @@ describe('POST /instance/:instanceId/cli/:uuid/send-cluster-command', () => {
name: `Should create string with redirection if needed (${node.host}:${node.port})`,
data: {
command: `set ${constants.TEST_STRING_KEY_1} ${node.host}`,
outputFormat: 'TEXT',
role: 'ALL',
nodeOptions: {
host: node.host,
Expand Down
Loading