Skip to content

Commit a78febb

Browse files
committed
Updated to add test as suggested in PR
1 parent c9060a6 commit a78febb

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

internal/fwserver/server_listresource.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,16 @@ var NoListResults = func(func(ListResult) bool) {}
8787
func (s *Server) ListResource(ctx context.Context, fwReq *ListRequest, fwStream *ListResultsStream) {
8888
listResource := fwReq.ListResource
8989

90-
if fwReq.Config == nil {
90+
if fwReq.Config == nil && fwReq.ResourceSchema != nil {
9191
fwReq.Config = &tfsdk.Config{
9292
Raw: tftypes.NewValue(fwReq.ResourceSchema.Type().TerraformType(ctx), nil),
9393
Schema: fwReq.ResourceSchema,
9494
}
95+
} else if fwReq.Config == nil && fwReq.ResourceIdentitySchema == nil {
96+
fwReq.Config = &tfsdk.Config{
97+
Raw: tftypes.NewValue(tftypes.Object{}, nil),
98+
Schema: fwReq.ResourceSchema,
99+
}
95100
}
96101

97102
req := list.ListRequest{

internal/fwserver/server_listresource_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,21 @@ func TestServerListResource(t *testing.T) {
167167
},
168168
},
169169
},
170+
"zero-results-on-nil-config": {
171+
server: &fwserver.Server{
172+
Provider: &testprovider.Provider{},
173+
},
174+
request: &fwserver.ListRequest{
175+
Config: nil, // Simulating a nil config
176+
ListResource: &testprovider.ListResource{
177+
ListMethod: func(ctx context.Context, req list.ListRequest, resp *list.ListResultsStream) {
178+
resp.Results = list.NoListResults // Expecting no results when config is nil
179+
},
180+
},
181+
},
182+
expectedStreamEvents: []fwserver.ListResult{},
183+
expectedError: "config cannot be nil",
184+
},
170185
}
171186

172187
for name, testCase := range testCases {

0 commit comments

Comments
 (0)