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
|
|
|
|
2015-06-03 17:13:52 -04:00
|
|
|
"github.com/aws/aws-sdk-go/aws"
|
|
|
|
"github.com/aws/aws-sdk-go/service/ec2"
|
2014-07-30 00:56:37 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func testImage() ec2.Image {
|
|
|
|
return ec2.Image{
|
2015-08-17 20:44:01 -04:00
|
|
|
ImageId: aws.String("ami-abcd1234"),
|
2015-04-05 17:58:48 -04:00
|
|
|
Name: aws.String("ami_test_name"),
|
|
|
|
Architecture: aws.String("x86_64"),
|
2015-08-17 20:44:01 -04:00
|
|
|
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-08-17 20:44:01 -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-08-17 20:44:01 -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
|
|
|
}
|
|
|
|
}
|