Modified the tests
This commit is contained in:
Родитель
aad9d88706
Коммит
5dd1a7d6da
|
@ -34,10 +34,9 @@ suite('OmnisharpDownloader', () => {
|
|||
setup(async () => {
|
||||
eventStream = new EventStream();
|
||||
eventBus = new TestEventBus(eventStream);
|
||||
downloader = new OmnisharpDownloader(networkSettingsProvider, eventStream, testPackageJSON, platformInfo);
|
||||
tmpDir = await CreateTmpDir(true);
|
||||
extensionPath = tmpDir.name;
|
||||
util.setExtensionPath(extensionPath);
|
||||
downloader = new OmnisharpDownloader(networkSettingsProvider, eventStream, testPackageJSON, platformInfo, extensionPath);
|
||||
server = await MockHttpsServer.CreateMockHttpsServer();
|
||||
testZip = await TestZip.createTestZipAsync(createTestFile("Foo", "foo.txt"));
|
||||
await server.start();
|
||||
|
|
|
@ -27,7 +27,7 @@ suite(OmnisharpManager.name, () => {
|
|||
const latestfilePath = "latestPath";
|
||||
const installPath = "somePath";
|
||||
let tmpInstallDir: TmpAsset;
|
||||
let tmpInstallPath: string;
|
||||
let extensionPath: string;
|
||||
let tmpFile: TmpAsset;
|
||||
let testZip: TestZip;
|
||||
|
||||
|
@ -63,9 +63,8 @@ suite(OmnisharpManager.name, () => {
|
|||
server = await MockHttpsServer.CreateMockHttpsServer();
|
||||
await server.start();
|
||||
tmpInstallDir = await CreateTmpDir(true);
|
||||
tmpInstallPath = tmpInstallDir.name;
|
||||
util.setExtensionPath(tmpInstallPath);
|
||||
manager = GetTestOmniSharpManager(elem.platformInfo, eventStream);
|
||||
extensionPath = tmpInstallDir.name;
|
||||
manager = GetTestOmniSharpManager(elem.platformInfo, eventStream, extensionPath);
|
||||
testZip = await TestZip.createTestZipAsync(createTestFile("Foo", "foo.txt"));
|
||||
server.addRequestHandler('GET', `/releases/${testVersion}/omnisharp-${elem.platformId}.zip`, 200, {
|
||||
"content-type": "application/zip",
|
||||
|
@ -83,56 +82,56 @@ suite(OmnisharpManager.name, () => {
|
|||
});
|
||||
|
||||
test('Throws error if the path is neither an absolute path nor a valid semver, nor the string "latest"', async () => {
|
||||
expect(manager.GetOmniSharpLaunchInfo(defaultVersion, "Some incorrect path", server.baseUrl, latestfilePath, installPath, tmpInstallPath)).to.be.rejectedWith(Error);
|
||||
expect(manager.GetOmniSharpLaunchInfo(defaultVersion, "Some incorrect path", server.baseUrl, latestfilePath, installPath, extensionPath)).to.be.rejectedWith(Error);
|
||||
});
|
||||
|
||||
test('Throws error when the specified path is an invalid semver', async () => {
|
||||
expect(manager.GetOmniSharpLaunchInfo(defaultVersion, "a.b.c", server.baseUrl, latestfilePath, installPath, tmpInstallPath)).to.be.rejectedWith(Error);
|
||||
expect(manager.GetOmniSharpLaunchInfo(defaultVersion, "a.b.c", server.baseUrl, latestfilePath, installPath, extensionPath)).to.be.rejectedWith(Error);
|
||||
});
|
||||
|
||||
test('Returns the same path if absolute path to an existing file is passed', async () => {
|
||||
tmpFile = await CreateTmpFile();
|
||||
let launchInfo = await manager.GetOmniSharpLaunchInfo(defaultVersion, tmpFile.name, server.baseUrl, latestfilePath, installPath, tmpInstallPath);
|
||||
let launchInfo = await manager.GetOmniSharpLaunchInfo(defaultVersion, tmpFile.name, server.baseUrl, latestfilePath, installPath, extensionPath);
|
||||
expect(launchInfo.LaunchPath).to.be.equal(tmpFile.name);
|
||||
});
|
||||
|
||||
test('Returns the default path if the omnisharp path is not set', async () => {
|
||||
let launchInfo = await manager.GetOmniSharpLaunchInfo(defaultVersion, "", server.baseUrl, latestfilePath, installPath, tmpInstallPath);
|
||||
expect(launchInfo.LaunchPath).to.be.equal(path.join(tmpInstallPath, ".omnisharp", defaultVersion, elem.executable));
|
||||
let launchInfo = await manager.GetOmniSharpLaunchInfo(defaultVersion, "", server.baseUrl, latestfilePath, installPath, extensionPath);
|
||||
expect(launchInfo.LaunchPath).to.be.equal(path.join(extensionPath, ".omnisharp", defaultVersion, elem.executable));
|
||||
if (elem.platformInfo.isWindows()) {
|
||||
expect(launchInfo.MonoLaunchPath).to.be.undefined;
|
||||
}
|
||||
else {
|
||||
expect(launchInfo.MonoLaunchPath).to.be.equal(path.join(tmpInstallPath, ".omnisharp", defaultVersion, "omnisharp", "OmniSharp.exe"));
|
||||
expect(launchInfo.MonoLaunchPath).to.be.equal(path.join(extensionPath, ".omnisharp", defaultVersion, "omnisharp", "OmniSharp.exe"));
|
||||
}
|
||||
});
|
||||
|
||||
test('Installs the latest version and returns the launch path ', async () => {
|
||||
let launchInfo = await manager.GetOmniSharpLaunchInfo(defaultVersion, "latest", server.baseUrl, latestfilePath, installPath, tmpInstallPath);
|
||||
expect(launchInfo.LaunchPath).to.be.equal(path.join(tmpInstallPath, installPath, latestVersion, elem.executable));
|
||||
let launchInfo = await manager.GetOmniSharpLaunchInfo(defaultVersion, "latest", server.baseUrl, latestfilePath, installPath, extensionPath);
|
||||
expect(launchInfo.LaunchPath).to.be.equal(path.join(extensionPath, installPath, latestVersion, elem.executable));
|
||||
if (elem.platformInfo.isWindows()) {
|
||||
expect(launchInfo.MonoLaunchPath).to.be.undefined;
|
||||
}
|
||||
else {
|
||||
expect(launchInfo.MonoLaunchPath).to.be.equal(path.join(tmpInstallPath, installPath, latestVersion, "omnisharp", "OmniSharp.exe"));
|
||||
expect(launchInfo.MonoLaunchPath).to.be.equal(path.join(extensionPath, installPath, latestVersion, "omnisharp", "OmniSharp.exe"));
|
||||
}
|
||||
});
|
||||
|
||||
test('Installs the test version and returns the launch path', async () => {
|
||||
let launchInfo = await manager.GetOmniSharpLaunchInfo(defaultVersion, testVersion, server.baseUrl, latestfilePath, installPath, tmpInstallPath);
|
||||
expect(launchInfo.LaunchPath).to.be.equal(path.join(tmpInstallPath, installPath, testVersion, elem.executable));
|
||||
let launchInfo = await manager.GetOmniSharpLaunchInfo(defaultVersion, testVersion, server.baseUrl, latestfilePath, installPath, extensionPath);
|
||||
expect(launchInfo.LaunchPath).to.be.equal(path.join(extensionPath, installPath, testVersion, elem.executable));
|
||||
if (elem.platformInfo.isWindows()) {
|
||||
expect(launchInfo.MonoLaunchPath).to.be.undefined;
|
||||
}
|
||||
else {
|
||||
expect(launchInfo.MonoLaunchPath).to.be.equal(path.join(tmpInstallPath, installPath, testVersion, "omnisharp", "OmniSharp.exe"));
|
||||
expect(launchInfo.MonoLaunchPath).to.be.equal(path.join(extensionPath, installPath, testVersion, "omnisharp", "OmniSharp.exe"));
|
||||
}
|
||||
});
|
||||
|
||||
test('Downloads package from given url and installs them at the specified path', async () => {
|
||||
await manager.GetOmniSharpLaunchInfo(defaultVersion, testVersion, server.baseUrl, latestfilePath, installPath, tmpInstallPath);
|
||||
await manager.GetOmniSharpLaunchInfo(defaultVersion, testVersion, server.baseUrl, latestfilePath, installPath, extensionPath);
|
||||
for (let elem of testZip.files) {
|
||||
let filePath = path.join(tmpInstallPath, installPath, testVersion, elem.path);
|
||||
let filePath = path.join(extensionPath, installPath, testVersion, elem.path);
|
||||
expect(await util.fileExists(filePath)).to.be.true;
|
||||
}
|
||||
});
|
||||
|
@ -146,11 +145,11 @@ suite(OmnisharpManager.name, () => {
|
|||
tmpFile = undefined;
|
||||
}
|
||||
tmpInstallDir.dispose();
|
||||
tmpInstallPath = undefined;
|
||||
extensionPath = undefined;
|
||||
});
|
||||
});
|
||||
|
||||
function GetTestOmniSharpManager(platformInfo: PlatformInformation, eventStream: EventStream): OmnisharpManager {
|
||||
let downloader = new OmnisharpDownloader(() => new NetworkSettings(undefined, false), eventStream, testPackageJSON, platformInfo);
|
||||
function GetTestOmniSharpManager(platformInfo: PlatformInformation, eventStream: EventStream, extensionPath: string): OmnisharpManager {
|
||||
let downloader = new OmnisharpDownloader(() => new NetworkSettings(undefined, false), eventStream, testPackageJSON, platformInfo, extensionPath);
|
||||
return new OmnisharpManager(downloader, platformInfo);
|
||||
}
|
|
@ -3,19 +3,20 @@
|
|||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
import * as chai from 'chai';
|
||||
import * as util from '../../../src/common';
|
||||
import { CreateTmpFile, TmpAsset } from "../../../src/CreateTmpAsset";
|
||||
import { PlatformInformation } from "../../../src/platform";
|
||||
import { filterPackages } from "../../../src/packageManager/PackageFilterer";
|
||||
import { ResolveFilePaths } from "../../../src/packageManager/PackageFilePathResolver";
|
||||
import { IPackage } from "../../../src/packageManager/Package";
|
||||
import { Package } from '../../../src/packageManager/Package';
|
||||
import { InstallablePackage } from '../../../src/packageManager/InstallablePackage';
|
||||
import { AbsolutePath } from '../../../src/packageManager/AbsolutePath';
|
||||
|
||||
let expect = chai.expect;
|
||||
|
||||
suite('PackageFilterer', () => {
|
||||
let tmpFile: TmpAsset;
|
||||
const extensionPath = "ExtensionPath";
|
||||
const packages = <IPackage[]>[
|
||||
let installablePackages: InstallablePackage[];
|
||||
const extensionPath = "/ExtensionPath";
|
||||
const packages = <Package[]>[
|
||||
{
|
||||
"description": "Platfrom1-Architecture1 uninstalled package",
|
||||
"platforms": [ "platform1" ],
|
||||
|
@ -62,15 +63,13 @@ suite('PackageFilterer', () => {
|
|||
|
||||
setup(async () => {
|
||||
tmpFile = await CreateTmpFile();
|
||||
packages[1].installTestPath = tmpFile.name;
|
||||
util.setExtensionPath(extensionPath);
|
||||
// we need to set the extension path because fileresolver uses it
|
||||
packages.forEach(pkg => ResolveFilePaths(pkg));
|
||||
installablePackages = packages.map(pkg => InstallablePackage.getInstallablePackage(pkg, extensionPath));
|
||||
installablePackages[1].installTestPath = new AbsolutePath(tmpFile.name);
|
||||
});
|
||||
|
||||
test('Filters the packages based on Platform Information', async () => {
|
||||
let platformInfo = new PlatformInformation("platform2", "architecture2");
|
||||
let filteredPackages = await filterPackages(packages, platformInfo);
|
||||
let filteredPackages = await filterPackages(installablePackages, platformInfo);
|
||||
expect(filteredPackages.length).to.be.equal(1);
|
||||
expect(filteredPackages[0].description).to.be.equal("Platfrom2-Architecture2 uninstalled package");
|
||||
expect(filteredPackages[0].platforms[0]).to.be.equal("platform2");
|
||||
|
@ -79,7 +78,7 @@ suite('PackageFilterer', () => {
|
|||
|
||||
test('Returns only uninstalled packages', async () => {
|
||||
let platformInfo = new PlatformInformation("platform1", "architecture1");
|
||||
let filteredPackages = await filterPackages(packages, platformInfo);
|
||||
let filteredPackages = await filterPackages(installablePackages, platformInfo);
|
||||
expect(filteredPackages.length).to.be.equal(1);
|
||||
expect(filteredPackages[0].description).to.be.equal("Platfrom1-Architecture1 uninstalled package");
|
||||
expect(filteredPackages[0].platforms[0]).to.be.equal("platform1");
|
||||
|
@ -88,7 +87,7 @@ suite('PackageFilterer', () => {
|
|||
|
||||
test('Doesnot filter the package if install test path is not specified', async () => {
|
||||
let platformInfo = new PlatformInformation("platform3", "architecture3");
|
||||
let filteredPackages = await filterPackages(packages, platformInfo);
|
||||
let filteredPackages = await filterPackages(installablePackages, platformInfo);
|
||||
expect(filteredPackages.length).to.be.equal(1);
|
||||
expect(filteredPackages[0].description).to.be.equal("Platfrom3-Architecture3 with no installTestPath specified");
|
||||
expect(filteredPackages[0].platforms[0]).to.be.equal("platform3");
|
||||
|
|
|
@ -15,6 +15,7 @@ import { BaseEvent, InstallationStart, ZipError } from '../../../src/omnisharp/l
|
|||
import { createTestFile } from '../testAssets/TestFile';
|
||||
import TestZip from '../testAssets/TestZip';
|
||||
import TestEventBus from '../testAssets/TestEventBus';
|
||||
import { AbsolutePath } from '../../../src/packageManager/AbsolutePath';
|
||||
|
||||
chai.use(require("chai-as-promised"));
|
||||
let expect = chai.expect;
|
||||
|
@ -31,7 +32,7 @@ suite('ZipInstaller', () => {
|
|||
];
|
||||
|
||||
let tmpInstallDir: TmpAsset;
|
||||
let installationPath: string;
|
||||
let installationPath: AbsolutePath;
|
||||
let testZip: TestZip;
|
||||
const fileDescription = "somefile";
|
||||
let eventStream: EventStream;
|
||||
|
@ -41,7 +42,7 @@ suite('ZipInstaller', () => {
|
|||
eventStream = new EventStream();
|
||||
eventBus = new TestEventBus(eventStream);
|
||||
tmpInstallDir = await CreateTmpDir(true);
|
||||
installationPath = tmpInstallDir.name;
|
||||
installationPath = new AbsolutePath(tmpInstallDir.name);
|
||||
testZip = await TestZip.createTestZipAsync(...files, ...binaries);
|
||||
util.setExtensionPath(tmpInstallDir.name);
|
||||
});
|
||||
|
@ -49,7 +50,7 @@ suite('ZipInstaller', () => {
|
|||
test('The folder is unzipped and all the files are present at the expected paths', async () => {
|
||||
await InstallZip(testZip.buffer, fileDescription, installationPath, [], eventStream);
|
||||
for (let elem of testZip.files) {
|
||||
let filePath = path.join(installationPath, elem.path);
|
||||
let filePath = path.join(installationPath.path, elem.path);
|
||||
expect(await util.fileExists(filePath)).to.be.true;
|
||||
}
|
||||
});
|
||||
|
@ -64,11 +65,11 @@ suite('ZipInstaller', () => {
|
|||
|
||||
test('The folder is unzipped and the binaries have the expected permissions(except on Windows)', async () => {
|
||||
if (!((await PlatformInformation.GetCurrent()).isWindows())) {
|
||||
let resolvedBinaryPaths = binaries.map(binary => path.join(installationPath, binary.path));
|
||||
await InstallZip(testZip.buffer, fileDescription, installationPath, resolvedBinaryPaths, eventStream);
|
||||
for (let binaryPath of resolvedBinaryPaths) {
|
||||
expect(await util.fileExists(binaryPath)).to.be.true;
|
||||
let mode = (await fs.stat(binaryPath)).mode;
|
||||
let absoluteBinaries = binaries.map(binary => AbsolutePath.getAbsolutePath(installationPath.path, binary.path));
|
||||
await InstallZip(testZip.buffer, fileDescription, installationPath, absoluteBinaries, eventStream);
|
||||
for (let binaryPath of absoluteBinaries) {
|
||||
expect(await util.fileExists(binaryPath.path)).to.be.true;
|
||||
let mode = (await fs.stat(binaryPath.path)).mode;
|
||||
expect(mode & 0o7777).to.be.equal(0o755, `Expected mode for path ${binaryPath}`);
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче