Documentation ¶
Overview ¶
Package fixture provides a micro-framework on top of the testing package that provides test setup and teardown handling in a reusable way. The package defines a (well-known) lifecycle to execute, which is in detail documented in the repo's README file.
A fixture is any go value. To hook into the lifecycle a fixture must satisfy any of the single-method interfaces defined.
Index ¶
- type AfterAll
- type AfterEach
- type BeforeAll
- type BeforeEach
- type Fixture
- type HTTPServerFixture
- func (f *HTTPServerFixture) AfterAll(t *testing.T) error
- func (f *HTTPServerFixture) BeforeAll(t *testing.T) error
- func (f *HTTPServerFixture) Handle(pattern string, handler http.Handler)
- func (f *HTTPServerFixture) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))
- func (f *HTTPServerFixture) URL(pathElements ...string) string
- type MultiFixture
- type Suite
- type TempDirFixture
- type TestFunc
- type TupleFixture
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BeforeEach ¶
BeforeEach is an extension hook interface that defines the BeforeEach hook.
type Fixture ¶
type Fixture interface{}
Fixture defines a "label" interface for fixtures providing values for tests. This interface defines no methods and is completely equivalent to any. It just serves the purpose of making the generic type annotations easier to reason about.
type HTTPServerFixture ¶
type HTTPServerFixture struct { UseTLS bool DisableHTTP2 bool // contains filtered or unexported fields }
HTTPServerFixture is a fixture that provides a httptest.Server for testing. The server will be started on BeforeAll and closed on AfterAll. The server is started with HTTP2 enabled but without TLS by default. Both can be changed by setting the boolean flags on the fixture.
func (*HTTPServerFixture) Handle ¶
func (f *HTTPServerFixture) Handle(pattern string, handler http.Handler)
func (*HTTPServerFixture) HandleFunc ¶
func (f *HTTPServerFixture) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))
func (*HTTPServerFixture) URL ¶
func (f *HTTPServerFixture) URL(pathElements ...string) string
URL returns the url used to connect to the test server formed by using the server's base url (which contains the randomly chosen port as well as the respective protocol) and all elements from pathElements joined with a /.
type MultiFixture ¶
type MultiFixture []Fixture
MultiFixture combines multiple fixtures into a single one to use with With. It implements every hook interface and delegates all hooks to each fixture. The order of delegation is defined by the hooks type:
- Before-hooks are execute first-to-last order
- After-hooks are executed in last-to-first order
func (MultiFixture) BeforeEach ¶
func (f MultiFixture) BeforeEach(t *testing.T) error
type TempDirFixture ¶
type TempDirFixture struct {
// contains filtered or unexported fields
}
func TempDir ¶
func TempDir(name string) *TempDirFixture
func (*TempDirFixture) Join ¶
func (f *TempDirFixture) Join(parts ...string) string
func (*TempDirFixture) Name ¶
func (f *TempDirFixture) Name() string
func (*TempDirFixture) Path ¶
func (f *TempDirFixture) Path() string
func (*TempDirFixture) String ¶
func (f *TempDirFixture) String() string
type TupleFixture ¶
type TupleFixture[A, B Fixture] struct { One A Two B // contains filtered or unexported fields }
TupleFixture is a convenience type used to combine exactly two fixtures into a single one to use with tests. It uses MultiFixture under the hood but wraps it inside a struct that exposes the fixtures statically typed.
func Tuple ¶
func Tuple[A, B Fixture](a A, b B) *TupleFixture[A, B]
func (*TupleFixture[A, B]) BeforeEach ¶
func (f *TupleFixture[A, B]) BeforeEach(t *testing.T) error