-
Notifications
You must be signed in to change notification settings - Fork 767
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <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
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
); | ||
}); | ||
}); |