-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcontainers_test.go
96 lines (84 loc) · 2.24 KB
/
containers_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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package cloudability
import (
"net/url"
"testing"
)
func TestContainersProvisioningEndpoint(t *testing.T) {
testClient := NewClient("testapikey")
e := testClient.Containers()
if e.BaseURL.String() != apiV3URL {
t.Errorf("ContaintersProvisioningEndpoint BaseURL mismatch. Got %s. Expected %s", e.BaseURL.String(), apiV3URL)
}
if e.EndpointPath != containersEndpoint {
t.Errorf("ContaintersProvisioningEndpoint EndpointPath mismatch. Got %s. Expected %s", e.EndpointPath, containersEndpoint)
}
}
func TestGetCluster(t *testing.T) {
testServer := testAPI(t, "GET", "/containers/provisioning", nil)
defer testServer.Close()
testClient := NewClient("testapikey")
e := testClient.Containers()
e.BaseURL, _ = url.Parse(testServer.URL)
_, err := e.GetCluster("1")
if err != nil {
t.Fail()
}
}
func TestGetClusterConfig(t *testing.T) {
mockYAML := `
apiVersion: v1
kind: Namespace
metadata:
name: cloudability
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: cloudability
namespace: cloudability
`
testServer := testAPI(t, "GET", "/containers/provisioning/1/config", mockYAML)
defer testServer.Close()
testClient := NewClient("testapikey")
e := testClient.Containers()
e.BaseURL, _ = url.Parse(testServer.URL)
config, err := e.GetClusterConfig("1")
if err != nil {
t.Fail()
}
if config != mockYAML {
t.Fail()
}
}
func TestNewCluster(t *testing.T) {
cluster := &Cluster{
ClusterName: "test-cluster-name",
ClusterVersion: "test-cluster-version",
KubernetesVersion: "1.11",
}
testServer := testAPI(t, "POST", "/containers/provisioning", cluster)
defer testServer.Close()
testClient := NewClient("testapikey")
e := testClient.Containers()
e.BaseURL, _ = url.Parse(testServer.URL)
_, err := e.NewCluster(cluster)
if err != nil {
t.Fail()
}
}
func TestUpdateCluster(t *testing.T) {
cluster := &Cluster{
ClusterName: "test-cluster-name",
ClusterVersion: "test-cluster-version",
KubernetesVersion: "test-kubernetes-version",
}
testServer := testAPI(t, "PUT", "/containers/provisioning/0", cluster)
defer testServer.Close()
testClient := NewClient("testapikey")
e := testClient.Containers()
e.BaseURL, _ = url.Parse(testServer.URL)
err := e.UpdateCluster(cluster)
if err != nil {
t.Fail()
}
}