forked from cloudfoundry/go-cfclient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_test.go
78 lines (70 loc) · 2.02 KB
/
client_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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package cfclient
import (
"testing"
"github.com/onsi/gomega"
. "github.com/smartystreets/goconvey/convey"
"net/http"
"time"
)
func TestDefaultConfig(t *testing.T) {
Convey("Default config", t, func() {
c := DefaultConfig()
So(c.ApiAddress, ShouldEqual, "http://api.bosh-lite.com")
So(c.Username, ShouldEqual, "admin")
So(c.Password, ShouldEqual, "admin")
So(c.SkipSslValidation, ShouldEqual, false)
So(c.Token, ShouldEqual, "")
So(c.UserAgent, ShouldEqual, "Go-CF-client/1.1")
})
}
func TestMakeRequest(t *testing.T) {
Convey("Test making request b", t, func() {
setup(MockRoute{"GET", "/v2/organizations", listOrgsPayload, "", 200, ""}, t)
defer teardown()
c := &Config{
ApiAddress: server.URL,
Username: "foo",
Password: "bar",
SkipSslValidation: true,
}
client, err := NewClient(c)
So(err, ShouldBeNil)
req := client.NewRequest("GET", "/v2/organizations")
resp, err := client.DoRequest(req)
So(err, ShouldBeNil)
So(resp, ShouldNotBeNil)
})
}
func TestMakeRequestWithTimeout(t *testing.T) {
Convey("Test making request b", t, func() {
setup(MockRoute{"GET", "/v2/organizations", listOrgsPayload, "", 200, ""}, t)
defer teardown()
c := &Config{
ApiAddress: server.URL,
Username: "foo",
Password: "bar",
SkipSslValidation: true,
HttpClient: &http.Client{Timeout: 10 * time.Nanosecond},
}
client, err := NewClient(c)
So(err, ShouldNotBeNil)
So(client, ShouldBeNil)
})
}
func TestTokenRefresh(t *testing.T) {
gomega.RegisterTestingT(t)
Convey("Test making request", t, func() {
setup(MockRoute{"GET", "/v2/organizations", listOrgsPayload, "", 200, ""}, t)
c := &Config{
ApiAddress: server.URL,
Username: "foo",
Password: "bar",
}
client, err := NewClient(c)
So(err, ShouldBeNil)
token, err := client.GetToken()
So(err, ShouldBeNil)
gomega.Consistently(token).Should(gomega.Equal("bearer foobar2"))
// gomega.Eventually(client.GetToken(), "3s").Should(gomega.Equal("bearer foobar3"))
})
}