|
4 | 4 | *--------------------------------------------------------*/
|
5 | 5 |
|
6 | 6 | import * as assert from 'assert';
|
| 7 | +import { defaultCipherList } from 'constants'; |
7 | 8 | import moment = require('moment');
|
8 | 9 | import semver = require('semver');
|
9 | 10 | import sinon = require('sinon');
|
| 11 | +import * as vscode from 'vscode'; |
10 | 12 | import * as lsp from '../../src/goLanguageServer';
|
11 | 13 | import { getTool, Tool } from '../../src/goTools';
|
| 14 | +import { getCheckForToolsUpdatesConfig as getCheckForToolUpdatesConfig, getGoConfig } from '../../src/util'; |
| 15 | + |
| 16 | +suite('getCheckForToolUpdatesConfig tests', () => { |
| 17 | + const CHECK_FOR_UPDATES = 'toolsManagement.checkForUpdates'; |
| 18 | + const LEGACY_CHECK_FOR_UPDATES = 'useGoProxyToCheckForToolUpdates'; |
| 19 | + const defaultConfigInspector = getGoConfig().inspect(CHECK_FOR_UPDATES); |
| 20 | + |
| 21 | + test('default is as expected', () => { |
| 22 | + const {key, defaultValue, globalValue, workspaceValue} = defaultConfigInspector; |
| 23 | + assert.deepStrictEqual( |
| 24 | + { key, defaultValue, globalValue, workspaceValue }, |
| 25 | + { key: `go.${CHECK_FOR_UPDATES}`, defaultValue : 'proxy', globalValue: undefined, workspaceValue: undefined}, |
| 26 | + CHECK_FOR_UPDATES); |
| 27 | + assert.strictEqual(getGoConfig().get(LEGACY_CHECK_FOR_UPDATES), true, LEGACY_CHECK_FOR_UPDATES); |
| 28 | + }); |
| 29 | + |
| 30 | + // wrapper class of vscode.WorkspaceConfiguration - the object returned by |
| 31 | + // vscode.getConfiguration is read-only, and doesn't allow property modification |
| 32 | + // so working with sinon directly doesn't seem possible. |
| 33 | + class TestWorkspaceConfiguration implements vscode.WorkspaceConfiguration { |
| 34 | + constructor(private _wrapped: vscode.WorkspaceConfiguration) {} |
| 35 | + public get<T>(params: string) { return this._wrapped.get<T>(params); } |
| 36 | + public has(params: string) { return this._wrapped.has(params); } |
| 37 | + public inspect<T>(params: string) { return this._wrapped.inspect<T>(params); } |
| 38 | + public update<T>( |
| 39 | + section: string, value: any, |
| 40 | + configurationTarget?: vscode.ConfigurationTarget | boolean, overrideInLanguage?: boolean) { |
| 41 | + return this._wrapped.update(section, value, configurationTarget, overrideInLanguage); |
| 42 | + } |
| 43 | + [key: string]: any; |
| 44 | + } |
| 45 | + |
| 46 | + teardown(() => { sinon.restore(); }); |
| 47 | + |
| 48 | + test('default checkForUpdates returns proxy', () => { |
| 49 | + const gocfg = getGoConfig(); |
| 50 | + assert.strictEqual(getCheckForToolUpdatesConfig(gocfg), 'proxy'); |
| 51 | + }); |
| 52 | + test('local when new config is not set and legacy config is set to false', () => { |
| 53 | + const gocfg = new TestWorkspaceConfiguration(getGoConfig()); |
| 54 | + sinon.stub(gocfg, 'get') |
| 55 | + .withArgs(LEGACY_CHECK_FOR_UPDATES).returns(false); |
| 56 | + |
| 57 | + assert.strictEqual(getCheckForToolUpdatesConfig(gocfg), 'local'); |
| 58 | + }); |
| 59 | + test('proxy when new config is "proxy" and legacy config is set to false', () => { |
| 60 | + const gocfg = new TestWorkspaceConfiguration(getGoConfig()); |
| 61 | + sinon.stub(gocfg, 'get') |
| 62 | + .withArgs(LEGACY_CHECK_FOR_UPDATES).returns(false) |
| 63 | + .withArgs(CHECK_FOR_UPDATES).returns('proxy'); |
| 64 | + sinon.stub(gocfg, 'inspect').withArgs(CHECK_FOR_UPDATES).returns( |
| 65 | + Object.assign({}, defaultConfigInspector, { globalValue: 'proxy' })); |
| 66 | + |
| 67 | + assert.strictEqual(getCheckForToolUpdatesConfig(gocfg), 'proxy'); |
| 68 | + }); |
| 69 | + test('off when new config (workspace) is "off" and legacy config is set to false', () => { |
| 70 | + const gocfg = new TestWorkspaceConfiguration(getGoConfig()); |
| 71 | + sinon.stub(gocfg, 'get') |
| 72 | + .withArgs(LEGACY_CHECK_FOR_UPDATES).returns(false) |
| 73 | + .withArgs(CHECK_FOR_UPDATES).returns('off'); |
| 74 | + sinon.stub(gocfg, 'inspect').withArgs(CHECK_FOR_UPDATES).returns( |
| 75 | + Object.assign({}, defaultConfigInspector, { workspaceValue: 'off' })); |
| 76 | + assert.strictEqual(getCheckForToolUpdatesConfig(gocfg), 'off'); |
| 77 | + }); |
| 78 | +}); |
12 | 79 |
|
13 | 80 | suite('gopls update tests', () => {
|
14 | 81 | test('prompt for update', async () => {
|
@@ -105,7 +172,7 @@ suite('gopls update tests', () => {
|
105 | 172 | enabled: true,
|
106 | 173 | path: 'bad/path/to/gopls',
|
107 | 174 | version: '',
|
108 |
| - checkForUpdates: true, |
| 175 | + checkForUpdates: 'proxy', |
109 | 176 | env: {},
|
110 | 177 | features: {
|
111 | 178 | diagnostics: true,
|
|
0 commit comments