Skip to content

Commit 588762b

Browse files
committed
set empty objects in NewListResult
1 parent 734d43a commit 588762b

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

internal/proto5server/server_listresource_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func TestServerListResource(t *testing.T) {
105105
continue
106106
}
107107

108-
result := req.NewListResult()
108+
result := req.NewListResult(ctx)
109109
result.DisplayName = name
110110

111111
diags = result.Identity.Set(ctx, resources[name].ThingResourceIdentity)

internal/proto6server/server_listresource_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func TestServerListResource(t *testing.T) {
105105
continue
106106
}
107107

108-
result := req.NewListResult()
108+
result := req.NewListResult(ctx)
109109
result.DisplayName = name
110110

111111
diags = result.Identity.Set(ctx, resources[name].ThingResourceIdentity)
@@ -131,7 +131,7 @@ func TestServerListResource(t *testing.T) {
131131
}
132132

133133
r.ListMethod = func(ctx context.Context, req list.ListRequest, resp *list.ListResultsStream) {
134-
result := req.NewListResult()
134+
result := req.NewListResult(ctx)
135135
result.DisplayName = "plateau"
136136

137137
diags := result.Identity.Set(ctx, resources["plateau"].ThingResourceIdentity)

list/list_resource.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
1212
"github.com/hashicorp/terraform-plugin-framework/resource"
1313
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
14+
"github.com/hashicorp/terraform-plugin-go/tftypes"
1415
)
1516

1617
// ListResource represents an implementation of listing instances of a managed resource
@@ -109,9 +110,15 @@ type ListRequest struct {
109110

110111
// NewListResult creates a new [ListResult] with convenient defaults
111112
// for each field.
112-
func (r ListRequest) NewListResult() ListResult {
113-
identity := &tfsdk.ResourceIdentity{Schema: r.ResourceIdentitySchema}
114-
resource := &tfsdk.Resource{Schema: r.ResourceSchema}
113+
func (r ListRequest) NewListResult(ctx context.Context) ListResult {
114+
identity := &tfsdk.ResourceIdentity{
115+
Raw: tftypes.NewValue(r.ResourceIdentitySchema.Type().TerraformType(ctx), nil),
116+
Schema: r.ResourceIdentitySchema,
117+
}
118+
resource := &tfsdk.Resource{
119+
Raw: tftypes.NewValue(r.ResourceSchema.Type().TerraformType(ctx), nil),
120+
Schema: r.ResourceSchema,
121+
}
115122

116123
return ListResult{
117124
DisplayName: "",

0 commit comments

Comments
 (0)