Skip to content

Commit

Permalink
Merge pull request #5757 from hashicorp/f-output-testing
Browse files Browse the repository at this point in the history
Add TestCheckOutput helper to resource testing
  • Loading branch information
jen20 committed Mar 21, 2016
2 parents cabece9 + 35f9d2e commit cb8a054
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions helper/resource/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
// Users should just use a *testing.T object, which implements this.
Expand Down

0 comments on commit cb8a054

Please sign in to comment.