-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod.test.js
77 lines (63 loc) · 1.96 KB
/
mod.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { assert, assertEquals, pluginFactory } from './dev_deps.js'
import RedisCacheAdapter from './mod.js'
const resolves = (val) => () => Promise.resolve(val)
const baseStubClient = {
get: resolves(),
mget: resolves(),
set: resolves(),
del: resolves(),
keys: resolves(),
scan: resolves(),
}
const options = {
url: 'http://user:[email protected]:6379',
client: { connect: resolves({ foo: 'bar' }) },
}
Deno.test('mod', async (t) => {
await t.step('validate factory schema', () => {
assert(pluginFactory(RedisCacheAdapter(options)))
})
await t.step('load', async (t) => {
await t.step('returns a redis client', async () => {
const res = await RedisCacheAdapter(options).load()
assert(res.redis)
assertEquals(res.redis.foo, 'bar')
})
await t.step('returns a redis cluster client using the host name and port', async () => {
const res = await RedisCacheAdapter({
hostname: 'foo',
port: 6380,
client: {
connect: (config) => Promise.resolve(config),
},
cluster: true,
}).load()
assert(res.redis)
assertEquals(res.redis.nodes[0].hostname, 'foo')
assertEquals(res.redis.nodes[0].port, 6380)
})
await t.step('returns options', async (t) => {
await t.step('with defaults', async () => {
const withDefault = await RedisCacheAdapter(options).load()
assertEquals(withDefault.scanCount, 10000)
})
await t.step('without defaults', async () => {
const withoutDefault = await RedisCacheAdapter({
...options,
// Pass in scan count through config
scanCount: 111,
}).load()
assertEquals(withoutDefault.scanCount, 111)
})
})
})
await t.step('link', async (t) => {
await t.step('returns an adapter', () => {
const res = RedisCacheAdapter().link({
redis: baseStubClient,
scanCount: 101,
})()
assert(res.createStore)
})
})
})