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