github.com/ttysteale/packer@v0.8.2-0.20150708160520-e5f8ea386ed8/builder/amazon/common/block_device_test.go (about)

     1  package common
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  
     7  	"github.com/aws/aws-sdk-go/aws"
     8  	"github.com/aws/aws-sdk-go/aws/awsutil"
     9  	"github.com/aws/aws-sdk-go/service/ec2"
    10  )
    11  
    12  func TestBlockDevice(t *testing.T) {
    13  	cases := []struct {
    14  		Config *BlockDevice
    15  		Result *ec2.BlockDeviceMapping
    16  	}{
    17  		{
    18  			Config: &BlockDevice{
    19  				DeviceName:          "/dev/sdb",
    20  				VirtualName:         "ephemeral0",
    21  				SnapshotId:          "snap-1234",
    22  				VolumeType:          "standard",
    23  				VolumeSize:          8,
    24  				DeleteOnTermination: true,
    25  				IOPS:                1000,
    26  			},
    27  
    28  			Result: &ec2.BlockDeviceMapping{
    29  				DeviceName:  aws.String("/dev/sdb"),
    30  				VirtualName: aws.String("ephemeral0"),
    31  				EBS: &ec2.EBSBlockDevice{
    32  					SnapshotID:          aws.String("snap-1234"),
    33  					VolumeType:          aws.String("standard"),
    34  					VolumeSize:          aws.Long(8),
    35  					DeleteOnTermination: aws.Boolean(true),
    36  				},
    37  			},
    38  		},
    39  		{
    40  			Config: &BlockDevice{
    41  				DeviceName: "/dev/sdb",
    42  				VolumeSize: 8,
    43  			},
    44  
    45  			Result: &ec2.BlockDeviceMapping{
    46  				DeviceName:  aws.String("/dev/sdb"),
    47  				VirtualName: aws.String(""),
    48  				EBS: &ec2.EBSBlockDevice{
    49  					VolumeType:          aws.String(""),
    50  					VolumeSize:          aws.Long(8),
    51  					DeleteOnTermination: aws.Boolean(false),
    52  				},
    53  			},
    54  		},
    55  		{
    56  			Config: &BlockDevice{
    57  				DeviceName:          "/dev/sdb",
    58  				VirtualName:         "ephemeral0",
    59  				VolumeType:          "io1",
    60  				VolumeSize:          8,
    61  				DeleteOnTermination: true,
    62  				IOPS:                1000,
    63  			},
    64  
    65  			Result: &ec2.BlockDeviceMapping{
    66  				DeviceName:  aws.String("/dev/sdb"),
    67  				VirtualName: aws.String("ephemeral0"),
    68  				EBS: &ec2.EBSBlockDevice{
    69  					VolumeType:          aws.String("io1"),
    70  					VolumeSize:          aws.Long(8),
    71  					DeleteOnTermination: aws.Boolean(true),
    72  					IOPS:                aws.Long(1000),
    73  				},
    74  			},
    75  		},
    76  	}
    77  
    78  	for _, tc := range cases {
    79  		blockDevices := BlockDevices{
    80  			AMIMappings:    []BlockDevice{*tc.Config},
    81  			LaunchMappings: []BlockDevice{*tc.Config},
    82  		}
    83  
    84  		expected := []*ec2.BlockDeviceMapping{tc.Result}
    85  		got := blockDevices.BuildAMIDevices()
    86  		if !reflect.DeepEqual(expected, got) {
    87  			t.Fatalf("Bad block device, \nexpected: %s\n\ngot: %s", awsutil.StringValue(expected), awsutil.StringValue(got))
    88  		}
    89  
    90  		if !reflect.DeepEqual(expected, blockDevices.BuildLaunchDevices()) {
    91  			t.Fatalf("Bad block device, \nexpected: %s\n\ngot: %s", awsutil.StringValue(expected), awsutil.StringValue(blockDevices.BuildLaunchDevices()))
    92  		}
    93  	}
    94  }