mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-16 03:32:54 -06:00
900e14e168
Fixes: #4922 ``` % make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSSpotDatafeedSubscription_' ==> Checking that code complies with gofmt requirements... /Users/stacko/Code/go/bin/stringer go generate $(go list ./... | grep -v /terraform/vendor/) 2016/08/24 10:46:23 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSSpotDatafeedSubscription_ -timeout 120m === RUN TestAccAWSSpotDatafeedSubscription_importBasic --- PASS: TestAccAWSSpotDatafeedSubscription_importBasic (56.31s) === RUN TestAccAWSSpotDatafeedSubscription_basic --- PASS: TestAccAWSSpotDatafeedSubscription_basic (56.77s) === RUN TestAccAWSSpotDatafeedSubscription_disappears --- PASS: TestAccAWSSpotDatafeedSubscription_disappears (56.79s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws 169.893s ```
140 lines
3.8 KiB
Go
140 lines
3.8 KiB
Go
package aws
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/aws/aws-sdk-go/aws/awserr"
|
|
"github.com/aws/aws-sdk-go/service/ec2"
|
|
"github.com/hashicorp/terraform/helper/acctest"
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
"github.com/hashicorp/terraform/terraform"
|
|
)
|
|
|
|
func TestAccAWSSpotDatafeedSubscription_basic(t *testing.T) {
|
|
var subscription ec2.SpotDatafeedSubscription
|
|
ri := acctest.RandInt()
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
Providers: testAccProviders,
|
|
CheckDestroy: testAccCheckAWSSpotDatafeedSubscriptionDestroy,
|
|
Steps: []resource.TestStep{
|
|
resource.TestStep{
|
|
Config: testAccAWSSpotDatafeedSubscription(ri),
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testAccCheckAWSSpotDatafeedSubscriptionExists("aws_spot_datafeed_subscription.default", &subscription),
|
|
),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func testAccCheckAWSSpotDatafeedSubscriptionDisappears(subscription *ec2.SpotDatafeedSubscription) resource.TestCheckFunc {
|
|
return func(s *terraform.State) error {
|
|
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
|
|
|
_, err := conn.DeleteSpotDatafeedSubscription(&ec2.DeleteSpotDatafeedSubscriptionInput{})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return resource.Retry(40*time.Minute, func() *resource.RetryError {
|
|
_, err := conn.DescribeSpotDatafeedSubscription(&ec2.DescribeSpotDatafeedSubscriptionInput{})
|
|
if err != nil {
|
|
cgw, ok := err.(awserr.Error)
|
|
if ok && cgw.Code() == "InvalidSpotDatafeed.NotFound" {
|
|
return nil
|
|
}
|
|
return resource.NonRetryableError(
|
|
fmt.Errorf("Error retrieving Spot Datafeed Subscription: %s", err))
|
|
}
|
|
return resource.RetryableError(fmt.Errorf("Waiting for Spot Datafeed Subscription"))
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestAccAWSSpotDatafeedSubscription_disappears(t *testing.T) {
|
|
var subscription ec2.SpotDatafeedSubscription
|
|
ri := acctest.RandInt()
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
Providers: testAccProviders,
|
|
CheckDestroy: testAccCheckAWSSpotDatafeedSubscriptionDestroy,
|
|
Steps: []resource.TestStep{
|
|
resource.TestStep{
|
|
Config: testAccAWSSpotDatafeedSubscription(ri),
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testAccCheckAWSSpotDatafeedSubscriptionExists("aws_spot_datafeed_subscription.default", &subscription),
|
|
testAccCheckAWSSpotDatafeedSubscriptionDisappears(&subscription),
|
|
),
|
|
ExpectNonEmptyPlan: true,
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func testAccCheckAWSSpotDatafeedSubscriptionExists(n string, subscription *ec2.SpotDatafeedSubscription) resource.TestCheckFunc {
|
|
return func(s *terraform.State) error {
|
|
rs, ok := s.RootModule().Resources[n]
|
|
if !ok {
|
|
return fmt.Errorf("Not found: %s", n)
|
|
}
|
|
|
|
if rs.Primary.ID == "" {
|
|
return fmt.Errorf("No policy ID is set")
|
|
}
|
|
|
|
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
|
|
|
resp, err := conn.DescribeSpotDatafeedSubscription(&ec2.DescribeSpotDatafeedSubscriptionInput{})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
*subscription = *resp.SpotDatafeedSubscription
|
|
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func testAccCheckAWSSpotDatafeedSubscriptionDestroy(s *terraform.State) error {
|
|
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
|
|
|
for _, rs := range s.RootModule().Resources {
|
|
if rs.Type != "aws_spot_datafeed_subscription" {
|
|
continue
|
|
}
|
|
|
|
// Try to get subscription
|
|
_, err := conn.DescribeSpotDatafeedSubscription(&ec2.DescribeSpotDatafeedSubscriptionInput{})
|
|
if err == nil {
|
|
return fmt.Errorf("still exist.")
|
|
}
|
|
|
|
awsErr, ok := err.(awserr.Error)
|
|
if !ok {
|
|
return err
|
|
}
|
|
if awsErr.Code() != "InvalidSpotDatafeed.NotFound" {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func testAccAWSSpotDatafeedSubscription(randInt int) string {
|
|
return fmt.Sprintf(`
|
|
resource "aws_s3_bucket" "default" {
|
|
bucket = "tf-spot-datafeed-%d"
|
|
}
|
|
|
|
resource "aws_spot_datafeed_subscription" "default" {
|
|
bucket = "${aws_s3_bucket.default.bucket}"
|
|
}
|
|
`, randInt)
|
|
}
|