Ash Wilson | 5b50549 | 2014-10-23 10:28:22 -0400 | [diff] [blame] | 1 | package diskconfig |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | "github.com/rackspace/gophercloud/openstack/compute/v2/servers" |
| 7 | th "github.com/rackspace/gophercloud/testhelper" |
| 8 | ) |
| 9 | |
| 10 | func 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 | |
| 35 | func TestRebuildOpts(t *testing.T) { |
| 36 | base := servers.RebuildOpts{ |
Ash Wilson | 237aad6 | 2014-10-23 12:49:13 -0400 | [diff] [blame^] | 37 | Name: "rebuiltserver", |
Ash Wilson | 5b50549 | 2014-10-23 10:28:22 -0400 | [diff] [blame] | 38 | 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 Wilson | 237aad6 | 2014-10-23 12:49:13 -0400 | [diff] [blame^] | 53 | "name": "rebuiltserver", |
Ash Wilson | 5b50549 | 2014-10-23 10:28:22 -0400 | [diff] [blame] | 54 | "imageRef": "asdfasdfasdf", |
| 55 | "adminPass": "swordfish", |
| 56 | "OS-DCF:diskConfig": "AUTO" |
| 57 | } |
| 58 | } |
| 59 | ` |
| 60 | th.CheckJSONEquals(t, expected, actual) |
| 61 | } |
Ash Wilson | 80387a0 | 2014-10-23 10:38:41 -0400 | [diff] [blame] | 62 | |
| 63 | func 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 | } |