-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver_groups_test.go
65 lines (59 loc) · 1.71 KB
/
server_groups_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
package brightbox
import (
"context"
"path"
"testing"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)
func TestAddServersToServerGroup(t *testing.T) {
instance := testLink(
t,
(*Client).AddServersToServerGroup,
"grp-sda44",
ServerGroupMemberList{[]ServerGroupMember{{"srv-lv426"}}},
"server_group",
"POST",
path.Join("server_groups", "grp-sda44", "add_servers"),
`{"servers":[{"server":"srv-lv426"}]}`,
)
assert.Equal(t, instance.ID, "grp-sda44")
}
func TestRemoveServersFromServerGroup(t *testing.T) {
instance := testLink(
t,
(*Client).RemoveServersFromServerGroup,
"grp-sda44",
ServerGroupMemberList{[]ServerGroupMember{{"srv-lv426"}}},
"server_group",
"POST",
path.Join("server_groups", "grp-sda44", "remove_servers"),
`{"servers":[{"server":"srv-lv426"}]}`,
)
assert.Equal(t, instance.ID, "grp-sda44")
}
func TestMoveServersToServerGroup(t *testing.T) {
modify := (*Client).MoveServersToServerGroup
from := "grp-sda44"
to := "grp-12345"
contents := ServerGroupMemberList{[]ServerGroupMember{{"srv-lv426"}}}
jsonPath := "server_group"
verb := "POST"
expectedPath := path.Join("server_groups", "grp-sda44", "move_servers")
expectedBody := `{"servers":[{"server":"srv-lv426"}],"destination":"grp-12345"}`
ts, client, err := SetupConnection(
&APIMock{
T: t,
ExpectMethod: verb,
ExpectURL: "/1.0/" + expectedPath,
ExpectBody: expectedBody,
GiveBody: readJSON(jsonPath),
},
)
defer ts.Close()
assert.Assert(t, is.Nil(err), "Connect returned an error")
instance, err := modify(client, context.Background(), from, to, contents)
assert.Assert(t, is.Nil(err))
assert.Assert(t, instance != nil)
assert.Equal(t, instance.ID, "grp-sda44")
}