From 7862e5b499fe141ba73a7beff22120114c39b7df Mon Sep 17 00:00:00 2001 From: Sean Chittenden Date: Wed, 11 Jan 2017 23:28:48 -0800 Subject: [PATCH] Differentiate between lookup failure and value inequality. Before this patch it was not possible to test for a key in a map where the value is an empty string. With this patch, however, it is now possible to write a check like: ``` resource.TestCheckResourceAttr("res.name", "mymap.KeyWithEmptyValue", ""), ``` To test that `KeyWithEmptyValue` is a valid key in `mymap`. --- helper/resource/testing.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/helper/resource/testing.go b/helper/resource/testing.go index 5d46e5dc8a..1c2da7b14b 100644 --- a/helper/resource/testing.go +++ b/helper/resource/testing.go @@ -581,7 +581,11 @@ func TestCheckResourceAttr(name, key, value string) TestCheckFunc { return fmt.Errorf("No primary instance: %s", name) } - if is.Attributes[key] != value { + if v, ok := is.Attributes[key]; !ok || v != value { + if !ok { + return fmt.Errorf("%s: Attribute '%s' not found", name, key) + } + return fmt.Errorf( "%s: Attribute '%s' expected %#v, got %#v", name,