Skip to content

Commit f3504cb

Browse files
committed
Fixed failing tests
1 parent 86d6787 commit f3504cb

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

Diff for: internal/fromproto6/moveresourcestate_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func TestMoveResourceStateRequest(t *testing.T) {
3232
testCases := map[string]struct {
3333
input *tfprotov6.MoveResourceStateRequest
3434
resourceSchema fwschema.Schema
35+
identitySchema fwschema.Schema
3536
resource resource.Resource
3637
expected *fwserver.MoveResourceStateRequest
3738
expectedDiagnostics diag.Diagnostics
@@ -192,7 +193,7 @@ func TestMoveResourceStateRequest(t *testing.T) {
192193
t.Run(name, func(t *testing.T) {
193194
t.Parallel()
194195

195-
got, diags := fromproto6.MoveResourceStateRequest(context.Background(), testCase.input, testCase.resource, testCase.resourceSchema)
196+
got, diags := fromproto6.MoveResourceStateRequest(context.Background(), testCase.input, testCase.resource, testCase.resourceSchema, testCase.identitySchema)
196197

197198
if diff := cmp.Diff(got, testCase.expected); diff != "" {
198199
t.Errorf("unexpected difference: %s", diff)

Diff for: internal/fwserver/server_moveresourcestate.go

+6-9
Original file line numberDiff line numberDiff line change
@@ -145,22 +145,19 @@ func (s *Server) MoveResourceState(ctx context.Context, req *MoveResourceStateRe
145145
SourceIdentitySchemaVersion: req.SourceIdentitySchemaVersion,
146146
}
147147

148-
var taridentity tftypes.Type
149-
150-
if req.IdentitySchema != nil {
151-
taridentity = req.IdentitySchema.Type().TerraformType(ctx)
152-
}
153-
154148
moveStateResp := resource.MoveStateResponse{
155149
TargetPrivate: privatestate.EmptyProviderData(ctx),
156150
TargetState: tfsdk.State{
157151
Schema: req.TargetResourceSchema,
158152
Raw: tftypes.NewValue(req.TargetResourceSchema.Type().TerraformType(ctx), nil),
159153
},
160-
TargetIdentity: &tfsdk.ResourceIdentity{
161-
Raw: tftypes.NewValue(taridentity, nil),
154+
}
155+
156+
if req.IdentitySchema != nil {
157+
moveStateResp.TargetIdentity = &tfsdk.ResourceIdentity{
158+
Raw: tftypes.NewValue(req.IdentitySchema.Type().TerraformType(ctx), nil),
162159
Schema: req.IdentitySchema,
163-
},
160+
}
164161
}
165162

166163
if resourceStateMover.SourceSchema != nil {

Diff for: internal/proto5server/server_moveresourcestate_test.go

+18-4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ func TestServerMoveResourceState(t *testing.T) {
4848
},
4949
}
5050

51+
testIdentityType := tftypes.Object{
52+
AttributeTypes: map[string]tftypes.Type{
53+
"test_id": tftypes.String,
54+
},
55+
}
56+
5157
testCases := map[string]struct {
5258
server *Server
5359
request *tfprotov5.MoveResourceStateRequest
@@ -508,7 +514,15 @@ func TestServerMoveResourceState(t *testing.T) {
508514
resp.Diagnostics.AddError("Unexpected req.SourceRawState difference", diff)
509515
}
510516

511-
resp.Diagnostics.Append(resp.TargetIdentity.SetAttribute(ctx, path.Root("test_id"), "test_id_value")...)
517+
expectedSourceIdentity := testNewTfprotov6RawState(t, map[string]interface{}{
518+
"test_id": "test-id-value",
519+
})
520+
521+
if diff := cmp.Diff(req.SourceIdentity, expectedSourceIdentity); diff != "" {
522+
resp.Diagnostics.AddError("Unexpected req.SourceIdentity difference", diff)
523+
}
524+
525+
resp.Diagnostics.Append(resp.TargetIdentity.SetAttribute(ctx, path.Root("test_id"), "test-id-value")...)
512526

513527
// Prevent missing implementation error, the values do not matter except for response assertion
514528
resp.Diagnostics.Append(resp.TargetState.SetAttribute(ctx, path.Root("id"), "test-id-value")...)
@@ -538,7 +552,7 @@ func TestServerMoveResourceState(t *testing.T) {
538552
TargetTypeName: "test_resource",
539553
},
540554
expectedResponse: &tfprotov5.MoveResourceStateResponse{
541-
TargetIdentity: &tfprotov5.ResourceIdentityData{IdentityData: testNewDynamicValue(t, schemaType, map[string]tftypes.Value{
555+
TargetIdentity: &tfprotov5.ResourceIdentityData{IdentityData: testNewDynamicValue(t, testIdentityType, map[string]tftypes.Value{
542556
"test_id": tftypes.NewValue(tftypes.String, "test-id-value"),
543557
})},
544558
TargetState: testNewDynamicValue(t, schemaType, map[string]tftypes.Value{
@@ -860,7 +874,7 @@ func TestServerMoveResourceState(t *testing.T) {
860874
return []resource.StateMover{
861875
{
862876
StateMover: func(_ context.Context, req resource.MoveStateRequest, resp *resource.MoveStateResponse) {
863-
resp.Diagnostics.Append(resp.TargetIdentity.SetAttribute(ctx, path.Root("test_id"), "test_id_value")...)
877+
resp.Diagnostics.Append(resp.TargetIdentity.SetAttribute(ctx, path.Root("test_id"), "test-id-value")...)
864878
resp.Diagnostics.Append(resp.TargetState.SetAttribute(ctx, path.Root("id"), "test-id-value")...)
865879
resp.Diagnostics.Append(resp.TargetState.SetAttribute(ctx, path.Root("required_attribute"), "true")...)
866880
},
@@ -893,7 +907,7 @@ func TestServerMoveResourceState(t *testing.T) {
893907
"optional_attribute": tftypes.NewValue(tftypes.String, nil),
894908
"required_attribute": tftypes.NewValue(tftypes.String, "true"),
895909
}),
896-
TargetIdentity: &tfprotov5.ResourceIdentityData{IdentityData: testNewDynamicValue(t, schemaType, map[string]tftypes.Value{
910+
TargetIdentity: &tfprotov5.ResourceIdentityData{IdentityData: testNewDynamicValue(t, testIdentityType, map[string]tftypes.Value{
897911
"test_id": tftypes.NewValue(tftypes.String, "test-id-value"),
898912
})},
899913
},

0 commit comments

Comments
 (0)