Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mgyucht committed Dec 9, 2024
1 parent 4feb053 commit d10447f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
7 changes: 7 additions & 0 deletions internal/providers/pluginfw/converters/converters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type DummyTfSdk struct {
Irrelevant types.String `tfsdk:"-"`
Object types.Object `tfsdk:"object" tf:"optional"`
ObjectPtr types.Object `tfsdk:"object_ptr" tf:"optional"`
Type_ types.String `tfsdk:"type" tf:""` // Test Type_ renaming
}

func (DummyTfSdk) GetComplexFieldTypes(ctx context.Context) map[string]reflect.Type {
Expand Down Expand Up @@ -101,6 +102,7 @@ type DummyGoSdk struct {
SliceStructPtr *DummyNestedGoSdk `json:"slice_struct_ptr"`
Object DummyNestedGoSdk `json:"object"`
ObjectPtr *DummyNestedGoSdk `json:"object_ptr"`
Type string `json:"type"` // Test Type_ renaming
ForceSendFields []string `json:"-"`
}

Expand Down Expand Up @@ -354,6 +356,11 @@ var tests = []struct {
ForceSendFields: []string{"Name", "Enabled"},
}, ForceSendFields: []string{"Object"}},
},
{
"type name",
DummyTfSdk{Type_: types.StringValue("abc")},
DummyGoSdk{Type: "abc", ForceSendFields: []string{"Type"}},
},
}

func TestConverter(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions internal/providers/pluginfw/converters/go_to_tf.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ func GoSdkToTfSdkStruct(ctx context.Context, gosdk interface{}, tfsdk interface{
if srcFieldTag == "-" {
continue
}
destField := destVal.FieldByName(toTfSdkName(srcFieldName))
destFieldType, ok := destVal.Type().FieldByName(field.StructField.Name)
destFieldStructName := toTfSdkName(srcFieldName)
destField := destVal.FieldByName(destFieldStructName)
destFieldType, ok := destVal.Type().FieldByName(destFieldStructName)
if !ok {
d.AddError(goSdkToTfSdkStructConversionFailureMessage, fmt.Sprintf("destination struct does not have field %s. %s", srcFieldName, common.TerraformBugErrorMessage))
return
Expand Down
3 changes: 3 additions & 0 deletions internal/providers/pluginfw/products/cluster/data_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ func (d *ClusterDataSource) Read(ctx context.Context, req datasource.ReadRequest

var tfCluster compute_tf.ClusterDetails
resp.Diagnostics.Append(converters.GoSdkToTfSdkStruct(ctx, cluster, &tfCluster)...)
if resp.Diagnostics.HasError() {
return
}

clusterInfo.ClusterId = tfCluster.ClusterId
clusterInfo.Name = tfCluster.ClusterName
Expand Down

0 comments on commit d10447f

Please sign in to comment.