forked from Cox-Automotive/alks-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_test.go
56 lines (41 loc) · 1.21 KB
/
api_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
package alks
import (
"testing"
)
func makeClient(t *testing.T) *Client {
client, err := NewClient("http://foo.bar.com", "brian", "pass", "acct", "role")
if err != nil {
t.Fatalf("err: %v", err)
}
if client.BaseURL != "http://foo.bar.com" {
t.Fatalf("base url not set on client: %s", client.BaseURL)
}
if client.Account.Username != "brian" {
t.Fatalf("account username not set on client: %s", client.Account.Username)
}
if client.Account.Password != "pass" {
t.Fatalf("account password not set on client: %s", client.Account.Password)
}
if client.Account.Account != "acct" {
t.Fatalf("account account not set on client: %s", client.Account.Account)
}
if client.Account.Role != "role" {
t.Fatalf("account role not set on client: %s", client.Account.Role)
}
return client
}
func TestClient_NewRequest(t *testing.T) {
c := makeClient(t)
json := []byte(`{"fooz":"barz"}`)
req, err := c.NewRequest(json, "POST", "/endpointfun")
if err != nil {
t.Fatalf("bad: %v", err)
}
if req.URL.String() != "http://foo.bar.com/endpointfun" {
t.Fatalf("bad base url: %v", req.URL.String())
}
if req.Method != "POST" {
t.Fatalf("bad method: %v", req.Method)
}
}
// TODO: tests for STS functionality