Skip to content

Commit ba54c52

Browse files
committed
Add error & warning cases to fwserver listresource test
1 parent ef63901 commit ba54c52

File tree

2 files changed

+68
-3
lines changed

2 files changed

+68
-3
lines changed

internal/fwserver/server_listresource_test.go

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ func TestServerListResource(t *testing.T) {
102102
},
103103
expectedStreamEvents: []fwserver.ListResult{},
104104
},
105-
106105
"success-with-multiple-results": {
107106
server: &fwserver.Server{
108107
Provider: &testprovider.Provider{},
@@ -166,6 +165,74 @@ func TestServerListResource(t *testing.T) {
166165
},
167166
},
168167
},
168+
"error-on-missing-resource-identity": {
169+
server: &fwserver.Server{
170+
Provider: &testprovider.Provider{},
171+
},
172+
request: &fwserver.ListRequest{
173+
ListResource: &testprovider.ListResource{
174+
ListMethod: func(ctx context.Context, req list.ListRequest, resp *list.ListResultsStream) { // TODO
175+
resp.Results = slices.Values([]list.ListResult{
176+
{
177+
Identity: nil,
178+
Resource: &tfsdk.Resource{
179+
Schema: testSchema,
180+
Raw: testResourceValue1,
181+
},
182+
DisplayName: "Test Resource 1",
183+
},
184+
})
185+
},
186+
},
187+
},
188+
expectedStreamEvents: []fwserver.ListResult{
189+
{
190+
Diagnostics: diag.Diagnostics{
191+
diag.NewErrorDiagnostic(
192+
"Incomplete List Result",
193+
"The provider did not populate the Identity field in the ListResourceResult. This may be due to an error in the provider's implementation.",
194+
),
195+
},
196+
},
197+
},
198+
},
199+
"warning-on-missing-resource": {
200+
server: &fwserver.Server{
201+
Provider: &testprovider.Provider{},
202+
},
203+
request: &fwserver.ListRequest{
204+
IncludeResource: true,
205+
ListResource: &testprovider.ListResource{
206+
ListMethod: func(ctx context.Context, req list.ListRequest, resp *list.ListResultsStream) {
207+
resp.Results = slices.Values([]list.ListResult{
208+
{
209+
Identity: &tfsdk.ResourceIdentity{
210+
Schema: testIdentitySchema,
211+
Raw: testIdentityValue1,
212+
},
213+
Resource: nil,
214+
DisplayName: "Test Resource 1",
215+
},
216+
})
217+
},
218+
},
219+
},
220+
expectedStreamEvents: []fwserver.ListResult{
221+
{
222+
Identity: &tfsdk.ResourceIdentity{
223+
Schema: testIdentitySchema,
224+
Raw: testIdentityValue1,
225+
},
226+
DisplayName: "Test Resource 1",
227+
Diagnostics: diag.Diagnostics{
228+
diag.NewWarningDiagnostic(
229+
"Incomplete List Result",
230+
"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.",
231+
),
232+
},
233+
},
234+
},
235+
},
169236
}
170237

171238
for name, testCase := range testCases {

internal/proto6server/server_listresource.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,11 @@ func (s *Server) ListResource(ctx context.Context, proto6Req *tfprotov6.ListReso
1313
// proto6Stream := &tfprotov6.ListResourceServerStream{Results: tfprotov6.NoListResults}
1414
proto6Stream := &tfprotov6.ListResourceServerStream{Results: func(func(tfprotov6.ListResourceResult) bool) {}}
1515

16-
// TODO: extract fromproto6.ListRequest
1716
listResource, err := s.FrameworkServer.ListResourceOrError(ctx, proto6Req.TypeName)
1817
if err != nil {
1918
return proto6Stream, err
2019
}
2120

22-
// TODO: extract fromproto6.ListResourceConfig
2321
listResourceSchema, diags := s.FrameworkServer.ListResourceSchema(ctx, proto6Req.TypeName)
2422
if diags.HasError() {
2523
return proto6Stream, &ListResourceSchemaNotFoundError{TypeName: proto6Req.TypeName}

0 commit comments

Comments
 (0)