From fa1fc2ca8e20a77bc70add3b9a7ec51bedd8b1dd Mon Sep 17 00:00:00 2001 From: Chris Marchesi Date: Sun, 28 May 2017 11:36:44 -0700 Subject: [PATCH] helper/schema: CustomizeDiff invocation test Just one more test to check to make sure that CustomizeDiff is called on resource level. --- helper/schema/resource_test.go | 38 ++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/helper/schema/resource_test.go b/helper/schema/resource_test.go index ab17d6025..22bfd1b8c 100644 --- a/helper/schema/resource_test.go +++ b/helper/schema/resource_test.go @@ -254,6 +254,44 @@ func TestResourceDiff_Timeout_diff(t *testing.T) { } } +func TestResourceDiff_CustomizeFunc(t *testing.T) { + r := &Resource{ + Schema: map[string]*Schema{ + "foo": &Schema{ + Type: TypeInt, + Optional: true, + }, + }, + } + + var called bool + + r.CustomizeDiff = func(d *ResourceDiff, m interface{}) error { + called = true + return nil + } + + raw, err := config.NewRawConfig( + map[string]interface{}{ + "foo": 42, + }) + if err != nil { + t.Fatalf("err: %s", err) + } + + var s *terraform.InstanceState + conf := terraform.NewResourceConfig(raw) + + _, err = r.Diff(s, conf, nil) + if err != nil { + t.Fatalf("err: %s", err) + } + + if !called { + t.Fatalf("diff customization not called") + } +} + func TestResourceApply_destroy(t *testing.T) { r := &Resource{ Schema: map[string]*Schema{