Skip to content

Commit 1a09d2f

Browse files
committed
tests and such 2
1 parent 5f7ad12 commit 1a09d2f

File tree

3 files changed

+117
-35
lines changed

3 files changed

+117
-35
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"AWS-cluster": {
3+
"cluster_mode": true,
4+
"hostname": "clustercfg.rg-0c94f0c1-db0a-495d-b385-4a44a87fc398.vwvwdz.euc1.cache.amazonaws.com",
5+
"password": "mock-password",
6+
"port": 3991,
7+
"tls": true,
8+
"uri": "rediss://:mock-password@clustercfg.rg-0c94f0c1-db0a-495d-b385-4a44a87fc398.vwvwdz.euc1.cache.amazonaws.com:3991",
9+
"urls": {
10+
"api_server": "https://api-backing-services.eu10-canary.data.services.cloud.sap"
11+
}
12+
},
13+
"AZURE": {
14+
"password": "mock-password",
15+
"hostname": "redis-389395bc-9765-4d9a-ba6b-7252c136abab.redis.cache.windows.net",
16+
"port": 6380,
17+
"uri": "rediss://:mock-password@redis-389395bc-9765-4d9a-ba6b-7252c136abab.redis.cache.windows.net:6380",
18+
"cluster_mode": false,
19+
"urls": {
20+
"api_server": "https://api-backing-services.eu20-001.data.services.cloud.sap"
21+
},
22+
"tls": {
23+
"host": "redis-389395bc-9765-4d9a-ba6b-7252c136abab.redis.cache.windows.net",
24+
"port": 6380,
25+
"ca": "null"
26+
}
27+
},
28+
"GCP": {
29+
"password": "mock-password",
30+
"hostname": "10.160.68.75",
31+
"port": 6378,
32+
"uri": "rediss://:[email protected]:6378",
33+
"cluster_mode": false,
34+
"urls": {
35+
"api_server": "https://api-backing-services.eu30.data.services.cloud.sap"
36+
},
37+
"tls": {
38+
"server_ca": "null"
39+
}
40+
}
41+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`redis-adapter test _createClientBase on CF | AWS-cluster 1`] = `
4+
[
5+
{
6+
"defaults": {
7+
"password": "mock-password",
8+
"pingInterval": 300000,
9+
"socket": {
10+
"host": "clustercfg.rg-0c94f0c1-db0a-495d-b385-4a44a87fc398.vwvwdz.euc1.cache.amazonaws.com",
11+
"port": 3991,
12+
"tls": true,
13+
},
14+
},
15+
"rootNodes": [
16+
{
17+
"password": "mock-password",
18+
"pingInterval": 300000,
19+
"socket": {
20+
"host": "clustercfg.rg-0c94f0c1-db0a-495d-b385-4a44a87fc398.vwvwdz.euc1.cache.amazonaws.com",
21+
"port": 3991,
22+
"tls": true,
23+
},
24+
},
25+
],
26+
},
27+
]
28+
`;
29+
30+
exports[`redis-adapter test _createClientBase on CF | AZURE 1`] = `
31+
[
32+
{
33+
"password": "mock-password",
34+
"pingInterval": 300000,
35+
"socket": {
36+
"ca": "null",
37+
"host": "redis-389395bc-9765-4d9a-ba6b-7252c136abab.redis.cache.windows.net",
38+
"port": 6380,
39+
"tls": true,
40+
},
41+
},
42+
]
43+
`;
44+
45+
exports[`redis-adapter test _createClientBase on CF | GCP 1`] = `
46+
[
47+
{
48+
"password": "mock-password",
49+
"pingInterval": 300000,
50+
"socket": {
51+
"host": "10.160.68.75",
52+
"port": 6378,
53+
"server_ca": "null",
54+
"tls": true,
55+
},
56+
},
57+
]
58+
`;

test/redis-adapter.test.js

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const mockClient = {
3131
const redis = require("@redis/client");
3232
jest.mock("@redis/client", () => ({
3333
createClient: jest.fn(() => mockClient),
34+
createCluster: jest.fn(() => mockClient),
3435
}));
3536

3637
const redisAdapter = require("../src/redis-adapter");
@@ -86,41 +87,23 @@ describe("redis-adapter test", () => {
8687
expect(loggerSpy.error).not.toHaveBeenCalled();
8788
});
8889

89-
test("_createClientBase on CF", async () => {
90-
const mockUrl = "rediss://BAD_USERNAME:pwd@mockUrl";
91-
92-
envMock.isOnCf = true;
93-
envMock.cfServiceCredentialsForLabel.mockReturnValueOnce({
94-
cluster_mode: false,
95-
uri: mockUrl,
96-
hostname: "my-domain.com",
97-
port: "1234",
98-
password: "mock-password",
99-
tls: { tlsOption: "tlsOption" },
100-
});
101-
102-
const client = redisAdapter._._createClientBase();
103-
104-
expect(envMock.cfServiceCredentialsForLabel).toHaveBeenCalledTimes(1);
105-
expect(envMock.cfServiceCredentialsForLabel).toHaveBeenCalledWith("redis-cache");
106-
expect(redis.createClient).toHaveBeenCalledTimes(1);
107-
expect(redis.createClient.mock.calls[0]).toMatchInlineSnapshot(`
108-
[
109-
{
110-
"password": "mock-password",
111-
"pingInterval": 300000,
112-
"socket": {
113-
"host": "my-domain.com",
114-
"port": "1234",
115-
"tls": true,
116-
"tlsOption": "tlsOption",
117-
},
118-
},
119-
]
120-
`);
121-
expect(client).toBe(mockClient);
122-
expect(loggerSpy.error).not.toHaveBeenCalled();
123-
});
90+
test.each(Object.entries(require("./__mocks__/mock-redis-credentials.json")))(
91+
"_createClientBase on CF | %s",
92+
async (_, credentials) => {
93+
envMock.isOnCf = true;
94+
envMock.cfServiceCredentialsForLabel.mockReturnValueOnce(credentials);
95+
96+
redisAdapter._._createClientBase();
97+
const { cluster_mode: isCluster } = credentials;
98+
const creator = isCluster ? redis.createCluster : redis.createClient;
99+
100+
expect(envMock.cfServiceCredentialsForLabel).toHaveBeenCalledTimes(1);
101+
expect(envMock.cfServiceCredentialsForLabel).toHaveBeenCalledWith("redis-cache");
102+
expect(creator).toHaveBeenCalledTimes(1);
103+
expect(creator.mock.calls[0]).toMatchSnapshot();
104+
expect(loggerSpy.error).not.toHaveBeenCalled();
105+
}
106+
);
124107

125108
test("getMainClient", async () => {
126109
const client = await redisAdapter.getMainClient();

0 commit comments

Comments
 (0)