Documentation ¶
Index ¶
- func CleanSnapshots(m *testing.M)
- func CreateTestDir(t *testing.T) string
- func IsAcceptanceTest() bool
- func LoadJSONFixture[V any](t *testing.T, path string) V
- func LoadJSONFixtureWithWindowsReplacements[V any](t *testing.T, path string, replacements map[string]string) V
- func Skip(t *testing.T, args ...any)
- func SkipIfNotAcceptanceTesting(t *testing.T, reason string)
- func ValueIfOnWindows(win, or string) string
- type MockHTTPServer
- func (m *MockHTTPServer) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (m *MockHTTPServer) SetAuthorization(t *testing.T, auth string)
- func (m *MockHTTPServer) SetResponse(t *testing.T, path string, response []byte)
- func (m *MockHTTPServer) SetResponseFromFile(t *testing.T, path string, filename string)
- type Snapshot
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CleanSnapshots ¶ added in v1.6.2
CleanSnapshots ensures that snapshots are relevant and sorted for consistency
func CreateTestDir ¶ added in v1.7.0
CreateTestDir makes a temporary directory for use in testing that involves writing and reading files from disk, which is automatically cleaned up when testing finishes
func IsAcceptanceTest ¶ added in v1.7.0
func IsAcceptanceTest() bool
Access to environment variable that toggles acceptance testing execution paths Acceptance testing is "On" only when var set to "true"
func LoadJSONFixture ¶
LoadJSONFixture returns the contents of the fixture file parsed as JSON
func LoadJSONFixtureWithWindowsReplacements ¶ added in v1.6.2
func LoadJSONFixtureWithWindowsReplacements[V any]( t *testing.T, path string, replacements map[string]string, ) V
LoadJSONFixtureWithWindowsReplacements returns the contents of the fixture file parsed as JSON after applying any replacements if running on Windows
func Skip ¶ added in v1.6.2
Skip is equivalent to t.Log followed by t.SkipNow, but allows tracking of what snapshots are skipped so that they're not marked as obsolete
func SkipIfNotAcceptanceTesting ¶ added in v1.7.0
AcceptanceTests marks this test function as a extended that require additional dependencies automatically skipped unless running in a CI environment
func ValueIfOnWindows ¶ added in v1.5.0
Types ¶
type MockHTTPServer ¶ added in v1.7.2
func NewMockHTTPServer ¶ added in v1.7.2
func NewMockHTTPServer(t *testing.T) *MockHTTPServer
NewMockHTTPServer starts and returns a new simple HTTP Server for mocking basic requests. The Server will automatically be shut down with Close() in the test Cleanup function.
Use the SetResponse / SetResponseFromFile to set the responses for specific URL paths.
func (*MockHTTPServer) ServeHTTP ¶ added in v1.7.2
func (m *MockHTTPServer) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP is the http.Handler for the underlying httptest.Server.
func (*MockHTTPServer) SetAuthorization ¶ added in v1.7.2
func (m *MockHTTPServer) SetAuthorization(t *testing.T, auth string)
SetAuthorization sets the contents of the 'Authorization' header the server expects for all endpoints.
The incoming requests' headers must match the auth string exactly, otherwise the server will response with 401 Unauthorized. If authorization is unset or empty, the server will not require authorization.
func (*MockHTTPServer) SetResponse ¶ added in v1.7.2
func (m *MockHTTPServer) SetResponse(t *testing.T, path string, response []byte)
SetResponse sets the Server's response for the URL path to be response bytes.
func (*MockHTTPServer) SetResponseFromFile ¶ added in v1.7.2
func (m *MockHTTPServer) SetResponseFromFile(t *testing.T, path string, filename string)
SetResponseFromFile sets the Server's response for the URL path to be the contents of the file at filename.
type Snapshot ¶ added in v1.6.2
type Snapshot struct {
// contains filtered or unexported fields
}
func NewSnapshot ¶ added in v1.6.2
func NewSnapshot() Snapshot
NewSnapshot creates a snapshot that can be passed around within tests
func (Snapshot) MatchJSON ¶ added in v1.6.2
MatchJSON asserts the existing snapshot matches what was gotten in the test, after being marshalled as JSON
func (Snapshot) MatchText ¶ added in v1.6.2
MatchText asserts the existing snapshot matches what was gotten in the test
func (Snapshot) WithCRLFReplacement ¶ added in v1.7.1
WithCRLFReplacement adds a Windows replacement for "\r\n" to "\n". This should be called after WithWindowsReplacements if used together.