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