Skip to content

Commit b7b9a3e

Browse files
committed
test/*: use getGoConfig instead of directly calling vscode API
Change-Id: I2338412b72ad8e73d3ea37c85b21edabc28ebccd Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/283260 Trust: Hyang-Ah Hana Kim <[email protected]> Run-TryBot: Hyang-Ah Hana Kim <[email protected]> TryBot-Result: kokoro <[email protected]> Reviewed-by: Suzy Mueller <[email protected]>
1 parent 3e3f506 commit b7b9a3e

File tree

6 files changed

+33
-37
lines changed

6 files changed

+33
-37
lines changed

test/gopls/configuration.test.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,12 @@
44
*--------------------------------------------------------*/
55

66
import * as assert from 'assert';
7-
import moment = require('moment');
8-
import semver = require('semver');
9-
import sinon = require('sinon');
10-
import * as vscode from 'vscode';
7+
import { getGoplsConfig } from '../../src/config';
118
import * as lsp from '../../src/goLanguageServer';
12-
import { getTool, Tool } from '../../src/goTools';
139

1410
suite('gopls configuration tests', () => {
1511
test('filterGoplsDefaultConfigValues', async () => {
16-
const defaultGoplsConfig = vscode.workspace.getConfiguration('gopls');
17-
const defaultGoplsAnalysesConfig = vscode.workspace.getConfiguration('gopls.analyses');
18-
12+
const defaultGoplsConfig = getGoplsConfig();
1913
interface TestCase {
2014
name: string;
2115
section: string;

test/integration/codelens.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import fs = require('fs-extra');
1010
import path = require('path');
1111
import sinon = require('sinon');
1212
import vscode = require('vscode');
13+
import { getGoConfig } from '../../src/config';
1314
import { updateGoVarsFromConfig } from '../../src/goInstallTools';
1415
import { GoRunTestCodeLensProvider } from '../../src/goRunTestCodelens';
1516
import { subTestAtCursor } from '../../src/goTest';
@@ -55,7 +56,7 @@ suite('Code lenses for testing and benchmarking', function () {
5556
return true;
5657
},
5758
});
58-
goConfig = vscode.workspace.getConfiguration('go');
59+
goConfig = getGoConfig();
5960
const uri = vscode.Uri.file(path.join(fixturePath, 'codelens_test.go'));
6061
document = await vscode.workspace.openTextDocument(uri);
6162
});

test/integration/config.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class MockCfg implements vscode.WorkspaceConfiguration {
7676
// getter
7777
Object.defineProperties(this, Object.getOwnPropertyDescriptors(workspaceSettings));
7878
this.map = new Map<string, any>(Object.entries(workspaceSettings));
79-
this.wrapped = vscode.workspace.getConfiguration('go');
79+
this.wrapped = vscode.workspace.getConfiguration('go'); // intentionally using vscode API directly.
8080
}
8181

8282
// tslint:disable: no-any

test/integration/extension.test.ts

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ suite('Go Extension Tests', function () {
192192
}
193193

194194
test('Test Definition Provider using godoc', async () => {
195-
const config = Object.create(vscode.workspace.getConfiguration('go'), {
195+
const config = Object.create(getGoConfig(), {
196196
docsTool: { value: 'godoc' }
197197
});
198198
await testDefinitionProvider(config);
@@ -204,7 +204,7 @@ suite('Go Extension Tests', function () {
204204
// gogetdoc is not installed, so skip the test
205205
return;
206206
}
207-
const config = Object.create(vscode.workspace.getConfiguration('go'), {
207+
const config = Object.create(getGoConfig(), {
208208
docsTool: { value: 'gogetdoc' }
209209
});
210210
await testDefinitionProvider(config);
@@ -243,7 +243,7 @@ encountered.
243243
['s string']
244244
]
245245
];
246-
const config = Object.create(vscode.workspace.getConfiguration('go'), {
246+
const config = Object.create(getGoConfig(), {
247247
docsTool: { value: 'godoc' }
248248
});
249249
await testSignatureHelpProvider(config, testCases);
@@ -286,7 +286,7 @@ It returns the number of bytes written and any write error encountered.
286286
['s string']
287287
]
288288
];
289-
const config = Object.create(vscode.workspace.getConfiguration('go'), {
289+
const config = Object.create(getGoConfig(), {
290290
docsTool: { value: 'gogetdoc' }
291291
});
292292
await testSignatureHelpProvider(config, testCases);
@@ -313,7 +313,7 @@ encountered.
313313
`This is an unexported function so couldn't get this comment on hover :( Not\nanymore!!\n`
314314
]
315315
];
316-
const config = Object.create(vscode.workspace.getConfiguration('go'), {
316+
const config = Object.create(getGoConfig(), {
317317
docsTool: { value: 'godoc' }
318318
});
319319
await testHoverProvider(config, testCases);
@@ -358,7 +358,7 @@ It returns the number of bytes written and any write error encountered.
358358
'IPv4Mask returns the IP mask (in 4-byte form) of the\nIPv4 mask a.b.c.d.\n'
359359
]
360360
];
361-
const config = Object.create(vscode.workspace.getConfiguration('go'), {
361+
const config = Object.create(getGoConfig(), {
362362
docsTool: { value: 'gogetdoc' }
363363
});
364364
await testHoverProvider(config, testCases);
@@ -370,7 +370,7 @@ It returns the number of bytes written and any write error encountered.
370370
sinon.spy(util, 'runTool');
371371
sinon.spy(processutil, 'killProcessTree');
372372

373-
const config = Object.create(vscode.workspace.getConfiguration('go'), {
373+
const config = Object.create(getGoConfig(), {
374374
vetOnSave: { value: 'package' },
375375
vetFlags: { value: ['-all'] },
376376
buildOnSave: { value: 'package' },
@@ -394,7 +394,7 @@ It returns the number of bytes written and any write error encountered.
394394
// the adjustment is made consistently across multiple open text documents.
395395
const file1 = await vscode.workspace.openTextDocument(vscode.Uri.file(path.join(fixturePath, 'linterTest', 'linter_1.go')));
396396
const file2 = await vscode.workspace.openTextDocument(vscode.Uri.file(path.join(fixturePath, 'linterTest', 'linter_2.go')));
397-
const warnings = await goLint(file2.uri, Object.create(vscode.workspace.getConfiguration('go'), {
397+
const warnings = await goLint(file2.uri, Object.create(getGoConfig(), {
398398
lintTool: { value: 'golint' },
399399
lintFlags: { value: [] }
400400
}), 'package');
@@ -412,7 +412,7 @@ It returns the number of bytes written and any write error encountered.
412412
});
413413

414414
test('Error checking', async () => {
415-
const config = Object.create(vscode.workspace.getConfiguration('go'), {
415+
const config = Object.create(getGoConfig(), {
416416
vetOnSave: { value: 'package' },
417417
vetFlags: { value: ['-all'] },
418418
lintOnSave: { value: 'package' },
@@ -575,7 +575,7 @@ It returns the number of bytes written and any write error encountered.
575575
});
576576

577577
test('Test Env Variables are passed to Tests', async () => {
578-
const config = Object.create(vscode.workspace.getConfiguration('go'), {
578+
const config = Object.create(getGoConfig(), {
579579
testEnvVars: { value: { dummyEnvVar: 'dummyEnvValue', dummyNonString: 1 } }
580580
});
581581
const uri = vscode.Uri.file(path.join(fixturePath, 'baseTest', 'sample_test.go'));
@@ -772,28 +772,28 @@ It returns the number of bytes written and any write error encountered.
772772

773773
test('Workspace Symbols', () => {
774774
const workspacePath = path.join(fixturePath, 'vendoring');
775-
const configWithoutIgnoringFolders = Object.create(vscode.workspace.getConfiguration('go'), {
775+
const configWithoutIgnoringFolders = Object.create(getGoConfig(), {
776776
gotoSymbol: {
777777
value: {
778778
ignoreFolders: []
779779
}
780780
}
781781
});
782-
const configWithIgnoringFolders = Object.create(vscode.workspace.getConfiguration('go'), {
782+
const configWithIgnoringFolders = Object.create(getGoConfig(), {
783783
gotoSymbol: {
784784
value: {
785785
ignoreFolders: ['vendor']
786786
}
787787
}
788788
});
789-
const configWithIncludeGoroot = Object.create(vscode.workspace.getConfiguration('go'), {
789+
const configWithIncludeGoroot = Object.create(getGoConfig(), {
790790
gotoSymbol: {
791791
value: {
792792
includeGoroot: true
793793
}
794794
}
795795
});
796-
const configWithoutIncludeGoroot = Object.create(vscode.workspace.getConfiguration('go'), {
796+
const configWithoutIncludeGoroot = Object.create(getGoConfig(), {
797797
gotoSymbol: {
798798
value: {
799799
includeGoroot: false
@@ -887,7 +887,7 @@ encountered.
887887
test('Test Completion Snippets For Functions', async () => {
888888
const provider = new GoCompletionItemProvider();
889889
const uri = vscode.Uri.file(path.join(fixturePath, 'completions', 'snippets.go'));
890-
const baseConfig = vscode.workspace.getConfiguration('go');
890+
const baseConfig = getGoConfig();
891891
const textDocument = await vscode.workspace.openTextDocument(uri);
892892
const editor = await vscode.window.showTextDocument(textDocument);
893893

@@ -1081,7 +1081,7 @@ encountered.
10811081
test('Test No Completion Snippets For Functions', async () => {
10821082
const provider = new GoCompletionItemProvider();
10831083
const uri = vscode.Uri.file(path.join(fixturePath, 'completions', 'nosnippets.go'));
1084-
const baseConfig = vscode.workspace.getConfiguration('go');
1084+
const baseConfig = getGoConfig();
10851085
const textDocument = await vscode.workspace.openTextDocument(uri);
10861086
const editor = await vscode.window.showTextDocument(textDocument);
10871087

@@ -1146,7 +1146,7 @@ encountered.
11461146
});
11471147

11481148
test('Test Completion on unimported packages', async () => {
1149-
const config = Object.create(vscode.workspace.getConfiguration('go'), {
1149+
const config = Object.create(getGoConfig(), {
11501150
autocompleteUnimportedPackages: { value: true }
11511151
});
11521152
const provider = new GoCompletionItemProvider();
@@ -1177,7 +1177,7 @@ encountered.
11771177
});
11781178

11791179
test('Test Completion on unimported packages (multiple)', async () => {
1180-
const config = Object.create(vscode.workspace.getConfiguration('go'), {
1180+
const config = Object.create(getGoConfig(), {
11811181
gocodeFlags: { value: ['-builtin'] }
11821182
});
11831183
const provider = new GoCompletionItemProvider();
@@ -1293,7 +1293,7 @@ encountered.
12931293
}
12941294
fmt.Print("Go!")
12951295
}`;
1296-
const goConfig = Object.create(vscode.workspace.getConfiguration('go'), {
1296+
const goConfig = Object.create(getGoConfig(), {
12971297
playground: { value: { run: true, openbrowser: false, share: false } }
12981298
});
12991299

@@ -1325,7 +1325,7 @@ encountered.
13251325
}
13261326
fmt.Print("Go!")
13271327
}`;
1328-
const goConfig = Object.create(vscode.workspace.getConfiguration('go'), {
1328+
const goConfig = Object.create(getGoConfig(), {
13291329
playground: { value: { run: true, openbrowser: false, share: true } }
13301330
});
13311331

@@ -1355,7 +1355,7 @@ encountered.
13551355
func fantasy() {
13561356
fmt.Print("not a main package, sorry")
13571357
}`;
1358-
const goConfig = Object.create(vscode.workspace.getConfiguration('go'), {
1358+
const goConfig = Object.create(getGoConfig(), {
13591359
playground: { value: { run: true, openbrowser: false, share: false } }
13601360
});
13611361

@@ -1417,29 +1417,29 @@ encountered.
14171417
});
14181418

14191419
test('Test Tags checking', async () => {
1420-
const config1 = Object.create(vscode.workspace.getConfiguration('go'), {
1420+
const config1 = Object.create(getGoConfig(), {
14211421
vetOnSave: { value: 'off' },
14221422
lintOnSave: { value: 'off' },
14231423
buildOnSave: { value: 'package' },
14241424
testTags: { value: null },
14251425
buildTags: { value: 'randomtag' }
14261426
});
14271427

1428-
const config2 = Object.create(vscode.workspace.getConfiguration('go'), {
1428+
const config2 = Object.create(getGoConfig(), {
14291429
vetOnSave: { value: 'off' },
14301430
lintOnSave: { value: 'off' },
14311431
buildOnSave: { value: 'package' },
14321432
testTags: { value: 'randomtag' }
14331433
});
14341434

1435-
const config3 = Object.create(vscode.workspace.getConfiguration('go'), {
1435+
const config3 = Object.create(getGoConfig(), {
14361436
vetOnSave: { value: 'off' },
14371437
lintOnSave: { value: 'off' },
14381438
buildOnSave: { value: 'package' },
14391439
testTags: { value: 'randomtag othertag' }
14401440
});
14411441

1442-
const config4 = Object.create(vscode.workspace.getConfiguration('go'), {
1442+
const config4 = Object.create(getGoConfig(), {
14431443
vetOnSave: { value: 'off' },
14441444
lintOnSave: { value: 'off' },
14451445
buildOnSave: { value: 'package' },

test/integration/install.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import sinon = require('sinon');
1313
import url = require('url');
1414
import util = require('util');
1515
import vscode = require('vscode');
16+
import { getGoConfig } from '../../src/config';
1617
import { toolInstallationEnvironment } from '../../src/goEnv';
1718
import { installTools } from '../../src/goInstallTools';
1819
import { allToolsInformation, getConfiguredTools, getTool, getToolAtVersion } from '../../src/goTools';
@@ -70,7 +71,7 @@ suite('Installation Tests', function () {
7071
let configStub: sinon.SinonStub;
7172
if (withLocalProxy) {
7273
proxyDir = buildFakeProxy([].concat(...testCases));
73-
const goConfig = Object.create(vscode.workspace.getConfiguration('go'), {
74+
const goConfig = Object.create(getGoConfig(), {
7475
toolsEnvVars: {
7576
value: {
7677
GOPROXY: url.pathToFileURL(proxyDir),

test/integration/test.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ suite('Test Go Test', function () {
135135
input: { isMod: boolean, includeSubDirectories: boolean, testFlags?: string[], applyCodeCoverage?: boolean },
136136
wantFiles: string[]) {
137137

138-
const config = Object.create(vscode.workspace.getConfiguration('go'));
138+
const config = Object.create(getGoConfig());
139139
const outputChannel = new FakeOutputChannel();
140140

141141
const testConfig = {

0 commit comments

Comments
 (0)