Ash Wilson | ae0ca65 | 2014-10-23 12:30:12 -0400 | [diff] [blame] | 1 | package servers |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | "github.com/rackspace/gophercloud/openstack/compute/v2/extensions/diskconfig" |
| 7 | th "github.com/rackspace/gophercloud/testhelper" |
| 8 | ) |
| 9 | |
| 10 | func 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 Perritt | ad5f1cb | 2015-05-20 10:38:13 -0600 | [diff] [blame^] | 25 | "flavorName": "", |
| 26 | "imageName": "", |
Ash Wilson | ae0ca65 | 2014-10-23 12:30:12 -0400 | [diff] [blame] | 27 | "key_name": "mykey", |
| 28 | "OS-DCF:diskConfig": "MANUAL" |
| 29 | } |
| 30 | } |
| 31 | ` |
Jon Perritt | 4149d7c | 2014-10-23 21:23:46 -0500 | [diff] [blame] | 32 | actual, err := opts.ToServerCreateMap() |
| 33 | th.AssertNoErr(t, err) |
| 34 | th.CheckJSONEquals(t, expected, actual) |
Ash Wilson | ae0ca65 | 2014-10-23 12:30:12 -0400 | [diff] [blame] | 35 | } |
Ash Wilson | d7814a3 | 2014-10-23 12:49:25 -0400 | [diff] [blame] | 36 | |
| 37 | func 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 | } |