Documentation ¶
Overview ¶
Package got is a collection of packages that aid in writing clearer tests by reducing boilerplate and encouraging clarity of intent.
Package got is a generated GoMock package.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Assert ¶ added in v1.0.0
Assert ensures that all the fields within the struct values match what is on disk, using reflection to Load a fresh copy and then comparing the 2 structs using go-cmp to perform the equality check.
When the "test.update-golden" flag is provided, the contents of each value struct will be persisted to disk instead. This allows any test to easily update their "golden files" and also do the assertion transparently.
func Load ¶ added in v1.0.0
Load extracts the contents of dir into values which are structs annotated with the "testdata" struct tag.
The main parameter of the struct tag will be a path to a file relative to the input directory.
Fields with string or []byte as their types will be populated with the raw contents of the file.
Struct values will be decoded using the file extension to map to a [Codec]. For example, ".json" files can be processed using [JSONCodec] if it has been registered. Additional codecs (eg: YAML, TOML) can be registered if desired.
Map values can be used to dynamically load the contents of a directory, in situations where you don't necessarily know all the files ahead of time.
The defined map type must use string keys, otherwise it will return an error. The filename in the struct tag will then be treated as a glob pattern, populating the map with a key for each matched file (relative to the input directory).
The values in the map can be either string, []byte or structs as described above.
Types ¶
type MockT ¶ added in v1.0.0
type MockT struct {
// contains filtered or unexported fields
}
MockT is a mock of T interface.
func NewMockT ¶ added in v1.0.0
func NewMockT(ctrl *gomock.Controller) *MockT
NewMockT creates a new mock instance.
func (*MockT) EXPECT ¶ added in v1.0.0
func (m *MockT) EXPECT() *MockTMockRecorder
EXPECT returns an object that allows the caller to indicate expected use.
type MockTMockRecorder ¶ added in v1.0.0
type MockTMockRecorder struct {
// contains filtered or unexported fields
}
MockTMockRecorder is the mock recorder for MockT.
func (*MockTMockRecorder) Fatal ¶ added in v1.0.0
func (mr *MockTMockRecorder) Fatal(arg0 ...interface{}) *gomock.Call
Fatal indicates an expected call of Fatal.
func (*MockTMockRecorder) Helper ¶ added in v1.0.0
func (mr *MockTMockRecorder) Helper() *gomock.Call
Helper indicates an expected call of Helper.
type TestCase ¶ added in v1.0.0
type TestCase struct { // Name is the base name for this test case (excluding any parent names). Name string // Skip indicates that the test should be skipped. This is indicated to the // TestSuite by having a directory name with a ".skip" suffix. Skip bool // Dir is the base directory for this test case. Dir string // suite has been configured to search for this. SharedDir string }
TestCase is used to wrap up test metadata.
type TestSuite ¶ added in v1.0.0
type TestSuite struct { // Dir is the location of your test suite. Dir string // // When set, this directory is scanned first and is treated as the primary // test suite. For each sub-directory, a corresponding sub-directory must also // be found in Dir, or that sub-test will fail. Any sub-directories found in // Dir will be added to the test suite. // // This allows a test suite to be defined for a common interface, which can // then be run for all implementations of that interface, while allowing each // implementation to inculde their own additional test cases and // configuration. SharedDir string // TestFunc is the hook for running test code, it will be called for each // found test case in the suite. TestFunc func(*testing.T, TestCase) }
TestSuite defines a collection of tests backed by directories/files on disk.