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
- func Main(m *testing.M) int
- func UniqueName(tb testing.TB, prefix string) string
- type Server
- func (s *Server) AwsConfig(ctx context.Context) (aws.Config, error)
- func (s *Server) CreateBucket(tb testing.TB, prefix string) string
- func (s *Server) GetObject(tb testing.TB, bucket, key string) []byte
- func (s *Server) ListKeys(tb testing.TB, bucket, prefix string) []string
- func (s *Server) MustAwsConfig(tb testing.TB) aws.Config
- func (s *Server) PutObject(tb testing.TB, bucket, key string, content []byte)
- func (s *Server) S3Client(tb testing.TB) *s3.Client
- func (s *Server) SetAwsEnv(t *testing.T)
- func (s *Server) Terminate() error
Constants ¶
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 ¶
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)) }
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 ¶
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 ¶
Start starts a container (or attaches to GOPHERSTACK_ENDPOINT) and waits until it is healthy.
func (*Server) AwsConfig ¶
AwsConfig returns an AWS config with static credentials, the region and the emulator endpoint.
func (*Server) CreateBucket ¶
CreateBucket creates a bucket named UniqueName(t, prefix) and returns its name.
func (*Server) MustAwsConfig ¶
MustAwsConfig is AwsConfig failing the test on error.