Fix accpetence test to work

This commit is contained in:
Colin Wood 2017-03-31 10:57:07 -07:00
parent a424fffd48
commit d7a319f239
1 changed files with 25 additions and 36 deletions

View File

@ -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"
}
}
`