@@ -5,6 +5,7 @@ package proto5server
55
66import (
77 "context"
8+ "github.com/hashicorp/terraform-plugin-framework/list"
89 "sort"
910 "testing"
1011
@@ -63,6 +64,7 @@ func TestServerGetMetadata(t *testing.T) {
6364 },
6465 },
6566 EphemeralResources : []tfprotov5.EphemeralResourceMetadata {},
67+ ListResources : []tfprotov5.ListResourceMetadata {},
6668 Functions : []tfprotov5.FunctionMetadata {},
6769 Resources : []tfprotov5.ResourceMetadata {},
6870 ServerCapabilities : & tfprotov5.ServerCapabilities {
@@ -110,8 +112,9 @@ func TestServerGetMetadata(t *testing.T) {
110112 "This is always an issue with the provider and should be reported to the provider developers." ,
111113 },
112114 },
113- Functions : []tfprotov5.FunctionMetadata {},
114- Resources : []tfprotov5.ResourceMetadata {},
115+ ListResources : []tfprotov5.ListResourceMetadata {},
116+ Functions : []tfprotov5.FunctionMetadata {},
117+ Resources : []tfprotov5.ResourceMetadata {},
115118 ServerCapabilities : & tfprotov5.ServerCapabilities {
116119 GetProviderSchemaOptional : true ,
117120 MoveResourceState : true ,
@@ -149,8 +152,9 @@ func TestServerGetMetadata(t *testing.T) {
149152 "This is always an issue with the provider and should be reported to the provider developers." ,
150153 },
151154 },
152- Functions : []tfprotov5.FunctionMetadata {},
153- Resources : []tfprotov5.ResourceMetadata {},
155+ ListResources : []tfprotov5.ListResourceMetadata {},
156+ Functions : []tfprotov5.FunctionMetadata {},
157+ Resources : []tfprotov5.ResourceMetadata {},
154158 ServerCapabilities : & tfprotov5.ServerCapabilities {
155159 GetProviderSchemaOptional : true ,
156160 MoveResourceState : true ,
@@ -194,8 +198,9 @@ func TestServerGetMetadata(t *testing.T) {
194198 TypeName : "test_ephemeral_resource2" ,
195199 },
196200 },
197- Functions : []tfprotov5.FunctionMetadata {},
198- Resources : []tfprotov5.ResourceMetadata {},
201+ ListResources : []tfprotov5.ListResourceMetadata {},
202+ Functions : []tfprotov5.FunctionMetadata {},
203+ Resources : []tfprotov5.ResourceMetadata {},
199204 ServerCapabilities : & tfprotov5.ServerCapabilities {
200205 GetProviderSchemaOptional : true ,
201206 MoveResourceState : true ,
@@ -241,8 +246,9 @@ func TestServerGetMetadata(t *testing.T) {
241246 "This is always an issue with the provider and should be reported to the provider developers." ,
242247 },
243248 },
244- Functions : []tfprotov5.FunctionMetadata {},
245- Resources : []tfprotov5.ResourceMetadata {},
249+ ListResources : []tfprotov5.ListResourceMetadata {},
250+ Functions : []tfprotov5.FunctionMetadata {},
251+ Resources : []tfprotov5.ResourceMetadata {},
246252 ServerCapabilities : & tfprotov5.ServerCapabilities {
247253 GetProviderSchemaOptional : true ,
248254 MoveResourceState : true ,
@@ -280,6 +286,141 @@ func TestServerGetMetadata(t *testing.T) {
280286 "This is always an issue with the provider and should be reported to the provider developers." ,
281287 },
282288 },
289+ ListResources : []tfprotov5.ListResourceMetadata {},
290+ Functions : []tfprotov5.FunctionMetadata {},
291+ Resources : []tfprotov5.ResourceMetadata {},
292+ ServerCapabilities : & tfprotov5.ServerCapabilities {
293+ GetProviderSchemaOptional : true ,
294+ MoveResourceState : true ,
295+ PlanDestroy : true ,
296+ },
297+ },
298+ },
299+ "listresources" : {
300+ server : & Server {
301+ FrameworkServer : fwserver.Server {
302+ Provider : & testprovider.Provider {
303+ ListResourcesMethod : func (_ context.Context ) []func () list.ListResource {
304+ return []func () list.ListResource {
305+ func () list.ListResource {
306+ return & testprovider.ListResource {
307+ MetadataMethod : func (_ context.Context , _ resource.MetadataRequest , resp * resource.MetadataResponse ) {
308+ resp .TypeName = "test_list_resource1"
309+ },
310+ }
311+ },
312+ func () list.ListResource {
313+ return & testprovider.ListResource {
314+ MetadataMethod : func (_ context.Context , _ resource.MetadataRequest , resp * resource.MetadataResponse ) {
315+ resp .TypeName = "test_list_resource2"
316+ },
317+ }
318+ },
319+ }
320+ },
321+ },
322+ },
323+ },
324+ request : & tfprotov5.GetMetadataRequest {},
325+ expectedResponse : & tfprotov5.GetMetadataResponse {
326+ DataSources : []tfprotov5.DataSourceMetadata {},
327+ EphemeralResources : []tfprotov5.EphemeralResourceMetadata {},
328+ ListResources : []tfprotov5.ListResourceMetadata {
329+ {
330+ TypeName : "test_list_resource1" ,
331+ },
332+ {
333+ TypeName : "test_list_resource2" ,
334+ },
335+ },
336+ Functions : []tfprotov5.FunctionMetadata {},
337+ Resources : []tfprotov5.ResourceMetadata {},
338+ ServerCapabilities : & tfprotov5.ServerCapabilities {
339+ GetProviderSchemaOptional : true ,
340+ MoveResourceState : true ,
341+ PlanDestroy : true ,
342+ },
343+ },
344+ },
345+ "listresources-duplicate-type-name" : {
346+ server : & Server {
347+ FrameworkServer : fwserver.Server {
348+ Provider : & testprovider.Provider {
349+ ListResourcesMethod : func (_ context.Context ) []func () list.ListResource {
350+ return []func () list.ListResource {
351+ func () list.ListResource {
352+ return & testprovider.ListResource {
353+ MetadataMethod : func (_ context.Context , _ resource.MetadataRequest , resp * resource.MetadataResponse ) {
354+ resp .TypeName = "test_list_resource"
355+ },
356+ }
357+ },
358+ func () list.ListResource {
359+ return & testprovider.ListResource {
360+ MetadataMethod : func (_ context.Context , _ resource.MetadataRequest , resp * resource.MetadataResponse ) {
361+ resp .TypeName = "test_list_resource"
362+ },
363+ }
364+ },
365+ }
366+ },
367+ },
368+ },
369+ },
370+ request : & tfprotov5.GetMetadataRequest {},
371+ expectedResponse : & tfprotov5.GetMetadataResponse {
372+ DataSources : []tfprotov5.DataSourceMetadata {},
373+ EphemeralResources : []tfprotov5.EphemeralResourceMetadata {},
374+ ListResources : []tfprotov5.ListResourceMetadata {},
375+ Diagnostics : []* tfprotov5.Diagnostic {
376+ {
377+ Severity : tfprotov5 .DiagnosticSeverityError ,
378+ Summary : "Duplicate List Resource Type Defined" ,
379+ Detail : "The test_list_resource list resource type name was returned for multiple list resources. " +
380+ "List resource type names must be unique. " +
381+ "This is always an issue with the provider and should be reported to the provider developers." ,
382+ },
383+ },
384+ Functions : []tfprotov5.FunctionMetadata {},
385+ Resources : []tfprotov5.ResourceMetadata {},
386+ ServerCapabilities : & tfprotov5.ServerCapabilities {
387+ GetProviderSchemaOptional : true ,
388+ MoveResourceState : true ,
389+ PlanDestroy : true ,
390+ },
391+ },
392+ },
393+ "listresources-empty-type-name" : {
394+ server : & Server {
395+ FrameworkServer : fwserver.Server {
396+ Provider : & testprovider.Provider {
397+ ListResourcesMethod : func (_ context.Context ) []func () list.ListResource {
398+ return []func () list.ListResource {
399+ func () list.ListResource {
400+ return & testprovider.ListResource {
401+ MetadataMethod : func (_ context.Context , _ resource.MetadataRequest , resp * resource.MetadataResponse ) {
402+ resp .TypeName = ""
403+ },
404+ }
405+ },
406+ }
407+ },
408+ },
409+ },
410+ },
411+ request : & tfprotov5.GetMetadataRequest {},
412+ expectedResponse : & tfprotov5.GetMetadataResponse {
413+ DataSources : []tfprotov5.DataSourceMetadata {},
414+ EphemeralResources : []tfprotov5.EphemeralResourceMetadata {},
415+ ListResources : []tfprotov5.ListResourceMetadata {},
416+ Diagnostics : []* tfprotov5.Diagnostic {
417+ {
418+ Severity : tfprotov5 .DiagnosticSeverityError ,
419+ Summary : "List Resource Type Name Missing" ,
420+ Detail : "The *testprovider.ListResource ListResource returned an empty string from the Metadata method. " +
421+ "This is always an issue with the provider and should be reported to the provider developers." ,
422+ },
423+ },
283424 Functions : []tfprotov5.FunctionMetadata {},
284425 Resources : []tfprotov5.ResourceMetadata {},
285426 ServerCapabilities : & tfprotov5.ServerCapabilities {
@@ -318,6 +459,7 @@ func TestServerGetMetadata(t *testing.T) {
318459 expectedResponse : & tfprotov5.GetMetadataResponse {
319460 DataSources : []tfprotov5.DataSourceMetadata {},
320461 EphemeralResources : []tfprotov5.EphemeralResourceMetadata {},
462+ ListResources : []tfprotov5.ListResourceMetadata {},
321463 Functions : []tfprotov5.FunctionMetadata {
322464 {
323465 Name : "function1" ,
@@ -372,8 +514,9 @@ func TestServerGetMetadata(t *testing.T) {
372514 "This is always an issue with the provider and should be reported to the provider developers." ,
373515 },
374516 },
375- Functions : []tfprotov5.FunctionMetadata {},
376- Resources : []tfprotov5.ResourceMetadata {},
517+ ListResources : []tfprotov5.ListResourceMetadata {},
518+ Functions : []tfprotov5.FunctionMetadata {},
519+ Resources : []tfprotov5.ResourceMetadata {},
377520 ServerCapabilities : & tfprotov5.ServerCapabilities {
378521 GetProviderSchemaOptional : true ,
379522 MoveResourceState : true ,
@@ -411,8 +554,9 @@ func TestServerGetMetadata(t *testing.T) {
411554 "This is always an issue with the provider and should be reported to the provider developers." ,
412555 },
413556 },
414- Functions : []tfprotov5.FunctionMetadata {},
415- Resources : []tfprotov5.ResourceMetadata {},
557+ ListResources : []tfprotov5.ListResourceMetadata {},
558+ Functions : []tfprotov5.FunctionMetadata {},
559+ Resources : []tfprotov5.ResourceMetadata {},
416560 ServerCapabilities : & tfprotov5.ServerCapabilities {
417561 GetProviderSchemaOptional : true ,
418562 MoveResourceState : true ,
@@ -449,6 +593,7 @@ func TestServerGetMetadata(t *testing.T) {
449593 expectedResponse : & tfprotov5.GetMetadataResponse {
450594 DataSources : []tfprotov5.DataSourceMetadata {},
451595 EphemeralResources : []tfprotov5.EphemeralResourceMetadata {},
596+ ListResources : []tfprotov5.ListResourceMetadata {},
452597 Functions : []tfprotov5.FunctionMetadata {},
453598 Resources : []tfprotov5.ResourceMetadata {
454599 {
@@ -503,8 +648,9 @@ func TestServerGetMetadata(t *testing.T) {
503648 "This is always an issue with the provider and should be reported to the provider developers." ,
504649 },
505650 },
506- Functions : []tfprotov5.FunctionMetadata {},
507- Resources : []tfprotov5.ResourceMetadata {},
651+ ListResources : []tfprotov5.ListResourceMetadata {},
652+ Functions : []tfprotov5.FunctionMetadata {},
653+ Resources : []tfprotov5.ResourceMetadata {},
508654 ServerCapabilities : & tfprotov5.ServerCapabilities {
509655 GetProviderSchemaOptional : true ,
510656 MoveResourceState : true ,
@@ -534,6 +680,7 @@ func TestServerGetMetadata(t *testing.T) {
534680 expectedResponse : & tfprotov5.GetMetadataResponse {
535681 DataSources : []tfprotov5.DataSourceMetadata {},
536682 EphemeralResources : []tfprotov5.EphemeralResourceMetadata {},
683+ ListResources : []tfprotov5.ListResourceMetadata {},
537684 Diagnostics : []* tfprotov5.Diagnostic {
538685 {
539686 Severity : tfprotov5 .DiagnosticSeverityError ,
@@ -572,6 +719,10 @@ func TestServerGetMetadata(t *testing.T) {
572719 return got .EphemeralResources [i ].TypeName < got .EphemeralResources [j ].TypeName
573720 })
574721
722+ sort .Slice (got .ListResources , func (i , j int ) bool {
723+ return got .ListResources [i ].TypeName < got .ListResources [j ].TypeName
724+ })
725+
575726 sort .Slice (got .Functions , func (i int , j int ) bool {
576727 return got .Functions [i ].Name < got .Functions [j ].Name
577728 })
0 commit comments