Skip to content

Commit 5828eb9

Browse files
committed
test/integration: do not depend on real packages in testing
Tests involving vendoring assumed that the source code of github.com/rogpeppe/godef and github.com/ramya-rao-a/go-outline is already checked out under GOPATH or toolsGopath. Since we install tools in modules mode, that is no longer true. This CL removes the assumption but adds a test fixture 'vendoring' that contains a vendor directory. Update #6 Change-Id: Id0e07ee3bd6a689c73652b306e7f6b3ed705bf72 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/244771 Run-TryBot: Hyang-Ah Hana Kim <[email protected]> TryBot-Result: kokoro <[email protected]> Reviewed-by: Rebecca Stambler <[email protected]>
1 parent 955499e commit 5828eb9

File tree

3 files changed

+30
-32
lines changed

3 files changed

+30
-32
lines changed

test/fixtures/vendoring/main.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"example.com/vendorpls"
7+
)
8+
9+
func main() {
10+
fmt.Prinln(vendorpls.F())
11+
}

test/fixtures/vendoring/vendor/example.com/vendorpls/lib.go

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/integration/extension.test.ts

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -634,21 +634,13 @@ It returns the number of bytes written and any write error encountered.
634634
});
635635

636636
test('Replace vendor packages with relative path', async () => {
637-
// This test needs a go project that has vendor folder and vendor packages
638-
// Since the Go extension takes a dependency on the godef tool at github.com/rogpeppe/godef
639-
// which has vendor packages, we are using it here to test the "replace vendor packages with relative path" feature.
640-
// If the extension ever stops depending on godef tool or if godef ever stops having vendor packages, then this test
641-
// will fail and will have to be replaced with any other go project with vendor packages
642-
643637
const vendorSupport = await isVendorSupported();
644-
const filePath = path.join(toolsGopath, 'src', 'github.com', 'rogpeppe', 'godef', 'go', 'ast', 'ast.go');
638+
const filePath = path.join(fixturePath, 'vendoring', 'main.go');
645639
const workDir = path.dirname(filePath);
646640
const vendorPkgsFullPath = [
647-
'github.com/rogpeppe/godef/vendor/9fans.net/go/acme',
648-
'github.com/rogpeppe/godef/vendor/9fans.net/go/plan9',
649-
'github.com/rogpeppe/godef/vendor/9fans.net/go/plan9/client'
641+
'test/testfixture/vendoring/vendor/example.com/vendorpls',
650642
];
651-
const vendorPkgsRelativePath = ['9fans.net/go/acme', '9fans.net/go/plan9', '9fans.net/go/plan9/client'];
643+
const vendorPkgsRelativePath = ['example.com/vendorpls'];
652644

653645
const gopkgsPromise = getAllPackages(workDir).then((pkgMap) => {
654646
const pkgs = Array.from(pkgMap.keys()).filter((p) => {
@@ -702,18 +694,10 @@ It returns the number of bytes written and any write error encountered.
702694
});
703695

704696
test('Vendor pkgs from other projects should not be allowed to import', async () => {
705-
// This test needs a go project that has vendor folder and vendor packages
706-
// Since the Go extension takes a dependency on the godef tool at github.com/rogpeppe/godef
707-
// which has vendor packages, we are using it here to test the "replace vendor packages with relative path" feature.
708-
// If the extension ever stops depending on godef tool or if godef ever stops having vendor packages, then this test
709-
// will fail and will have to be replaced with any other go project with vendor packages
710-
711697
const vendorSupport = await isVendorSupported();
712-
const filePath = path.join(toolsGopath, 'src', 'github.com', 'ramya-rao-a', 'go-outline', 'main.go');
698+
const filePath = path.join(fixturePath, 'baseTest', 'test.go');
713699
const vendorPkgs = [
714-
'github.com/rogpeppe/godef/vendor/9fans.net/go/acme',
715-
'github.com/rogpeppe/godef/vendor/9fans.net/go/plan9',
716-
'github.com/rogpeppe/godef/vendor/9fans.net/go/plan9/client'
700+
'test/testfixture/vendoring/vendor/example.com/vendorpls',
717701
];
718702

719703
const gopkgsPromise = new Promise<void>((resolve, reject) => {
@@ -757,13 +741,7 @@ It returns the number of bytes written and any write error encountered.
757741
});
758742

759743
test('Workspace Symbols', () => {
760-
// This test needs a go project that has vendor folder and vendor packages
761-
// Since the Go extension takes a dependency on the godef tool at github.com/rogpeppe/godef
762-
// which has vendor packages, we are using it here to test the "replace vendor packages with relative path" feature.
763-
// If the extension ever stops depending on godef tool or if godef ever stops having vendor packages, then this test
764-
// will fail and will have to be replaced with any other go project with vendor packages
765-
766-
const workspacePath = path.join(toolsGopath, 'src', 'github.com', 'rogpeppe', 'godef');
744+
const workspacePath = path.join(fixturePath, 'vendoring');
767745
const configWithoutIgnoringFolders = Object.create(vscode.workspace.getConfiguration('go'), {
768746
gotoSymbol: {
769747
value: {
@@ -795,16 +773,16 @@ It returns the number of bytes written and any write error encountered.
795773

796774
const withoutIgnoringFolders = getWorkspaceSymbols(
797775
workspacePath,
798-
'WinInfo',
776+
'SomethingStr',
799777
dummyCancellationSource.token,
800778
configWithoutIgnoringFolders
801779
).then((results) => {
802-
assert.equal(results[0].name, 'WinInfo');
803-
assert.equal(results[0].path, path.join(workspacePath, 'vendor/9fans.net/go/acme/acme.go'));
780+
assert.equal(results[0].name, 'SomethingStrange');
781+
assert.equal(results[0].path, path.join(workspacePath, 'vendor/example.com/vendorpls/lib.go'));
804782
});
805783
const withIgnoringFolders = getWorkspaceSymbols(
806784
workspacePath,
807-
'WinInfo',
785+
'SomethingStr',
808786
dummyCancellationSource.token,
809787
configWithIgnoringFolders
810788
).then((results) => {

0 commit comments

Comments
 (0)