-
Notifications
You must be signed in to change notification settings - Fork 0
/
resilience_test.go
46 lines (34 loc) · 1.03 KB
/
resilience_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
44
45
46
package resilience
import (
"net/http"
"net/url"
"testing"
"github.com/darshanime/resilience4go/bulkhead"
"github.com/stretchr/testify/assert"
)
type noopRoundTripper struct {
next http.RoundTripper
}
func (n *noopRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
return n.next.RoundTrip(req)
}
func TestResilience(t *testing.T) {
r := New("test")
assert.Equal(t, "test", r.name)
bh := bulkhead.New()
r = r.WithBulkHead(bh)
assert.Equal(t, bh, r.bh)
r.Build()
assert.Equal(t, http.DefaultTransport, r.next)
myHTTPClient := &http.Client{}
myTransport := &noopRoundTripper{next: http.DefaultTransport}
myHTTPClient.Transport = myTransport
newHTTPClient := r.BuildWithHTTPClient(myHTTPClient)
assert.Equal(t, myTransport, r.next)
assert.Equal(t, r, newHTTPClient.Transport)
u, _ := url.Parse("http://foo.bar")
req := &http.Request{URL: u}
assert.Equal(t, "http://foo.bar", r.reqNamer(req))
r.WithRequestNamer(func(req *http.Request) string { return "foobar" })
assert.Equal(t, "foobar", r.reqNamer(req))
}