Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Context ¶
Context returns a context that is cancelled when either:
- the test is completed OR
- 10 seconds elapsed
This ensures that no (sub-)test is running longer than 10 seconds.
func Database ¶
Database provides a working database if a valid database connection is provided with the TEST_DATABASE_DSN environment variable. If not, the test is marked as failed.
func PartialEqual ¶
PartialEqual takes a partially-initialized struct its expected (first argument) side, and compares all non-zero values on it or any substructs to the symmetrical values of actual (second argument). In other words, it can take a struct that only has values that the caller cares about, and compares just those, even if actual has other non-zero values.
Example use:
testhelper.PartialEqual(t, dbsqlc.Cluster{ Environment: sql.NullString{String: string(dbsqlc.ClusterEnvironmentProduction), Valid: true}, Name: cluster.Name, }, cluster)
WARNING: In Go, there's no difference between an explicit zero value versus an implicit one from when a field is just left out of a struct initialization, so there's no way for this helper to compare zero values set on the expected side -- they'll just be silently ignored. So watch out for use of anything like `false`, `nil`, `sql.NullString{}`, etc. as none of them will work. Recommended work around is to compare non-zero values with this assertion, and then assert on values expected to be zero with `require.Zero`. For API resources, also consider making fields pointer primitives like `*bool` or `*int` so that an explicit `ptrutil.Ptr(false)` or `ptrutil.Ptr(0)` can be checked.
This is taken and adapted from: https://brandur.org/fragments/partial-equal
func RandomString ¶
RandomString returns a random string of the given length.
Types ¶
This section is empty.