blob: 17418a3ce3accf7d49180d57bdacc590fc22f5af [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",
Jon Perrittad5f1cb2015-05-20 10:38:13 -060028 "flavorName": "",
29 "imageName": "",
Ash Wilson5b505492014-10-23 10:28:22 -040030 "OS-DCF:diskConfig": "MANUAL"
31 }
32 }
33 `
Jon Perritt4149d7c2014-10-23 21:23:46 -050034 actual, err := ext.ToServerCreateMap()
35 th.AssertNoErr(t, err)
36 th.CheckJSONEquals(t, expected, actual)
Ash Wilson5b505492014-10-23 10:28:22 -040037}
38
39func TestRebuildOpts(t *testing.T) {
40 base := servers.RebuildOpts{
Ash Wilson237aad62014-10-23 12:49:13 -040041 Name: "rebuiltserver",
Ash Wilson5b505492014-10-23 10:28:22 -040042 AdminPass: "swordfish",
43 ImageID: "asdfasdfasdf",
44 }
45
46 ext := RebuildOptsExt{
47 RebuildOptsBuilder: base,
48 DiskConfig: Auto,
49 }
50
51 actual, err := ext.ToServerRebuildMap()
52 th.AssertNoErr(t, err)
53
54 expected := `
55 {
56 "rebuild": {
Ash Wilson237aad62014-10-23 12:49:13 -040057 "name": "rebuiltserver",
Ash Wilson5b505492014-10-23 10:28:22 -040058 "imageRef": "asdfasdfasdf",
59 "adminPass": "swordfish",
60 "OS-DCF:diskConfig": "AUTO"
61 }
62 }
63 `
64 th.CheckJSONEquals(t, expected, actual)
65}
Ash Wilson80387a02014-10-23 10:38:41 -040066
67func TestResizeOpts(t *testing.T) {
68 base := servers.ResizeOpts{
69 FlavorRef: "performance1-8",
70 }
71
72 ext := ResizeOptsExt{
73 ResizeOptsBuilder: base,
74 DiskConfig: Auto,
75 }
76
77 actual, err := ext.ToServerResizeMap()
78 th.AssertNoErr(t, err)
79
80 expected := `
81 {
82 "resize": {
83 "flavorRef": "performance1-8",
84 "OS-DCF:diskConfig": "AUTO"
85 }
86 }
87 `
88 th.CheckJSONEquals(t, expected, actual)
89}