forked from asecurityteam/transport
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrotate_test.go
37 lines (33 loc) · 904 Bytes
/
rotate_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
package transport
import (
"errors"
"net/http"
"testing"
)
type roundTripperForRotatorTests struct {
v string // Need a value here to make instances unique values
}
func (roundTripperForRotatorTests) RoundTrip(*http.Request) (*http.Response, error) {
return nil, errors.New("")
}
func TestRotatorOptionInstances(t *testing.T) {
var factory = func() http.RoundTripper {
return &roundTripperForRotatorTests{v: "string"}
}
var r = NewRotator(factory)
if len(r.instances) != 1 {
t.Fatal("did not default to one instance")
}
r = NewRotator(factory, RotatorOptionInstances(2))
if len(r.instances) != 2 {
t.Fatal("did not create the right number of instances")
}
_, _ = r.RoundTrip(nil)
if r.currentOffset != 1 {
t.Fatal("did not rotate through instances after using")
}
_, _ = r.RoundTrip(nil)
if r.currentOffset != 0 {
t.Fatal("did not rotate back through the beginning")
}
}