From ed0ba6132954c9577ca73b5b8ffeb68767bb657b Mon Sep 17 00:00:00 2001 From: guineveresaenger Date: Fri, 13 Dec 2024 16:00:56 -0800 Subject: [PATCH] Prioritize Pulumi-supplied deprecation message over any TF ones --- pkg/tfgen/generate.go | 8 ++++---- pkg/tfgen/generate_test.go | 41 ++++++++++++++++++++++++++++++++------ 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/pkg/tfgen/generate.go b/pkg/tfgen/generate.go index c9d58e8a6..067342389 100644 --- a/pkg/tfgen/generate.go +++ b/pkg/tfgen/generate.go @@ -634,14 +634,14 @@ func (v *variable) Name() string { return v.name } func (v *variable) Doc() string { return v.doc } func (v *variable) deprecationMessage() string { - if v.schema != nil && v.schema.Deprecated() != "" { - return v.schema.Deprecated() - } - if v.info != nil && v.info.DeprecationMessage != "" { return v.info.DeprecationMessage } + if v.schema != nil && v.schema.Deprecated() != "" { + return v.schema.Deprecated() + } + return "" } diff --git a/pkg/tfgen/generate_test.go b/pkg/tfgen/generate_test.go index 84c1bf278..4d636c555 100644 --- a/pkg/tfgen/generate_test.go +++ b/pkg/tfgen/generate_test.go @@ -39,15 +39,44 @@ import ( shimv1 "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/sdk-v1" ) -func Test_DeprecationFromTFSchema(t *testing.T) { +func Test_DeprecationMessage(t *testing.T) { t.Parallel() - v := &variable{ - name: "v", - schema: shimv1.NewSchema(&schema.Schema{Type: schema.TypeString, Deprecated: "This is deprecated"}), + + cases := []struct { + name string + variable *variable + expectedMessage string + }{ + { + name: "From TF Schema", + variable: &variable{ + schema: shimv1.NewSchema(&schema.Schema{Deprecated: "Terraform says this is deprecated"}), + }, + expectedMessage: "Terraform says this is deprecated", + }, + { + name: "From Pulumi Resources File", + variable: &variable{ + schema: shimv1.NewSchema(&schema.Schema{Deprecated: "Pulumi says this is deprecated"}), + }, + expectedMessage: "Pulumi says this is deprecated", + }, + { + name: "From Pulumi Resources File Overrides TF Schema", + variable: &variable{ + info: &tfbridge.SchemaInfo{DeprecationMessage: "Pulumi says this is deprecated"}, + schema: shimv1.NewSchema(&schema.Schema{Deprecated: "Terraform says this is deprecated"}), + }, + expectedMessage: "Pulumi says this is deprecated", + }, } - deprecationMessage := v.deprecationMessage() - assert.Equal(t, "This is deprecated", deprecationMessage) + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + deprecationMessage := tc.variable.deprecationMessage() + assert.Equal(t, tc.expectedMessage, deprecationMessage) + }) + } } func Test_ForceNew(t *testing.T) {