blob: 1f4f6268c26375f8f3e889f96679a817245634fc [file] [log] [blame]
Ash Wilson5b505492014-10-23 10:28:22 -04001package diskconfig
2
3import (
4 "testing"
5
6 "github.com/rackspace/gophercloud/openstack/compute/v2/servers"
7 th "github.com/rackspace/gophercloud/testhelper"
8)
9
10func TestCreateOpts(t *testing.T) {
11 base := servers.CreateOpts{
12 Name: "createdserver",
13 ImageRef: "asdfasdfasdf",
14 FlavorRef: "performance1-1",
15 }
16
17 ext := CreateOptsExt{
18 CreateOptsBuilder: base,
19 DiskConfig: Manual,
20 }
21
22 expected := `
23 {
24 "server": {
25 "name": "createdserver",
26 "imageRef": "asdfasdfasdf",
27 "flavorRef": "performance1-1",
28 "OS-DCF:diskConfig": "MANUAL"
29 }
30 }
31 `
32 th.CheckJSONEquals(t, expected, ext.ToServerCreateMap())
33}
34
35func TestRebuildOpts(t *testing.T) {
36 base := servers.RebuildOpts{
Ash Wilson237aad62014-10-23 12:49:13 -040037 Name: "rebuiltserver",
Ash Wilson5b505492014-10-23 10:28:22 -040038 AdminPass: "swordfish",
39 ImageID: "asdfasdfasdf",
40 }
41
42 ext := RebuildOptsExt{
43 RebuildOptsBuilder: base,
44 DiskConfig: Auto,
45 }
46
47 actual, err := ext.ToServerRebuildMap()
48 th.AssertNoErr(t, err)
49
50 expected := `
51 {
52 "rebuild": {
Ash Wilson237aad62014-10-23 12:49:13 -040053 "name": "rebuiltserver",
Ash Wilson5b505492014-10-23 10:28:22 -040054 "imageRef": "asdfasdfasdf",
55 "adminPass": "swordfish",
56 "OS-DCF:diskConfig": "AUTO"
57 }
58 }
59 `
60 th.CheckJSONEquals(t, expected, actual)
61}
Ash Wilson80387a02014-10-23 10:38:41 -040062
63func TestResizeOpts(t *testing.T) {
64 base := servers.ResizeOpts{
65 FlavorRef: "performance1-8",
66 }
67
68 ext := ResizeOptsExt{
69 ResizeOptsBuilder: base,
70 DiskConfig: Auto,
71 }
72
73 actual, err := ext.ToServerResizeMap()
74 th.AssertNoErr(t, err)
75
76 expected := `
77 {
78 "resize": {
79 "flavorRef": "performance1-8",
80 "OS-DCF:diskConfig": "AUTO"
81 }
82 }
83 `
84 th.CheckJSONEquals(t, expected, actual)
85}