From 96b4abd2449c911e933fabbf73b92eafb593f5c8 Mon Sep 17 00:00:00 2001 From: edwardfeng-db Date: Tue, 9 Jul 2024 22:49:10 +0200 Subject: [PATCH] update --- common/reflect_resource_plugin_framework.go | 26 ++++++++----------- .../reflect_resource_plugin_framework_test.go | 2 +- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/common/reflect_resource_plugin_framework.go b/common/reflect_resource_plugin_framework.go index 0f2a8ad520..42a375fe15 100644 --- a/common/reflect_resource_plugin_framework.go +++ b/common/reflect_resource_plugin_framework.go @@ -68,38 +68,34 @@ func tfSdkToGoSdkSingleField(srcField reflect.Value, destField reflect.Value, sr return err } } else if srcField.Kind() == reflect.Struct { - switch srcFieldValue.(type) { + switch v := srcFieldValue.(type) { case types.Bool: - boolVal := srcFieldValue.(types.Bool) - destField.SetBool(boolVal.ValueBool()) - if !boolVal.IsNull() { + destField.SetBool(v.ValueBool()) + if !v.IsNull() { addToForceSendFields(srcFieldName, forceSendFieldsField) } case types.Int64: - intVal := srcFieldValue.(types.Int64) - destField.SetInt(intVal.ValueInt64()) - if !intVal.IsNull() { + destField.SetInt(v.ValueInt64()) + if !v.IsNull() { addToForceSendFields(srcFieldName, forceSendFieldsField) } case types.Float64: - floatVal := srcFieldValue.(types.Float64) - destField.SetFloat(floatVal.ValueFloat64()) - if !floatVal.IsNull() { + destField.SetFloat(v.ValueFloat64()) + if !v.IsNull() { addToForceSendFields(srcFieldName, forceSendFieldsField) } case types.String: - strVal := srcFieldValue.(types.String) - destField.SetString(strVal.ValueString()) - if !strVal.IsNull() { + destField.SetString(v.ValueString()) + if !v.IsNull() { addToForceSendFields(srcFieldName, forceSendFieldsField) } case types.List: - diag := srcFieldValue.(types.List).ElementsAs(ctx, destField.Addr().Interface(), false) + diag := v.ElementsAs(ctx, destField.Addr().Interface(), false) if len(diag) != 0 { panic("Error") } case types.Map: - srcFieldValue.(types.Map).ElementsAs(ctx, destField.Addr().Interface(), false) + v.ElementsAs(ctx, destField.Addr().Interface(), false) default: // If it is a real stuct instead of a tfsdk type, recursively resolve it. if err := TfSdkToGoSdkStruct(srcFieldValue, destField.Addr().Interface(), ctx); err != nil { diff --git a/common/reflect_resource_plugin_framework_test.go b/common/reflect_resource_plugin_framework_test.go index b600b527ed..99fb143d2b 100644 --- a/common/reflect_resource_plugin_framework_test.go +++ b/common/reflect_resource_plugin_framework_test.go @@ -248,7 +248,7 @@ func TestStructConversion(t *testing.T) { // Convert the gosdk struct back to tfsdk struct convertedTfSdkStruct := DummyTfSdk{} - e = GoSdkToTfSdk(convertedGoSdkStruct, &convertedTfSdkStruct, ctx) + e = GoSdkToTfSdkStruct(convertedGoSdkStruct, &convertedTfSdkStruct, ctx) assert.NoError(t, e) // Assert that the struct is exactly the same after tfsdk --> gosdk --> tfsdk