gopherstack

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 20 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package gopherstack starts the gopherstack AWS emulator (https://github.com/blackbirdworks/gopherstack) in a Docker container, to run end-to-end tests of the AWS-backed components (S3, Kinesis, SQS).

One emulator is shared by all the tests of a package: the TestMain of the package runs Main, which starts it and removes it when the tests are done, and the tests get it with Connect.

Environment variables:

  • GOPHERSTACK_ENDPOINT reuses an already running instance (ex: http://127.0.0.1:8000) instead of starting a container.
  • GOPHERSTACK_IMAGE overrides Image.

Index

Constants

View Source
const (
	// Image is the pinned gopherstack image (sha256:3683df48d7ed91df17214e3b6169609420d0d3a59b21a26f808b556be4cd8f78).
	Image = "ghcr.io/blackbirdworks/gopherstack:1.9.1"
	// Port is the port gopherstack listens on in the container.
	Port = "8000/tcp"
	// HealthPath is the health check endpoint.
	HealthPath = "/_gopherstack/health"

	// Region is the region used by the tests.
	Region = "us-east-1"
	// AccessKey is the (not validated) access key id used by the tests.
	AccessKey = "test"
	// SecretKey is the (not validated) secret access key used by the tests.
	SecretKey = "test"

	// EnvEndpoint is the env var to reuse a running instance.
	EnvEndpoint = "GOPHERSTACK_ENDPOINT"
	// EnvImage is the env var to override Image.
	EnvImage = "GOPHERSTACK_IMAGE"
)

Variables

This section is empty.

Functions

func Main

func Main(m *testing.M) int

Main is the body of the TestMain of a package that runs end-to-end tests against the emulator. It starts one emulator for the package (unless GOPHERSTACK_ENDPOINT already points to one) when Docker is available, publishes its endpoint in GOPHERSTACK_ENDPOINT for Connect, runs the tests and removes the container. When Docker is not available the tests that call Connect are skipped.

func TestMain(m *testing.M) { os.Exit(gopherstack.Main(m)) }

func UniqueName

func UniqueName(tb testing.TB, prefix string) string

UniqueName returns a name unique to the test and the run (lowercase, DNS valid, <= 63 chars), usable as bucket, queue or stream name.

Types

type Server

type Server struct {

	// Endpoint is the base URL (ex: http://127.0.0.1:49153). An IP host makes the AWS SDK use
	// path-style S3 addressing, so no DNS is needed.
	Endpoint string
	// contains filtered or unexported fields
}

Server is a running gopherstack instance.

func Connect

func Connect(tb testing.TB) *Server

Connect returns the emulator that Main started (or that GOPHERSTACK_ENDPOINT points to). The test is skipped if there is none, because Docker is not available.

func Start

func Start(ctx context.Context) (*Server, error)

Start starts a container (or attaches to GOPHERSTACK_ENDPOINT) and waits until it is healthy.

func (*Server) AwsConfig

func (s *Server) AwsConfig(ctx context.Context) (aws.Config, error)

AwsConfig returns an AWS config with static credentials, the region and the emulator endpoint.

func (*Server) CreateBucket

func (s *Server) CreateBucket(tb testing.TB, prefix string) string

CreateBucket creates a bucket named UniqueName(t, prefix) and returns its name.

func (*Server) GetObject

func (s *Server) GetObject(tb testing.TB, bucket, key string) []byte

GetObject downloads bucket/key.

func (*Server) ListKeys

func (s *Server) ListKeys(tb testing.TB, bucket, prefix string) []string

ListKeys returns all the keys of the bucket under prefix.

func (*Server) MustAwsConfig

func (s *Server) MustAwsConfig(tb testing.TB) aws.Config

MustAwsConfig is AwsConfig failing the test on error.

func (*Server) PutObject

func (s *Server) PutObject(tb testing.TB, bucket, key string, content []byte)

PutObject uploads content at bucket/key.

func (*Server) S3Client

func (s *Server) S3Client(tb testing.TB) *s3.Client

S3Client returns an S3 client on the emulator.

func (*Server) SetAwsEnv

func (s *Server) SetAwsEnv(t *testing.T)

SetAwsEnv points the AWS SDK default config chain (used by the relay proxy, which has no endpoint setting) to the emulator. It uses t.Setenv so the calling test can't be parallel.

func (*Server) Terminate

func (s *Server) Terminate() error

Terminate removes the container (no-op for an external instance).

Jump to

Keyboard shortcuts

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