-
Notifications
You must be signed in to change notification settings - Fork 30.9k
/
Copy pathreadonlyFileSystem.test.ts
63 lines (57 loc) · 2.43 KB
/
readonlyFileSystem.test.ts
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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import * as vscode from 'vscode';
import { TestFS } from '../memfs';
import { assertNoRpc, closeAllEditors } from '../utils';
suite('vscode API - file system', () => {
teardown(async function () {
assertNoRpc();
await closeAllEditors();
});
test('readonly file system - boolean', async function () {
const fs = new TestFS('this-fs', false);
const reg = vscode.workspace.registerFileSystemProvider(fs.scheme, fs, { isReadonly: true });
let error: any | undefined;
try {
await vscode.workspace.fs.writeFile(vscode.Uri.parse('this-fs:/foo.txt'), Buffer.from('Hello World'));
} catch (e) {
error = e;
}
assert.strictEqual(vscode.workspace.fs.isWritableFileSystem('this-fs'), false);
assert.strictEqual(error instanceof vscode.FileSystemError, true);
const fileError: vscode.FileSystemError = error;
assert.strictEqual(fileError.code, 'NoPermissions');
reg.dispose();
});
test('readonly file system - markdown', async function () {
const fs = new TestFS('this-fs', false);
const reg = vscode.workspace.registerFileSystemProvider(fs.scheme, fs, { isReadonly: new vscode.MarkdownString('This file is readonly.') });
let error: any | undefined;
try {
await vscode.workspace.fs.writeFile(vscode.Uri.parse('this-fs:/foo.txt'), Buffer.from('Hello World'));
} catch (e) {
error = e;
}
assert.strictEqual(vscode.workspace.fs.isWritableFileSystem('this-fs'), false);
assert.strictEqual(error instanceof vscode.FileSystemError, true);
const fileError: vscode.FileSystemError = error;
assert.strictEqual(fileError.code, 'NoPermissions');
reg.dispose();
});
test('writeable file system', async function () {
const fs = new TestFS('this-fs', false);
const reg = vscode.workspace.registerFileSystemProvider(fs.scheme, fs);
let error: any | undefined;
try {
await vscode.workspace.fs.writeFile(vscode.Uri.parse('this-fs:/foo.txt'), Buffer.from('Hello World'));
} catch (e) {
error = e;
}
assert.strictEqual(vscode.workspace.fs.isWritableFileSystem('this-fs'), true);
assert.strictEqual(error, undefined);
reg.dispose();
});
});