forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplatformData.test.ts
More file actions
84 lines (70 loc) · 3.67 KB
/
Copy pathplatformData.test.ts
File metadata and controls
84 lines (70 loc) · 3.67 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
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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// tslint:disable:no-unused-variable
import * as assert from 'assert';
import * as TypeMoq from 'typemoq';
import { PlatformData } from '../../client/activation/platformData';
import { IFileSystem, IPlatformService } from '../../client/common/platform/types';
import { initialize } from '../initialize';
const testDataWinMac = [
{ isWindows: true, is64Bit: true, expectedName: 'win-x64' },
{ isWindows: true, is64Bit: false, expectedName: 'win-x86' },
{ isWindows: false, is64Bit: true, expectedName: 'osx-x64' }
];
const testDataLinux = [
{ name: 'centos', expectedName: 'centos-x64' },
{ name: 'debian', expectedName: 'debian-x64' },
{ name: 'fedora', expectedName: 'fedora-x64' },
{ name: 'ol', expectedName: 'ol-x64' },
{ name: 'opensuse', expectedName: 'opensuse-x64' },
{ name: 'rhel', expectedName: 'rhel-x64' },
{ name: 'ubuntu', expectedName: 'ubuntu-x64' }
];
const testDataModuleName = [
{ isWindows: true, expectedName: 'Microsoft.PythonTools.VsCode.exe' },
{ isWindows: false, expectedName: 'Microsoft.PythonTools.VsCode' }
];
// tslint:disable-next-line:max-func-body-length
suite('Activation - platform data', () => {
suiteSetup(initialize);
test('Name and hash (Windows/Mac)', async () => {
for (const t of testDataWinMac) {
const platformService = TypeMoq.Mock.ofType<IPlatformService>();
platformService.setup(x => x.isWindows).returns(() => t.isWindows);
platformService.setup(x => x.isMac).returns(() => !t.isWindows);
platformService.setup(x => x.is64bit).returns(() => t.is64Bit);
const fs = TypeMoq.Mock.ofType<IFileSystem>();
const pd = new PlatformData(platformService.object, fs.object);
let actual = await pd.getPlatformName();
assert.equal(actual, t.expectedName, `${actual} does not match ${t.expectedName}`);
actual = await pd.getExpectedHash();
assert.equal(actual, t.expectedName, `${actual} hash not match ${t.expectedName}`);
}
});
test('Name and hash (Linux)', async () => {
for (const t of testDataLinux) {
const platformService = TypeMoq.Mock.ofType<IPlatformService>();
platformService.setup(x => x.isWindows).returns(() => false);
platformService.setup(x => x.isMac).returns(() => false);
platformService.setup(x => x.isLinux).returns(() => true);
platformService.setup(x => x.is64bit).returns(() => true);
const fs = TypeMoq.Mock.ofType<IFileSystem>();
fs.setup(x => x.readFile(TypeMoq.It.isAnyString())).returns(() => Promise.resolve(`NAME="name"\nID=${t.name}\nID_LIKE=debian`));
const pd = new PlatformData(platformService.object, fs.object);
let actual = await pd.getPlatformName();
assert.equal(actual, t.expectedName, `${actual} does not match ${t.expectedName}`);
actual = await pd.getExpectedHash();
assert.equal(actual, t.expectedName, `${actual} hash not match ${t.expectedName}`);
}
});
test('Module name', async () => {
for (const t of testDataModuleName) {
const platformService = TypeMoq.Mock.ofType<IPlatformService>();
platformService.setup(x => x.isWindows).returns(() => t.isWindows);
const fs = TypeMoq.Mock.ofType<IFileSystem>();
const pd = new PlatformData(platformService.object, fs.object);
const actual = pd.getEngineExecutableName();
assert.equal(actual, t.expectedName, `${actual} does not match ${t.expectedName}`);
}
});
});