Skip to content

Commit c14a3ee

Browse files
committed
test/integration: test go explorer tree view ui
For #2049 Change-Id: I5b66e4565f0d615a6cff31677981913a3e02d4b7 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/389454 Trust: Jamal Carvalho <[email protected]> Run-TryBot: Jamal Carvalho <[email protected]> Reviewed-by: Hyang-Ah Hana Kim <[email protected]> TryBot-Result: kokoro <[email protected]>
1 parent 4e80a4f commit c14a3ee

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

test/integration/goExplorer.test.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*---------------------------------------------------------
2+
* Copyright 2022 The Go Authors. All rights reserved.
3+
* Licensed under the MIT License. See LICENSE in the project root for license information.
4+
*--------------------------------------------------------*/
5+
6+
import assert from 'assert';
7+
import path from 'path';
8+
import { TreeItem, Uri, window, workspace } from 'vscode';
9+
import { getGoConfig, getGoplsConfig } from '../../src/config';
10+
11+
import { GoExplorerProvider } from '../../src/goExplorer';
12+
import { getConfiguredTools } from '../../src/goTools';
13+
import { getGoVersion } from '../../src/util';
14+
import { resolveHomeDir } from '../../src/utils/pathUtils';
15+
import { MockExtensionContext } from '../mocks/MockContext';
16+
17+
suite('GoExplorerProvider', () => {
18+
const fixtureDir = path.join(__dirname, '../../../test/testdata/baseTest');
19+
const ctx = MockExtensionContext.new();
20+
let explorer: GoExplorerProvider;
21+
22+
suiteSetup(async () => {
23+
explorer = GoExplorerProvider.setup(ctx);
24+
const uri = Uri.file(path.join(fixtureDir, 'test.go'));
25+
await workspace.openTextDocument(uri);
26+
await window.showTextDocument(uri);
27+
});
28+
29+
suiteTeardown(() => {
30+
ctx.teardown();
31+
});
32+
33+
test('env tree', async () => {
34+
const [env] = await explorer.getChildren();
35+
assert.strictEqual(env.label, 'env');
36+
assert.strictEqual(env.contextValue, 'go:explorer:env');
37+
});
38+
39+
test('env tree items', async () => {
40+
const [env] = await explorer.getChildren();
41+
const [goenv, gomod] = (await explorer.getChildren(env)) as { key: string; value: string }[];
42+
assert.strictEqual(goenv.key, 'GOENV');
43+
assert.strictEqual(gomod.key, 'GOMOD');
44+
assert.strictEqual(resolveHomeDir(gomod.value), `${fixtureDir}/go.mod`);
45+
});
46+
47+
test('tools tree', async () => {
48+
const [, tools] = await explorer.getChildren();
49+
assert(tools.label === 'tools');
50+
assert.strictEqual(tools.contextValue, 'go:explorer:tools');
51+
});
52+
53+
test('tools tree items', async () => {
54+
const goVersion = await getGoVersion();
55+
const allTools = getConfiguredTools(goVersion, getGoConfig(), getGoplsConfig());
56+
const expectTools = allTools.map((t) => t.name);
57+
const [, tools] = await explorer.getChildren();
58+
const items = (await explorer.getChildren(tools)) as TreeItem[];
59+
assert.deepStrictEqual(
60+
items.map((t) => t.label),
61+
expectTools
62+
);
63+
});
64+
});

0 commit comments

Comments
 (0)