From 88f121ff3fc236065d703072f46c95aca8c46139 Mon Sep 17 00:00:00 2001 From: "Hana (Hyang-Ah) Kim" Date: Thu, 12 Mar 2020 10:59:23 -0400 Subject: [PATCH 1/4] test/integration: use default GOPATH when the env var is not set If the env var GOPATH is not set when the test runs, now it runs `go env GOPATH` to retrieve the default value the underlying go commands will use. I wished I could make this command run asynchronously, but I am not familiar with the test framework and failed to make it working with async functions. So, like many other file operations used in the test setup phase, I am using execFileSync. --- test/integration/extension.test.ts | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/test/integration/extension.test.ts b/test/integration/extension.test.ts index b6f5368130..24e81cc952 100644 --- a/test/integration/extension.test.ts +++ b/test/integration/extension.test.ts @@ -36,9 +36,29 @@ import { isVendorSupported } from '../../src/util'; +function queryDefaultGopathSync(): string { + const goExecutable = getBinPath('go'); + if (!goExecutable) { + console.warn(`Failed to run "go env GOPATH" to find mod file as the "go" binary cannot be found`); + return null; + } + let gopath: string; + try { + const stdout = cp.execFileSync(goExecutable, ['env', 'GOPATH']); + console.log(`Got go env GOPATH result: ${stdout}`); + gopath = stdout.toString().trim(); + } catch (err) { + console.warn(`Error when running go env GOPATH: ${err}`); + } + return gopath; +} + suite('Go Extension Tests', function() { this.timeout(10000); - const gopath = getCurrentGoPath(); + let gopath = getCurrentGoPath(); + if (!gopath) { + gopath = queryDefaultGopathSync(); + } if (!gopath) { assert.ok(gopath, 'Cannot run tests if GOPATH is not set as environment variable'); return; From 64099f2b385eb70dcd7353fbbe0a71df65d332b3 Mon Sep 17 00:00:00 2001 From: "Hana (Hyang-Ah) Kim" Date: Thu, 12 Mar 2020 11:14:14 -0400 Subject: [PATCH 2/4] github/workflows: remove GOPATH setting --- .github/workflows/ci.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fe90629425..b600becd94 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,10 +2,6 @@ name: build on: [push, pull_request] -env: - GOPATH: /tmp/go - # Because some tests require explicit setting of GOPATH. TODO: FIX THEM. - jobs: build: name: ${{ matrix.os }} ${{ matrix.version }} From c071bebbc7b4421fbdd75a81d8bdc6d4fbdaaee4 Mon Sep 17 00:00:00 2001 From: "Hana (Hyang-Ah) Kim" Date: Thu, 12 Mar 2020 11:29:59 -0400 Subject: [PATCH 3/4] test/integration: replace getCurrentGoPath with gopath --- test/integration/extension.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/extension.test.ts b/test/integration/extension.test.ts index 24e81cc952..a535f57494 100644 --- a/test/integration/extension.test.ts +++ b/test/integration/extension.test.ts @@ -71,7 +71,7 @@ suite('Go Extension Tests', function() { const generateTestsSourcePath = path.join(repoPath, 'generatetests'); const generateFunctionTestSourcePath = path.join(repoPath, 'generatefunctiontest'); const generatePackageTestSourcePath = path.join(repoPath, 'generatePackagetest'); - const toolsGopath = getToolsGopath() || getCurrentGoPath(); + const toolsGopath = getToolsGopath() || gopath; const dummyCancellationSource = new vscode.CancellationTokenSource(); From 62221580ddaae0062ec79a3ab3efc6258c912117 Mon Sep 17 00:00:00 2001 From: "Hana (Hyang-Ah) Kim" Date: Tue, 17 Mar 2020 10:56:48 -0400 Subject: [PATCH 4/4] test/integration: explicitly specify all possible return types --- test/integration/extension.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/extension.test.ts b/test/integration/extension.test.ts index a535f57494..5ff5c67bf8 100644 --- a/test/integration/extension.test.ts +++ b/test/integration/extension.test.ts @@ -36,7 +36,7 @@ import { isVendorSupported } from '../../src/util'; -function queryDefaultGopathSync(): string { +function queryDefaultGopathSync(): string | null { const goExecutable = getBinPath('go'); if (!goExecutable) { console.warn(`Failed to run "go env GOPATH" to find mod file as the "go" binary cannot be found`);