2014-07-30 00:56:37 -04:00
|
|
|
package chroot
|
|
|
|
|
|
|
|
import (
|
2014-09-02 12:55:06 -04:00
|
|
|
"testing"
|
2015-04-05 17:58:48 -04:00
|
|
|
|
|
|
|
"github.com/awslabs/aws-sdk-go/aws"
|
|
|
|
"github.com/awslabs/aws-sdk-go/service/ec2"
|
2014-07-30 00:56:37 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func testImage() ec2.Image {
|
|
|
|
return ec2.Image{
|
2015-04-05 17:58:48 -04:00
|
|
|
ImageID: aws.String("ami-abcd1234"),
|
|
|
|
Name: aws.String("ami_test_name"),
|
|
|
|
Architecture: aws.String("x86_64"),
|
|
|
|
KernelID: aws.String("aki-abcd1234"),
|
2014-07-30 00:56:37 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStepRegisterAmi_buildRegisterOpts_pv(t *testing.T) {
|
|
|
|
config := Config{}
|
|
|
|
config.AMIName = "test_ami_name"
|
|
|
|
config.AMIDescription = "test_ami_description"
|
|
|
|
config.AMIVirtType = "paravirtual"
|
|
|
|
|
|
|
|
image := testImage()
|
|
|
|
|
2015-04-05 17:58:48 -04:00
|
|
|
blockDevices := []*ec2.BlockDeviceMapping{}
|
2014-07-30 00:56:37 -04:00
|
|
|
|
|
|
|
opts := buildRegisterOpts(&config, &image, blockDevices)
|
|
|
|
|
|
|
|
expected := config.AMIVirtType
|
2015-04-05 17:58:48 -04:00
|
|
|
if *opts.VirtualizationType != expected {
|
|
|
|
t.Fatalf("Unexpected VirtType value: expected %s got %s\n", expected, *opts.VirtualizationType)
|
2014-07-30 00:56:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
expected = config.AMIName
|
2015-04-05 17:58:48 -04:00
|
|
|
if *opts.Name != expected {
|
|
|
|
t.Fatalf("Unexpected Name value: expected %s got %s\n", expected, *opts.Name)
|
2014-07-30 00:56:37 -04:00
|
|
|
}
|
|
|
|
|
2015-04-05 17:58:48 -04:00
|
|
|
expected = *image.KernelID
|
|
|
|
if *opts.KernelID != expected {
|
|
|
|
t.Fatalf("Unexpected KernelId value: expected %s got %s\n", expected, *opts.KernelID)
|
2014-07-30 00:56:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStepRegisterAmi_buildRegisterOpts_hvm(t *testing.T) {
|
|
|
|
config := Config{}
|
|
|
|
config.AMIName = "test_ami_name"
|
|
|
|
config.AMIDescription = "test_ami_description"
|
|
|
|
config.AMIVirtType = "hvm"
|
|
|
|
|
|
|
|
image := testImage()
|
|
|
|
|
2015-04-05 17:58:48 -04:00
|
|
|
blockDevices := []*ec2.BlockDeviceMapping{}
|
2014-07-30 00:56:37 -04:00
|
|
|
|
|
|
|
opts := buildRegisterOpts(&config, &image, blockDevices)
|
|
|
|
|
|
|
|
expected := config.AMIVirtType
|
2015-04-05 17:58:48 -04:00
|
|
|
if *opts.VirtualizationType != expected {
|
|
|
|
t.Fatalf("Unexpected VirtType value: expected %s got %s\n", expected, *opts.VirtualizationType)
|
2014-07-30 00:56:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
expected = config.AMIName
|
2015-04-05 17:58:48 -04:00
|
|
|
if *opts.Name != expected {
|
|
|
|
t.Fatalf("Unexpected Name value: expected %s got %s\n", expected, *opts.Name)
|
2014-07-30 00:56:37 -04:00
|
|
|
}
|
|
|
|
|
2015-04-05 17:58:48 -04:00
|
|
|
if opts.KernelID != nil {
|
|
|
|
t.Fatalf("Unexpected KernelId value: expected nil got %s\n", *opts.KernelID)
|
2014-07-30 00:56:37 -04:00
|
|
|
}
|
|
|
|
}
|