-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcluster_test.go
97 lines (75 loc) · 2.25 KB
/
cluster_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
97
package instellar
import (
"fmt"
"testing"
"github.com/jarcoal/httpmock"
"github.com/stretchr/testify/assert"
)
const slug = "some-test"
const clusterJSON = `
{
"data": {
"attributes": {
"current_state": "%s",
"id": 8,
"endpoint": "127.0.0.1:8443",
"region": "ap-southeast-1",
"provider": "aws",
"slug": "%s"
},
"id": "8",
"links": {
"self": "http://localhost:4000/provision/clusters/8"
},
"relationships": {},
"type": "clusters"
},
"included": [],
"links": {
"self": "http://localhost:4000/provision/clusters/8"
}
}
`
func TestGetCluster(t *testing.T) {
setup()
defer teardown()
httpmock.RegisterResponder("GET", "/provision/clusters/some-test",
httpmock.NewStringResponder(200, fmt.Sprintf(clusterJSON, "healthy", slug)))
cluster, _ := client.GetCluster(slug)
assert.Equal(t, cluster.Data.Attributes.Slug, slug)
}
func TestCreateCluster(t *testing.T) {
setup()
defer teardown()
httpmock.RegisterResponder("POST", "/provision/clusters",
httpmock.NewStringResponder(201, fmt.Sprintf(clusterJSON, "connecting", slug)))
var clusterParams = ClusterParams{
Name: slug,
Provider: "aws",
CredentialEndpoint: "something:8443",
CredentialPassword: "somepass",
CredentialPasswordConfirmation: "somepass",
InsterraComponentID: 1,
}
cluster, _ := client.CreateCluster(clusterParams)
assert.Equal(t, cluster.Data.Attributes.CurrentState, "connecting")
}
func TestUpdateCluster(t *testing.T) {
setup()
defer teardown()
httpmock.RegisterResponder("PATCH", "/provision/clusters/some-test",
httpmock.NewStringResponder(200, fmt.Sprintf(clusterJSON, "syncing", slug)))
var clusterParams = ClusterParams{
CredentialEndpoint: "anotherthing:8443",
}
cluster, _ := client.UpdateCluster(slug, clusterParams)
assert.Equal(t, cluster.Data.Attributes.CurrentState, "syncing")
}
func TestDeleteCluster(t *testing.T) {
setup()
defer teardown()
httpmock.RegisterResponder("DELETE", "/provision/clusters/some-test",
httpmock.NewStringResponder(200, fmt.Sprintf(clusterJSON, "deleted", slug)))
cluster, _ := client.DeleteCluster(slug)
assert.Equal(t, cluster.Data.Attributes.CurrentState, "deleted")
}