...
1## Examples
2
3### go_library
4``` bzl
5go_library(
6 name = "foo",
7 srcs = [
8 "foo.go",
9 "bar.go",
10 ],
11 deps = [
12 "//tools",
13 "@org_golang_x_utils//stuff",
14 ],
15 importpath = "github.com/example/project/foo",
16 visibility = ["//visibility:public"],
17)
18```
19
20### go_test
21
22To write an internal test, reference the library being tested with the `embed`
23instead of `deps`. This will compile the test sources into the same package as the library
24sources.
25
26#### Internal test example
27
28This builds a test that can use the internal interface of the package being tested.
29
30In the normal go toolchain this would be the kind of tests formed by adding writing
31`<file>_test.go` files in the same package.
32
33It references the library being tested with `embed`.
34
35
36``` bzl
37go_library(
38 name = "lib",
39 srcs = ["lib.go"],
40)
41
42go_test(
43 name = "lib_test",
44 srcs = ["lib_test.go"],
45 embed = [":lib"],
46)
47```
48
49#### External test example
50
51This builds a test that can only use the public interface(s) of the packages being tested.
52
53In the normal go toolchain this would be the kind of tests formed by adding an `<name>_test`
54package.
55
56It references the library(s) being tested with `deps`.
57
58``` bzl
59go_library(
60 name = "lib",
61 srcs = ["lib.go"],
62)
63
64go_test(
65 name = "lib_xtest",
66 srcs = ["lib_x_test.go"],
67 deps = [":lib"],
68)
69```
70
View as plain text