Created
March 19, 2015 16:54
-
-
Save vivienschilis/f771b5cd9c0ac9093e04 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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