Merge pull request #5757 from hashicorp/f-output-testing

Add TestCheckOutput helper to resource testing
This commit is contained in:
James Nugent 2016-03-21 17:19:08 +00:00
commit cb8a0549e1
1 changed files with 21 additions and 0 deletions

View File

@ -418,6 +418,27 @@ func TestCheckResourceAttrPtr(name string, key string, value *string) TestCheckF
} }
} }
// TestCheckOutput checks an output in the Terraform configuration
func TestCheckOutput(name, value string) TestCheckFunc {
return func(s *terraform.State) error {
ms := s.RootModule()
rs, ok := ms.Outputs[name]
if !ok {
return fmt.Errorf("Not found: %s", name)
}
if rs != value {
return fmt.Errorf(
"Output '%s': expected %#v, got %#v",
name,
value,
rs)
}
return nil
}
}
// TestT is the interface used to handle the test lifecycle of a test. // TestT is the interface used to handle the test lifecycle of a test.
// //
// Users should just use a *testing.T object, which implements this. // Users should just use a *testing.T object, which implements this.