Documentation ¶
Index ¶
- func AssertFileContents[C string | []byte](t assert.TestingT, fs afero.Fs, path string, expected C, ...) bool
- func AssertFileExists(t assert.TestingT, fs afero.Fs, path string, msgAndArgs ...interface{}) bool
- func AssertFsFileEquivalent(t assert.TestingT, expected, actual afero.Fs, path string, ...) bool
- func EnsureFileContent(t *testing.T, fs afero.Fs, path, content string)
- func EnsureYAMLFileContent(t *testing.T, fs afero.Fs, path string, content interface{})
- func IntegrationTest(t SkippableTest)
- func NewSelfSignedCertificate(t require.TestingT, fs afero.Fs, destinationFolder string, hosts ...string)
- func RequireFileContents[C string | []byte](t require.TestingT, fs afero.Fs, path string, expected C, ...)
- func RequireFileExists(t require.TestingT, fs afero.Fs, path string, msgAndArgs ...interface{})
- func RequireFsFileEquivalent(t require.TestingT, expected, actual afero.Fs, path string, ...)
- func StringBody(body string) io.ReadCloser
- type FakeTest
- type HTTPResponseBuilder
- func (b *HTTPResponseBuilder) Build() *http.Response
- func (b *HTTPResponseBuilder) WithBody(body io.ReadCloser) *HTTPResponseBuilder
- func (b *HTTPResponseBuilder) WithJsonBody(body interface{}) *HTTPResponseBuilder
- func (b *HTTPResponseBuilder) WithStatusCode(code int) *HTTPResponseBuilder
- func (b *HTTPResponseBuilder) WithTB(tb testing.TB) *HTTPResponseBuilder
- type MsgAndArgs
- type RoundTripperFunc
- type SkippableTest
- type TestHelper
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertFileContents ¶
func AssertFileExists ¶
func AssertFsFileEquivalent ¶
func AssertFsFileEquivalent(t assert.TestingT, expected, actual afero.Fs, path string, msgAndArgs ...interface{}) bool
AssertFsFileEquivalent asserts that a file is equivalent on 2 different file systems
AssertFsFileEquivalent(t, referenceFs, testedFs, path, "error message %s", "formatted")
Equivalence considers the availability of the file (no error returned when opening it), the file permissions, size and its content. Creation, Modification and Access time stamps are excluded from the comparison
func EnsureYAMLFileContent ¶
func IntegrationTest ¶
func IntegrationTest(t SkippableTest)
func NewSelfSignedCertificate ¶
func NewSelfSignedCertificate(t require.TestingT, fs afero.Fs, destinationFolder string, hosts ...string)
NewSelfSignedCertificate generates a new self-signed public key and certificate in the destination folder.
The certificate is stored in destinationFolder/tls.crt The private key in destinationFolder/tls.key
Example ¶
package main import ( "fmt" "sort" "strings" testutils "github.com/adevinta/go-testutils-toolkit" "github.com/spf13/afero" ) func main() { // use the real *testing.T from the test t := &testutils.FakeTest{Name: "TestICanCreateCertificates"} fs := afero.NewMemMapFs() testutils.NewSelfSignedCertificate(t, fs, "/my/certificates", "localhost") fd, err := fs.Open("/my/certificates") if err != nil { return } names, err := fd.Readdirnames(-1) if err != nil { return } sort.Strings(names) fmt.Println(strings.Join(names, " ")) // Usually, this is done by the go framework fmt.Println(t) }
Output: tls.crt tls.key --- PASS: TestICanCreateCertificates
func RequireFileContents ¶
func RequireFileExists ¶
func RequireFsFileEquivalent ¶
func RequireFsFileEquivalent(t require.TestingT, expected, actual afero.Fs, path string, msgAndArgs ...interface{})
RequireFsFileEquivalent asserts that a file is equivalent on 2 different file systems
RequireFsFileEquivalent(t, referenceFs, testedFs, path, "error message %s", "formatted")
Equivalence considers the availability of the file (no error returned when opening it), the file permissions, size and its content. Creation, Modification and Access time stamps are excluded from the comparison
func StringBody ¶
func StringBody(body string) io.ReadCloser
Types ¶
type FakeTest ¶
type FakeTest struct { ErrorFormats []MsgAndArgs ErrorMessages []string Failed bool Name string }
type HTTPResponseBuilder ¶
type HTTPResponseBuilder struct {
// contains filtered or unexported fields
}
func NewHTTPResponseBuilder ¶
func NewHTTPResponseBuilder() *HTTPResponseBuilder
func (*HTTPResponseBuilder) Build ¶
func (b *HTTPResponseBuilder) Build() *http.Response
func (*HTTPResponseBuilder) WithBody ¶
func (b *HTTPResponseBuilder) WithBody(body io.ReadCloser) *HTTPResponseBuilder
func (*HTTPResponseBuilder) WithJsonBody ¶
func (b *HTTPResponseBuilder) WithJsonBody(body interface{}) *HTTPResponseBuilder
func (*HTTPResponseBuilder) WithStatusCode ¶
func (b *HTTPResponseBuilder) WithStatusCode(code int) *HTTPResponseBuilder
func (*HTTPResponseBuilder) WithTB ¶
func (b *HTTPResponseBuilder) WithTB(tb testing.TB) *HTTPResponseBuilder
type MsgAndArgs ¶
type MsgAndArgs struct { MSG string Args []interface{} }
type RoundTripperFunc ¶
type SkippableTest ¶
type SkippableTest interface { Helper() Skip(...any) }
type TestHelper ¶
type TestHelper interface {
Helper()
}