I am testing this very simple Go code on MacOS using VS Code. The project consists of these sample packages / files:
- azure.com/myproj/cmd/service/main/main.go
- azure.com/myproj/cmd/service/service.go
- azure.com/myproj/cmd/service/tests/test.go
- azure.com/myproj/internal/common/common.go
On the terminal command line, everything builds and all tests pass: go build . // (works in every folder) go test . // (tests work and pass)
However, from VS code I have 2 problems: 1. Imports from package to package do not work at all. For example:
package test
import (
service "azure.com/myproj/cmd/service" // VS complains on this line when running the test.
)
- The command that VS code runs is not just "go test . ". It passes extra parameters that include what seems to be a cached path, which I tried deleting from the file system, but it did not have an effect. This is what VS.code's Output tab contains:
Go Tests tab:
unknown import path "azure.com/myproj/cmd/service":
cannot find module providing package
azure.com/myproj/cmd/service
Go tab:
/Users/computername/go/src/azure.com/projname/cmd/service/tests
>Finished running tool: /usr/local/bin/go test -c -o
/var/folders/q5/hm9v_6x53lj0gj02yxqtkmd40000gn/T/vscode-goKGOMES/go- code-check azure.com/myproj/cmd/service/tests
can't load package: package
azure.com/myproj/cmd/service: unknown import path
"azure.com/myproj/cmd/service": cannot find module
providing package azure.com/myproj/cmd/service
I do not understand what VS code is doing above with hm9v_6x53lj0gj02yxqtkmd40000gn and how I can change it. It looks like a cache.
So to summarize: When testing through VS Code, i do not understand why it's using the command that it is to run the tests (above), and why it can not find the imports, which the regular "go build . " and "go test . " commands have no problem with through the terminal.
Once again: From the terminal command line everything builds and all tests pass.
Seems to clearly be a VS Code related issue.