How to tell gazelle that a go file is meant for go_default_test and not go_default_library?

497 views Asked by At

I have a file, embed_testdata.go, meant to be used in tests but does not itself have tests (so I don't want to suffix it with _test.go). How do I tell gazelle that it's really test source and not prod source?

FYI, simply adding it to go_default_test and removing it from go_default_library doesn't work since gazelle undoes that manual edit.

1

There are 1 answers

0
Noel Yap On BEST ANSWER

https://github.com/bazelbuild/bazel-gazelle#directives are all the valid gazelle directives.

There's no specific directive that tells it to treat a non-_test.go file as a test but there are two that can be used to that effect, exclude and keep:

# gazelle:exclude embed_testdata.go
…
go_test(
    name = "go_default_test",
    srcs = [
        "embed_testdata.go",  # keep
…

When embedding a file system, something like the following is also needed:

go_test(
    name = "go_default_test",
…
    embedsrcs = glob(["testdata/**"]), # keep
…