Documentation ¶
Overview ¶
Package testutil contains helper functions for writing tests.
Index ¶
- func CanReplay(replayFilename string) bool
- func JWTConfig() (*jwt.Config, error)
- func NewRand(t time.Time) *rand.Rand
- func ProjectID() string
- func TokenSource(ctx context.Context, scopes ...string) oauth2.TokenSource
- func TokenSourceEnv(ctx context.Context, envVar string, scopes ...string) oauth2.TokenSource
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CanReplay ¶
CanReplay reports whether an integration test can be run in replay mode. The replay file must exist, and the GCLOUD_TESTS_GOLANG_ENABLE_REPLAY environment variable must be non-empty.
func JWTConfig ¶
JWTConfig reads the JSON private key file whose name is in the default environment variable, and returns the jwt.Config it contains. It ignores scopes. If the environment variable is empty, it returns (nil, nil).
func NewRand ¶
NewRand creates a new *rand.Rand seeded with t. The return value is safe for use with multiple goroutines.
func ProjectID ¶
func ProjectID() string
ProjectID returns the project ID to use in integration tests, or the empty string if none is configured.
func TokenSource ¶
func TokenSource(ctx context.Context, scopes ...string) oauth2.TokenSource
TokenSource returns the OAuth2 token source to use in integration tests, or nil if none is configured. It uses the standard environment variable for tests in this repo.
func TokenSourceEnv ¶
TokenSourceEnv returns the OAuth2 token source to use in integration tests. or nil if none is configured. It tries to get credentials from the filename in the environment variable envVar. If the environment variable is unset, TokenSourceEnv will try to find 'Application Default Credentials'. Else, TokenSourceEnv will return nil. TokenSourceEnv will log.Fatal if the token source is specified but missing or invalid.
Types ¶
This section is empty.