-
Notifications
You must be signed in to change notification settings - Fork 7
/
client_test.go
54 lines (46 loc) · 1.55 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
package appoptics
import (
"fmt"
"net/url"
"testing"
)
func TestNewClient_Defaults(t *testing.T) {
token := "deadbeef"
c := NewClient(token)
t.Run("token should be set to passed-in value", func(t *testing.T) {
if c.token != token {
t.Errorf("expected '%s' to match '%s'", c.token, token)
}
})
t.Run("baseURL should be set to default", func(t *testing.T) {
clientURL, _ := url.Parse(defaultBaseURL)
if *c.baseURL != *clientURL {
t.Errorf("expected '%v' to match '%v'", *c.baseURL, *clientURL)
}
})
t.Run("callerUserAgentFragment should be set to default", func(t *testing.T) {
if c.completeUserAgentString() != clientVersionString() {
t.Errorf("expected '%s' to match '%s'", c.completeUserAgentString(), clientVersionString())
}
})
}
func TestNewClient_Customized(t *testing.T) {
token := "deadbeef"
altUserAgentString := "totally-different-thing"
altBaseURLString := "https://metrics-api.appoptics.com"
t.Run("custom user agent string", func(t *testing.T) {
c := NewClient(token, UserAgentClientOption(altUserAgentString))
chkString := fmt.Sprintf("%s:%s", altUserAgentString, clientVersionString())
req, _ := c.NewRequest("GET", "foo", nil)
if req.UserAgent() != chkString {
t.Errorf("expected '%s' to match '%s'", req.UserAgent(), chkString)
}
})
t.Run("custom base URL", func(t *testing.T) {
c := NewClient(token, BaseURLClientOption(altBaseURLString))
testAltBaseURL, _ := url.Parse(altBaseURLString)
if *c.baseURL != *testAltBaseURL {
t.Errorf("expected '%v' to match '%v'", *c.baseURL, *testAltBaseURL)
}
})
}