blob: e3c26d49a5526f3b57be8b9263f774d8295151dc [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 `
Jon Perritt4149d7c2014-10-23 21:23:46 -050032 actual, err := ext.ToServerCreateMap()
33 th.AssertNoErr(t, err)
34 th.CheckJSONEquals(t, expected, actual)
Ash Wilson5b505492014-10-23 10:28:22 -040035}
36
37func TestRebuildOpts(t *testing.T) {
38 base := servers.RebuildOpts{
Ash Wilson237aad62014-10-23 12:49:13 -040039 Name: "rebuiltserver",
Ash Wilson5b505492014-10-23 10:28:22 -040040 AdminPass: "swordfish",
41 ImageID: "asdfasdfasdf",
42 }
43
44 ext := RebuildOptsExt{
45 RebuildOptsBuilder: base,
46 DiskConfig: Auto,
47 }
48
49 actual, err := ext.ToServerRebuildMap()
50 th.AssertNoErr(t, err)
51
52 expected := `
53 {
54 "rebuild": {
Ash Wilson237aad62014-10-23 12:49:13 -040055 "name": "rebuiltserver",
Ash Wilson5b505492014-10-23 10:28:22 -040056 "imageRef": "asdfasdfasdf",
57 "adminPass": "swordfish",
58 "OS-DCF:diskConfig": "AUTO"
59 }
60 }
61 `
62 th.CheckJSONEquals(t, expected, actual)
63}
Ash Wilson80387a02014-10-23 10:38:41 -040064
65func TestResizeOpts(t *testing.T) {
66 base := servers.ResizeOpts{
67 FlavorRef: "performance1-8",
68 }
69
70 ext := ResizeOptsExt{
71 ResizeOptsBuilder: base,
72 DiskConfig: Auto,
73 }
74
75 actual, err := ext.ToServerResizeMap()
76 th.AssertNoErr(t, err)
77
78 expected := `
79 {
80 "resize": {
81 "flavorRef": "performance1-8",
82 "OS-DCF:diskConfig": "AUTO"
83 }
84 }
85 `
86 th.CheckJSONEquals(t, expected, actual)
87}