|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +'use strict'; |
| 5 | + |
| 6 | +// tslint:disable:no-unused-variable |
| 7 | + |
| 8 | +import * as assert from 'assert'; |
| 9 | +import * as TypeMoq from 'typemoq'; |
| 10 | +import { LanguageServerDownloader } from '../../client/activation/downloader'; |
| 11 | +import { IFileSystem, IPlatformService } from '../../client/common/platform/types'; |
| 12 | +import { IOutputChannel } from '../../client/common/types'; |
| 13 | +import { IServiceContainer } from '../../client/ioc/types'; |
| 14 | + |
| 15 | +const downloadUriPrefix = 'https://pvsc.blob.core.windows.net/python-language-server'; |
| 16 | +const downloadBaseFileName = 'Python-Language-Server'; |
| 17 | +const downloadVersion = '0.1.0'; |
| 18 | +const downloadFileExtension = '.nupkg'; |
| 19 | + |
| 20 | +suite('Activation - Downloader', () => { |
| 21 | + let languageServerDownloader: LanguageServerDownloader; |
| 22 | + let serviceContainer: TypeMoq.IMock<IServiceContainer>; |
| 23 | + let platformService: TypeMoq.IMock<IPlatformService>; |
| 24 | + setup(() => { |
| 25 | + serviceContainer = TypeMoq.Mock.ofType<IServiceContainer>(); |
| 26 | + platformService = TypeMoq.Mock.ofType<IPlatformService>(); |
| 27 | + const fs = TypeMoq.Mock.ofType<IFileSystem>(); |
| 28 | + const output = TypeMoq.Mock.ofType<IOutputChannel>(); |
| 29 | + |
| 30 | + serviceContainer.setup(c => c.get(TypeMoq.It.isValue(IOutputChannel), TypeMoq.It.isAny())).returns(() => output.object); |
| 31 | + serviceContainer.setup(c => c.get(TypeMoq.It.isValue(IPlatformService))).returns(() => platformService.object); |
| 32 | + serviceContainer.setup(c => c.get(TypeMoq.It.isValue(IFileSystem))).returns(() => fs.object); |
| 33 | + |
| 34 | + languageServerDownloader = new LanguageServerDownloader(serviceContainer.object, ''); |
| 35 | + }); |
| 36 | + type PlatformIdentifier = { |
| 37 | + windows?: boolean; |
| 38 | + mac?: boolean; |
| 39 | + linux?: boolean; |
| 40 | + is64Bit?: boolean; |
| 41 | + }; |
| 42 | + function setupPlatform(platform: PlatformIdentifier) { |
| 43 | + platformService.setup(x => x.isWindows).returns(() => platform.windows === true); |
| 44 | + platformService.setup(x => x.isMac).returns(() => platform.mac === true); |
| 45 | + platformService.setup(x => x.isLinux).returns(() => platform.linux === true); |
| 46 | + platformService.setup(x => x.is64bit).returns(() => platform.is64Bit === true); |
| 47 | + } |
| 48 | + test('Windows 32Bit', async () => { |
| 49 | + setupPlatform({ windows: true }); |
| 50 | + const link = await languageServerDownloader.getDownloadUri(); |
| 51 | + assert.equal(link, `${downloadUriPrefix}/${downloadBaseFileName}-win-x86.${downloadVersion}${downloadFileExtension}`); |
| 52 | + }); |
| 53 | + test('Windows 64Bit', async () => { |
| 54 | + setupPlatform({ windows: true, is64Bit: true }); |
| 55 | + const link = await languageServerDownloader.getDownloadUri(); |
| 56 | + assert.equal(link, `${downloadUriPrefix}/${downloadBaseFileName}-win-x64.${downloadVersion}${downloadFileExtension}`); |
| 57 | + }); |
| 58 | + test('Mac 64Bit', async () => { |
| 59 | + setupPlatform({ mac: true, is64Bit: true }); |
| 60 | + const link = await languageServerDownloader.getDownloadUri(); |
| 61 | + assert.equal(link, `${downloadUriPrefix}/${downloadBaseFileName}-osx-x64.${downloadVersion}${downloadFileExtension}`); |
| 62 | + }); |
| 63 | + test('Linux 64Bit', async () => { |
| 64 | + setupPlatform({ linux: true, is64Bit: true }); |
| 65 | + const link = await languageServerDownloader.getDownloadUri(); |
| 66 | + assert.equal(link, `${downloadUriPrefix}/${downloadBaseFileName}-linux-x64.${downloadVersion}${downloadFileExtension}`); |
| 67 | + }); |
| 68 | +}); |
0 commit comments