cloudtest

package
v0.4.6 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package cloudtest provides helpers for cloud integration tests using moto.

These helpers enable testing against a local S3-compatible endpoint without requiring real AWS credentials. Tests using this package should be tagged with //go:build cloudintegration.

Usage:

func TestMyS3Function(t *testing.T) {
    cloudtest.SkipIfUnavailable(t)
    bucket := cloudtest.CreateBucket(t, ctx)
    cloudtest.PutObject(t, ctx, bucket, "key", []byte("content"))
    // ... test code ...
}

Index

Constants

View Source
const (
	// DefaultEndpoint is the default moto server endpoint.
	// Port 5555 avoids conflict with macOS AirTunes on 5000.
	DefaultEndpoint = "http://localhost:5555"

	// DefaultRegion is the default AWS region for tests.
	DefaultRegion = "us-east-1"

	// TestAccessKeyID is the access key used for moto (accepts any).
	TestAccessKeyID = "testing"

	// TestSecretAccessKey is the secret key used for moto (accepts any).
	TestSecretAccessKey = "testing"
)
View Source
const (
	// RealGCSBucketEnv is the opt-in bucket for real GCS integration tests.
	RealGCSBucketEnv = "GONIMBUS_GCS_TEST_BUCKET"

	// RealGCSProjectEnv is an optional GCP project hint for real GCS tests.
	RealGCSProjectEnv = "GONIMBUS_GCS_TEST_PROJECT"

	// RealGCSPrefixEnv optionally scopes real GCS test objects within the
	// supplied bucket. Tests still append a unique per-test suffix.
	RealGCSPrefixEnv = "GONIMBUS_GCS_TEST_PREFIX"
)
View Source
const (
	// RealS3BucketEnv is the opt-in bucket for real S3-compatible integration
	// tests.
	RealS3BucketEnv = "GONIMBUS_S3_TEST_BUCKET"

	// RealS3EndpointEnv optionally points tests at an S3-compatible endpoint.
	RealS3EndpointEnv = "GONIMBUS_S3_TEST_ENDPOINT"

	// RealS3RegionEnv optionally supplies the AWS region or S3-compatible
	// signing region.
	RealS3RegionEnv = "GONIMBUS_S3_TEST_REGION"

	// RealS3ProfileEnv optionally selects an AWS shared-config profile for
	// tests. If unset, the SDK default credential chain is used.
	RealS3ProfileEnv = "GONIMBUS_S3_TEST_PROFILE"

	// RealS3PrefixEnv optionally scopes real S3 test objects within the
	// supplied bucket. Tests still append a unique per-test suffix.
	RealS3PrefixEnv = "GONIMBUS_S3_TEST_PREFIX"

	// RealS3ForcePathStyleEnv optionally overrides the default path-style
	// behavior. When unset, endpoint-backed S3-compatible tests use path-style.
	RealS3ForcePathStyleEnv = "GONIMBUS_S3_TEST_FORCE_PATH_STYLE"
)

Variables

View Source
var (
	// Endpoint is the moto server endpoint, configurable via MOTO_ENDPOINT env var.
	Endpoint = getEnvOrDefault("MOTO_ENDPOINT", DefaultEndpoint)

	// Region is the AWS region for tests, configurable via MOTO_REGION env var.
	Region = getEnvOrDefault("MOTO_REGION", DefaultRegion)
)

Functions

func Available

func Available() bool

Available checks if the moto server is reachable.

func Client

func Client() (*s3.Client, error)

Client returns a shared S3 client configured for moto.

func ClientT

func ClientT(t *testing.T) *s3.Client

ClientT returns the S3 client, failing the test on error.

func CreateBucket

func CreateBucket(t *testing.T, ctx context.Context) string

CreateBucket creates a test bucket with a unique name and registers cleanup.

func CreateGCSObjectPrefix

func CreateGCSObjectPrefix(t *testing.T, ctx context.Context) (bucket string, prefix string)

CreateGCSObjectPrefix returns the configured bucket and a unique object prefix for a real GCS test. Cleanup deletes only objects under that generated prefix.

func DeleteBucket

func DeleteBucket(t *testing.T, ctx context.Context, bucket string)

DeleteBucket deletes a bucket and all its contents.

func PutBucketPolicy

func PutBucketPolicy(t *testing.T, ctx context.Context, bucket, policyJSON string)

PutBucketPolicy sets a bucket policy.

func PutObject

func PutObject(t *testing.T, ctx context.Context, bucket, key string, content []byte)

PutObject uploads an object to the bucket.

func PutObjects

func PutObjects(t *testing.T, ctx context.Context, bucket string, keys []string)

PutObjects uploads multiple objects with the given keys and empty content.

func PutObjectsWithContent

func PutObjectsWithContent(t *testing.T, ctx context.Context, bucket string, objects map[string][]byte)

PutObjectsWithContent uploads multiple objects with specified content.

func RealGCSBucket

func RealGCSBucket(t *testing.T) string

RealGCSBucket returns the bring-your-own GCS test bucket, or skips when the opt-in environment is absent.

func RealGCSProject

func RealGCSProject() string

RealGCSProject returns the optional project hint for GCS client construction.

func RealS3Provider

func RealS3Provider(t *testing.T, ctx context.Context, cfg RealS3Config) *providers3.Provider

func Reset

func Reset(ctx context.Context) error

Reset clears all moto state. Call this between tests for isolation.

func ResetT

func ResetT(t *testing.T, ctx context.Context)

ResetT resets moto state, failing the test on error.

func SkipIfUnavailable

func SkipIfUnavailable(t *testing.T)

SkipIfUnavailable skips the test if moto server is not available.

Types

type RealS3Config

type RealS3Config struct {
	Bucket         string
	Endpoint       string
	Region         string
	Profile        string
	Prefix         string
	ForcePathStyle bool
}

func CreateS3ObjectPrefix

func CreateS3ObjectPrefix(t *testing.T, ctx context.Context) (RealS3Config, string)

CreateS3ObjectPrefix returns the configured bucket and a unique object prefix for a real S3-compatible test. Cleanup deletes only objects under that generated prefix.

func RealS3ConfigFromEnv

func RealS3ConfigFromEnv(t *testing.T) RealS3Config

RealS3ConfigFromEnv returns the bring-your-own S3-compatible test configuration, or skips when the opt-in bucket environment is absent.

func (RealS3Config) ObjectURI

func (cfg RealS3Config) ObjectURI(key string) string

func (RealS3Config) ProviderConfig

func (cfg RealS3Config) ProviderConfig() providers3.Config

Jump to

Keyboard shortcuts

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