I have a folder structure that looks like this:
my/path/to/service
└── internal
└── module_name
├── BUILD.bazel
├── module_logic.go
└── module_test.go
└── endpoint_1
├── BUILD.bazel
├── logic.go
├── logic_test.go
└── variables_test.go
And a Go BUILD.bazel
file set-up as follows:
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
go_library(
name = "module_name",
srcs = ["module_logic.go"],
importpath = "github.com/path/service/internal/module_name",
visibility = ["//visibility:public"],
deps = [
"//proto/path:go",
"@org_golang_google_grpc//codes",
"@org_golang_google_grpc//status",
],
)
go_test(
name = "module_test",
srcs = [
"module_test.go",
// endpoint_1/variables_test.go
],
embed = [":pagination"],
deps = [
"@com_github_stretchr_testify//assert",
"@com_github_stretchr_testify//require",
],
)
Am I able to access the values of variables_test.go
within module_test.go
?
Typically bazel targets only use files from their own package in srcs
, and to get things in other packages, you use targets from that other package in deps
.
So probably the right thing to do is make a go_library
of what is shared between module_test
and variables_test
and have both depend on that in their deps, e.g. //my/path/to/service/endpoint_1:variables
.