From b42701380c4f7472d977f14f58027b9828314c35 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Mon, 29 Jul 2019 12:11:59 -0700 Subject: [PATCH] add test for nil case --- .../common/step_ami_region_copy_test.go | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/builder/amazon/common/step_ami_region_copy_test.go b/builder/amazon/common/step_ami_region_copy_test.go index d434b777f..2e1628aab 100644 --- a/builder/amazon/common/step_ami_region_copy_test.go +++ b/builder/amazon/common/step_ami_region_copy_test.go @@ -271,6 +271,31 @@ func TestStepAmiRegionCopy_true_encryption(t *testing.T) { } } +func TestStepAmiRegionCopy_nil_intermediary(t *testing.T) { + // create step + stepAMIRegionCopy := StepAMIRegionCopy{ + AccessConfig: testAccessConfig(), + Regions: make([]string, 0), + AMIKmsKeyId: "", + RegionKeyIds: make(map[string]string), + EncryptBootVolume: aws.Bool(false), + Name: "fake-ami-name", + OriginalRegion: "us-east-1", + } + // mock out the region connection code + stepAMIRegionCopy.getRegionConn = getMockConn + + state := tState() + stepAMIRegionCopy.Run(context.Background(), state) + + if stepAMIRegionCopy.toDelete != "" { + t.Fatalf("Should not delete original AMI if no intermediary") + } + if len(stepAMIRegionCopy.Regions) != 0 { + t.Fatalf("Should not have added original ami to Regions") + } +} + func TestStepAmiRegionCopy_AMISkipBuildRegion(t *testing.T) { // ------------------------------------------------------------------------ // skip build region is true