-
Notifications
You must be signed in to change notification settings - Fork 23
/
options_test.go
59 lines (47 loc) · 1.96 KB
/
options_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
package customerio_test
import (
"net/http"
"reflect"
"testing"
"github.com/customerio/go-customerio/v3"
)
func TestAPIOptions(t *testing.T) {
client := customerio.NewAPIClient("mykey")
if client.URL != customerio.RegionUS.ApiURL {
t.Errorf("wrong default url. got: %s, want: %s", client.URL, customerio.RegionUS.ApiURL)
}
client = customerio.NewAPIClient("mykey", customerio.WithRegion(customerio.RegionEU))
if client.URL != customerio.RegionEU.ApiURL {
t.Errorf("wrong url. got: %s, want: %s", client.URL, customerio.RegionEU.ApiURL)
}
hc := &http.Client{}
client = customerio.NewAPIClient("mykey", customerio.WithHTTPClient(hc))
if !reflect.DeepEqual(client.Client, hc) {
t.Errorf("wrong http client. got: %#v, want: %#v", client.Client, hc)
}
customUserAgent := "Customer.io"
client = customerio.NewAPIClient("mykey", customerio.WithUserAgent(customUserAgent))
if client.UserAgent != customUserAgent {
t.Errorf("wrong user-agent. got: %s, want: %s", client.UserAgent, customUserAgent)
}
}
func TestTrackOptions(t *testing.T) {
client := customerio.NewTrackClient("site_id", "api_key")
if client.URL != customerio.RegionUS.TrackURL {
t.Errorf("wrong default url. got: %s, want: %s", client.URL, customerio.RegionUS.TrackURL)
}
client = customerio.NewTrackClient("site_id", "api_key", customerio.WithRegion(customerio.RegionEU))
if client.URL != customerio.RegionEU.TrackURL {
t.Errorf("wrong url. got: %s, want: %s", client.URL, customerio.RegionEU.TrackURL)
}
hc := &http.Client{}
client = customerio.NewTrackClient("site_id", "api_key", customerio.WithHTTPClient(hc))
if !reflect.DeepEqual(client.Client, hc) {
t.Errorf("wrong http client. got: %#v, want: %#v", client.Client, hc)
}
customUserAgent := "Customer.io"
client = customerio.NewTrackClient("site_id", "api_key", customerio.WithUserAgent(customUserAgent))
if client.UserAgent != customUserAgent {
t.Errorf("wrong user-agent. got: %s, want: %s", client.UserAgent, customUserAgent)
}
}