forked from rlmcpherson/s3gof3r
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetter_test.go
43 lines (38 loc) · 945 Bytes
/
getter_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package s3gof3r
import (
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"
)
func TestGetterRetryRequest(t *testing.T) {
expectedTries := 3
actualTries := 0
testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
actualTries++
_, err := ioutil.ReadAll(r.Body)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
if actualTries < expectedTries {
http.Error(w, "InternalError", http.StatusInternalServerError)
} else {
http.Error(w, "ok", http.StatusOK)
}
}))
r, _, err := b.GetReader("test", nil)
if err != nil {
t.Fatal(err)
}
g, ok := r.(*getter)
if !ok {
t.Fatal("getter type cast failed")
}
_, err = g.retryRequest("GET", testServer.URL, nil)
if err != nil {
t.Fatalf("Expected no error, got: %s", err.Error())
}
if actualTries != expectedTries {
t.Fatalf("Expected %d tries, got: %d", expectedTries, actualTries)
}
}