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
- func Within(ctx context.Context, perCall time.Duration) (context.Context, context.CancelFunc)
- type Calls
- type LogTail
- type OpError
- type PollReport
- 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.10.0" // 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.
When the tests fail and Main started the container, it prints the last 200 lines of the log of the emulator to stderr, read through the Docker API, before it removes the container. For an external instance (GOPHERSTACK_ENDPOINT) it has no container and prints nothing.
func TestMain(m *testing.M) { os.Exit(gopherstack.Main(m)) }
func UniqueName ¶
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 Calls ¶
type Calls struct {
// contains filtered or unexported fields
}
Calls makes the calls of one step. Each call gets its own context, cut at the per-call bound and never later than the deadline of the whole wait, so a call that is slow does not take the time of the next one, and nothing runs past the deadline. A step cannot share one context across calls by mistake: it has no other way to call.
type LogTail ¶
type LogTail struct {
// ReadErr is the error that ended the read before the end of the log, nil when the log was read to its end.
ReadErr error
// Lines are the last lines read, in order. A line longer than the cap is cut and ends with a marker.
Lines []string
// MaxLine is the cap of a line, in bytes.
MaxLine int
// CutLines counts the lines that were longer than MaxLine.
CutLines int
// Want is the number of lines asked for.
Want int
}
LogTail is the end of a log, with what could not be kept.
func TailLog ¶
TailLog reads r to its end (or its first error) and keeps the last want lines. A line longer than maxLine bytes is cut there and ends with a visible marker, and is counted. It cannot fail on a long line.
type OpError ¶
type OpError struct {
// Err is the first error with this text.
Err error
// Op is the name of the operation, as the caller gave it.
Op string
// Count is the number of times the same operation failed with the same text.
Count int
}
OpError is an error of a call of the emulator, with the operation that failed and how many times it did.
type PollReport ¶
type PollReport struct {
// Errors lists the distinct errors (operation and text) in the order they first happened, at most
// maxDistinctErrors of them.
Errors []OpError
// Polls is the number of steps that ran.
Polls int
// Incomplete is the number of steps that made no failed call and did not finish the job.
Incomplete int
// Dropped counts the errors that were not listed because the list was full.
Dropped int
// Done reports that a step finished the job.
Done bool
}
PollReport is what Poll saw, for the failure message of a test that polls the emulator.
func Poll ¶
func Poll(ctx context.Context, perCall, interval time.Duration, step func(c *Calls) bool) *PollReport
Poll runs step until it returns true or ctx ends. The deadline of the whole wait is the one of ctx. The step makes its calls through the Calls it is given. Between two steps Poll waits interval (or until ctx ends). It makes no read of the clock.
func (*PollReport) String ¶
func (r *PollReport) String() string
String says what happened, for a failure message built after the polling ended.
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 StartIsolated ¶
StartIsolated always starts a new container, ignoring GOPHERSTACK_ENDPOINT, so that a test can have a second emulator whose buckets are not those of the shared one (the same bucket name then names two distinct stores). The caller removes it with Server.Terminate.
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.