From f0da725b2273b7a2a642203a75b4277b12d45267 Mon Sep 17 00:00:00 2001 From: Marcin Tojek Date: Wed, 22 Mar 2023 18:41:25 +0100 Subject: [PATCH] fix: annotate multi-words fields (#116) --- provider/decode_test.go | 28 ++++++++++++++++++++++++++++ provider/parameter.go | 4 ++-- 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 provider/decode_test.go diff --git a/provider/decode_test.go b/provider/decode_test.go new file mode 100644 index 00000000..31a1612d --- /dev/null +++ b/provider/decode_test.go @@ -0,0 +1,28 @@ +package provider_test + +import ( + "testing" + + "github.com/coder/terraform-provider-coder/provider" + "github.com/mitchellh/mapstructure" + "github.com/stretchr/testify/require" +) + +func TestDecode(t *testing.T) { + const ( + legacyVariable = "Legacy Variable" + legacyVariableName = "Legacy Variable Name" + ) + + aMap := map[string]interface{}{ + "name": "Parameter Name", + "legacy_variable": legacyVariable, + "legacy_variable_name": legacyVariableName, + } + + var param provider.Parameter + err := mapstructure.Decode(aMap, ¶m) + require.NoError(t, err) + require.Equal(t, legacyVariable, param.LegacyVariable) + require.Equal(t, legacyVariableName, param.LegacyVariableName) +} diff --git a/provider/parameter.go b/provider/parameter.go index d8ec5d98..d908f2ce 100644 --- a/provider/parameter.go +++ b/provider/parameter.go @@ -51,8 +51,8 @@ type Parameter struct { Validation []Validation Optional bool - LegacyVariableName string - LegacyVariable string + LegacyVariableName string `mapstructure:"legacy_variable_name"` + LegacyVariable string `mapstructure:"legacy_variable"` } func parameterDataSource() *schema.Resource {