summaryrefslogtreecommitdiff
path: root/node_modules/node-file-cache/tests
diff options
context:
space:
mode:
author8cy <[email protected]>2020-04-03 02:37:42 -0700
committer8cy <[email protected]>2020-04-03 02:37:42 -0700
commit60867fb030bae582082340ead7dbc7efdc2f5398 (patch)
tree4c6a7356351be2e4914e15c4703172597c45656e /node_modules/node-file-cache/tests
parentcommenting (diff)
downloads5nical-60867fb030bae582082340ead7dbc7efdc2f5398.tar.xz
s5nical-60867fb030bae582082340ead7dbc7efdc2f5398.zip
2020/04/03, 02:34, v1.2.0
Diffstat (limited to 'node_modules/node-file-cache/tests')
-rw-r--r--node_modules/node-file-cache/tests/basic-test.js69
-rw-r--r--node_modules/node-file-cache/tests/db-test.js18
-rw-r--r--node_modules/node-file-cache/tests/expire-test.js70
3 files changed, 157 insertions, 0 deletions
diff --git a/node_modules/node-file-cache/tests/basic-test.js b/node_modules/node-file-cache/tests/basic-test.js
new file mode 100644
index 0000000..ea690ef
--- /dev/null
+++ b/node_modules/node-file-cache/tests/basic-test.js
@@ -0,0 +1,69 @@
+'use strict';
+
+const assert = require('assert');
+const cache = require('../lib/index').create();
+
+// cleanup
+cache.clear();
+assert.equal(cache.size(), 0);
+
+// add record
+const item1 = { yo: 'dawg' };
+const key1 = 'mittenz';
+cache.set(key1, item1);
+
+const result1 = cache.get(key1);
+assert.deepEqual(item1, result1);
+assert.equal(cache.size(), 1);
+
+// add same record
+cache.set(key1, item1);
+assert.deepEqual(item1, result1);
+assert.equal(cache.size(), 1);
+
+// add next record
+const item2 = {
+ foo: 'bar'
+};
+const key2 = 'kittenz';
+cache.set(key2, item2);
+
+const result2 = cache.get(key2);
+assert.deepEqual(item2, result2);
+assert.equal(cache.size(), 2);
+
+// add record with tags
+const item3 = {
+ bar: 'baz'
+};
+const key3 = 'bat';
+const tags3 = ['bat-3'];
+cache.set(key3, item3, {
+ tags: tags3
+});
+
+const result3 = cache.get(key3);
+assert.deepEqual(item3, result3);
+assert.equal(cache.size(), 3);
+
+// expire by tags
+cache.expire(tags3);
+assert.equal(cache.size(), 2);
+
+// add record with lifespan
+const item4 = {
+ bar: 'baziliero'
+};
+const key4 = 'batbaz';
+const span = 1;
+cache.set(key4, item4, {
+ life: span
+});
+
+setTimeout(() => {
+ const result4 = cache.get(key4);
+ assert.equal(result4, null);
+ assert.equal(cache.size(), 2);
+}, 3000);
+
+
diff --git a/node_modules/node-file-cache/tests/db-test.js b/node_modules/node-file-cache/tests/db-test.js
new file mode 100644
index 0000000..8ff01a1
--- /dev/null
+++ b/node_modules/node-file-cache/tests/db-test.js
@@ -0,0 +1,18 @@
+'use strict';
+
+const assert = require('assert');
+const cache = require('../lib/index.js').create({
+ file: __dirname + '/ga-api-cache.json'
+});
+
+cache.clear();
+assert.equal(cache.size(), 0);
+
+cache.set('key', 1, {
+ life: 3
+});
+
+assert.equal(cache.size(), 1);
+
+assert.equal(cache.get('key'), 1);
+setTimeout(() => assert.equal(cache.get('key'), null), 5000); \ No newline at end of file
diff --git a/node_modules/node-file-cache/tests/expire-test.js b/node_modules/node-file-cache/tests/expire-test.js
new file mode 100644
index 0000000..9f39529
--- /dev/null
+++ b/node_modules/node-file-cache/tests/expire-test.js
@@ -0,0 +1,70 @@
+'use strict';
+
+const assert = require('assert');
+const cache = require('../lib/index').create();
+
+cache.clear();
+assert.equal(cache.size(), 0);
+
+const items = [
+ {
+ key: 'one',
+ item: {
+ name: 'one'
+ },
+ options: {}
+ },
+ {
+ key: 'two',
+ item: {
+ name: 'two'
+ },
+ options: {
+ tags: [ 'two' ]
+ }
+ },
+ {
+ key: 'three',
+ item: {
+ name: 'three'
+ },
+ options: {
+ life: 60
+ }
+ },
+ {
+ key: 'four',
+ item: {
+ name: 'four'
+ },
+ options: {
+ tags: [ 'four' ],
+ life: -1
+ }
+ }
+];
+
+items.forEach((item) => {
+ cache.set(item.key, item.item, item.options);
+});
+
+assert.equal(cache.size(), items.length);
+
+// expire by key
+cache.expire('one');
+assert.equal(cache.get('one'), null);
+assert.equal(cache.size(), items.length - 1);
+
+// expire by tags
+cache.expire(['two']);
+assert.equal(cache.get('two'), null);
+assert.equal(cache.size(), items.length - 2);
+
+// expire by callback
+cache.expire((record) => record.key === 'three');
+assert.equal(cache.get('three'), null);
+assert.equal(cache.size(), items.length - 3);
+
+// expire by lifespan
+assert.equal(cache.get('four'), null);
+assert.equal(cache.size(), items.length - 4); \ No newline at end of file