Skip to content

Commit 7ad4ae1

Browse files
committed
tidy
1 parent ba54c52 commit 7ad4ae1

File tree

5 files changed

+17
-12
lines changed

5 files changed

+17
-12
lines changed

internal/fwserver/server_listresource.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package fwserver
55

66
import (
77
"context"
8+
"fmt"
89
"iter"
910

1011
"github.com/hashicorp/terraform-plugin-framework/diag"
@@ -22,8 +23,7 @@ type ListRequest struct {
2223

2324
// Config is the configuration the user supplied for listing resource
2425
// instances.
25-
Config tfsdk.Config
26-
// TODO: Config *tfsdk.Config
26+
Config *tfsdk.Config
2727

2828
// IncludeResource indicates whether the provider should populate the
2929
// Resource field in the ListResult struct.
@@ -75,8 +75,12 @@ type ListResult struct {
7575
func (s *Server) ListResource(ctx context.Context, fwReq *ListRequest, fwStream *ListResultsStream) error {
7676
listResource := fwReq.ListResource
7777

78+
if fwReq.Config == nil {
79+
return fmt.Errorf("request config is nil") // TODO: nicer error
80+
}
81+
7882
req := list.ListRequest{
79-
Config: fwReq.Config,
83+
Config: *fwReq.Config,
8084
IncludeResource: fwReq.IncludeResource,
8185
ResourceSchema: fwReq.ResourceSchema,
8286
ResourceIdentitySchema: fwReq.ResourceIdentitySchema,
@@ -110,7 +114,7 @@ func processListResults(req list.ListRequest, stream iter.Seq[list.ListResult])
110114
// processListResult validates the content of a list.ListResult and returns a
111115
// ListResult
112116
func processListResult(req list.ListRequest, result list.ListResult) ListResult {
113-
if !result.Diagnostics.HasError() && result.Identity == nil { // TODO: write a test
117+
if !result.Diagnostics.HasError() && result.Identity == nil {
114118
return ListResult{
115119
Diagnostics: diag.Diagnostics{
116120
diag.NewErrorDiagnostic(
@@ -121,7 +125,7 @@ func processListResult(req list.ListRequest, result list.ListResult) ListResult
121125
}
122126
}
123127

124-
if !result.Diagnostics.HasError() && req.IncludeResource && result.Resource == nil { // TODO: write a test
128+
if !result.Diagnostics.HasError() && req.IncludeResource && result.Resource == nil {
125129
result.Diagnostics.AddWarning(
126130
"Incomplete List Result",
127131
"The provider did not populate the Resource field in the ListResourceResult. This may be due to the provider not supporting this functionality or an error in the provider's implementation.",

internal/fwserver/server_listresource_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ func TestServerListResource(t *testing.T) {
8181
Provider: &testprovider.Provider{},
8282
},
8383
request: &fwserver.ListRequest{
84+
Config: &tfsdk.Config{},
8485
ListResource: &testprovider.ListResource{
8586
ListMethod: func(ctx context.Context, req list.ListRequest, resp *list.ListResultsStream) { // TODO
8687
resp.Results = list.NoListResults
@@ -94,6 +95,7 @@ func TestServerListResource(t *testing.T) {
9495
Provider: &testprovider.Provider{},
9596
},
9697
request: &fwserver.ListRequest{
98+
Config: &tfsdk.Config{},
9799
ListResource: &testprovider.ListResource{
98100
ListMethod: func(ctx context.Context, req list.ListRequest, resp *list.ListResultsStream) { // TODO
99101
// Do nothing, so that resp.Results is nil
@@ -107,6 +109,7 @@ func TestServerListResource(t *testing.T) {
107109
Provider: &testprovider.Provider{},
108110
},
109111
request: &fwserver.ListRequest{
112+
Config: &tfsdk.Config{},
110113
ListResource: &testprovider.ListResource{
111114
ListMethod: func(ctx context.Context, req list.ListRequest, resp *list.ListResultsStream) { // TODO
112115
resp.Results = slices.Values([]list.ListResult{
@@ -170,6 +173,7 @@ func TestServerListResource(t *testing.T) {
170173
Provider: &testprovider.Provider{},
171174
},
172175
request: &fwserver.ListRequest{
176+
Config: &tfsdk.Config{},
173177
ListResource: &testprovider.ListResource{
174178
ListMethod: func(ctx context.Context, req list.ListRequest, resp *list.ListResultsStream) { // TODO
175179
resp.Results = slices.Values([]list.ListResult{
@@ -201,6 +205,7 @@ func TestServerListResource(t *testing.T) {
201205
Provider: &testprovider.Provider{},
202206
},
203207
request: &fwserver.ListRequest{
208+
Config: &tfsdk.Config{},
204209
IncludeResource: true,
205210
ListResource: &testprovider.ListResource{
206211
ListMethod: func(ctx context.Context, req list.ListRequest, resp *list.ListResultsStream) {

internal/proto5server/server_listresource.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func (s *Server) ListResource(ctx context.Context, proto5Req *tfprotov5.ListReso
4444

4545
req := &fwserver.ListRequest{
4646
ListResource: listResource,
47-
Config: *config, // TODO: mayBe // this can explode with null input btW
47+
Config: config,
4848
IncludeResource: proto5Req.IncludeResource,
4949
ResourceSchema: resourceSchema,
5050
ResourceIdentitySchema: resourceIdentitySchema,

internal/proto6server/server_listresource.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func (s *Server) ListResource(ctx context.Context, proto6Req *tfprotov6.ListReso
3939
}
4040

4141
req := &fwserver.ListRequest{
42-
Config: *config,
42+
Config: config,
4343
ListResource: listResource,
4444
ResourceSchema: resourceSchema,
4545
ResourceIdentitySchema: identitySchema,

internal/proto6server/server_listresource_test.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,7 @@ func TestServerListResource(t *testing.T) {
122122
}
123123

124124
r.ListMethod = func(ctx context.Context, req list.ListRequest, resp *list.ListResultsStream) {
125-
result := req.ToResult(
126-
ctx,
127-
resources["plateau"].ThingResourceIdentity,
128-
nil,
129-
"plateau")
125+
result := req.ToResult(ctx, resources["plateau"].ThingResourceIdentity, nil, "plateau")
130126

131127
resp.Results = slices.Values([]list.ListResult{result})
132128
}

0 commit comments

Comments
 (0)