Documentation ¶
Overview ¶
Package testutil provides utility functions for writing unit tests.
Index ¶
- Constants
- func CombineMutations(msSlice ...[]*spanner.Mutation) []*spanner.Mutation
- func ConnectToRedis() bool
- func GetSignedURLOptions(ctx context.Context) *storage.SignedURLOptions
- func MustApply(ctx context.Context, t testing.TB, ms ...*spanner.Mutation) time.Time
- func MustNotFindRow(ctx context.Context, t testing.TB, table string, key spanner.Key, ...)
- func MustReadRow(ctx context.Context, t testing.TB, table string, key spanner.Key, ...)
- func SetGCSAllowedBuckets(ctx context.Context, t testing.TB, project, user, bucket string) context.Context
- func SpannerTestContext(tb testing.TB) context.Context
- func SpannerTestMain(m *testing.M)
- func TestInvocationExtendedProperties() map[string]*structpb.Struct
- func TestProjectConfigContext(ctx context.Context, t testing.TB, project, user, bucket string) context.Context
- func TestProperties() *structpb.Struct
- func TestSources() *pb.Sources
- func TestSourcesWithChangelistNumbers(changelistNumbers ...int) *pb.Sources
- func TestingContext() context.Context
Constants ¶
const ( // Client email for testing. ClientEmail = "serviceacct@example.com" // Private key from inactive service account for testing. PrivateKey = "" /* 1732-byte string literal not displayed */ )
const ( // IntegrationTestEnvVar is the name of the environment variable which controls // whether spanner tests are executed. // The value must be "1" for integration tests to run. IntegrationTestEnvVar = "INTEGRATION_TESTS" // RedisTestEnvVar is the name of the environment variable which controls // whether tests will attempt to connect to *local* Redis at port 6379. // The value must be "1" to connect to Redis. // // Note that this mode does not support running multiple test binaries in // parallel, e.g. `go test ./...`. // This could be mitigated by using different Redis databases in different // test binaries, but the default limit is only 16. RedisTestEnvVar = "INTEGRATION_TESTS_REDIS" // EmulatorEnvVar is the name of the environment variable which controls // whether to run spanner tests using Cloud Spanner Emulator. // The value must be "1" to use emulator. EmulatorEnvVar = "SPANNER_EMULATOR" )
Variables ¶
This section is empty.
Functions ¶
func CombineMutations ¶
CombineMutations concatenates mutations
func ConnectToRedis ¶
func ConnectToRedis() bool
ConnectToRedis returns true if tests should connect to Redis.
func GetSignedURLOptions ¶
func GetSignedURLOptions(ctx context.Context) *storage.SignedURLOptions
GetSignedURLOptions used for testing.
func MustApply ¶
MustApply applies the mutations to the spanner client in the context. Asserts that application succeeds. Returns the commit timestamp.
func MustNotFindRow ¶
func MustNotFindRow(ctx context.Context, t testing.TB, table string, key spanner.Key, ptrMap map[string]any)
MustNotFindRow is a shortcut to do a single row read in a single transaction using the current client, and assert the row was not found.
func MustReadRow ¶
func MustReadRow(ctx context.Context, t testing.TB, table string, key spanner.Key, ptrMap map[string]any)
MustReadRow is a shortcut to do a single row read in a single transaction using the current client, and assert success.
func SetGCSAllowedBuckets ¶
func SetGCSAllowedBuckets(ctx context.Context, t testing.TB, project, user, bucket string) context.Context
SetGCSAllowedBuckets overrides the only existing project-config GcsAllowlist entry to match the rule defined by project, realm, bucket and prefix.
func SpannerTestContext ¶
SpannerTestContext returns a context for testing code that talks to Spanner. Skips the test if integration tests are not enabled.
Tests that use Spanner must not call t.Parallel().
func SpannerTestMain ¶
SpannerTestMain is a test main function for packages that have tests that talk to spanner. It creates/destroys a temporary spanner database before/after running tests.
This function never returns. Instead it calls os.Exit with the value returned by m.Run().
func TestProjectConfigContext ¶
func TestProjectConfigContext(ctx context.Context, t testing.TB, project, user, bucket string) context.Context
TestProjectConfigContext returns a context to be used in project config related tests.
func TestProperties ¶
func TestSources ¶
func TestingContext ¶
TestingContext returns a context to be used in tests.
Types ¶
This section is empty.