Skip to content

Commit 7c84c84

Browse files
committed
tests with client
1 parent bd4913f commit 7c84c84

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

packages/client/lib/sentinel/index.spec.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,43 @@ describe('RedisSentinel', () => {
6565
})
6666

6767
});
68+
69+
describe('nodeAddressMap', () => {
70+
testUtils.testWithClientSentinel('should apply object mapping', async sentinel => {
71+
await sentinel.set('key', 'value');
72+
assert.equal(await sentinel.get('key'), 'value');
73+
}, {
74+
...GLOBAL.SENTINEL.OPEN,
75+
sentinelOptions: {
76+
nodeAddressMap: {
77+
'127.0.0.1:6379': { host: '127.0.0.1', port: 6379 }
78+
}
79+
}
80+
});
81+
82+
testUtils.testWithClientSentinel('should apply function mapping', async sentinel => {
83+
await sentinel.set('key', 'value');
84+
assert.equal(await sentinel.get('key'), 'value');
85+
}, {
86+
...GLOBAL.SENTINEL.OPEN,
87+
sentinelOptions: {
88+
nodeAddressMap: (address: string) => {
89+
const [host, port] = address.split(':');
90+
return { host, port: Number(port) };
91+
}
92+
}
93+
});
94+
95+
testUtils.testWithClientSentinel('should fall back to original address when function returns undefined', async sentinel => {
96+
await sentinel.set('key', 'value');
97+
assert.equal(await sentinel.get('key'), 'value');
98+
}, {
99+
...GLOBAL.SENTINEL.OPEN,
100+
sentinelOptions: {
101+
nodeAddressMap: () => undefined
102+
}
103+
});
104+
});
68105
});
69106
});
70107

0 commit comments

Comments
 (0)