Skip to content

Instantly share code, notes, and snippets.

@vivienschilis
Created March 19, 2015 16:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vivienschilis/f771b5cd9c0ac9093e04 to your computer and use it in GitHub Desktop.
Save vivienschilis/f771b5cd9c0ac9093e04 to your computer and use it in GitHub Desktop.
package aws_test
import (
"fmt"
"github.com/mitchellh/goamz/aws"
"github.com/mitchellh/goamz/s3"
"net/http"
"net/http/httptest"
"testing"
)
// Retrieve the response from handler using aws.RetryingClient
func serveAndGet(handler http.HandlerFunc) (body string, err error) {
ts := httptest.NewServer(handler)
defer ts.Close()
region := aws.Region{
Name: "local-1",
S3Endpoint: ts.URL,
S3LocationConstraint: true,
}
auth, err := aws.GetAuth("foo", "bar")
s3Client := s3.New(auth, region)
s3Client.HTTPClient = func() *http.Client {
return aws.RetryingClient
}
err = s3Client.Bucket("foobar").Put("foofile", []byte("data to send"), "applications/json", s3.Private)
return
}
func TestClient_retries(t *testing.T) {
failed := false
// Fail once before succeeding.
_, err := serveAndGet(func(w http.ResponseWriter, r *http.Request) {
if !failed {
http.Error(w, "error", 500)
failed = true
} else {
fmt.Fprintln(w, "ok")
}
})
if failed != true {
t.Error("We didn't retry!")
}
if err != nil {
t.Fatal(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment