-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnodecache.configsetup.test.js
151 lines (129 loc) · 4.48 KB
/
nodecache.configsetup.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
const NodeCache = require("../index")
describe("NodeCache.js Configuration Setup Suit", () => {
let cache
afterEach(() => {
cache.close()
})
test("NodeCache.js with no configuration options to be defined", () => {
cache = new NodeCache()
expect(cache).toBeDefined()
expect(cache.getLogConfig()).toBeDefined()
expect(cache.getLogConfig()).toStrictEqual(expect.any(Object))
expect(cache.getCacheConfig()).toBeDefined()
expect(cache.getCacheConfig()).toStrictEqual({
forceString: true,
valueOnly: true,
maxKeys: -1,
stdTTL: 0,
cacheHit: 0,
cacheMiss: 0,
keyCount: 0,
})
})
test("NodeCache.js with explicit null configuration options to be defined", () => {
cache = new NodeCache({
forceString: null,
valueOnly: null,
maxKeys: null,
stdTTL: null
})
expect(cache).toBeDefined()
expect(cache.getLogConfig()).toBeDefined()
expect(cache.getLogConfig()).toStrictEqual(expect.any(Object))
expect(cache.getCacheConfig()).toBeDefined()
expect(cache.getCacheConfig()).toStrictEqual({
forceString: true,
valueOnly: true,
maxKeys: -1,
stdTTL: 0,
cacheHit: 0,
cacheMiss: 0,
keyCount: 0,
})
})
test("NodeCache.js with valueOnly false configuration options to be defined", () => {
cache = new NodeCache({
valueOnly: false
})
expect(cache).toBeDefined()
const loggerConfiguration = cache.getLogConfig()
const configuration = cache.getCacheConfig()
expect(loggerConfiguration).toBeDefined()
expect(loggerConfiguration).toStrictEqual(expect.any(Object))
expect(configuration).toStrictEqual(expect.any(Object))
expect(configuration).toBeDefined()
expect(configuration).toStrictEqual({
forceString: true,
valueOnly: false,
maxKeys: -1,
stdTTL: 0,
cacheHit: 0,
cacheMiss: 0,
keyCount: 0,
})
cache.set("config-1", 707301, 60 * 60 * 1000)
expect(cache.get("config-1")).toStrictEqual({
value: expect.any(String),
ttl: expect.any(Number)
})
})
test("NodeCache.js with forceString false configuration options to be defined", () => {
cache = new NodeCache({
forceString: false
//valueOnly: true by default
})
expect(cache).toBeDefined()
const loggerConfiguration = cache.getLogConfig()
const configuration = cache.getCacheConfig()
expect(loggerConfiguration).toBeDefined()
expect(loggerConfiguration).toStrictEqual(expect.any(Object))
expect(configuration).toBeDefined()
expect(configuration).toStrictEqual({
forceString: false,
valueOnly: true,
maxKeys: -1,
stdTTL: 0,
cacheHit: 0,
cacheMiss: 0,
keyCount: 0,
})
cache.set("config-1", 707301, 60 * 60 * 1000)
expect(cache.get("config-1")).toStrictEqual(707301)
})
test("NodeCache.js with all valid configuration options to be defined", () => {
cache = new NodeCache({
forceString: false,
valueOnly: false,
maxKeys: 3,
stdTTL: 2 * 60 * 60 * 1000
})
expect(cache).toBeDefined()
const loggerConfiguration = cache.getLogConfig()
const configuration = cache.getCacheConfig()
expect(loggerConfiguration).toBeDefined()
expect(loggerConfiguration).toStrictEqual(expect.any(Object))
expect(configuration).toBeDefined()
expect(configuration).toStrictEqual({
forceString: false,
valueOnly: false,
maxKeys: 3,
stdTTL: 2 * 60 * 60 * 1000,
cacheHit: 0,
cacheMiss: 0,
keyCount: 0,
})
cache.set("config-1", 707301)
expect(cache.get("config-1")).toStrictEqual({
value: 707301,
ttl: expect.any(Number)
})
cache.setM([
{ key: 1, value: { data: 7073011 } },
{ key: 2, value: { data: 7073012 } }
])
expect(cache.get(1)).toStrictEqual({
value: { data: 7073011 },
ttl: expect.any(Number)
})
})
})