Skip to content

Commit 0a6415e

Browse files
committed
wip: add a test with null identity
1 parent 63b1416 commit 0a6415e

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

internal/fwserver/server_updateresource_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,58 @@ func TestServerUpdateResource(t *testing.T) {
927927
Private: testEmptyPrivate,
928928
},
929929
},
930+
"response-new-identity-null": {
931+
server: &fwserver.Server{
932+
Provider: &testprovider.Provider{},
933+
},
934+
request: &fwserver.UpdateResourceRequest{
935+
PlannedState: &tfsdk.Plan{
936+
Raw: tftypes.NewValue(testSchemaType, map[string]tftypes.Value{
937+
"test_computed": tftypes.NewValue(tftypes.String, nil),
938+
"test_required": tftypes.NewValue(tftypes.String, "test-plannedstate-value"),
939+
}),
940+
Schema: testSchema,
941+
},
942+
PlannedIdentity: &tfsdk.ResourceIdentity{
943+
Raw: tftypes.NewValue(testIdentityType, map[string]tftypes.Value{
944+
"test_id": tftypes.NewValue(tftypes.String, nil),
945+
}),
946+
Schema: testIdentitySchema,
947+
},
948+
IdentitySchema: testIdentitySchema,
949+
ResourceSchema: testSchema,
950+
Resource: &testprovider.ResourceWithIdentity{
951+
Resource: &testprovider.Resource{
952+
UpdateMethod: func(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
953+
var data testSchemaData
954+
resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...)
955+
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
956+
957+
var identityData testIdentitySchemaData
958+
resp.Diagnostics.Append(req.Identity.Get(ctx, &identityData)...)
959+
resp.Diagnostics.Append(resp.Identity.Set(ctx, &identityData)...)
960+
961+
},
962+
},
963+
},
964+
},
965+
expectedResponse: &fwserver.UpdateResourceResponse{
966+
NewIdentity: &tfsdk.ResourceIdentity{
967+
Raw: tftypes.NewValue(testIdentityType, map[string]tftypes.Value{
968+
"test_id": tftypes.NewValue(tftypes.String, nil),
969+
}),
970+
Schema: testIdentitySchema,
971+
},
972+
NewState: &tfsdk.State{
973+
Raw: tftypes.NewValue(testSchemaType, map[string]tftypes.Value{
974+
"test_computed": tftypes.NewValue(tftypes.String, nil),
975+
"test_required": tftypes.NewValue(tftypes.String, "test-plannedstate-value"),
976+
}),
977+
Schema: testSchema,
978+
},
979+
Private: testEmptyPrivate,
980+
},
981+
},
930982
"response-newstate-semantic-equality": {
931983
server: &fwserver.Server{
932984
Provider: &testprovider.Provider{},

0 commit comments

Comments
 (0)