@@ -23,39 +23,42 @@ import (
2323func TestServerListResource (t * testing.T ) {
2424 t .Parallel ()
2525
26- type ThingResource struct {
27- Name string `tfsdk:"name "`
26+ type ThingResourceIdentity struct {
27+ Id string `tfsdk:"id "`
2828 }
2929
30- type ThingResourceIdentity struct {
30+ type ThingResource struct {
31+ // TODO: how do we feel about this?
32+ ThingResourceIdentity
3133 Name string `tfsdk:"name"`
3234 }
3335
3436 resources := map [string ]ThingResource {}
35- resourceIdentities := map [string ]ThingResourceIdentity {}
3637 expectedResources := map [string ]* tfprotov6.DynamicValue {}
3738 expectedResourceIdentities := map [string ]* tfprotov6.ResourceIdentityData {}
3839
3940 examples := []string {"bookbag" , "bookshelf" , "bookworm" , "plateau" , "platinum" , "platypus" }
4041 for _ , example := range examples {
41- resources [ example ] = ThingResource { Name : example }
42- resourceIdentities [example ] = ThingResourceIdentity {Name : example }
42+ id := "id-" + example
43+ resources [example ] = ThingResource {Name : example , ThingResourceIdentity : ThingResourceIdentity { Id : id } }
4344
4445 expectedResources [example ] = testNewDynamicValue (t , tftypes.Object {
4546 AttributeTypes : map [string ]tftypes.Type {
47+ "id" : tftypes .String ,
4648 "name" : tftypes .String ,
4749 },
4850 }, map [string ]tftypes.Value {
51+ "id" : tftypes .NewValue (tftypes .String , id ),
4952 "name" : tftypes .NewValue (tftypes .String , example ),
5053 })
5154
5255 expectedResourceIdentities [example ] = & tfprotov6.ResourceIdentityData {
5356 IdentityData : testNewDynamicValue (t , tftypes.Object {
5457 AttributeTypes : map [string ]tftypes.Type {
55- "name " : tftypes .String ,
58+ "id " : tftypes .String ,
5659 },
5760 }, map [string ]tftypes.Value {
58- "name " : tftypes .NewValue (tftypes .String , example ),
61+ "id " : tftypes .NewValue (tftypes .String , id ),
5962 }),
6063 }
6164 }
@@ -100,25 +103,12 @@ func TestServerListResource(t *testing.T) {
100103 continue
101104 }
102105
103- result := list.ListResult {}
104- identity , diags := req .ToIdentity (ctx , resourceIdentities [name ])
105- if diags .HasError () {
106- result .Diagnostics = diags
107- results = append (results , result )
108- continue
109- }
110-
111- resource , diags := req .ToResource (ctx , resources [name ])
112- if diags .HasError () {
113- result .Diagnostics = diags
114- results = append (results , result )
115- continue
116- }
106+ result := req .ToResult (
107+ ctx ,
108+ resources [name ].ThingResourceIdentity ,
109+ resources [name ],
110+ name )
117111
118- result .DisplayName = name
119- result .Identity = identity
120- result .Resource = resource // maybe only include if request says so
121- result .Diagnostics = diags
122112 results = append (results , result )
123113 }
124114 resp .Results = slices .Values (results )
@@ -134,7 +124,7 @@ func TestServerListResource(t *testing.T) {
134124 IdentitySchemaMethod : func (ctx context.Context , req resource.IdentitySchemaRequest , resp * resource.IdentitySchemaResponse ) {
135125 resp .IdentitySchema = identityschema.Schema {
136126 Attributes : map [string ]identityschema.Attribute {
137- "name " : identityschema.StringAttribute {},
127+ "id " : identityschema.StringAttribute {},
138128 },
139129 }
140130 },
@@ -145,6 +135,7 @@ func TestServerListResource(t *testing.T) {
145135 SchemaMethod : func (ctx context.Context , req resource.SchemaRequest , resp * resource.SchemaResponse ) {
146136 resp .Schema = resourceschema.Schema {
147137 Attributes : map [string ]resourceschema.Attribute {
138+ "id" : resourceschema.StringAttribute {},
148139 "name" : resourceschema.StringAttribute {},
149140 },
150141 }
0 commit comments