Skip to content

Commit 5f04d04

Browse files
committed
Merge branch 'main' into e2e/feature/RI-3483_highlight-big-keys
2 parents d7c4852 + a25fb03 commit 5f04d04

File tree

103 files changed

+2685
-1469
lines changed

Some content is hidden

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

103 files changed

+2685
-1469
lines changed

.circleci/config.yml

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -877,30 +877,29 @@ workflows:
877877
jobs:
878878
- unit-tests-ui:
879879
name: UTest - UI
880-
# filters:
881-
# branches:
882-
# only:
883-
# - /^fe/feature.*/
884-
# - /^fe/bugfix.*/
880+
filters:
881+
branches:
882+
only:
883+
- /^fe/feature.*/
884+
- /^fe/bugfix.*/
885885
# BE Unit + Integration (limited RTEs) tests for "be/feature" or "be/bugfix" branches only
886886
backend-tests:
887887
jobs:
888888
- unit-tests-api:
889889
name: UTest - API
890-
# filters:
891-
# branches:
892-
# only:
893-
# - /^be/feature.*/
894-
# - /^be/bugfix.*/
890+
filters:
891+
branches:
892+
only:
893+
- /^be/feature.*/
894+
- /^be/bugfix.*/
895895
- integration-tests-run:
896896
matrix:
897897
alias: itest-code
898898
parameters:
899-
rte: *iTestsNames
900-
# rte: *iTestsNamesShort
899+
rte: *iTestsNamesShort
901900
name: ITest - << matrix.rte >> (code)
902-
# requires:
903-
# - UTest - API
901+
requires:
902+
- UTest - API
904903
# E2E tests for "e2e/feature" or "e2e/bugfix" branches only
905904
e2e-tests:
906905
jobs:

redisinsight/api/src/__mocks__/certificates.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ export const mockCaCertificateRepository = jest.fn(() => ({
4141
}));
4242

4343
export const mockCaCertificateService = jest.fn(() => ({
44-
getAll: jest.fn(),
45-
getOneById: jest.fn(),
44+
get: jest.fn().mockResolvedValue(mockCaCertificate),
4645
}));
4746

4847
// ================== Client Certificate ==================
@@ -85,6 +84,5 @@ export const mockClientCertificateRepository = jest.fn(() => ({
8584
}));
8685

8786
export const mockClientCertificateService = jest.fn(() => ({
88-
getAll: jest.fn(),
89-
getOneById: jest.fn(),
87+
get: jest.fn().mockResolvedValue(mockClientCertificate),
9088
}));

redisinsight/api/src/__mocks__/databases.ts

Lines changed: 105 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import { Database } from 'src/modules/database/models/database';
2-
import {
3-
mockCaCertificate,
4-
mockClientCertificate,
5-
} from 'src/__mocks__/certificates';
2+
import { mockCaCertificate, mockClientCertificate } from 'src/__mocks__/certificates';
63
import { SentinelMaster } from 'src/modules/redis-sentinel/models/sentinel-master';
74
import { ConnectionType, DatabaseEntity } from 'src/modules/database/entities/database.entity';
85
import { EncryptionStrategy } from 'src/modules/encryption/models';
96
import { mockIORedisClient } from 'src/__mocks__/redis';
7+
import { mockSentinelMasterDto } from 'src/__mocks__/redis-sentinel';
8+
import { pick } from 'lodash';
9+
import { RedisDatabaseInfoResponse } from 'src/modules/database/dto/redis-info.dto';
10+
import { ClientMetadata } from 'src/modules/redis/models/client-metadata';
11+
import { AppTool } from 'src/models';
12+
import { DatabaseOverview } from 'src/modules/database/models/database-overview';
1013

1114
export const mockDatabaseId = 'a77b23c1-7816-4ea4-b61f-d37795a0f805-db-id';
1215

@@ -21,8 +24,8 @@ export const mockDatabaseSentinelMasterPasswordPlain = 'some sentinel pass';
2124
export const mockDatabase = Object.assign(new Database(), {
2225
id: mockDatabaseId,
2326
name: 'database-name',
24-
host: 'localhost',
25-
port: 3679,
27+
host: '127.0.100.1',
28+
port: 6379,
2629
connectionType: ConnectionType.STANDALONE,
2730
});
2831

