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 | ` |
Jon Perritt | 4149d7c | 2014-10-23 21:23:46 -0500 | [diff] [blame] | 32 | actual, err := ext.ToServerCreateMap() |
| 33 | th.AssertNoErr(t, err) |
| 34 | th.CheckJSONEquals(t, expected, actual) |
Ash Wilson | 5b50549 | 2014-10-23 10:28:22 -0400 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | func TestRebuildOpts(t *testing.T) { |
| 38 | base := servers.RebuildOpts{ |
Ash Wilson | 237aad6 | 2014-10-23 12:49:13 -0400 | [diff] [blame] | 39 | Name: "rebuiltserver", |
Ash Wilson | 5b50549 | 2014-10-23 10:28:22 -0400 | [diff] [blame] | 40 | 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 Wilson | 237aad6 | 2014-10-23 12:49:13 -0400 | [diff] [blame] | 55 | "name": "rebuiltserver", |
Ash Wilson | 5b50549 | 2014-10-23 10:28:22 -0400 | [diff] [blame] | 56 | "imageRef": "asdfasdfasdf", |
| 57 | "adminPass": "swordfish", |
| 58 | "OS-DCF:diskConfig": "AUTO" |
| 59 | } |
| 60 | } |
| 61 | ` |
| 62 | th.CheckJSONEquals(t, expected, actual) |
| 63 | } |
Ash Wilson | 80387a0 | 2014-10-23 10:38:41 -0400 | [diff] [blame] | 64 | |
| 65 | func 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 | } |