Documentation ¶
Index ¶
- Constants
- Variables
- func ApplyDump(ctx context.Context, t *testing.T, db *sql.DB, dumpFile string) error
- func ApplyMigrations(t *testing.T, db *sql.DB) (countMigrations int, err error)
- func ApplyTestFixtures(ctx context.Context, t *testing.T, db *sql.DB) (countFixtures int, err error)
- func CompareAll(t *testing.T, base map[string]string, toCheck map[string]string, ...)
- func CompareAllPayload(t *testing.T, base map[string]interface{}, toCheck map[string]string, ...)
- func CompareFileHashes(t *testing.T, expectedFile string, actualFile string)
- func DotEnvLoadFileOrSkipTest(t *testing.T, absolutePathToEnvFile string)
- func DotEnvLoadLocalOrSkipTest(t *testing.T)
- func GetLastSentMail(t *testing.T, m *mailer.Mailer) *email.Email
- func GetMapFromStruct(s interface{}) map[string]string
- func GetMapFromStructByTag(tag string, s interface{}) map[string]string
- func GetSentMails(t *testing.T, m *mailer.Mailer) []*email.Email
- func GetTestMailerMockTransport(t *testing.T, m *mailer.Mailer) *transport.MockMailTransport
- func HeadersWithAPIKeyAuth(t TestingT, token string) http.Header
- func HeadersWithAuth(t TestingT, token string) http.Header
- func HeadersWithConfigurableAuth(t TestingT, scheme string, token string) http.Header
- func NewSMTPMailerFromDefaultEnv(t *testing.T) *mailer.Mailer
- func NewTestMailer(t *testing.T) *mailer.Mailer
- func NewTestPusher(t *testing.T, db *sql.DB) *push.Service
- func ParseResponseAndValidate(t TestingT, res *httptest.ResponseRecorder, v runtime.Validatable)
- func ParseResponseBody(t TestingT, res *httptest.ResponseRecorder, v interface{})
- func PerformRequest(t TestingT, s *api.Server, method string, path string, body GenericPayload, ...) *httptest.ResponseRecorder
- func PerformRequestWithArray(t TestingT, s *api.Server, method string, path string, ...) *httptest.ResponseRecorder
- func PerformRequestWithArrayAndParams(t TestingT, s *api.Server, method string, path string, ...) *httptest.ResponseRecorder
- func PerformRequestWithParams(t TestingT, s *api.Server, method string, path string, body GenericPayload, ...) *httptest.ResponseRecorder
- func PerformRequestWithRawBody(t TestingT, s *api.Server, method string, path string, body io.Reader, ...) *httptest.ResponseRecorder
- func RequireHTTPError(t *testing.T, res *httptest.ResponseRecorder, httpError *httperrors.HTTPError) httperrors.HTTPError
- func WithTestDatabase(t *testing.T, closure func(db *sql.DB))
- func WithTestDatabaseContext(ctx context.Context, t *testing.T, closure func(db *sql.DB))
- func WithTestDatabaseEmpty(t *testing.T, closure func(db *sql.DB))
- func WithTestDatabaseEmptyContext(ctx context.Context, t *testing.T, closure func(db *sql.DB))
- func WithTestDatabaseFromDump(t *testing.T, config DatabaseDumpConfig, closure func(db *sql.DB))
- func WithTestDatabaseFromDumpContext(ctx context.Context, t *testing.T, config DatabaseDumpConfig, ...)
- func WithTestPusher(t *testing.T, closure func(p *push.Service, db *sql.DB))
- func WithTestServer(t *testing.T, closure func(s *api.Server))
- func WithTestServerConfigurable(t *testing.T, config config.Server, closure func(s *api.Server))
- func WithTestServerConfigurableContext(ctx context.Context, t *testing.T, config config.Server, ...)
- func WithTestServerConfigurableFromDump(t *testing.T, config config.Server, dumpConfig DatabaseDumpConfig, ...)
- func WithTestServerConfigurableFromDumpContext(ctx context.Context, t *testing.T, config config.Server, ...)
- func WithTestServerFromDump(t *testing.T, dumpConfig DatabaseDumpConfig, closure func(s *api.Server))
- type DatabaseDumpConfig
- type FixtureMap
- type GenericArrayPayload
- type GenericPayload
- type Insertable
- type TestingT
Constants ¶
const ( PlainTestUserPassword = "password" HashedTestUserPassword = "$argon2id$v=19$m=65536,t=1,p=4$RFO8ulg2c2zloG0029pAUQ$2Po6NUIhVCMm9vivVDuzo7k5KVWfZzJJfeXzC+n+row" //nolint:gosec )
const (
TestMailerDefaultSender = "test@example.com"
)
Variables ¶
var ( DefaultSnapshotDirPathAbs = filepath.Join(util.GetProjectRootDir(), "/test/testdata/snapshots") UpdateGoldenGlobal = util.GetEnvAsBool("TEST_UPDATE_GOLDEN", false) )
var Snapshoter = snapshoter{ // contains filtered or unexported fields }
Functions ¶
func ApplyMigrations ¶
ApplyMigrations applies all current database migrations to db
func ApplyTestFixtures ¶
func ApplyTestFixtures(ctx context.Context, t *testing.T, db *sql.DB) (countFixtures int, err error)
ApplyTestFixtures applies all current test fixtures (insert) to db
func CompareAll ¶
func CompareAllPayload ¶
func CompareFileHashes ¶
func DotEnvLoadFileOrSkipTest ¶
DotEnvLoadFileOrSkipTest tries to load the overgiven path to the dotenv file overwriting ENV vars. If the file is not found, the test will be automatically skipped.
func DotEnvLoadLocalOrSkipTest ¶
DotEnvLoadLocalOrSkipTest tries to load the `.env.local` file in the projectroot overwriting ENV vars. If the file is not found, the test will be automatically skipped.
func GetMapFromStruct ¶
func GetMapFromStructByTag ¶
GetMapFromStructByTag returns a map of a given struct using a tag name as key and the string of the property value as value. inspired by: https://stackoverflow.com/questions/55879028/golang-get-structs-field-name-by-json-tag
func ParseResponseAndValidate ¶
func ParseResponseAndValidate(t TestingT, res *httptest.ResponseRecorder, v runtime.Validatable)
func ParseResponseBody ¶
func ParseResponseBody(t TestingT, res *httptest.ResponseRecorder, v interface{})
func PerformRequest ¶
func PerformRequest(t TestingT, s *api.Server, method string, path string, body GenericPayload, headers http.Header) *httptest.ResponseRecorder
func PerformRequestWithArray ¶
func PerformRequestWithArray(t TestingT, s *api.Server, method string, path string, body GenericArrayPayload, headers http.Header) *httptest.ResponseRecorder
func RequireHTTPError ¶
func RequireHTTPError(t *testing.T, res *httptest.ResponseRecorder, httpError *httperrors.HTTPError) httperrors.HTTPError
func WithTestDatabase ¶
WithTestDatabase returns an isolated test database based on the current migrations and fixtures.
func WithTestDatabaseContext ¶
WithTestDatabaseContext returns an isolated test database based on the current migrations and fixtures. The provided context will be used during setup (instead of the default background context).
func WithTestDatabaseEmpty ¶
WithTestDatabaseEmpty returns an isolated test database with no migrations applied or fixtures inserted.
func WithTestDatabaseEmptyContext ¶
WithTestDatabaseEmptyContext returns an isolated test database with no migrations applied or fixtures inserted. The provided context will be used during setup (instead of the default background context).
func WithTestDatabaseFromDump ¶
func WithTestDatabaseFromDump(t *testing.T, config DatabaseDumpConfig, closure func(db *sql.DB))
WithTestDatabaseFromDump returns an isolated test database based on a dump file.
func WithTestDatabaseFromDumpContext ¶
func WithTestDatabaseFromDumpContext(ctx context.Context, t *testing.T, config DatabaseDumpConfig, closure func(db *sql.DB))
WithTestDatabaseFromDumpContext returns an isolated test database based on a dump file. The provided context will be used during setup (instead of the default background context).
func WithTestServer ¶
WithTestServer returns a fully configured server (using the default server config).
func WithTestServerConfigurable ¶
WithTestServerConfigurable returns a fully configured server, allowing for configuration using the provided server config.
func WithTestServerConfigurableContext ¶
func WithTestServerConfigurableContext(ctx context.Context, t *testing.T, config config.Server, closure func(s *api.Server))
WithTestServerConfigurableContext returns a fully configured server, allowing for configuration using the provided server config. The provided context will be used during setup (instead of the default background context).
func WithTestServerConfigurableFromDump ¶
func WithTestServerConfigurableFromDump(t *testing.T, config config.Server, dumpConfig DatabaseDumpConfig, closure func(s *api.Server))
WithTestServerConfigurableFromDump returns a fully configured server, allowing for configuration using the provided server config and a database dump to be injected.
func WithTestServerConfigurableFromDumpContext ¶
func WithTestServerConfigurableFromDumpContext(ctx context.Context, t *testing.T, config config.Server, dumpConfig DatabaseDumpConfig, closure func(s *api.Server))
WithTestServerConfigurableFromDumpContext returns a fully configured server, allowing for configuration using the provided server config and a database dump to be injected. The provided context will be used during setup (instead of the default background context).
func WithTestServerFromDump ¶
func WithTestServerFromDump(t *testing.T, dumpConfig DatabaseDumpConfig, closure func(s *api.Server))
WithTestServerFromDump returns a fully configured server (using the default server config) and allows for a database dump to be injected.
Types ¶
type DatabaseDumpConfig ¶
type FixtureMap ¶
type FixtureMap struct { User1 *models.User User1AppUserProfile *models.AppUserProfile User1AccessToken1 *models.AccessToken User1RefreshToken1 *models.RefreshToken User2 *models.User User2AppUserProfile *models.AppUserProfile User2AccessToken1 *models.AccessToken User2RefreshToken1 *models.RefreshToken UserDeactivated *models.User UserDeactivatedAppUserProfile *models.AppUserProfile UserDeactivatedAccessToken1 *models.AccessToken UserDeactivatedRefreshToken1 *models.RefreshToken User1PushToken *models.PushToken User1PushTokenAPN *models.PushToken Trip1 *models.Trip Trip2 *models.Trip Trip3 *models.Trip }
The main definition which fixtures are available through Fixtures(). Mind the declaration order! The fields get inserted exactly in the order they are declared.
func Fixtures ¶
func Fixtures() FixtureMap
Fixtures returns a function wrapping our fixtures, which tests are allowed to manipulate. Each test (which may run concurrently) receives a fresh copy, preventing side effects between test runs.
type GenericArrayPayload ¶
type GenericArrayPayload []interface{}
type GenericPayload ¶
type GenericPayload map[string]interface{}
type Insertable ¶
type Insertable interface {
Insert(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) error
}
Insertable represents a common interface for all model instances so they may be inserted via the Inserts() func
func Inserts ¶
func Inserts() []Insertable
Inserts defines the order in which the fixtures will be inserted into the test database
type TestingT ¶
type TestingT interface { Cleanup(func()) Error(args ...interface{}) Errorf(format string, args ...interface{}) Fail() FailNow() Failed() bool Fatal(args ...interface{}) Fatalf(format string, args ...interface{}) Helper() Log(args ...interface{}) Logf(format string, args ...interface{}) Name() string Skip(args ...interface{}) SkipNow() Skipf(format string, args ...interface{}) Skipped() bool TempDir() string }
TestingT is used to generate a mock of testing.T to enable testing of helper methods which are using assert/require Inspired by: https://github.com/uber-go/zap/blob/master/zaptest/testingt_test.go, commit 5b0fd114dcc089875ee61dfad3617c3a43c2e93e