-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.fs.ledger.js
112 lines (109 loc) · 3.01 KB
/
test.fs.ledger.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
const tap = require('tap');
const {unlink} = require('fs/promises');
const {join} = require('path');
const ledger = require('../../lib/fs/ledger');
const ls1 = {
cwd: 'tests/unit/runtime/ledger',
cwf: 'abc'
};
const ul = async(obj) => {
try {
await unlink(join(obj.cwd, obj.cwf));
} catch (e) {}
}
tap.test('Ledger', async(t0) => {
ledger();
const ledger1 = ledger({cwd: './abc/dadeda'});
const ledgerSuccess1 = ledger(ls1);
await ul(ls1);
tap.test('Incorrect cwd', (t1) => {
t1.rejects(
ledger1.check,
'check should rejects'
);
t1.rejects(
ledger1.init,
'init should rejects'
);
t1.rejects(
ledger1.lock,
'lock should rejects'
);
t1.rejects(
ledger1.unlock,
'unlock should rejects'
);
t1.rejects(
() => ledger1.exists({
baseName: 'z',
path: 'y'
}),
'exists should rejects'
);
t1.rejects(
() => ledger1.markExists({
baseName: 'z',
path: 'y'
}),
'markExists should rejects'
);
t1.resolves(
() => ledger1.exec({}),
'exec should resolves'
);
t1.end();
});
tap.test('Correct cwd', async(t1) => {
await t1.rejects(
ledgerSuccess1.check,
'check should rejects'
);
await t1.resolves(
ledgerSuccess1.init,
'check should resolves'
);
await t1.resolves(
ledgerSuccess1.check,
'check should resolves now'
);
await t1.resolves(
ledgerSuccess1.lock,
'lock should resolves'
);
await t1.resolves(
ledgerSuccess1.unlock,
'unlock should resolves'
);
await t1.resolveMatch(
() => ledgerSuccess1.exists({baseName: 'a', path: 'a/b/c'}),
false,
'exists should resolves to false, resource not in list'
);
await t1.resolves(
() => ledgerSuccess1.markExists({baseName: 'a', path: 'a/b/c'}),
'markExists should resolves'
);
await t1.resolveMatch(
() => ledgerSuccess1.exists({baseName: 'a', path: 'a/b/c'}),
true,
'exists should resolves to true, resource in list'
);
await t1.resolveMatch(
() => ledgerSuccess1.exists({baseName: 'z', path: 'a/b/c'}),
false,
'exists should resolves to false, resource not in list'
);
await ledgerSuccess1.lock();
await t1.rejects(
ledgerSuccess1.lock,
'lock should rejects, already locked'
);
await ledgerSuccess1.unlock();
await t1.rejects(
ledgerSuccess1.unlock,
'unlock should rejects, already unlocked'
);
t1.end();
});
t0.end();
});