From d7a319f239df0e010a29ae7cf05c4f2c9bd6c25b Mon Sep 17 00:00:00 2001 From: Colin Wood Date: Fri, 31 Mar 2017 10:57:07 -0700 Subject: [PATCH] Fix accpetence test to work --- .../aws/data_source_aws_subnet_ids_test.go | 61 ++++++++----------- 1 file changed, 25 insertions(+), 36 deletions(-) diff --git a/builtin/providers/aws/data_source_aws_subnet_ids_test.go b/builtin/providers/aws/data_source_aws_subnet_ids_test.go index acc309000..53c26aa37 100644 --- a/builtin/providers/aws/data_source_aws_subnet_ids_test.go +++ b/builtin/providers/aws/data_source_aws_subnet_ids_test.go @@ -1,11 +1,9 @@ package aws import ( - "fmt" "testing" "github.com/hashicorp/terraform/helper/resource" - "github.com/hashicorp/terraform/terraform" ) func TestAccDataSourceAwsSubnetIDs(t *testing.T) { @@ -13,47 +11,20 @@ func TestAccDataSourceAwsSubnetIDs(t *testing.T) { PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: testAccDataSourceAwsSubnetIDsConfig, + }, + { + Config: testAccDataSourceAwsSubnetIDsConfigWithDataSource, Check: resource.ComposeTestCheckFunc( - testAccDataSourceAwsSubnetIDsCheck("data.aws_subnet_ids.selected"), + resource.TestCheckResourceAttr("data.aws_subnet_ids.selected", "ids.#", "1"), ), }, }, }) } -func testAccDataSourceAwsSubnetIDsCheck(name string) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[name] - if !ok { - return fmt.Errorf("root module has no resource called %s", name) - } - - vpcRs, ok := s.RootModule().Resources["aws_vpc.test"] - if !ok { - return fmt.Errorf("can't find aws_vpc.test in state") - } - _, ok = s.RootModule().Resources["aws_subnet.test"] - if !ok { - return fmt.Errorf("can't find aws_subnet.test in state") - } - - attr := rs.Primary.Attributes - - if rs.Primary.ID != vpcRs.Primary.ID { - return fmt.Errorf("ID of this resource should be the vpc id") - } - - return nil - } -} - -const testAccDataSourceAwsSubnetIDsConfig = ` -provider "aws" { - region = "us-west-2" -} - +const testAccDataSourceAwsSubnetIDsConfigWithDataSource = ` resource "aws_vpc" "test" { cidr_block = "172.16.0.0/16" @@ -74,6 +45,24 @@ resource "aws_subnet" "test" { data "aws_subnet_ids" "selected" { vpc_id = "${aws_vpc.test.id}" - depends_on = ["aws_subnet.test"] +} +` +const testAccDataSourceAwsSubnetIDsConfig = ` +resource "aws_vpc" "test" { + cidr_block = "172.16.0.0/16" + + tags { + Name = "terraform-testacc-subnet-ids-data-source" + } +} + +resource "aws_subnet" "test" { + vpc_id = "${aws_vpc.test.id}" + cidr_block = "172.16.123.0/24" + availability_zone = "us-west-2a" + + tags { + Name = "terraform-testacc-subnet-ids-data-source" + } } `