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
- Variables
- func Available() bool
- func Client() (*s3.Client, error)
- func ClientT(t *testing.T) *s3.Client
- func CreateBucket(t *testing.T, ctx context.Context) string
- func CreateGCSObjectPrefix(t *testing.T, ctx context.Context) (bucket string, prefix string)
- func DeleteBucket(t *testing.T, ctx context.Context, bucket string)
- func PutBucketPolicy(t *testing.T, ctx context.Context, bucket, policyJSON string)
- func PutObject(t *testing.T, ctx context.Context, bucket, key string, content []byte)
- func PutObjects(t *testing.T, ctx context.Context, bucket string, keys []string)
- func PutObjectsWithContent(t *testing.T, ctx context.Context, bucket string, objects map[string][]byte)
- func RealGCSBucket(t *testing.T) string
- func RealGCSProject() string
- func RealS3Provider(t *testing.T, ctx context.Context, cfg RealS3Config) *providers3.Provider
- func Reset(ctx context.Context) error
- func ResetT(t *testing.T, ctx context.Context)
- func SkipIfUnavailable(t *testing.T)
- type RealS3Config
Constants ¶
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" )
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" )
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 ¶
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 CreateBucket ¶
CreateBucket creates a test bucket with a unique name and registers cleanup.
func CreateGCSObjectPrefix ¶
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 ¶
DeleteBucket deletes a bucket and all its contents.
func PutBucketPolicy ¶
PutBucketPolicy sets a bucket policy.
func PutObjects ¶
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 ¶
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 SkipIfUnavailable ¶
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 ¶
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