1 |
|
2 |
|
3 | require('../src/dev/test/init');
|
4 |
|
5 |
|
6 | const assert = require('assert');
|
7 | const _ = require('lodash');
|
8 |
|
9 | const cache = require('../src/cache');
|
10 |
|
11 | describe('igo.cache', function() {
|
12 |
|
13 | it('should return undefined if key is not found', function(done) {
|
14 | cache.get('nsx', 0, function(err, value) {
|
15 | assert(value === undefined);
|
16 | done();
|
17 | });
|
18 | });
|
19 |
|
20 | it('should store string values', function(done) {
|
21 | cache.put('ns', 0, 'hello', function() {
|
22 | cache.get('ns', 0, function(err, value) {
|
23 | assert(value === 'hello');
|
24 | done();
|
25 | });
|
26 | });
|
27 | });
|
28 |
|
29 | it('should store null values', function(done) {
|
30 | cache.put('ns', 0, null, function() {
|
31 | cache.get('ns', 0, function(err, value) {
|
32 | assert(value === null);
|
33 | done();
|
34 | });
|
35 | })
|
36 | });
|
37 |
|
38 | it('should store dates', function(done) {
|
39 | cache.put('ns', 0, new Date(), function() {
|
40 | cache.get('ns', 0, function(err, value) {
|
41 | assert(value !== null);
|
42 | assert(_.isDate(value));
|
43 | done();
|
44 | });
|
45 | })
|
46 | });
|
47 |
|
48 | it('should store objects with dates', function(done) {
|
49 | cache.put('ns', 0, { t0: new Date() }, function() {
|
50 | cache.get('ns', 0, function(err, value) {
|
51 | assert(value !== null);
|
52 | assert(_.isDate(value.t0));
|
53 | done();
|
54 | });
|
55 | })
|
56 | });
|
57 |
|
58 | it('should store buffers', function(done) {
|
59 | const buffer = Buffer.from('hello world', 'utf8');
|
60 | cache.put('ns', 0, buffer, function() {
|
61 | cache.get('ns', 0, function(err, value) {
|
62 | assert(value !== null);
|
63 | assert(_.isBuffer(value));
|
64 | assert.equal(buffer.toString(), value.toString());
|
65 | done();
|
66 | });
|
67 | })
|
68 | });
|
69 | });
|