forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathfs-temp.unit.test.ts
More file actions
56 lines (47 loc) · 1.64 KB
/
fs-temp.unit.test.ts
File metadata and controls
56 lines (47 loc) · 1.64 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { expect } from 'chai';
import * as TypeMoq from 'typemoq';
import { TemporaryFileSystem } from '../../../client/common/platform/fs-temp';
interface IDeps {
// tmp module
fileSync(config: {
postfix?: string;
mode?: number;
}): {
name: string;
fd: number;
removeCallback(): void;
};
}
suite('FileSystem - temp files', () => {
let deps: TypeMoq.IMock<IDeps>;
let temp: TemporaryFileSystem;
setup(() => {
deps = TypeMoq.Mock.ofType<IDeps>(undefined, TypeMoq.MockBehavior.Strict);
temp = new TemporaryFileSystem(deps.object);
});
function verifyAll() {
deps.verifyAll();
}
suite('createFile', () => {
test(`fails if the raw call fails`, async () => {
const failure = new Error('oops');
deps.setup((d) => d.fileSync({ postfix: '.tmp', mode: undefined }))
// fail with an arbitrary error
.throws(failure);
const promise = temp.createFile('.tmp');
await expect(promise).to.eventually.be.rejected;
verifyAll();
});
test(`fails if the raw call "returns" an error`, async () => {
const failure = new Error('oops');
deps.setup((d) => d.fileSync({ postfix: '.tmp', mode: undefined })).callback((_cfg, cb) =>
cb(failure, '...', -1, () => {}),
);
const promise = temp.createFile('.tmp');
await expect(promise).to.eventually.be.rejected;
verifyAll();
});
});
});