blob: 3c0f806936f0987893f8777d69a1457f02bf1e98 [file] [log] [blame]
Ash Wilsonae0ca652014-10-23 12:30:12 -04001package servers
2
3import (
4 "testing"
5
6 "github.com/rackspace/gophercloud/openstack/compute/v2/extensions/diskconfig"
7 th "github.com/rackspace/gophercloud/testhelper"
8)
9
10func TestCreateOpts(t *testing.T) {
11 opts := CreateOpts{
12 Name: "createdserver",
13 ImageRef: "image-id",
14 FlavorRef: "flavor-id",
15 KeyPair: "mykey",
16 DiskConfig: diskconfig.Manual,
17 }
18
19 expected := `
20 {
21 "server": {
22 "name": "createdserver",
23 "imageRef": "image-id",
24 "flavorRef": "flavor-id",
25 "key_name": "mykey",
26 "OS-DCF:diskConfig": "MANUAL"
27 }
28 }
29 `
Jon Perritt4149d7c2014-10-23 21:23:46 -050030 actual, err := opts.ToServerCreateMap()
31 th.AssertNoErr(t, err)
32 th.CheckJSONEquals(t, expected, actual)
Ash Wilsonae0ca652014-10-23 12:30:12 -040033}
Ash Wilsond7814a32014-10-23 12:49:25 -040034
35func TestRebuildOpts(t *testing.T) {
36 opts := RebuildOpts{
37 Name: "rebuiltserver",
38 AdminPass: "swordfish",
39 ImageID: "asdfasdfasdf",
40 DiskConfig: diskconfig.Auto,
41 }
42
43 actual, err := opts.ToServerRebuildMap()
44 th.AssertNoErr(t, err)
45
46 expected := `
47 {
48 "rebuild": {
49 "name": "rebuiltserver",
50 "imageRef": "asdfasdfasdf",
51 "adminPass": "swordfish",
52 "OS-DCF:diskConfig": "AUTO"
53 }
54 }
55 `
56 th.CheckJSONEquals(t, expected, actual)
57}