forked from rlmcpherson/s3gof3r
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathputter_test.go
43 lines (38 loc) · 953 Bytes
/
putter_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 TestPutterRetryRequest(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)
}
}))
w, err := b.PutWriter("test", nil, nil)
if err != nil {
t.Fatal(err)
}
p, ok := w.(*putter)
if !ok {
t.Fatal("putter type cast failed")
}
_, err = p.retryRequest("POST", testServer.URL, nil, 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)
}
}