/
name-sync-test.js
113 lines (100 loc) · 3.96 KB
/
name-sync-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
/* eslint-disable no-octal */
// vim: expandtab:ts=2:sw=2
const
assert = require('assert'),
os = require('os'),
inbandStandardTests = require('./name-inband-standard'),
tmp = require('../lib/tmp');
describe('tmp', function () {
describe('#tmpNameSync()', function () {
describe('when running inband standard tests', function () {
inbandStandardTests(function before() {
this.topic = tmp.tmpNameSync(this.opts);
});
describe('with invalid tries', function () {
it('should result in an error on negative tries', function () {
try {
tmp.tmpNameSync({ tries: -1 });
assert.fail('should have failed');
} catch (err) {
assert.ok(err instanceof Error);
}
});
it('should result in an error on non numeric tries', function () {
try {
tmp.tmpNameSync({ tries: 'nan' });
assert.fail('should have failed');
} catch (err) {
assert.ok(err instanceof Error);
}
});
});
});
describe('when running issue specific inband tests', function () {
describe('on issue #176', function () {
const origfn = os.tmpdir;
function _generateSpecName(optsDir, osTmpDir) {
return 'opts.dir = "$1", os.tmpdir() = "$2"'.replace('$1', optsDir).replace('$2', osTmpDir);
}
const failing = ['', ' ', undefined, null];
const nonFailing = ['tmp']; // the origfn cannot be trusted as the os may or may not have a valid tmp dir
describe('must fail on invalid os.tmpdir() and invalid opts.dir', function () {
// test all failing permutations
for (let oidx = 0; oidx < failing.length; oidx++) {
for (let iidx = 0; iidx < failing.length; iidx++) {
it(_generateSpecName(failing[iidx], failing[oidx]), function () {
os.tmpdir = function () { return failing[oidx]; };
try {
tmp.tmpNameSync({ dir: failing[iidx] });
assert.fail('expected this to fail');
} catch (err) {
assert.ok(err instanceof Error, 'error expected');
} finally {
os.tmpdir = origfn;
}
});
}
}
});
describe('must not fail on invalid os.tmpdir() and valid opts.dir', function () {
// test all non failing permutations for non failing opts.dir and failing osTmpDir
for (let oidx = 0; oidx < failing.length; oidx++) {
for (let iidx = 0; iidx < nonFailing.length; iidx++) {
it(_generateSpecName(nonFailing[iidx], failing[oidx]), function () {
os.tmpdir = function () { return failing[oidx]; };
try {
tmp.tmpNameSync({ dir: nonFailing[iidx] });
} catch (err) {
assert.fail(err);
} finally {
os.tmpdir = origfn;
}
});
}
}
});
describe('must not fail on valid os.tmpdir() and invalid opts.dir', function () {
// test all non failing permutations for failing opts.dir and non failing osTmpDir
for (let oidx = 0; oidx < nonFailing.length; oidx++) {
for (let iidx = 0; iidx < failing.length; iidx++) {
it(_generateSpecName(failing[iidx], nonFailing[oidx]), function () {
os.tmpdir = function () { return nonFailing[oidx]; };
try {
tmp.tmpNameSync({ dir: failing[iidx] });
} catch (err) {
assert.fail(err);
} finally {
os.tmpdir = origfn;
}
});
}
}
});
});
});
describe('when running standard outband tests', function () {
});
describe('when running issue specific outband tests', function () {
});
});
});