From 35f9d2e081dd64ba4740e6a302191306ed7ffa24 Mon Sep 17 00:00:00 2001 From: James Nugent Date: Mon, 21 Mar 2016 16:54:02 +0000 Subject: [PATCH] Add TestCheckOutput helper to resource testing This allows outputs in test configuration to have test functions written conveniently. Useful for azurerm_template_deployment. --- helper/resource/testing.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/helper/resource/testing.go b/helper/resource/testing.go index 5d1e195a5..659cf2641 100644 --- a/helper/resource/testing.go +++ b/helper/resource/testing.go @@ -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.