github.com/mmcquillan/packer@v1.1.1-0.20171009221028-c85cf0483a5d/builder/amazon/chroot/step_register_ami_test.go (about)

     1  package chroot
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/aws/aws-sdk-go/aws"
     7  	"github.com/aws/aws-sdk-go/service/ec2"
     8  )
     9  
    10  func testImage() ec2.Image {
    11  	return ec2.Image{
    12  		ImageId:      aws.String("ami-abcd1234"),
    13  		Name:         aws.String("ami_test_name"),
    14  		Architecture: aws.String("x86_64"),
    15  		KernelId:     aws.String("aki-abcd1234"),
    16  	}
    17  }
    18  
    19  func TestStepRegisterAmi_buildRegisterOpts_pv(t *testing.T) {
    20  	config := Config{}
    21  	config.AMIName = "test_ami_name"
    22  	config.AMIDescription = "test_ami_description"
    23  	config.AMIVirtType = "paravirtual"
    24  
    25  	image := testImage()
    26  
    27  	blockDevices := []*ec2.BlockDeviceMapping{}
    28  
    29  	opts := buildRegisterOpts(&config, &image, blockDevices)
    30  
    31  	expected := config.AMIVirtType
    32  	if *opts.VirtualizationType != expected {
    33  		t.Fatalf("Unexpected VirtType value: expected %s got %s\n", expected, *opts.VirtualizationType)
    34  	}
    35  
    36  	expected = config.AMIName
    37  	if *opts.Name != expected {
    38  		t.Fatalf("Unexpected Name value: expected %s got %s\n", expected, *opts.Name)
    39  	}
    40  
    41  	expected = *image.KernelId
    42  	if *opts.KernelId != expected {
    43  		t.Fatalf("Unexpected KernelId value: expected %s got %s\n", expected, *opts.KernelId)
    44  	}
    45  
    46  }
    47  
    48  func TestStepRegisterAmi_buildRegisterOpts_hvm(t *testing.T) {
    49  	config := Config{}
    50  	config.AMIName = "test_ami_name"
    51  	config.AMIDescription = "test_ami_description"
    52  	config.AMIVirtType = "hvm"
    53  
    54  	image := testImage()
    55  
    56  	blockDevices := []*ec2.BlockDeviceMapping{}
    57  
    58  	opts := buildRegisterOpts(&config, &image, blockDevices)
    59  
    60  	expected := config.AMIVirtType
    61  	if *opts.VirtualizationType != expected {
    62  		t.Fatalf("Unexpected VirtType value: expected %s got %s\n", expected, *opts.VirtualizationType)
    63  	}
    64  
    65  	expected = config.AMIName
    66  	if *opts.Name != expected {
    67  		t.Fatalf("Unexpected Name value: expected %s got %s\n", expected, *opts.Name)
    68  	}
    69  
    70  	if opts.KernelId != nil {
    71  		t.Fatalf("Unexpected KernelId value: expected nil got %s\n", *opts.KernelId)
    72  	}
    73  }