github.com/turtlemonvh/terraform@v0.6.9-0.20151204001754-8e40b6b855e8/builtin/providers/terraform/resource_state_test.go (about) 1 package terraform 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/hashicorp/terraform/helper/resource" 8 "github.com/hashicorp/terraform/terraform" 9 ) 10 11 func TestAccState_basic(t *testing.T) { 12 resource.Test(t, resource.TestCase{ 13 PreCheck: func() { testAccPreCheck(t) }, 14 Providers: testAccProviders, 15 Steps: []resource.TestStep{ 16 resource.TestStep{ 17 Config: testAccState_basic, 18 Check: resource.ComposeTestCheckFunc( 19 testAccCheckStateValue( 20 "terraform_remote_state.foo", "foo", "bar"), 21 ), 22 }, 23 }, 24 }) 25 } 26 27 func testAccCheckStateValue(id, name, value string) resource.TestCheckFunc { 28 return func(s *terraform.State) error { 29 rs, ok := s.RootModule().Resources[id] 30 if !ok { 31 return fmt.Errorf("Not found: %s", id) 32 } 33 if rs.Primary.ID == "" { 34 return fmt.Errorf("No ID is set") 35 } 36 37 v := rs.Primary.Attributes["output."+name] 38 if v != value { 39 return fmt.Errorf( 40 "Value for %s is %s, not %s", name, v, value) 41 } 42 43 return nil 44 } 45 } 46 47 const testAccState_basic = ` 48 resource "terraform_remote_state" "foo" { 49 backend = "_local" 50 51 config { 52 path = "./test-fixtures/basic.tfstate" 53 } 54 }`