forked from linode/linodego
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_test.go
60 lines (45 loc) · 1.51 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
package linodego
import (
"fmt"
"github.com/google/go-cmp/cmp"
"testing"
)
func TestClient_SetAPIVersion(t *testing.T) {
defaultURL := "https://api.linode.com/v4"
baseURL := "api.very.cool.com"
apiVersion := "v4beta"
expectedHost := fmt.Sprintf("https://%s/%s", baseURL, apiVersion)
updatedBaseURL := "api.more.cool.com"
updatedAPIVersion := "v4beta_changed"
updatedExpectedHost := fmt.Sprintf("https://%s/%s", updatedBaseURL, updatedAPIVersion)
protocolBaseURL := "http://api.more.cool.com"
protocolAPIVersion := "v4_http"
protocolExpectedHost := fmt.Sprintf("%s/%s", protocolBaseURL, protocolAPIVersion)
client := NewClient(nil)
if client.resty.HostURL != defaultURL {
t.Fatal(cmp.Diff(client.resty.HostURL, defaultURL))
}
client.SetBaseURL(baseURL)
client.SetAPIVersion(apiVersion)
if client.resty.HostURL != expectedHost {
t.Fatal(cmp.Diff(client.resty.HostURL, expectedHost))
}
// Ensure setting twice does not cause conflicts
client.SetBaseURL(updatedBaseURL)
client.SetAPIVersion(updatedAPIVersion)
if client.resty.HostURL != updatedExpectedHost {
t.Fatal(cmp.Diff(client.resty.HostURL, updatedExpectedHost))
}
// Revert
client.SetBaseURL(baseURL)
client.SetAPIVersion(apiVersion)
if client.resty.HostURL != expectedHost {
t.Fatal(cmp.Diff(client.resty.HostURL, expectedHost))
}
// Custom protocol
client.SetBaseURL(protocolBaseURL)
client.SetAPIVersion(protocolAPIVersion)
if client.resty.HostURL != protocolExpectedHost {
t.Fatal(cmp.Diff(client.resty.HostURL, expectedHost))
}
}