bumpy-spoon-55438
10/29/2022, 4:07 AMgo test
thoughbumpy-spoon-55438
10/29/2022, 4:07 AMimport (
"<http://golang.org/x/tools/go/packages|golang.org/x/tools/go/packages>"
"go/token"
)
const loadMode = packages.NeedName |
packages.NeedFiles |
packages.NeedCompiledGoFiles |
packages.NeedImports |
packages.NeedDeps |
packages.NeedTypes |
packages.NeedSyntax |
packages.NeedTypesInfo
loadConfig := packages.Config{
Mode: loadMode,
Fset: token.NewFileSet(),
}
pkgs, err := packages.Load(&loadConfig, packageName)
bumpy-spoon-55438
10/29/2022, 4:08 AMhappy-kitchen-89482
10/29/2022, 4:34 AMbumpy-spoon-55438
10/29/2022, 4:37 AMgo_package(
dependencies=[":gofile"],
)
file(
name="gofile",
source="test_cases/models.go",
)
the packageName is like github.com/xxx/xxx/.../test_casesfast-nail-55400
10/29/2022, 2:11 PMfile
to resource
fast-nail-55400
10/29/2022, 3:19 PMresource
is included in the package and file
is made available as a loose file not in the package when running tests (present relative to the directory in which the test runner is running)fast-nail-55400
10/29/2022, 3:24 PMfile
and access the file in the local filesystem? go
guarantees the current directory for the test runner is the package directory. and pants does the same (although in the execution sandbox)fast-nail-55400
10/29/2022, 3:29 PMgo
sources do this. https://github.com/golang/go/tree/master/misc/cgo -- you will note test data is also put under a testdata
directory which go
generally uses for fixtures. Pants respects that convention and will ignore anything under testdata
when running ./pants tailor
so the test .go
file will never have a BUILD file written for it.fast-nail-55400
10/29/2022, 3:30 PM<http://golang.org/x/tools/go/packages|golang.org/x/tools/go/packages>
?bumpy-spoon-55438
10/29/2022, 5:24 PMbumpy-spoon-55438
10/29/2022, 5:25 PMfast-nail-55400
10/29/2022, 5:38 PMbumpy-spoon-55438
10/29/2022, 6:31 PMbumpy-spoon-55438
10/29/2022, 6:32 PMgo test ./...
it would pass the test but if run with ./pants test ::
, it would failbumpy-spoon-55438
11/02/2022, 6:17 PMfast-nail-55400
11/02/2022, 7:12 PM