@@ -5,6 +5,7 @@ package toproto5_test
55
66import (
77 "context"
8+ "github.com/hashicorp/terraform-plugin-framework/resource/identityschema"
89 "testing"
910
1011 "github.com/google/go-cmp/cmp"
@@ -33,6 +34,44 @@ func TestMoveResourceStateResponse(t *testing.T) {
3334 },
3435 )
3536
37+ testIdentityProto5Type := tftypes.Object {
38+ AttributeTypes : map [string ]tftypes.Type {
39+ "test_id" : tftypes .String ,
40+ },
41+ }
42+
43+ testIdentityProto5Value := tftypes .NewValue (testIdentityProto5Type , map [string ]tftypes.Value {
44+ "test_id" : tftypes .NewValue (tftypes .String , "id-123" ),
45+ })
46+
47+ testIdentityProto5DynamicValue , err := tfprotov5 .NewDynamicValue (testIdentityProto5Type , testIdentityProto5Value )
48+
49+ if err != nil {
50+ t .Fatalf ("unexpected error calling tfprotov5.NewDynamicValue(): %s" , err )
51+ }
52+
53+ testIdentity := & tfsdk.ResourceIdentity {
54+ Raw : testIdentityProto5Value ,
55+ Schema : identityschema.Schema {
56+ Attributes : map [string ]identityschema.Attribute {
57+ "test_id" : identityschema.StringAttribute {
58+ RequiredForImport : true ,
59+ },
60+ },
61+ },
62+ }
63+
64+ testIdentityInvalid := & tfsdk.ResourceIdentity {
65+ Raw : testIdentityProto5Value ,
66+ Schema : identityschema.Schema {
67+ Attributes : map [string ]identityschema.Attribute {
68+ "test_id" : identityschema.BoolAttribute {
69+ RequiredForImport : true ,
70+ },
71+ },
72+ },
73+ }
74+
3675 testCases := map [string ]struct {
3776 input * fwserver.MoveResourceStateResponse
3877 expected * tfprotov5.MoveResourceStateResponse
@@ -152,6 +191,47 @@ func TestMoveResourceStateResponse(t *testing.T) {
152191 },
153192 },
154193 },
194+ "TargetIdentity" : {
195+ input : & fwserver.MoveResourceStateResponse {
196+ TargetIdentity : testIdentity ,
197+ },
198+ expected : & tfprotov5.MoveResourceStateResponse {
199+ TargetIdentity : & tfprotov5.ResourceIdentityData {
200+ IdentityData : & testIdentityProto5DynamicValue ,
201+ },
202+ },
203+ },
204+ "TargetIdentity-invalid" : {
205+ input : & fwserver.MoveResourceStateResponse {
206+ Diagnostics : diag.Diagnostics {
207+ diag .NewWarningDiagnostic ("test warning summary" , "test warning details" ),
208+ diag .NewErrorDiagnostic ("test error summary" , "test error details" ),
209+ },
210+ TargetIdentity : testIdentityInvalid ,
211+ },
212+ expected : & tfprotov5.MoveResourceStateResponse {
213+ Diagnostics : []* tfprotov5.Diagnostic {
214+ {
215+ Severity : tfprotov5 .DiagnosticSeverityWarning ,
216+ Summary : "test warning summary" ,
217+ Detail : "test warning details" ,
218+ },
219+ {
220+ Severity : tfprotov5 .DiagnosticSeverityError ,
221+ Summary : "test error summary" ,
222+ Detail : "test error details" ,
223+ },
224+ {
225+ Severity : tfprotov5 .DiagnosticSeverityError ,
226+ Summary : "Unable to Convert Resource Identity" ,
227+ Detail : "An unexpected error was encountered when converting the resource identity to the protocol type. " +
228+ "This is always an issue in terraform-plugin-framework used to implement the provider and should be reported to the provider developers.\n \n " +
229+ "Please report this to the provider developer:\n \n " +
230+ "Unable to create DynamicValue: AttributeName(\" test_id\" ): unexpected value type string, tftypes.Bool values must be of type bool" ,
231+ },
232+ },
233+ },
234+ },
155235 }
156236
157237 for name , testCase := range testCases {
0 commit comments