Skip to content

Commit 747ca15

Browse files
committed
ListResource Type Defined without a Matching Managed Resource Type
1 parent 707e888 commit 747ca15

File tree

1 file changed

+57
-8
lines changed

1 file changed

+57
-8
lines changed

internal/proto5server/server_listresource_test.go

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -282,19 +282,68 @@ func TestServerListResource(t *testing.T) {
282282
}
283283
}
284284

285+
type SDKContext string
286+
287+
var SDKResource SDKContext = "sdk_resource"
288+
289+
// a resource type defined in SDKv2
290+
var sdkResource sdk.Resource = sdk.Resource{
291+
Schema: map[string]*sdk.Schema{
292+
"id": &sdk.Schema{
293+
Type: sdk.TypeString,
294+
},
295+
"name": &sdk.Schema{
296+
Type: sdk.TypeString,
297+
},
298+
},
299+
}
300+
301+
func listFunc(ctx context.Context, req list.ListRequest, stream *list.ListResultsStream) {
302+
panic("hats")
303+
}
304+
285305
func TestServerListResourceProto5ToProto5(t *testing.T) {
286306
t.Parallel()
287307

288-
// 1: we have a resource type defined in SDKv2
289-
sdkResource := sdk.Resource{
290-
Schema: map[string]*sdk.Schema{
291-
"id": &sdk.Schema{
292-
Type: sdk.TypeString,
308+
server := func(listResource func() list.ListResource) *Server {
309+
return &Server{
310+
FrameworkServer: fwserver.Server{
311+
Provider: &testprovider.Provider{
312+
ListResourcesMethod: func(ctx context.Context) []func() list.ListResource {
313+
return []func() list.ListResource{listResource}
314+
},
315+
},
293316
},
294-
"name": &sdk.Schema{
295-
Type: sdk.TypeString,
317+
}
318+
}
319+
320+
listResource := func() list.ListResource {
321+
return &testprovider.ListResource{
322+
ListMethod: listFunc,
323+
MetadataMethod: func(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
324+
resp.TypeName = "test_resource"
296325
},
297-
},
326+
}
327+
}
328+
aServer := server(listResource)
329+
330+
ctx := context.Background()
331+
ctx = context.WithValue(ctx, SDKResource, sdkResource)
332+
req := &tfprotov5.ListResourceRequest{}
333+
334+
stream, err := aServer.ListResource(ctx, req)
335+
if err != nil {
336+
t.Fatalf("unexpected error returned from ListResource: %v", err)
337+
}
338+
339+
values := slices.Collect(stream.Results)
340+
if len(values) > 0 {
341+
if len(values[0].Diagnostics) > 0 {
342+
for _, diag := range values[0].Diagnostics {
343+
t.Logf("unexpected diagnostic returned from ListResource: %v", diag)
344+
}
345+
t.FailNow()
346+
}
298347
}
299348

300349
// 2: from the resource type, we can obtain an initialized ResourceData value

0 commit comments

Comments
 (0)