forked from cloudron-io/asnlookup
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
72 lines (50 loc) · 1.71 KB
/
test.js
File metadata and controls
72 lines (50 loc) · 1.71 KB
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
"use strict";
/* global it:false */
/* global describe:false */
/* global before:false */
/* global after:false */
const expect = require("expect.js"),
fs = require("fs"),
path = require("path");
const TEST_CACHE_FILE = ".asnlookup.tests.cache";
function cleanup() {
try {
fs.unlinkSync(path.resolve(TEST_CACHE_FILE));
} catch (e) {}
}
describe("asnlookup", function () {
this.timeout(10000);
before(cleanup);
after(cleanup);
it("last updated is Infinity without cache", function () {
const asnlookup = require("./index.js")(TEST_CACHE_FILE);
const lastUpdated = asnlookup.lastUpdated();
expect(lastUpdated).to.equal(Infinity);
});
it("can update cache initially", async function () {
this.timeout(0);
const asnlookup = require("./index.js")(TEST_CACHE_FILE);
console.log("Updating cache, this takes some time...");
await asnlookup.update();
const lastUpdated = asnlookup.lastUpdated();
expect(lastUpdated).to.equal(0);
});
it("can load from cache", async function () {
const asnlookup = require("./index.js")(TEST_CACHE_FILE);
await asnlookup.load();
const lastUpdated = asnlookup.lastUpdated();
expect(lastUpdated).to.equal(0);
});
it("lookup succeeds for 8.8.8.8", async function () {
const asnlookup = require("./index.js")(TEST_CACHE_FILE);
await asnlookup.load();
const asn = asnlookup.lookup("8.8.8.8");
expect(asn).to.equal("15169");
expect(asnlookup.asnToName(asn)).to.equal("GOOGLE");
});
it("lookup succeeds with null for 127.0.0.1", async function () {
const asnlookup = require("./index.js")(TEST_CACHE_FILE);
await asnlookup.load();
expect(asnlookup.lookup("127.0.0.1")).to.eql(null);
});
});