testutil

package
v0.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 6, 2018 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package testutil contains helper functions for writing tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CanReplay

func CanReplay(replayFilename string) bool

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

func JWTConfig() (*jwt.Config, error)

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

func NewRand(t time.Time) *rand.Rand

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

func TokenSourceEnv(ctx context.Context, envVar string, scopes ...string) oauth2.TokenSource

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL