From 775df57217e0f9cf442bee27bc36c8ea9ec71eb1 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Wed, 23 Jan 2019 20:03:10 -0500 Subject: [PATCH] add more tests verify that changes to defaults are detected --- .../providers/test/resource_defaults_test.go | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/builtin/providers/test/resource_defaults_test.go b/builtin/providers/test/resource_defaults_test.go index 79b164e1c..b2659966d 100644 --- a/builtin/providers/test/resource_defaults_test.go +++ b/builtin/providers/test/resource_defaults_test.go @@ -33,6 +33,89 @@ resource "test_resource_defaults" "foo" { }) } +func TestResourceDefaults_change(t *testing.T) { + resource.UnitTest(t, resource.TestCase{ + Providers: testAccProviders, + CheckDestroy: testAccCheckResourceDestroy, + Steps: []resource.TestStep{ + { + Config: strings.TrimSpace(` +resource "test_resource_defaults" "foo" { +} + `), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr( + "test_resource_defaults.foo", "default_string", "default string", + ), + resource.TestCheckResourceAttr( + "test_resource_defaults.foo", "default_bool", "1", + ), + resource.TestCheckNoResourceAttr( + "test_resource_defaults.foo", "nested.#", + ), + ), + }, + { + Config: strings.TrimSpace(` +resource "test_resource_defaults" "foo" { + default_string = "new" + default_bool = false + nested { + optional = "nested" + } +} + `), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr( + "test_resource_defaults.foo", "default_string", "new", + ), + resource.TestCheckResourceAttr( + "test_resource_defaults.foo", "default_bool", "false", + ), + resource.TestCheckResourceAttr( + "test_resource_defaults.foo", "nested.#", "1", + ), + resource.TestCheckResourceAttr( + "test_resource_defaults.foo", "nested.2950978312.optional", "nested", + ), + resource.TestCheckResourceAttr( + "test_resource_defaults.foo", "nested.2950978312.string", "default nested", + ), + ), + }, + { + Config: strings.TrimSpace(` +resource "test_resource_defaults" "foo" { + default_string = "new" + default_bool = false + nested { + optional = "nested" + string = "new" + } +} + `), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr( + "test_resource_defaults.foo", "default_string", "new", + ), + resource.TestCheckResourceAttr( + "test_resource_defaults.foo", "default_bool", "false", + ), + resource.TestCheckResourceAttr( + "test_resource_defaults.foo", "nested.#", "1", + ), + resource.TestCheckResourceAttr( + "test_resource_defaults.foo", "nested.782850362.optional", "nested", + ), + resource.TestCheckResourceAttr( + "test_resource_defaults.foo", "nested.782850362.string", "new", + ), + ), + }, + }, + }) +} + func TestResourceDefaults_inSet(t *testing.T) { resource.UnitTest(t, resource.TestCase{ Providers: testAccProviders,