blob: 828b5dc491e0e13034314b7d4a46247082f1c0e9 [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",
Jon Perrittad5f1cb2015-05-20 10:38:13 -060025 "flavorName": "",
26 "imageName": "",
Ash Wilsonae0ca652014-10-23 12:30:12 -040027 "key_name": "mykey",
28 "OS-DCF:diskConfig": "MANUAL"
29 }
30 }
31 `
Jon Perritt4149d7c2014-10-23 21:23:46 -050032 actual, err := opts.ToServerCreateMap()
33 th.AssertNoErr(t, err)
34 th.CheckJSONEquals(t, expected, actual)
Ash Wilsonae0ca652014-10-23 12:30:12 -040035}
Ash Wilsond7814a32014-10-23 12:49:25 -040036
37func TestRebuildOpts(t *testing.T) {
38 opts := RebuildOpts{
39 Name: "rebuiltserver",
40 AdminPass: "swordfish",
41 ImageID: "asdfasdfasdf",
42 DiskConfig: diskconfig.Auto,
43 }
44
45 actual, err := opts.ToServerRebuildMap()
46 th.AssertNoErr(t, err)
47
48 expected := `
49 {
50 "rebuild": {
51 "name": "rebuiltserver",
52 "imageRef": "asdfasdfasdf",
53 "adminPass": "swordfish",
54 "OS-DCF:diskConfig": "AUTO"
55 }
56 }
57 `
58 th.CheckJSONEquals(t, expected, actual)
59}