@@ -69,7 +72,7 @@ export const mockDatabaseWithTlsAuthEntity = Object.assign(new DatabaseEntity(),
6972
});
7073

7174
export const mockSentinelMaster = Object.assign(new SentinelMaster(), {
72-
name: 'master_group_name',
75+
name: 'mymaster',
7376
username: 'master_group_username',
7477
password: mockDatabaseSentinelMasterPasswordPlain,
7578
});
@@ -78,6 +81,7 @@ export const mockSentinelDatabaseWithTlsAuth = Object.assign(new Database(), {
7881
...mockDatabaseWithTlsAuth,
7982
sentinelMaster: mockSentinelMaster,
8083
connectionType: ConnectionType.SENTINEL,
84+
nodes: mockSentinelMasterDto.nodes,
8185
});
8286

8387
export const mockSentinelDatabaseWithTlsAuthEntity = Object.assign(new DatabaseEntity(), {
@@ -86,18 +90,83 @@ export const mockSentinelDatabaseWithTlsAuthEntity = Object.assign(new DatabaseE
8690
sentinelMasterUsername: mockSentinelMaster.username,
8791
sentinelMasterPassword: mockDatabaseSentinelMasterPasswordEncrypted,
8892
connectionType: ConnectionType.SENTINEL,
93+
nodes: JSON.stringify(mockSentinelDatabaseWithTlsAuth.nodes),
8994
});
95+
export const mockClusterNodes = [
96+
{
97+
host: '127.0.100.1',
98+
port: 6379,
99+
},
100+
{
101+
host: '127.0.100.2',
102+
port: 6379,
103+
},
104+
];
90105

91106
export const mockClusterDatabaseWithTlsAuth = Object.assign(new Database(), {
92107
...mockDatabaseWithTlsAuth,
93108
connectionType: ConnectionType.CLUSTER,
109+
nodes: mockClusterNodes,
94110
});
95111

96112
export const mockClusterDatabaseWithTlsAuthEntity = Object.assign(new DatabaseEntity(), {
97113
...mockDatabaseWithTlsAuthEntity,
98114
connectionType: ConnectionType.CLUSTER,
115+
nodes: JSON.stringify(mockClusterNodes),
99116
});
100117

118+
export const mockClientMetadata: ClientMetadata = {
119+
databaseId: mockDatabase.id,
120+
namespace: AppTool.Common,
121+
};
122+
123+
export const mockDatabaseOverview: DatabaseOverview = {
124+
version: '6.2.4',
125+
usedMemory: 1,
126+
totalKeys: 2,
127+
totalKeysPerDb: {
128+
db0: 1,
129+
},
130+
connectedClients: 1,
131+
opsPerSecond: 1,
132+
networkInKbps: 1,
133+
networkOutKbps: 1,
134+
cpuUsagePercentage: null,
135+
};
136+
137+
export const mockRedisServerInfoDto = {
138+
redis_version: '6.0.5',
139+
redis_mode: 'standalone',
140+
os: 'Linux 4.15.0-1087-gcp x86_64',
141+
arch_bits: '64',
142+
tcp_port: '11113',
143+
uptime_in_seconds: '1000',
144+
};
145+
146+
export const mockRedisGeneralInfo: RedisDatabaseInfoResponse = {
147+
version: mockRedisServerInfoDto.redis_version,
148+
databases: 16,
149+
role: 'master',
150+
server: mockRedisServerInfoDto,
151+
usedMemory: 1000000,
152+
totalKeys: 1,
153+
connectedClients: 1,
154+
uptimeInSeconds: 1000,
155+
hitRatio: 1,
156+
};
157+
158+
export const mockDatabaseRepository = jest.fn(() => ({
159+
exists: jest.fn().mockResolvedValue(true),
160+
get: jest.fn().mockResolvedValue(mockDatabase),
161+
create: jest.fn().mockResolvedValue(mockDatabase),
162+
update: jest.fn().mockResolvedValue(mockDatabase),
163+
delete: jest.fn(),
164+
list: jest.fn().mockResolvedValue([
165+
pick(mockDatabase, 'id', 'name'),
166+
pick(mockDatabase, 'id', 'name'),
167+
]),
168+
}));
169+
101170
export const mockDatabaseService = jest.fn(() => ({
102171
get: jest.fn().mockResolvedValue(mockDatabase),
103172
create: jest.fn().mockResolvedValue(mockDatabase),
@@ -107,3 +176,32 @@ export const mockDatabaseService = jest.fn(() => ({
107176
export const mockDatabaseConnectionService = jest.fn(() => ({
108177
getOrCreateClient: jest.fn().mockResolvedValue(mockIORedisClient),
109178
}));
179+
180+
export const mockDatabaseInfoProvider = jest.fn(() => ({
181+
isCluster: jest.fn(),
182+
isSentinel: jest.fn(),
183+
determineDatabaseModules: jest.fn(),
184+
determineSentinelMasterGroups: jest.fn().mockReturnValue([mockSentinelMasterDto]),
185+
determineClusterNodes: jest.fn().mockResolvedValue(mockClusterNodes),
186+
getRedisGeneralInfo: jest.fn().mockResolvedValueOnce(mockRedisGeneralInfo),
187+
}));
188+
189+
export const mockDatabaseOverviewProvider = jest.fn(() => ({
190+
getOverview: jest.fn().mockResolvedValue(mockDatabaseOverview),
191+
}));
192+
193+
export const mockDatabaseFactory = jest.fn(() => ({
194+
createDatabaseModel: jest.fn().mockResolvedValue(mockDatabase),
195+
createStandaloneDatabaseModel: jest.fn().mockResolvedValue(mockDatabase),
196+
createClusterDatabaseModel: jest.fn().mockResolvedValue(mockClusterDatabaseWithTlsAuth),
197+
createSentinelDatabaseModel: jest.fn().mockResolvedValue(mockSentinelDatabaseWithTlsAuth),
198+
}));
199+
200+
export const mockDatabaseAnalytics = jest.fn(() => ({
201+
sendInstanceListReceivedEvent: jest.fn(),
202+
sendConnectionFailedEvent: jest.fn(),
203+
sendInstanceAddedEvent: jest.fn(),
204+
sendInstanceAddFailedEvent: jest.fn(),
205+
sendInstanceEditedEvent: jest.fn(),
206+
sendInstanceDeletedEvent: jest.fn(),
207+
}));

redisinsight/api/src/__mocks__/errors.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import { ReplyError } from 'src/models';
22

3+
export const mockRedisNoAuthError: ReplyError = {
4+
name: 'ReplyError',
5+
command: 'AUTH',
6+
message: 'NOAUTH authentication is required',
7+
};
8+
39
export const mockRedisNoPermError: ReplyError = {
410
name: 'ReplyError',
511
command: 'GET',

redisinsight/api/src/__mocks__/redis-sentinel.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
import { SentinelMaster, SentinelMasterStatus } from 'src/modules/redis-sentinel/models/sentinel-master';
2+
import { Endpoint } from 'src/common/models';
23

3-
export const mockSentinelMasterDto: SentinelMaster = {
4-
name: 'mymaster',
4+
export const mockSentinelMasterEndpoint: Endpoint = {
55
host: '127.0.0.1',
66
port: 6379,
7+
};
8+
9+
export const mockSentinelMasterDto: SentinelMaster = {
10+
name: 'mymaster',
11+
host: mockSentinelMasterEndpoint.host,
12+
port: mockSentinelMasterEndpoint.port,
713
numberOfSlaves: 1,
814
status: SentinelMasterStatus.Active,
915
nodes: [{
Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import IORedis from 'ioredis';
22

3-
export const mockIORedisClient = {
4-
...Object.create(IORedis.prototype),
3+
const getRedisCommanderMockFunctions = () => ({
54
sendCommand: jest.fn(),
65
info: jest.fn(),
76
monitor: jest.fn(),
@@ -13,6 +12,44 @@ export const mockIORedisClient = {
1312
unsubscribe: jest.fn(),
1413
punsubscribe: jest.fn(),
1514
publish: jest.fn(),
15+
cluster: jest.fn(),
16+
quit: jest.fn(),
17+
});
18+
19+
export const mockIORedisClient = {
20+
...Object.create(IORedis.prototype),
21+
...getRedisCommanderMockFunctions(),
22+
status: 'ready',
23+
options: {
24+
db: 0,
25+
},
26+
};
27+
28+
export const mockIOClusterNode1 = {
29+
...Object.create(IORedis.prototype),
30+
...getRedisCommanderMockFunctions(),
31+
status: 'ready',
32+
options: {
33+
host: '127.0.100.1',
34+
port: 6379,
35+
db: 0,
36+
},
37+
};
38+
39+
export const mockIOClusterNode2 = {
40+
...Object.create(IORedis.prototype),
41+
...getRedisCommanderMockFunctions(),
42+
status: 'ready',
43+
options: {
44+
host: '127.0.100.2',
45+
port: 6379,
46+
db: 0,
47+
},
48+
};
49+
50+
export const mockIORedisSentinel = {
51+
...Object.create(IORedis.prototype),
52+
...getRedisCommanderMockFunctions(),
1653
status: 'ready',
1754
options: {
1855
db: 0,
@@ -21,22 +58,21 @@ export const mockIORedisClient = {
2158

2259
export const mockIORedisCluster = {
2360
...Object.create(IORedis.Cluster.prototype),
61+
...getRedisCommanderMockFunctions(),
2462
isCluster: true,
25-
sendCommand: jest.fn(),
26-
info: jest.fn(),
27-
monitor: jest.fn(),
28-
disconnect: jest.fn(),
29-
duplicate: jest.fn(),
30-
call: jest.fn(),
31-
subscribe: jest.fn(),
32-
psubscribe: jest.fn(),
33-
unsubscribe: jest.fn(),
34-
punsubscribe: jest.fn(),
35-
publish: jest.fn(),
3663
status: 'ready',
37-
nodes: jest.fn().mockReturnValue([mockIORedisClient, mockIORedisClient]),
64+
nodes: jest.fn().mockReturnValue([mockIOClusterNode1, mockIOClusterNode2]),
3865
};
3966

4067
export const mockRedisService = jest.fn(() => ({
41-
createStandaloneClient: jest.fn(),
68+
getClientInstance: jest.fn().mockResolvedValue({
69+
client: mockIORedisClient,
70+
}),
71+
setClientInstance: jest.fn(),
72+
isClientConnected: jest.fn().mockReturnValue(true),
73+
connectToDatabaseInstance: jest.fn().mockResolvedValue(mockIORedisClient),
74+
createStandaloneClient: jest.fn().mockResolvedValue(mockIORedisClient),
75+
createSentinelClient: jest.fn().mockResolvedValue(mockIORedisSentinel),
76+
createClusterClient: jest.fn().mockResolvedValue(mockIORedisCluster),
77+
removeClientInstance: jest.fn(),
4278
}));

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export class CliAnalyticsService extends CommandTelemetryBaseService {
8888
databaseId,
8989
...(await this.getCommandAdditionalInfo(additionalData['command'])),
9090
...additionalData,
91+
command: additionalData['command']?.toUpperCase() || undefined,
9192
},
9293
);
9394
} catch (e) {
@@ -101,14 +102,15 @@ export class CliAnalyticsService extends CommandTelemetryBaseService {
101102
additionalData: object = {},
102103
): Promise<void> {
103104
try {
105+
const commandFromError = error?.command?.name?.toUpperCase() || undefined;
104106
this.sendEvent(
105107
TelemetryEvents.CliCommandErrorReceived,
106108
{
107109
databaseId,
108110
error: error?.name,
109-
command: error?.command?.name?.toUpperCase(),
110111
...(await this.getCommandAdditionalInfo(additionalData['command'])),
111112
...additionalData,
113+
command: additionalData['command']?.toUpperCase() || commandFromError,
112114
},
113115
);
114116
} catch (e) {
@@ -130,18 +132,20 @@ export class CliAnalyticsService extends CommandTelemetryBaseService {
130132
databaseId,
131133
...(await this.getCommandAdditionalInfo(additionalData['command'])),
132134
...additionalData,
135+
command: additionalData['command']?.toUpperCase() || undefined,
133136
},
134137
);
135138
}
136139
if (status === CommandExecutionStatus.Fail) {
140+
const commandFromError = error?.command?.name?.toUpperCase() || undefined;
137141
this.sendEvent(
138142
TelemetryEvents.CliCommandErrorReceived,
139143
{
140144
databaseId,
141145
error: error.name,
142-
command: error?.command?.name?.toUpperCase(),
143146
...(await this.getCommandAdditionalInfo(additionalData['command'])),
144147
...additionalData,
148+
command: additionalData['command']?.toUpperCase() || commandFromError,
145149
},
146150
);
147151
}

0 commit comments

Comments
 (0)