From 87d98b1ff1cc885f51e9a018c68ccaf16d2ef571 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Mon, 23 Jan 2017 16:53:02 -0500 Subject: [PATCH] Correct aws_s3_bucket_object data source acceptance tests. (#11346) --- .../data_source_aws_s3_bucket_object_test.go | 4 ++-- helper/resource/testing.go | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/builtin/providers/aws/data_source_aws_s3_bucket_object_test.go b/builtin/providers/aws/data_source_aws_s3_bucket_object_test.go index ecfae9098..0bef65ae4 100644 --- a/builtin/providers/aws/data_source_aws_s3_bucket_object_test.go +++ b/builtin/providers/aws/data_source_aws_s3_bucket_object_test.go @@ -39,7 +39,7 @@ func TestAccDataSourceAWSS3BucketObject_basic(t *testing.T) { resource.TestCheckResourceAttr("data.aws_s3_bucket_object.obj", "etag", "b10a8db164e0754105b7a99be72e3fe5"), resource.TestMatchResourceAttr("data.aws_s3_bucket_object.obj", "last_modified", regexp.MustCompile("^[a-zA-Z]{3}, [0-9]+ [a-zA-Z]+ [0-9]{4} [0-9:]+ [A-Z]+$")), - resource.TestCheckResourceAttr("data.aws_s3_bucket_object.obj", "body", ""), + resource.TestCheckNoResourceAttr("data.aws_s3_bucket_object.obj", "body"), ), }, }, @@ -145,7 +145,7 @@ func TestAccDataSourceAWSS3BucketObject_allParams(t *testing.T) { resource.TestMatchResourceAttr("data.aws_s3_bucket_object.obj", "last_modified", regexp.MustCompile("^[a-zA-Z]{3}, [0-9]+ [a-zA-Z]+ [0-9]{4} [0-9:]+ [A-Z]+$")), resource.TestMatchResourceAttr("data.aws_s3_bucket_object.obj", "version_id", regexp.MustCompile("^.{32}$")), - resource.TestCheckResourceAttr("data.aws_s3_bucket_object.obj", "body", ""), + resource.TestCheckNoResourceAttr("data.aws_s3_bucket_object.obj", "body"), resource.TestCheckResourceAttr("data.aws_s3_bucket_object.obj", "cache_control", "no-cache"), resource.TestCheckResourceAttr("data.aws_s3_bucket_object.obj", "content_disposition", "attachment"), resource.TestCheckResourceAttr("data.aws_s3_bucket_object.obj", "content_encoding", "gzip"), diff --git a/helper/resource/testing.go b/helper/resource/testing.go index 1c2da7b14..014e5411d 100644 --- a/helper/resource/testing.go +++ b/helper/resource/testing.go @@ -598,6 +598,29 @@ func TestCheckResourceAttr(name, key, value string) TestCheckFunc { } } +// TestCheckNoResourceAttr is a TestCheckFunc which ensures that +// NO value exists in state for the given name/key combination. +func TestCheckNoResourceAttr(name, key string) TestCheckFunc { + return func(s *terraform.State) error { + ms := s.RootModule() + rs, ok := ms.Resources[name] + if !ok { + return fmt.Errorf("Not found: %s", name) + } + + is := rs.Primary + if is == nil { + return fmt.Errorf("No primary instance: %s", name) + } + + if _, ok := is.Attributes[key]; ok { + return fmt.Errorf("%s: Attribute '%s' found when not expected", name, key) + } + + return nil + } +} + func TestMatchResourceAttr(name, key string, r *regexp.Regexp) TestCheckFunc { return func(s *terraform.State) error { ms := s.RootModule()