Skip to content

Commit 93602b7

Browse files
committed
list: doc comments & tidying
1 parent 9c0fecc commit 93602b7

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

internal/proto5server/server_listresource_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,14 @@ func TestServerListResource(t *testing.T) {
106106
}
107107

108108
result := req.NewListResult()
109-
result.Identity.Set(ctx, resources[name].ThingResourceIdentity)
110-
result.Resource.Set(ctx, resources[name])
111109
result.DisplayName = name
112110

111+
diags = result.Identity.Set(ctx, resources[name].ThingResourceIdentity)
112+
result.Diagnostics.Append(diags...)
113+
114+
diags = result.Resource.Set(ctx, resources[name])
115+
result.Diagnostics.Append(diags...)
116+
113117
results = append(results, result)
114118
}
115119
resp.Results = slices.Values(results)

internal/proto6server/server_listresource_test.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,14 @@ func TestServerListResource(t *testing.T) {
106106
}
107107

108108
result := req.NewListResult()
109-
result.Identity.Set(ctx, resources[name].ThingResourceIdentity)
110-
result.Resource.Set(ctx, resources[name])
111109
result.DisplayName = name
112110

111+
diags = result.Identity.Set(ctx, resources[name].ThingResourceIdentity)
112+
result.Diagnostics = append(result.Diagnostics, diags...)
113+
114+
diags = result.Resource.Set(ctx, resources[name])
115+
result.Diagnostics = append(result.Diagnostics, diags...)
116+
113117
results = append(results, result)
114118
}
115119
resp.Results = slices.Values(results)
@@ -128,10 +132,13 @@ func TestServerListResource(t *testing.T) {
128132

129133
r.ListMethod = func(ctx context.Context, req list.ListRequest, resp *list.ListResultsStream) {
130134
result := req.NewListResult()
131-
result.Identity.Set(ctx, resources["plateau"].ThingResourceIdentity)
132135
result.DisplayName = "plateau"
133136

134-
resp.Results = slices.Values([]list.ListResult{result})
137+
diags := result.Identity.Set(ctx, resources["plateau"].ThingResourceIdentity)
138+
result.Diagnostics = append(result.Diagnostics, diags...)
139+
140+
results := []list.ListResult{result}
141+
resp.Results = slices.Values(results)
135142
}
136143

137144
return r

list/list_resource.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ type ListRequest struct {
103103
ResourceIdentitySchema fwschema.Schema
104104
}
105105

106+
// NewListResult creates a new [ListResult] with convenient defaults
107+
// for each field.
106108
func (r ListRequest) NewListResult() ListResult {
107109
identity := &tfsdk.ResourceIdentity{Schema: r.ResourceIdentitySchema}
108110
resource := &tfsdk.Resource{Schema: r.ResourceSchema}
@@ -132,10 +134,10 @@ type ListResultsStream struct {
132134
}
133135

134136
// NoListResults is an iterator that pushes zero results.
135-
var NoListResults = func(func(ListResult) bool) {}
137+
var NoListResults = func(push func(ListResult) bool) {}
136138

137139
// ListResultsStreamDiagnostics returns a function that yields a single
138-
// [[ListResult]] with the given Diagnostics
140+
// [ListResult] with the given Diagnostics
139141
func ListResultsStreamDiagnostics(diags diag.Diagnostics) iter.Seq[ListResult] {
140142
return func(push func(ListResult) bool) {
141143
if !push(ListResult{Diagnostics: diags}) {
@@ -144,7 +146,8 @@ func ListResultsStreamDiagnostics(diags diag.Diagnostics) iter.Seq[ListResult] {
144146
}
145147
}
146148

147-
// ListResult represents a listed managed resource instance.
149+
// ListResult represents a listed managed resource instance. For convenience,
150+
// create new values using [NewListResult] instead of struct literals.
148151
type ListResult struct {
149152
// Identity is the identity of the managed resource instance.
150153
//

0 commit comments

Comments
 (0)