Skip to content

test/integration: use default GOPATH when the env var is not set #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
24 changes: 22 additions & 2 deletions test/integration/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,29 @@ import {
isVendorSupported
} from '../../src/util';

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`);
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;
Expand All @@ -51,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();

Expand Down