Skip to content

Instantly share code, notes, and snippets.

@munisystem
Created September 3, 2017 11:29
Show Gist options
  • Save munisystem/3460879e5164d0261ff1773f55d202ae to your computer and use it in GitHub Desktop.
Save munisystem/3460879e5164d0261ff1773f55d202ae to your computer and use it in GitHub Desktop.
package s3
import (
"bytes"
"fmt"
"io"
"net/http"
"testing"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/endpoints"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
dockertest "gopkg.in/ory-am/dockertest.v3"
)
func prepareS3Container(t *testing.T) (func(), string) {
pool, err := dockertest.NewPool("")
if err != nil {
t.Fatalf("couldn't not connect docker host: %s", err.Error())
}
resource, err := pool.Run("atlassianlabs/localstack", "latest", []string{})
if err != nil {
t.Fatalf("couldn't start S3 container: %s", err.Error())
}
addr := fmt.Sprintf("http://localhost:%s", resource.GetPort("4572/tcp"))
cleanup := func() {
if err := pool.Purge(resource); err != nil {
t.Fatalf("couldn't cleanup S3 container: %s", err.Error())
}
}
if err = pool.Retry(func() error {
resp, err := http.Get(addr)
if err != nil {
return err
}
if resp.StatusCode != 200 {
return fmt.Errorf("didn't return status code 200: %s", resp.Status)
}
return nil
}); err != nil {
t.Fatalf("couldn't prepare S3 container: %s", err.Error())
}
return cleanup, addr
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment