File tree Expand file tree Collapse file tree 2 files changed +10
-5
lines changed Expand file tree Collapse file tree 2 files changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -83,7 +83,7 @@ func TestServerListResource(t *testing.T) {
8383 request : & fwserver.ListRequest {
8484 ListResource : & testprovider.ListResource {
8585 ListMethod : func (ctx context.Context , req list.ListRequest , resp * list.ListResultsStream ) { // TODO
86- resp .Results = slices . Values ([] list.ListResult {})
86+ resp .Results = list .NoListResults
8787 },
8888 },
8989 },
@@ -110,7 +110,7 @@ func TestServerListResource(t *testing.T) {
110110 request : & fwserver.ListRequest {
111111 ListResource : & testprovider.ListResource {
112112 ListMethod : func (ctx context.Context , req list.ListRequest , resp * list.ListResultsStream ) { // TODO
113- resp .Results = slices . Values ([]list.ListResult {
113+ resp .Results = list . FromValues ([]list.ListResult {
114114 {
115115 Identity : & tfsdk.ResourceIdentity {
116116 Schema : testIdentitySchema ,
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ package list
55
66import (
77 "context"
8+ "slices"
89
910 "github.com/hashicorp/terraform-plugin-framework/diag"
1011 "github.com/hashicorp/terraform-plugin-framework/resource"
@@ -104,9 +105,7 @@ type ListRequest struct {
104105// that pushes zero or more results of type ListResult.
105106//
106107// For convenience, a provider implementation may choose to convert a slice of
107- // results into an iterator using [slices.Values].
108- //
109- // [slices.Values]: https://pkg.go.dev/slices#Values
108+ // results into an iterator using [list.FromValues].
110109type ListResultsStream struct {
111110 // Results is a function that emits ListResult values via its push
112111 // function argument.
@@ -120,6 +119,12 @@ type ListResults func(push func(ListResult) bool)
120119
121120var NoListResults = func (func (ListResult ) bool ) {}
122121
122+ // FromValues converts a slice of ListResult values into a ListResults
123+ // iterator for streaming.
124+ func FromValues (values []ListResult ) ListResults {
125+ return ListResults (slices .Values (values ))
126+ }
127+
123128// ListResult represents a listed managed resource instance.
124129type ListResult struct {
125130 // Identity is the identity of the managed resource instance.
You can’t perform that action at this time.
0 commit comments