From 15ccf2dda54f8a11b00d6b272c0f81b14e4be9c3 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Wed, 11 Jul 2018 22:34:39 -0400 Subject: [PATCH] use a custom comparer for cty.Type Make sure we also compare cty.Types in `cmp.Equal`, even though they contain unexported fields. --- helper/schema/core_schema_test.go | 8 ++++---- helper/schema/provider_test.go | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/helper/schema/core_schema_test.go b/helper/schema/core_schema_test.go index 197e9b2f3..94669c788 100644 --- a/helper/schema/core_schema_test.go +++ b/helper/schema/core_schema_test.go @@ -11,8 +11,8 @@ import ( ) var ( - ignoreUnexported = cmpopts.IgnoreUnexported(cty.Type{}) - equateEmpty = cmpopts.EquateEmpty() + equateEmpty = cmpopts.EquateEmpty() + typeComparer = cmp.Comparer(cty.Type.Equals) ) // add the implicit "id" attribute for test resources @@ -305,8 +305,8 @@ func TestSchemaMapCoreConfigSchema(t *testing.T) { for name, test := range tests { t.Run(name, func(t *testing.T) { got := schemaMap(test.Schema).CoreConfigSchema() - if !cmp.Equal(got, test.Want, equateEmpty, ignoreUnexported) { - cmp.Diff(got, test.Want, equateEmpty, ignoreUnexported) + if !cmp.Equal(got, test.Want, typeComparer) { + cmp.Diff(got, test.Want, typeComparer) } }) } diff --git a/helper/schema/provider_test.go b/helper/schema/provider_test.go index 2a45a97d7..6bf8c5bdf 100644 --- a/helper/schema/provider_test.go +++ b/helper/schema/provider_test.go @@ -91,8 +91,8 @@ func TestProviderGetSchema(t *testing.T) { t.Fatalf("unexpected error %s", err) } - if !cmp.Equal(got, want, equateEmpty, ignoreUnexported) { - t.Error("wrong result:\n", cmp.Diff(got, want, equateEmpty, ignoreUnexported)) + if !cmp.Equal(got, want, equateEmpty, typeComparer) { + t.Error("wrong result:\n", cmp.Diff(got, want, equateEmpty, typeComparer)) } }