Fixes acceptance test
The original acceptance test required a manual check. This one does not.
This commit is contained in:
parent
4e1e2c18d5
commit
576f6f1b39
|
@ -47,21 +47,59 @@ func TestBuilderAcc_forceDeregister(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBuilderAcc_forceDeleteSnapshot(t *testing.T) {
|
func TestBuilderAcc_forceDeleteSnapshot(t *testing.T) {
|
||||||
|
amiName := "packer-test-dereg"
|
||||||
|
|
||||||
// Build the same AMI name twice, with force_delete_snapshot on the second run
|
// Build the same AMI name twice, with force_delete_snapshot on the second run
|
||||||
builderT.Test(t, builderT.TestCase{
|
builderT.Test(t, builderT.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Builder: &Builder{},
|
Builder: &Builder{},
|
||||||
Template: buildForceDeleteSnapshotConfig("false", "dereg"),
|
Template: buildForceDeleteSnapshotConfig("false", amiName),
|
||||||
SkipArtifactTeardown: true,
|
SkipArtifactTeardown: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Get image data by AMI name
|
||||||
|
ec2conn, _ := testEC2Conn()
|
||||||
|
imageResp, _ := ec2conn.DescribeImages(
|
||||||
|
&ec2.DescribeImagesInput{Filters: []*ec2.Filter{
|
||||||
|
{
|
||||||
|
Name: aws.String("name"),
|
||||||
|
Values: []*string{aws.String(amiName)},
|
||||||
|
},
|
||||||
|
}},
|
||||||
|
)
|
||||||
|
image := imageResp.Images[0]
|
||||||
|
|
||||||
|
// Get snapshot ids for image
|
||||||
|
snapshotIds := []*string{}
|
||||||
|
for _, device := range image.BlockDeviceMappings {
|
||||||
|
if device.Ebs != nil && device.Ebs.SnapshotId != nil {
|
||||||
|
snapshotIds = append(snapshotIds, device.Ebs.SnapshotId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
builderT.Test(t, builderT.TestCase{
|
builderT.Test(t, builderT.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Builder: &Builder{},
|
Builder: &Builder{},
|
||||||
Template: buildForceDeleteSnapshotConfig("true", "dereg"),
|
Template: buildForceDeleteSnapshotConfig("true", amiName),
|
||||||
|
Check: checkSnapshotsDeleted(snapshotIds),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func checkSnapshotsDeleted(snapshotIds []*string) builderT.TestCheckFunc {
|
||||||
|
return func(artifacts []packer.Artifact) error {
|
||||||
|
// Verify the snapshots are gone
|
||||||
|
ec2conn, _ := testEC2Conn()
|
||||||
|
snapshotResp, _ := ec2conn.DescribeSnapshots(
|
||||||
|
&ec2.DescribeSnapshotsInput{SnapshotIds: snapshotIds},
|
||||||
|
)
|
||||||
|
|
||||||
|
if len(snapshotResp.Snapshots) > 0 {
|
||||||
|
return fmt.Errorf("Snapshots weren't successfully deleted by `force_delete_snapshot`")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestBuilderAcc_amiSharing(t *testing.T) {
|
func TestBuilderAcc_amiSharing(t *testing.T) {
|
||||||
builderT.Test(t, builderT.TestCase{
|
builderT.Test(t, builderT.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
|
Loading…
Reference in New Issue