-
Notifications
You must be signed in to change notification settings - Fork 0
/
balancer_test.go
113 lines (91 loc) · 2.33 KB
/
balancer_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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package instellar
import (
"testing"
"github.com/jarcoal/httpmock"
"github.com/stretchr/testify/assert"
)
const balancerJSON = `
{
"data": {
"attributes": {
"id": 1,
"name": "some-balancer",
"address": "some.example.com",
"current_state": "active"
},
"id": "1",
"links": {
"self": "http://localhost:4000/provision/balancers/1"
},
"relationships": {},
"type": "balancers"
},
"included": [],
"links": {
"self": "http://localhost:4000/provision/balancers/1"
}
}
`
const deletedBalancerJSON = `
{
"data": {
"attributes": {
"id": 1,
"name": "some-balancer",
"address": "some.example.com",
"current_state": "deleted"
},
"id": "1",
"links": {
"self": "http://localhost:4000/provision/balancers/1"
},
"relationships": {},
"type": "balancers"
},
"included": [],
"links": {
"self": "http://localhost:4000/provision/balancers/1"
}
}
`
func TestGetBalancer(t *testing.T) {
setup()
defer teardown()
httpmock.RegisterResponder("GET", "/provision/balancers/1",
httpmock.NewStringResponder(200, balancerJSON))
balancer, _ := client.GetBalancer("1")
assert.Equal(t, balancer.Data.Attributes.Name, "some-balancer")
}
func TestCreateBalancer(t *testing.T) {
setup()
defer teardown()
httpmock.RegisterResponder("POST", "/provision/clusters/1/balancers",
httpmock.NewStringResponder(201, balancerJSON))
balancerParams := BalancerParams{
Name: "some-balancer",
Address: "some.example.com",
}
balancer, _ := client.CreateBalancer("1", balancerParams)
assert.Equal(t, balancer.Data.Attributes.CurrentState, "active")
}
func TestUpdateBalancer(t *testing.T) {
setup()
defer teardown()
httpmock.RegisterResponder("PATCH", "/provision/balancers/1",
httpmock.NewStringResponder(200, balancerJSON))
balancerParams := BalancerParams{
Name: "some-balancer",
Address: "some.example.com",
}
balancer, _ := client.UpdateBalancer("1", balancerParams)
assert.Equal(t, balancer.Data.Attributes.Name, "some-balancer")
assert.Equal(t, balancer.Data.Attributes.Address, "some.example.com")
}
func TestDeleteBalancer(t *testing.T) {
setup()
defer teardown()
httpmock.RegisterResponder("DELETE", "/provision/balancers/1",
httpmock.NewStringResponder(200, deletedBalancerJSON))
balancer, _ := client.DeleteBalancer("1")
assert.Equal(t, balancer.Data.Attributes.CurrentState, "deleted")
}