|
1 | 1 | /* eslint-disable no-octal */
|
| 2 | +// vim: expandtab:ts=2:sw=2 |
2 | 3 |
|
3 | 4 | var
|
4 |
| - vows = require('vows'), |
5 | 5 | assert = require('assert'),
|
| 6 | + inbandStandardTests = require('./inband-standard.js'), |
| 7 | + tmp = require('../lib/tmp.js'); |
| 8 | + |
| 9 | + |
| 10 | +describe('tmp', function () { |
| 11 | + describe('#dirSync()', function () { |
| 12 | + // API call standard inband tests |
| 13 | + describe('when running inband standard tests', function () { |
| 14 | + |
| 15 | + inbandStandardTests(false, function before() { |
| 16 | + this.topic = tmp.dirSync(this.opts); |
| 17 | + }); |
| 18 | + |
| 19 | + describe('with invalid tries', function () { |
| 20 | + it('should result in an error on negative tries', function () { |
| 21 | + try { |
| 22 | + tmp.dirSync({tries: -1}); |
| 23 | + assert.fail('should have failed'); |
| 24 | + } catch (err) { |
| 25 | + assert.ok(err instanceof Error); |
| 26 | + } |
| 27 | + }); |
| 28 | + }); |
| 29 | + }); |
| 30 | + |
| 31 | + // API call issue specific inband tests |
| 32 | + describe('when running issue specific inband tests', function () { |
| 33 | + // add your issue specific tests here |
| 34 | + }); |
| 35 | + |
| 36 | + // API call standard outband tests |
| 37 | + describe('when running standard outband tests', function () { |
| 38 | + }); |
| 39 | + |
| 40 | + // API call issue specific outband tests |
| 41 | + describe('when running issue specific outband tests', function () { |
| 42 | + // add your issue specific tests here |
| 43 | + }); |
| 44 | + }); |
| 45 | +}); |
6 | 46 |
|
7 |
| - path = require('path'), |
8 |
| - fs = require('fs'), |
9 |
| - existsSync = fs.existsSync || path.existsSync, |
10 |
| - |
11 |
| - tmp = require('../lib/tmp.js'), |
12 |
| - Test = require('./base.js'); |
13 |
| - |
14 |
| - |
15 |
| -function _testDir(mode) { |
16 |
| - return function _testDirGenerated(result) { |
17 |
| - assert.ok(existsSync(result.name), 'should exist'); |
18 |
| - |
19 |
| - var stat = fs.statSync(result.name); |
20 |
| - assert.ok(stat.isDirectory(), 'should be a directory'); |
21 |
| - |
22 |
| - Test.testStat(stat, mode); |
23 |
| - }; |
24 |
| -} |
25 |
| - |
26 |
| -vows.describe('Synchronous directory creation').addBatch({ |
27 |
| - 'when using without parameters': { |
28 |
| - topic: function () { |
29 |
| - return tmp.dirSync(); |
30 |
| - }, |
31 |
| - |
32 |
| - 'should return with a name': Test.assertNameSync, |
33 |
| - 'should be a directory': _testDir(040700), |
34 |
| - 'should have the default prefix': Test.testPrefixSync('tmp-') |
35 |
| - }, |
36 |
| - |
37 |
| - 'when using with prefix': { |
38 |
| - topic: function () { |
39 |
| - return tmp.dirSync({ prefix: 'something' }); |
40 |
| - }, |
41 |
| - |
42 |
| - 'should return with a name': Test.assertNameSync, |
43 |
| - 'should be a directory': _testDir(040700), |
44 |
| - 'should have the provided prefix': Test.testPrefixSync('something') |
45 |
| - }, |
46 |
| - |
47 |
| - 'when using with postfix': { |
48 |
| - topic: function () { |
49 |
| - return tmp.dirSync({ postfix: '.txt' }); |
50 |
| - }, |
51 |
| - |
52 |
| - 'should return with a name': Test.assertNameSync, |
53 |
| - 'should be a directory': _testDir(040700), |
54 |
| - 'should have the provided postfix': Test.testPostfixSync('.txt') |
55 |
| - }, |
56 |
| - |
57 |
| - 'when using template': { |
58 |
| - topic: function () { |
59 |
| - return tmp.dirSync({ template: path.join(tmp.tmpdir, 'clike-XXXXXX-postfix') }); |
60 |
| - }, |
61 |
| - |
62 |
| - 'should return with a name': Test.assertNameSync, |
63 |
| - 'should be a directory': _testDir(040700), |
64 |
| - 'should have the provided prefix': Test.testPrefixSync('clike-'), |
65 |
| - 'should have the provided postfix': Test.testPostfixSync('-postfix') |
66 |
| - }, |
67 |
| - |
68 |
| - 'when using name': { |
69 |
| - topic: function () { |
70 |
| - return tmp.dirSync({ name: 'using-name' }); |
71 |
| - }, |
72 |
| - |
73 |
| - 'should return with a name': Test.assertNameSync, |
74 |
| - 'should have the provided name': Test.testNameSync(path.join(tmp.tmpdir, 'using-name')), |
75 |
| - 'should be a directory': function (result) { |
76 |
| - _testDir(040700)(result); |
77 |
| - result.removeCallback(); |
78 |
| - assert.ok(!existsSync(result.name), 'Directory should be removed'); |
79 |
| - } |
80 |
| - }, |
81 |
| - |
82 |
| - 'when using multiple options': { |
83 |
| - topic: function () { |
84 |
| - return tmp.dirSync({ prefix: 'foo', postfix: 'bar', mode: 0750 }); |
85 |
| - }, |
86 |
| - |
87 |
| - 'should return with a name': Test.assertNameSync, |
88 |
| - 'should be a directory': _testDir(040750), |
89 |
| - 'should have the provided prefix': Test.testPrefixSync('foo'), |
90 |
| - 'should have the provided postfix': Test.testPostfixSync('bar') |
91 |
| - }, |
92 |
| - |
93 |
| - 'when using multiple options and mode': { |
94 |
| - topic: function () { |
95 |
| - return tmp.dirSync({ prefix: 'complicated', postfix: 'options', mode: 0755 }); |
96 |
| - }, |
97 |
| - |
98 |
| - 'should return with a name': Test.assertNameSync, |
99 |
| - 'should be a directory': _testDir(040755), |
100 |
| - 'should have the provided prefix': Test.testPrefixSync('complicated'), |
101 |
| - 'should have the provided postfix': Test.testPostfixSync('options') |
102 |
| - }, |
103 |
| - |
104 |
| - 'no tries': { |
105 |
| - topic: function () { |
106 |
| - try { |
107 |
| - return tmp.dirSync({ tries: -1 }); |
108 |
| - } |
109 |
| - catch (e) { |
110 |
| - return e; |
111 |
| - } |
112 |
| - }, |
113 |
| - |
114 |
| - 'should return with an error': function (topic) { |
115 |
| - assert.instanceOf(topic, Error); |
116 |
| - } |
117 |
| - }, |
118 |
| - |
119 |
| - 'keep testing': { |
120 |
| - topic: function () { |
121 |
| - Test.testKeepSync('dir', '1', this.callback); |
122 |
| - }, |
123 |
| - |
124 |
| - 'should not return with an error': assert.isNull, |
125 |
| - 'should return with a name': Test.assertName, |
126 |
| - 'should be a dir': function (err, name) { |
127 |
| - _testDir(040700)({ name: name }); |
128 |
| - fs.rmdirSync(name); |
129 |
| - } |
130 |
| - }, |
131 |
| - |
132 |
| - 'unlink testing': { |
133 |
| - topic: function () { |
134 |
| - Test.testKeepSync('dir', '0', this.callback); |
135 |
| - }, |
136 |
| - |
137 |
| - 'should not return with error': assert.isNull, |
138 |
| - 'should return with a name': Test.assertName, |
139 |
| - 'should not exist': function (err, name) { |
140 |
| - assert.ok(!existsSync(name), 'Directory should be removed'); |
141 |
| - } |
142 |
| - }, |
143 |
| - |
144 |
| - 'non graceful testing': { |
145 |
| - topic: function () { |
146 |
| - Test.testGracefulSync('dir', '0', this.callback); |
147 |
| - }, |
148 |
| - |
149 |
| - 'should not return with error': assert.isNull, |
150 |
| - 'should return with a name': Test.assertName, |
151 |
| - 'should be a dir': function (err, name) { |
152 |
| - _testDir(040700)({ name: name }); |
153 |
| - fs.rmdirSync(name); |
154 |
| - } |
155 |
| - }, |
156 |
| - |
157 |
| - 'graceful testing': { |
158 |
| - topic: function () { |
159 |
| - Test.testGracefulSync('dir', '1', this.callback); |
160 |
| - }, |
161 |
| - |
162 |
| - 'should not return with an error': assert.isNull, |
163 |
| - 'should return with a name': Test.assertName, |
164 |
| - 'should not exist': function (err, name) { |
165 |
| - assert.ok(!existsSync(name), 'Directory should be removed'); |
166 |
| - } |
167 |
| - }, |
168 |
| - |
169 |
| - 'unsafeCleanup === true': { |
170 |
| - topic: function () { |
171 |
| - Test.testUnsafeCleanupSync('1', this.callback); |
172 |
| - }, |
173 |
| - |
174 |
| - 'should not return with an error': assert.isNull, |
175 |
| - 'should return with a name': Test.assertName, |
176 |
| - 'should not exist': function (err, name) { |
177 |
| - assert.ok(!existsSync(name), 'Directory should be removed'); |
178 |
| - }, |
179 |
| - 'should remove symlinked dir': function(err, name) { |
180 |
| - assert.ok( |
181 |
| - !existsSync(name + '/symlinkme-target'), |
182 |
| - 'should remove target' |
183 |
| - ); |
184 |
| - }, |
185 |
| - 'should not remove contents of symlink dir': function() { |
186 |
| - assert.ok( |
187 |
| - existsSync(__dirname + '/symlinkme/file.js'), |
188 |
| - 'should not remove symlinked directory\'s content' |
189 |
| - ); |
190 |
| - } |
191 |
| - }, |
192 |
| - |
193 |
| - 'unsafeCleanup === true with issue62 structure': { |
194 |
| - topic: function () { |
195 |
| - Test.testIssue62Sync(this.callback); |
196 |
| - }, |
197 |
| - |
198 |
| - 'should not return with an error': assert.isNull, |
199 |
| - 'should return with a name': Test.assertName, |
200 |
| - 'should not exist': function (err, name) { |
201 |
| - assert.ok(!existsSync(name), 'Directory should be removed'); |
202 |
| - } |
203 |
| - }, |
204 |
| - |
205 |
| - 'unsafeCleanup === false': { |
206 |
| - topic: function () { |
207 |
| - Test.testUnsafeCleanupSync('0', this.callback); |
208 |
| - }, |
209 |
| - |
210 |
| - 'should not return with an error': assert.isNull, |
211 |
| - 'should return with a name': Test.assertName, |
212 |
| - 'should be a directory': function (err, name) { |
213 |
| - _testDir(040700)({name:name}); |
214 |
| - // make sure that everything gets cleaned up |
215 |
| - fs.unlinkSync(path.join(name, 'should-be-removed.file')); |
216 |
| - fs.unlinkSync(path.join(name, 'symlinkme-target')); |
217 |
| - fs.rmdirSync(name); |
218 |
| - } |
219 |
| - }, |
220 |
| - |
221 |
| - 'remove callback': { |
222 |
| - topic: function () { |
223 |
| - return tmp.dirSync(); |
224 |
| - }, |
225 |
| - |
226 |
| - 'should return with a name': Test.assertNameSync, |
227 |
| - 'removeCallback should remove directory': function (result) { |
228 |
| - result.removeCallback(); |
229 |
| - assert.ok(!existsSync(result.name), 'Directory should be removed'); |
230 |
| - } |
231 |
| - } |
232 |
| -}).exportTo(module); |
0 commit comments