go_test()
This is liable to change in the future.
A go_test()
rule builds a native binary from the specified Go source and resource files—and a generated main file. It's similar to the go test
command.
If your test requires static files you should specify these in the resources argument. If you do not specify these files, they won't be available when your test runs.
Buck currently supports Go version 1.10.
Arguments
name
(required) #The short name for this build target.
srcs
(required) #The set of source files to be compiled by this rule. .go files will be compiled with the Go compiler, .s files will be compiled with the assembler, and everything else is assumed to be files that may be
#include
d by the assembler.library
(defaults toNone
) #Specify the library that this internal test is testing. This will copy the
srcs
,package_name
anddeps
from the target specified so you don't have to duplicate them.package_name
(defaults togo.prefix + path relative to the buck root + "_test"
) #Sets the full name of the test package being compiled. This defaults to the path from the buck root with "_test" appended. (e.g. given a ./.buckconfig, a rule in ./a/b/BUCK defaults to package "a/b_test")
Note: if you want to test packages internally (i.e. same package name), use the
library
parameter instead of settingpackage_name
to include the tested source files.coverage_mode
(defaults toNone
) #Test coverage functionality will be included in the executable. Modes: set, count, atomic
deps
(defaults to[]
) #The set of dependencies of this rule. Currently, this only supports go_library rules.
link_style
(defaults tostatic_pic
) #Determines whether to build and link this rule's dependencies statically or dynamically. Can be one of the following values:
static
,static_pic
orshared
. This argument is relevant only if the cgo extension is enabled. Otherwise, Buck ignores this argument.link_mode
(defaults to) #
Determines the link mode (equivalent of
-mode
). Can be one of the following values:internal
,external
. If no value is provided, the mode is set automatically depending on the other args.compiler_flags
(defaults to[]
) #The set of additional compiler flags to pass to
go tool compile
.assembler_flags
(defaults to[]
) #The set of additional assembler flags to pass to
go tool asm
.linker_flags
(defaults to[]
) #Extra linker flags passed to go link
external_linker_flags
(defaults to[]
) #Extra external linker flags passed to go link via
-extld
argument. If argument is non-empty orcgo_library
is used, the link mode will switch toexternal
.resources
(defaults to[]
) #Static files that are symlinked into the working directory of the test. You can access these files in your test by opening them using relative paths, such as
ioutil.ReadFile("testdata/input")
.labels
(defaults to[]
) #A list of labels to be applied to these tests. These labels are arbitrary text strings and have no meaning within buck itself. They can, however, have meaning for you as a test author (e.g.,
smoke
orfast
). A label can be used to filter or include a specific test rule when executingbuck test
.test_rule_timeout_ms
(defaults toNone
) #If set specifies the maximum amount of time (in milliseconds) in which all of the tests in this rule should complete. This overrides the default
rule_timeout
if any has been specified in[test].rule_timeout
.env
(defaults to{}
) #A map of environment variables and values to set when running the test.
run_test_separately
(defaults toFalse
) #If set to
True
, the test(s) in this rule are run separately from all other tests. (This is useful for integration tests which access a physical device or other limited resource.)If unset, the test(s) in this rule in parallel with all other tests.
contacts
(defaults to[]
) #A list of organizational contacts for this test. These could be individuals who you would contact in the event of a test failure or other issue with the test.
contacts = [ 'Joe Sixpack', 'Erika Mustermann' ]
visibility
(defaults to[]
) #List of build target patterns that identify the build rules that can include this rule as a dependency, for example, by listing it in their
deps
orexported_deps
attributes. For more information, see visibility.licenses
(defaults to[]
) #Set of license files for this library. To get the list of license files for a given build rule and all of its dependencies, you can use
buck query
.labels
(defaults to[]
) #Set of arbitrary strings which allow you to annotate a build rule with tags that can be searched for over an entire dependency tree using
buck query attrfilter()
.
Examples
For more examples, check out our integration tests.
go_library( name='greeting', srcs=[ 'greeting.go', ], deps=[ ':join', ], ) go_test( name='greeting-test', srcs=[ 'greeting_ext_test.go', ], deps=[ ':greeting' ], ) go_test( name='greeting-internal-test', package_name='greeting', srcs=[ 'greeting.go', 'greeting_test.go', ], deps=[ ':join', ], ) # Or go_test( name='greeting-better-internal-test', srcs=['greeting_test.go'], library=':greeting', )