Jon Perritt | 654fb0e | 2014-10-23 20:54:14 -0500 | [diff] [blame] | 1 | package bootfromvolume |
Jon Perritt | d9a4bf7 | 2014-10-23 23:44:04 -0500 | [diff] [blame] | 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame] | 6 | "github.com/gophercloud/gophercloud/openstack/compute/v2/servers" |
| 7 | th "github.com/gophercloud/gophercloud/testhelper" |
Jon Perritt | d9a4bf7 | 2014-10-23 23:44:04 -0500 | [diff] [blame] | 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, |
Jon Perritt | 01686cd | 2014-10-24 14:10:16 -0500 | [diff] [blame] | 19 | BlockDevice: []BlockDevice{ |
| 20 | BlockDevice{ |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame^] | 21 | UUID: "123456", |
| 22 | SourceType: Image, |
| 23 | DestinationType: "volume", |
| 24 | VolumeSize: 10, |
| 25 | DeleteOnTermination: false, |
Jon Perritt | 01686cd | 2014-10-24 14:10:16 -0500 | [diff] [blame] | 26 | }, |
Jon Perritt | d9a4bf7 | 2014-10-23 23:44:04 -0500 | [diff] [blame] | 27 | }, |
| 28 | } |
| 29 | |
| 30 | expected := ` |
| 31 | { |
| 32 | "server": { |
| 33 | "name": "createdserver", |
| 34 | "imageRef": "asdfasdfasdf", |
| 35 | "flavorRef": "performance1-1", |
| 36 | "block_device_mapping_v2":[ |
| 37 | { |
| 38 | "uuid":"123456", |
| 39 | "source_type":"image", |
| 40 | "destination_type":"volume", |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame^] | 41 | "boot_index": 0, |
| 42 | "delete_on_termination": false, |
| 43 | "volume_size": 10 |
Jon Perritt | d9a4bf7 | 2014-10-23 23:44:04 -0500 | [diff] [blame] | 44 | } |
| 45 | ] |
| 46 | } |
| 47 | } |
| 48 | ` |
| 49 | actual, err := ext.ToServerCreateMap() |
| 50 | th.AssertNoErr(t, err) |
| 51 | th.CheckJSONEquals(t, expected, actual) |
| 52 | } |
Joe Topjian | ecf63dd | 2015-12-12 20:33:50 +0000 | [diff] [blame] | 53 | |
| 54 | func TestCreateMultiEphemeralOpts(t *testing.T) { |
| 55 | base := servers.CreateOpts{ |
| 56 | Name: "createdserver", |
| 57 | ImageRef: "asdfasdfasdf", |
| 58 | FlavorRef: "performance1-1", |
| 59 | } |
| 60 | |
| 61 | ext := CreateOptsExt{ |
| 62 | CreateOptsBuilder: base, |
| 63 | BlockDevice: []BlockDevice{ |
| 64 | BlockDevice{ |
| 65 | BootIndex: 0, |
| 66 | DeleteOnTermination: true, |
| 67 | DestinationType: "local", |
| 68 | SourceType: Image, |
| 69 | UUID: "123456", |
| 70 | }, |
| 71 | BlockDevice{ |
| 72 | BootIndex: -1, |
| 73 | DeleteOnTermination: true, |
| 74 | DestinationType: "local", |
| 75 | GuestFormat: "ext4", |
| 76 | SourceType: Blank, |
| 77 | VolumeSize: 1, |
| 78 | }, |
| 79 | BlockDevice{ |
| 80 | BootIndex: -1, |
| 81 | DeleteOnTermination: true, |
| 82 | DestinationType: "local", |
| 83 | GuestFormat: "ext4", |
| 84 | SourceType: Blank, |
| 85 | VolumeSize: 1, |
| 86 | }, |
| 87 | }, |
| 88 | } |
| 89 | |
| 90 | expected := ` |
| 91 | { |
| 92 | "server": { |
| 93 | "name": "createdserver", |
| 94 | "imageRef": "asdfasdfasdf", |
| 95 | "flavorRef": "performance1-1", |
Joe Topjian | ecf63dd | 2015-12-12 20:33:50 +0000 | [diff] [blame] | 96 | "block_device_mapping_v2":[ |
| 97 | { |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame^] | 98 | "boot_index": 0, |
| 99 | "delete_on_termination": true, |
Joe Topjian | ecf63dd | 2015-12-12 20:33:50 +0000 | [diff] [blame] | 100 | "destination_type":"local", |
| 101 | "source_type":"image", |
| 102 | "uuid":"123456", |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame^] | 103 | "volume_size": 0 |
Joe Topjian | ecf63dd | 2015-12-12 20:33:50 +0000 | [diff] [blame] | 104 | }, |
| 105 | { |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame^] | 106 | "boot_index": -1, |
| 107 | "delete_on_termination": true, |
Joe Topjian | ecf63dd | 2015-12-12 20:33:50 +0000 | [diff] [blame] | 108 | "destination_type":"local", |
| 109 | "guest_format":"ext4", |
| 110 | "source_type":"blank", |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame^] | 111 | "volume_size": 1 |
Joe Topjian | ecf63dd | 2015-12-12 20:33:50 +0000 | [diff] [blame] | 112 | }, |
| 113 | { |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame^] | 114 | "boot_index": -1, |
| 115 | "delete_on_termination": true, |
Joe Topjian | ecf63dd | 2015-12-12 20:33:50 +0000 | [diff] [blame] | 116 | "destination_type":"local", |
| 117 | "guest_format":"ext4", |
| 118 | "source_type":"blank", |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame^] | 119 | "volume_size": 1 |
Joe Topjian | ecf63dd | 2015-12-12 20:33:50 +0000 | [diff] [blame] | 120 | } |
| 121 | ] |
| 122 | } |
| 123 | } |
| 124 | ` |
| 125 | actual, err := ext.ToServerCreateMap() |
| 126 | th.AssertNoErr(t, err) |
| 127 | th.CheckJSONEquals(t, expected, actual) |
| 128 | } |