diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index acababe3f..85c0e04dd 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -153,6 +153,12 @@ specific package / folder. The `TESTARGS` variable is recommended to filter down to a specific resource to test, since testing all of them at once can sometimes take a very long time. +To run only a specific test, use the `-run` argument: + +``` +make testacc TEST=./builder/amazon/ebs TESTARGS="-run TestBuilderAcc_forceDeleteSnapshot" +``` + Acceptance tests typically require other environment variables to be set for things such as API tokens and keys. Each test should error and tell you which credentials are missing, so those are not documented here. diff --git a/builder/amazon/ebs/builder_acc_test.go b/builder/amazon/ebs/builder_acc_test.go index 9ea9c87f9..b42472a39 100644 --- a/builder/amazon/ebs/builder_acc_test.go +++ b/builder/amazon/ebs/builder_acc_test.go @@ -1,8 +1,11 @@ +/* +Deregister the test image with +aws ec2 deregister-image --image-id $(aws ec2 describe-images --output text --filters "Name=name,Values=packer-test-packer-test-dereg" --query 'Images[*].{ID:ImageId}') +*/ package ebs import ( "fmt" - "os" "testing" "github.com/aws/aws-sdk-go/aws" @@ -58,14 +61,14 @@ func TestBuilderAcc_forceDeleteSnapshot(t *testing.T) { // 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)}, - }, - }}, - ) + describeInput := &ec2.DescribeImagesInput{Filters: []*ec2.Filter{ + { + Name: aws.String("name"), + Values: []*string{aws.String(amiName)}, + }, + }} + ec2conn.WaitUntilImageExists(describeInput) + imageResp, _ := ec2conn.DescribeImages(describeInput) image := imageResp.Images[0] // Get snapshot ids for image @@ -243,13 +246,6 @@ func checkBootEncrypted() builderT.TestCheckFunc { } func testAccPreCheck(t *testing.T) { - if v := os.Getenv("AWS_ACCESS_KEY_ID"); v == "" { - t.Fatal("AWS_ACCESS_KEY_ID must be set for acceptance tests") - } - - if v := os.Getenv("AWS_SECRET_ACCESS_KEY"); v == "" { - t.Fatal("AWS_SECRET_ACCESS_KEY must be set for acceptance tests") - } } func testEC2Conn() (*ec2.EC2, error) { @@ -298,7 +294,7 @@ const testBuilderAccForceDeregister = ` "source_ami": "ami-76b2a71e", "ssh_username": "ubuntu", "force_deregister": "%s", - "ami_name": "packer-test-%s" + "ami_name": "%s" }] } ` @@ -313,7 +309,7 @@ const testBuilderAccForceDeleteSnapshot = ` "ssh_username": "ubuntu", "force_deregister": "%s", "force_delete_snapshot": "%s", - "ami_name": "packer-test-%s" + "ami_name": "%s" }] } `