2013-08-15 17:05:08 -04:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
2013-10-16 22:29:53 -04:00
|
|
|
"reflect"
|
2013-08-15 17:05:08 -04:00
|
|
|
"testing"
|
2015-04-05 17:58:48 -04:00
|
|
|
|
2015-06-03 17:13:52 -04:00
|
|
|
"github.com/aws/aws-sdk-go/aws"
|
|
|
|
"github.com/aws/aws-sdk-go/service/ec2"
|
2013-08-15 17:05:08 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestBlockDevice(t *testing.T) {
|
2014-09-04 00:27:43 -04:00
|
|
|
cases := []struct {
|
|
|
|
Config *BlockDevice
|
|
|
|
Result *ec2.BlockDeviceMapping
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
Config: &BlockDevice{
|
|
|
|
DeviceName: "/dev/sdb",
|
|
|
|
SnapshotId: "snap-1234",
|
|
|
|
VolumeType: "standard",
|
|
|
|
VolumeSize: 8,
|
|
|
|
DeleteOnTermination: true,
|
|
|
|
},
|
|
|
|
|
|
|
|
Result: &ec2.BlockDeviceMapping{
|
2015-10-18 14:00:05 -04:00
|
|
|
DeviceName: aws.String("/dev/sdb"),
|
2015-08-17 20:44:01 -04:00
|
|
|
Ebs: &ec2.EbsBlockDevice{
|
|
|
|
SnapshotId: aws.String("snap-1234"),
|
2015-04-05 17:58:48 -04:00
|
|
|
VolumeType: aws.String("standard"),
|
2015-07-28 20:10:21 -04:00
|
|
|
VolumeSize: aws.Int64(8),
|
|
|
|
DeleteOnTermination: aws.Bool(true),
|
2015-06-09 12:56:40 -04:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2015-06-10 11:20:41 -04:00
|
|
|
{
|
|
|
|
Config: &BlockDevice{
|
2015-06-17 23:23:04 -04:00
|
|
|
DeviceName: "/dev/sdb",
|
|
|
|
VolumeSize: 8,
|
2015-06-10 11:20:41 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
Result: &ec2.BlockDeviceMapping{
|
2015-10-18 14:00:05 -04:00
|
|
|
DeviceName: aws.String("/dev/sdb"),
|
2015-08-17 20:44:01 -04:00
|
|
|
Ebs: &ec2.EbsBlockDevice{
|
2015-07-28 20:10:21 -04:00
|
|
|
VolumeSize: aws.Int64(8),
|
|
|
|
DeleteOnTermination: aws.Bool(false),
|
2015-06-10 11:20:41 -04:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2015-06-09 12:56:40 -04:00
|
|
|
{
|
|
|
|
Config: &BlockDevice{
|
|
|
|
DeviceName: "/dev/sdb",
|
|
|
|
VolumeType: "io1",
|
|
|
|
VolumeSize: 8,
|
|
|
|
DeleteOnTermination: true,
|
|
|
|
IOPS: 1000,
|
|
|
|
},
|
|
|
|
|
|
|
|
Result: &ec2.BlockDeviceMapping{
|
2015-10-18 14:00:05 -04:00
|
|
|
DeviceName: aws.String("/dev/sdb"),
|
2015-08-17 20:44:01 -04:00
|
|
|
Ebs: &ec2.EbsBlockDevice{
|
2015-06-09 12:56:40 -04:00
|
|
|
VolumeType: aws.String("io1"),
|
2015-07-28 20:10:21 -04:00
|
|
|
VolumeSize: aws.Int64(8),
|
|
|
|
DeleteOnTermination: aws.Bool(true),
|
2015-08-17 20:44:01 -04:00
|
|
|
Iops: aws.Int64(1000),
|
2015-04-05 17:58:48 -04:00
|
|
|
},
|
2014-09-04 00:27:43 -04:00
|
|
|
},
|
2013-08-15 17:05:08 -04:00
|
|
|
},
|
2015-08-24 17:19:11 -04:00
|
|
|
{
|
|
|
|
Config: &BlockDevice{
|
|
|
|
DeviceName: "/dev/sdb",
|
|
|
|
VolumeType: "gp2",
|
|
|
|
VolumeSize: 8,
|
|
|
|
DeleteOnTermination: true,
|
|
|
|
Encrypted: true,
|
|
|
|
},
|
|
|
|
|
|
|
|
Result: &ec2.BlockDeviceMapping{
|
2015-10-18 14:00:05 -04:00
|
|
|
DeviceName: aws.String("/dev/sdb"),
|
2015-08-24 17:19:11 -04:00
|
|
|
Ebs: &ec2.EbsBlockDevice{
|
|
|
|
VolumeType: aws.String("gp2"),
|
|
|
|
VolumeSize: aws.Int64(8),
|
|
|
|
DeleteOnTermination: aws.Bool(true),
|
|
|
|
Encrypted: aws.Bool(true),
|
2015-10-18 16:04:41 -04:00
|
|
|
},
|
2015-07-01 18:02:31 -04:00
|
|
|
},
|
|
|
|
},
|
2015-07-21 01:07:30 -04:00
|
|
|
{
|
|
|
|
Config: &BlockDevice{
|
|
|
|
DeviceName: "/dev/sdb",
|
|
|
|
VolumeType: "standard",
|
|
|
|
DeleteOnTermination: true,
|
|
|
|
},
|
|
|
|
|
|
|
|
Result: &ec2.BlockDeviceMapping{
|
2015-10-18 16:04:41 -04:00
|
|
|
DeviceName: aws.String("/dev/sdb"),
|
|
|
|
Ebs: &ec2.EbsBlockDevice{
|
2015-07-21 01:07:30 -04:00
|
|
|
VolumeType: aws.String("standard"),
|
2015-10-18 16:04:41 -04:00
|
|
|
DeleteOnTermination: aws.Bool(true),
|
2015-08-24 17:19:11 -04:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2015-07-01 18:02:31 -04:00
|
|
|
{
|
|
|
|
Config: &BlockDevice{
|
|
|
|
DeviceName: "/dev/sdb",
|
|
|
|
VirtualName: "ephemeral0",
|
|
|
|
},
|
|
|
|
|
|
|
|
Result: &ec2.BlockDeviceMapping{
|
|
|
|
DeviceName: aws.String("/dev/sdb"),
|
|
|
|
VirtualName: aws.String("ephemeral0"),
|
|
|
|
},
|
|
|
|
},
|
2015-08-24 17:19:11 -04:00
|
|
|
{
|
|
|
|
Config: &BlockDevice{
|
|
|
|
DeviceName: "/dev/sdb",
|
|
|
|
NoDevice: true,
|
|
|
|
},
|
|
|
|
|
|
|
|
Result: &ec2.BlockDeviceMapping{
|
2015-10-18 14:00:05 -04:00
|
|
|
DeviceName: aws.String("/dev/sdb"),
|
|
|
|
NoDevice: aws.String(""),
|
2015-08-24 17:19:11 -04:00
|
|
|
},
|
|
|
|
},
|
2013-08-15 17:05:08 -04:00
|
|
|
}
|
|
|
|
|
2014-09-04 00:27:43 -04:00
|
|
|
for _, tc := range cases {
|
|
|
|
blockDevices := BlockDevices{
|
|
|
|
AMIMappings: []BlockDevice{*tc.Config},
|
|
|
|
LaunchMappings: []BlockDevice{*tc.Config},
|
|
|
|
}
|
2013-08-15 17:05:08 -04:00
|
|
|
|
2015-04-05 17:58:48 -04:00
|
|
|
expected := []*ec2.BlockDeviceMapping{tc.Result}
|
|
|
|
got := blockDevices.BuildAMIDevices()
|
|
|
|
if !reflect.DeepEqual(expected, got) {
|
2015-10-11 15:18:23 -04:00
|
|
|
t.Fatalf("Bad block device, \nexpected: %#v\n\ngot: %#v",
|
2015-07-28 20:10:21 -04:00
|
|
|
expected, got)
|
2014-09-04 00:27:43 -04:00
|
|
|
}
|
2013-10-16 22:29:53 -04:00
|
|
|
|
2014-09-04 00:27:43 -04:00
|
|
|
if !reflect.DeepEqual(expected, blockDevices.BuildLaunchDevices()) {
|
2015-10-11 15:18:23 -04:00
|
|
|
t.Fatalf("Bad block device, \nexpected: %#v\n\ngot: %#v",
|
2015-07-28 20:10:21 -04:00
|
|
|
expected,
|
|
|
|
blockDevices.BuildLaunchDevices())
|
2014-09-04 00:27:43 -04:00
|
|
|
}
|
2013-10-16 22:29:53 -04:00
|
|
|
}
|
2013-08-15 17:05:08 -04:00
|
|
|
}
|