Skip to content

Commit 5dd1a7d

Browse files
committed
Modified the tests
1 parent aad9d88 commit 5dd1a7d

File tree

4 files changed

+41
-43
lines changed

4 files changed

+41
-43
lines changed

test/unitTests/OmnisharpDownloader.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,9 @@ suite('OmnisharpDownloader', () => {
3434
setup(async () => {
3535
eventStream = new EventStream();
3636
eventBus = new TestEventBus(eventStream);
37-
downloader = new OmnisharpDownloader(networkSettingsProvider, eventStream, testPackageJSON, platformInfo);
3837
tmpDir = await CreateTmpDir(true);
3938
extensionPath = tmpDir.name;
40-
util.setExtensionPath(extensionPath);
39+
downloader = new OmnisharpDownloader(networkSettingsProvider, eventStream, testPackageJSON, platformInfo, extensionPath);
4140
server = await MockHttpsServer.CreateMockHttpsServer();
4241
testZip = await TestZip.createTestZipAsync(createTestFile("Foo", "foo.txt"));
4342
await server.start();

test/unitTests/OmnisharpManager.test.ts

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ suite(OmnisharpManager.name, () => {
2727
const latestfilePath = "latestPath";
2828
const installPath = "somePath";
2929
let tmpInstallDir: TmpAsset;
30-
let tmpInstallPath: string;
30+
let extensionPath: string;
3131
let tmpFile: TmpAsset;
3232
let testZip: TestZip;
3333

@@ -63,9 +63,8 @@ suite(OmnisharpManager.name, () => {
6363
server = await MockHttpsServer.CreateMockHttpsServer();
6464
await server.start();
6565
tmpInstallDir = await CreateTmpDir(true);
66-
tmpInstallPath = tmpInstallDir.name;
67-
util.setExtensionPath(tmpInstallPath);
68-
manager = GetTestOmniSharpManager(elem.platformInfo, eventStream);
66+
extensionPath = tmpInstallDir.name;
67+
manager = GetTestOmniSharpManager(elem.platformInfo, eventStream, extensionPath);
6968
testZip = await TestZip.createTestZipAsync(createTestFile("Foo", "foo.txt"));
7069
server.addRequestHandler('GET', `/releases/${testVersion}/omnisharp-${elem.platformId}.zip`, 200, {
7170
"content-type": "application/zip",
@@ -83,56 +82,56 @@ suite(OmnisharpManager.name, () => {
8382
});
8483

8584
test('Throws error if the path is neither an absolute path nor a valid semver, nor the string "latest"', async () => {
86-
expect(manager.GetOmniSharpLaunchInfo(defaultVersion, "Some incorrect path", server.baseUrl, latestfilePath, installPath, tmpInstallPath)).to.be.rejectedWith(Error);
85+
expect(manager.GetOmniSharpLaunchInfo(defaultVersion, "Some incorrect path", server.baseUrl, latestfilePath, installPath, extensionPath)).to.be.rejectedWith(Error);
8786
});
8887

8988
test('Throws error when the specified path is an invalid semver', async () => {
90-
expect(manager.GetOmniSharpLaunchInfo(defaultVersion, "a.b.c", server.baseUrl, latestfilePath, installPath, tmpInstallPath)).to.be.rejectedWith(Error);
89+
expect(manager.GetOmniSharpLaunchInfo(defaultVersion, "a.b.c", server.baseUrl, latestfilePath, installPath, extensionPath)).to.be.rejectedWith(Error);
9190
});
9291

9392
test('Returns the same path if absolute path to an existing file is passed', async () => {
9493
tmpFile = await CreateTmpFile();
95-
let launchInfo = await manager.GetOmniSharpLaunchInfo(defaultVersion, tmpFile.name, server.baseUrl, latestfilePath, installPath, tmpInstallPath);
94+
let launchInfo = await manager.GetOmniSharpLaunchInfo(defaultVersion, tmpFile.name, server.baseUrl, latestfilePath, installPath, extensionPath);
9695
expect(launchInfo.LaunchPath).to.be.equal(tmpFile.name);
9796
});
9897

9998
test('Returns the default path if the omnisharp path is not set', async () => {
100-
let launchInfo = await manager.GetOmniSharpLaunchInfo(defaultVersion, "", server.baseUrl, latestfilePath, installPath, tmpInstallPath);
101-
expect(launchInfo.LaunchPath).to.be.equal(path.join(tmpInstallPath, ".omnisharp", defaultVersion, elem.executable));
99+
let launchInfo = await manager.GetOmniSharpLaunchInfo(defaultVersion, "", server.baseUrl, latestfilePath, installPath, extensionPath);
100+
expect(launchInfo.LaunchPath).to.be.equal(path.join(extensionPath, ".omnisharp", defaultVersion, elem.executable));
102101
if (elem.platformInfo.isWindows()) {
103102
expect(launchInfo.MonoLaunchPath).to.be.undefined;
104103
}
105104
else {
106-
expect(launchInfo.MonoLaunchPath).to.be.equal(path.join(tmpInstallPath, ".omnisharp", defaultVersion, "omnisharp", "OmniSharp.exe"));
105+
expect(launchInfo.MonoLaunchPath).to.be.equal(path.join(extensionPath, ".omnisharp", defaultVersion, "omnisharp", "OmniSharp.exe"));
107106
}
108107
});
109108

110109
test('Installs the latest version and returns the launch path ', async () => {
111-
let launchInfo = await manager.GetOmniSharpLaunchInfo(defaultVersion, "latest", server.baseUrl, latestfilePath, installPath, tmpInstallPath);
112-
expect(launchInfo.LaunchPath).to.be.equal(path.join(tmpInstallPath, installPath, latestVersion, elem.executable));
110+
let launchInfo = await manager.GetOmniSharpLaunchInfo(defaultVersion, "latest", server.baseUrl, latestfilePath, installPath, extensionPath);
111+
expect(launchInfo.LaunchPath).to.be.equal(path.join(extensionPath, installPath, latestVersion, elem.executable));
113112
if (elem.platformInfo.isWindows()) {
114113
expect(launchInfo.MonoLaunchPath).to.be.undefined;
115114
}
116115
else {
117-
expect(launchInfo.MonoLaunchPath).to.be.equal(path.join(tmpInstallPath, installPath, latestVersion, "omnisharp", "OmniSharp.exe"));
116+
expect(launchInfo.MonoLaunchPath).to.be.equal(path.join(extensionPath, installPath, latestVersion, "omnisharp", "OmniSharp.exe"));
118117
}
119118
});
120119

121120
test('Installs the test version and returns the launch path', async () => {
122-
let launchInfo = await manager.GetOmniSharpLaunchInfo(defaultVersion, testVersion, server.baseUrl, latestfilePath, installPath, tmpInstallPath);
123-
expect(launchInfo.LaunchPath).to.be.equal(path.join(tmpInstallPath, installPath, testVersion, elem.executable));
121+
let launchInfo = await manager.GetOmniSharpLaunchInfo(defaultVersion, testVersion, server.baseUrl, latestfilePath, installPath, extensionPath);
122+
expect(launchInfo.LaunchPath).to.be.equal(path.join(extensionPath, installPath, testVersion, elem.executable));
124123
if (elem.platformInfo.isWindows()) {
125124
expect(launchInfo.MonoLaunchPath).to.be.undefined;
126125
}
127126
else {
128-
expect(launchInfo.MonoLaunchPath).to.be.equal(path.join(tmpInstallPath, installPath, testVersion, "omnisharp", "OmniSharp.exe"));
127+
expect(launchInfo.MonoLaunchPath).to.be.equal(path.join(extensionPath, installPath, testVersion, "omnisharp", "OmniSharp.exe"));
129128
}
130129
});
131130

132131
test('Downloads package from given url and installs them at the specified path', async () => {
133-
await manager.GetOmniSharpLaunchInfo(defaultVersion, testVersion, server.baseUrl, latestfilePath, installPath, tmpInstallPath);
132+
await manager.GetOmniSharpLaunchInfo(defaultVersion, testVersion, server.baseUrl, latestfilePath, installPath, extensionPath);
134133
for (let elem of testZip.files) {
135-
let filePath = path.join(tmpInstallPath, installPath, testVersion, elem.path);
134+
let filePath = path.join(extensionPath, installPath, testVersion, elem.path);
136135
expect(await util.fileExists(filePath)).to.be.true;
137136
}
138137
});
@@ -146,11 +145,11 @@ suite(OmnisharpManager.name, () => {
146145
tmpFile = undefined;
147146
}
148147
tmpInstallDir.dispose();
149-
tmpInstallPath = undefined;
148+
extensionPath = undefined;
150149
});
151150
});
152151

153-
function GetTestOmniSharpManager(platformInfo: PlatformInformation, eventStream: EventStream): OmnisharpManager {
154-
let downloader = new OmnisharpDownloader(() => new NetworkSettings(undefined, false), eventStream, testPackageJSON, platformInfo);
152+
function GetTestOmniSharpManager(platformInfo: PlatformInformation, eventStream: EventStream, extensionPath: string): OmnisharpManager {
153+
let downloader = new OmnisharpDownloader(() => new NetworkSettings(undefined, false), eventStream, testPackageJSON, platformInfo, extensionPath);
155154
return new OmnisharpManager(downloader, platformInfo);
156155
}

test/unitTests/Packages/PackageFilterer.test.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,20 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55
import * as chai from 'chai';
6-
import * as util from '../../../src/common';
76
import { CreateTmpFile, TmpAsset } from "../../../src/CreateTmpAsset";
87
import { PlatformInformation } from "../../../src/platform";
98
import { filterPackages } from "../../../src/packageManager/PackageFilterer";
10-
import { ResolveFilePaths } from "../../../src/packageManager/PackageFilePathResolver";
11-
import { IPackage } from "../../../src/packageManager/Package";
9+
import { Package } from '../../../src/packageManager/Package';
10+
import { InstallablePackage } from '../../../src/packageManager/InstallablePackage';
11+
import { AbsolutePath } from '../../../src/packageManager/AbsolutePath';
1212

1313
let expect = chai.expect;
1414

1515
suite('PackageFilterer', () => {
1616
let tmpFile: TmpAsset;
17-
const extensionPath = "ExtensionPath";
18-
const packages = <IPackage[]>[
17+
let installablePackages: InstallablePackage[];
18+
const extensionPath = "/ExtensionPath";
19+
const packages = <Package[]>[
1920
{
2021
"description": "Platfrom1-Architecture1 uninstalled package",
2122
"platforms": [ "platform1" ],
@@ -62,15 +63,13 @@ suite('PackageFilterer', () => {
6263

6364
setup(async () => {
6465
tmpFile = await CreateTmpFile();
65-
packages[1].installTestPath = tmpFile.name;
66-
util.setExtensionPath(extensionPath);
67-
// we need to set the extension path because fileresolver uses it
68-
packages.forEach(pkg => ResolveFilePaths(pkg));
66+
installablePackages = packages.map(pkg => InstallablePackage.getInstallablePackage(pkg, extensionPath));
67+
installablePackages[1].installTestPath = new AbsolutePath(tmpFile.name);
6968
});
7069

7170
test('Filters the packages based on Platform Information', async () => {
7271
let platformInfo = new PlatformInformation("platform2", "architecture2");
73-
let filteredPackages = await filterPackages(packages, platformInfo);
72+
let filteredPackages = await filterPackages(installablePackages, platformInfo);
7473
expect(filteredPackages.length).to.be.equal(1);
7574
expect(filteredPackages[0].description).to.be.equal("Platfrom2-Architecture2 uninstalled package");
7675
expect(filteredPackages[0].platforms[0]).to.be.equal("platform2");
@@ -79,7 +78,7 @@ suite('PackageFilterer', () => {
7978

8079
test('Returns only uninstalled packages', async () => {
8180
let platformInfo = new PlatformInformation("platform1", "architecture1");
82-
let filteredPackages = await filterPackages(packages, platformInfo);
81+
let filteredPackages = await filterPackages(installablePackages, platformInfo);
8382
expect(filteredPackages.length).to.be.equal(1);
8483
expect(filteredPackages[0].description).to.be.equal("Platfrom1-Architecture1 uninstalled package");
8584
expect(filteredPackages[0].platforms[0]).to.be.equal("platform1");
@@ -88,7 +87,7 @@ suite('PackageFilterer', () => {
8887

8988
test('Doesnot filter the package if install test path is not specified', async () => {
9089
let platformInfo = new PlatformInformation("platform3", "architecture3");
91-
let filteredPackages = await filterPackages(packages, platformInfo);
90+
let filteredPackages = await filterPackages(installablePackages, platformInfo);
9291
expect(filteredPackages.length).to.be.equal(1);
9392
expect(filteredPackages[0].description).to.be.equal("Platfrom3-Architecture3 with no installTestPath specified");
9493
expect(filteredPackages[0].platforms[0]).to.be.equal("platform3");

test/unitTests/Packages/ZipInstaller.test.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { BaseEvent, InstallationStart, ZipError } from '../../../src/omnisharp/l
1515
import { createTestFile } from '../testAssets/TestFile';
1616
import TestZip from '../testAssets/TestZip';
1717
import TestEventBus from '../testAssets/TestEventBus';
18+
import { AbsolutePath } from '../../../src/packageManager/AbsolutePath';
1819

1920
chai.use(require("chai-as-promised"));
2021
let expect = chai.expect;
@@ -31,7 +32,7 @@ suite('ZipInstaller', () => {
3132
];
3233

3334
let tmpInstallDir: TmpAsset;
34-
let installationPath: string;
35+
let installationPath: AbsolutePath;
3536
let testZip: TestZip;
3637
const fileDescription = "somefile";
3738
let eventStream: EventStream;
@@ -41,15 +42,15 @@ suite('ZipInstaller', () => {
4142
eventStream = new EventStream();
4243
eventBus = new TestEventBus(eventStream);
4344
tmpInstallDir = await CreateTmpDir(true);
44-
installationPath = tmpInstallDir.name;
45+
installationPath = new AbsolutePath(tmpInstallDir.name);
4546
testZip = await TestZip.createTestZipAsync(...files, ...binaries);
4647
util.setExtensionPath(tmpInstallDir.name);
4748
});
4849

4950
test('The folder is unzipped and all the files are present at the expected paths', async () => {
5051
await InstallZip(testZip.buffer, fileDescription, installationPath, [], eventStream);
5152
for (let elem of testZip.files) {
52-
let filePath = path.join(installationPath, elem.path);
53+
let filePath = path.join(installationPath.path, elem.path);
5354
expect(await util.fileExists(filePath)).to.be.true;
5455
}
5556
});
@@ -64,11 +65,11 @@ suite('ZipInstaller', () => {
6465

6566
test('The folder is unzipped and the binaries have the expected permissions(except on Windows)', async () => {
6667
if (!((await PlatformInformation.GetCurrent()).isWindows())) {
67-
let resolvedBinaryPaths = binaries.map(binary => path.join(installationPath, binary.path));
68-
await InstallZip(testZip.buffer, fileDescription, installationPath, resolvedBinaryPaths, eventStream);
69-
for (let binaryPath of resolvedBinaryPaths) {
70-
expect(await util.fileExists(binaryPath)).to.be.true;
71-
let mode = (await fs.stat(binaryPath)).mode;
68+
let absoluteBinaries = binaries.map(binary => AbsolutePath.getAbsolutePath(installationPath.path, binary.path));
69+
await InstallZip(testZip.buffer, fileDescription, installationPath, absoluteBinaries, eventStream);
70+
for (let binaryPath of absoluteBinaries) {
71+
expect(await util.fileExists(binaryPath.path)).to.be.true;
72+
let mode = (await fs.stat(binaryPath.path)).mode;
7273
expect(mode & 0o7777).to.be.equal(0o755, `Expected mode for path ${binaryPath}`);
7374
}
7475
}

0 commit comments

Comments
 (0)