Skip to content

Commit ff99b03

Browse files
committed
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. Update #6 Change-Id: Id075827ab8ebd955f7a86460aaa7ea4e0e7cd183 GitHub-Last-Rev: 6222158 GitHub-Pull-Request: #8 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/223177 Reviewed-by: Andrew Bonventre <[email protected]>
1 parent d60e8c1 commit ff99b03

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ name: build
22

33
on: [push, pull_request]
44

5-
env:
6-
GOPATH: /tmp/go
7-
# Because some tests require explicit setting of GOPATH. TODO: FIX THEM.
8-
95
jobs:
106
build:
117
name: ${{ matrix.os }} ${{ matrix.version }}

test/integration/extension.test.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,29 @@ import {
3636
isVendorSupported
3737
} from '../../src/util';
3838

39+
function queryDefaultGopathSync(): string | null {
40+
const goExecutable = getBinPath('go');
41+
if (!goExecutable) {
42+
console.warn(`Failed to run "go env GOPATH" to find mod file as the "go" binary cannot be found`);
43+
return null;
44+
}
45+
let gopath: string;
46+
try {
47+
const stdout = cp.execFileSync(goExecutable, ['env', 'GOPATH']);
48+
console.log(`Got go env GOPATH result: ${stdout}`);
49+
gopath = stdout.toString().trim();
50+
} catch (err) {
51+
console.warn(`Error when running go env GOPATH: ${err}`);
52+
}
53+
return gopath;
54+
}
55+
3956
suite('Go Extension Tests', function() {
4057
this.timeout(10000);
41-
const gopath = getCurrentGoPath();
58+
let gopath = getCurrentGoPath();
59+
if (!gopath) {
60+
gopath = queryDefaultGopathSync();
61+
}
4262
if (!gopath) {
4363
assert.ok(gopath, 'Cannot run tests if GOPATH is not set as environment variable');
4464
return;
@@ -51,7 +71,7 @@ suite('Go Extension Tests', function() {
5171
const generateTestsSourcePath = path.join(repoPath, 'generatetests');
5272
const generateFunctionTestSourcePath = path.join(repoPath, 'generatefunctiontest');
5373
const generatePackageTestSourcePath = path.join(repoPath, 'generatePackagetest');
54-
const toolsGopath = getToolsGopath() || getCurrentGoPath();
74+
const toolsGopath = getToolsGopath() || gopath;
5575

5676
const dummyCancellationSource = new vscode.CancellationTokenSource();
5777

0 commit comments

Comments
 (0)