forked from stereosteve/go-balanced
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbalanced_test.go
More file actions
44 lines (35 loc) · 1.14 KB
/
balanced_test.go
File metadata and controls
44 lines (35 loc) · 1.14 KB
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
package balanced
import (
"io/ioutil"
"testing"
)
const secret = "d0342b8a10e611e3adaf026ba7d31e6f"
func TestNewClient(t *testing.T) {
c := NewClient(nil, "")
if c.BaseURL.String() != defaultBaseURL {
t.Errorf("NewClient BaseURL = %v, want %v", c.BaseURL.String(), defaultBaseURL)
}
if c.UserAgent != userAgent {
t.Errorf("NewClient UserAgent = %v, want %v", c.UserAgent, userAgent)
}
}
func TestNewRequest(t *testing.T) {
c := NewClient(nil, "")
inURL, outURL := "/foo", defaultBaseURL+"foo"
inBody, outBody := &Customer{Name: "l"}, `{"name":"l"}`+"\n"
req, _ := c.NewRequest("GET", inURL, inBody)
// test that relative URL was expanded
if req.URL.String() != outURL {
t.Errorf("NewRequest(%v) URL = %v, want %v", inURL, req.URL, outURL)
}
// test that body was JSON encoded
body, _ := ioutil.ReadAll(req.Body)
if string(body) != outBody {
t.Errorf("NewRequest(%v) Body = %v, want %v", inBody, string(body), outBody)
}
// test that default user-agent is attached to the request
userAgent := req.Header.Get("User-Agent")
if c.UserAgent != userAgent {
t.Errorf("NewRequest() User-Agent = %v, want %v", userAgent, c.UserAgent)
}
}