Skip to content

Commit

Permalink
test/integration: test go explorer tree view ui
Browse files Browse the repository at this point in the history
For #2049

Change-Id: I5b66e4565f0d615a6cff31677981913a3e02d4b7
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/389454
Trust: Jamal Carvalho <jamal@golang.org>
Run-TryBot: Jamal Carvalho <jamal@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
  • Loading branch information
jamalc committed Mar 9, 2022
1 parent 4e80a4f commit c14a3ee
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions test/integration/goExplorer.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*---------------------------------------------------------
* Copyright 2022 The Go Authors. All rights reserved.
* Licensed under the MIT License. See LICENSE in the project root for license information.
*--------------------------------------------------------*/

import assert from 'assert';
import path from 'path';
import { TreeItem, Uri, window, workspace } from 'vscode';
import { getGoConfig, getGoplsConfig } from '../../src/config';

import { GoExplorerProvider } from '../../src/goExplorer';
import { getConfiguredTools } from '../../src/goTools';
import { getGoVersion } from '../../src/util';
import { resolveHomeDir } from '../../src/utils/pathUtils';
import { MockExtensionContext } from '../mocks/MockContext';

suite('GoExplorerProvider', () => {
const fixtureDir = path.join(__dirname, '../../../test/testdata/baseTest');
const ctx = MockExtensionContext.new();
let explorer: GoExplorerProvider;

suiteSetup(async () => {
explorer = GoExplorerProvider.setup(ctx);
const uri = Uri.file(path.join(fixtureDir, 'test.go'));
await workspace.openTextDocument(uri);
await window.showTextDocument(uri);
});

suiteTeardown(() => {
ctx.teardown();
});

test('env tree', async () => {
const [env] = await explorer.getChildren();
assert.strictEqual(env.label, 'env');
assert.strictEqual(env.contextValue, 'go:explorer:env');
});

test('env tree items', async () => {
const [env] = await explorer.getChildren();
const [goenv, gomod] = (await explorer.getChildren(env)) as { key: string; value: string }[];
assert.strictEqual(goenv.key, 'GOENV');
assert.strictEqual(gomod.key, 'GOMOD');
assert.strictEqual(resolveHomeDir(gomod.value), `${fixtureDir}/go.mod`);
});

test('tools tree', async () => {
const [, tools] = await explorer.getChildren();
assert(tools.label === 'tools');
assert.strictEqual(tools.contextValue, 'go:explorer:tools');
});

test('tools tree items', async () => {
const goVersion = await getGoVersion();
const allTools = getConfiguredTools(goVersion, getGoConfig(), getGoplsConfig());
const expectTools = allTools.map((t) => t.name);
const [, tools] = await explorer.getChildren();
const items = (await explorer.getChildren(tools)) as TreeItem[];
assert.deepStrictEqual(
items.map((t) => t.label),
expectTools
);
});
});

0 comments on commit c14a3ee

Please # to comment.