gocloud.devgocloud.dev/internal/testing/setup Index | Files

package setup

import "gocloud.dev/internal/testing/setup"

Index

Variables

var Record = flag.Bool("record", false, "whether to run tests against cloud resources and record the interactions")

Record is true iff the tests are being run in "record" mode.

Functions

func FakeGCPCredentials

func FakeGCPCredentials(ctx context.Context) (*google.Credentials, error)

FakeGCPCredentials gets fake GCP credentials.

func FakeGCPDefaultCredentials

func FakeGCPDefaultCredentials(t *testing.T) func()

FakeGCPDefaultCredentials sets up the environment with fake GCP credentials. It returns a cleanup function.

func HasDockerTestEnvironment

func HasDockerTestEnvironment() bool

HasDockerTestEnvironment returns true when either: 1) Not on Github Actions. 2) On Github's Linux environment, where Docker is available.

func NewAWSSession

func NewAWSSession(ctx context.Context, t *testing.T, region string) (sess *session.Session,
	rt http.RoundTripper, cleanup func(), initState int64,
)

NewAWSSession creates a new session for testing against AWS. If the test is in --record mode, the test will call out to AWS, and the results are recorded in a replay file. Otherwise, the session reads a replay file and runs the test as a replay, which never makes an outgoing HTTP call and uses fake credentials. An initState is returned for tests that need a state to have deterministic results, for example, a seed to generate random sequences.

func NewAWSv2Config

func NewAWSv2Config(ctx context.Context, t *testing.T, region string, scrubBody bool) (cfg awsv2.Config, rt http.RoundTripper, cleanup func(), initState int64)

NewAWSv2Config creates a new aws.Config for testing against AWS. If the test is in --record mode, the test will call out to AWS, and the results are recorded in a replay file. Otherwise, the session reads a replay file and runs the test as a replay, which never makes an outgoing HTTP call and uses fake credentials. An initState is returned for tests that need a state to have deterministic results, for example, a seed to generate random sequences.

If scrubBody is true, the entire HTTP POST body is cleared for matching, so the tests will rely entirely on ordering and headers.

func NewAzureKeyVaultTestClient

func NewAzureKeyVaultTestClient(ctx context.Context, t *testing.T) (*http.Client, func())

NewAzureKeyVaultTestClient creates a *http.Client for Azure KeyVault test recordings.

func NewAzureTestBlobClient

func NewAzureTestBlobClient(ctx context.Context, t *testing.T) (*http.Client, func())

NewAzureTestBlobClient creates a new connection for testing against Azure Blob.

func NewGCPClient

func NewGCPClient(ctx context.Context, t *testing.T) (client *gcp.HTTPClient, rt http.RoundTripper, done func())

NewGCPClient creates a new HTTPClient for testing against GCP. NewGCPClient creates a new HTTPClient for testing against GCP. If the test is in --record mode, the client will call out to GCP, and the results are recorded in a replay file. Otherwise, the session reads a replay file and runs the test as a replay, which never makes an outgoing HTTP call and uses fake credentials.

func NewGCPgRPCConn

func NewGCPgRPCConn(ctx context.Context, t *testing.T, endPoint, api string) (*grpc.ClientConn, func())

NewGCPgRPCConn creates a new connection for testing against GCP via gRPC. If the test is in --record mode, the client will call out to GCP, and the results are recorded in a replay file. Otherwise, the session reads a replay file and runs the test as a replay, which never makes an outgoing RPC and uses fake credentials.

func NewRecordReplayClient

func NewRecordReplayClient(ctx context.Context, t *testing.T, rf func(r *httpreplay.Recorder)) (c *http.Client, cleanup func(), initState int64)

NewRecordReplayClient creates a new http.Client for tests. This client's activity is being either recorded to files (when *Record is set) or replayed from files. rf is a modifier function that will be invoked with the address of the httpreplay.Recorder object used to obtain the client; this function can mutate the recorder to add service-specific header filters, for example. An initState is returned for tests that need a state to have deterministic results, for example, a seed to generate random sequences.

Source Files

setup.go

Version
v0.43.0 (latest)
Published
Jul 19, 2025
Platform
linux/amd64
Imports
23 packages
Last checked
1 day ago

Tools for package owners.