From d6d73d10bd82dc3acfefea2e0a8071f4c41a66b9 Mon Sep 17 00:00:00 2001 From: Jakub Dyszkiewicz Date: Mon, 18 Sep 2023 13:08:29 +0200 Subject: [PATCH] fix(api-server): empty list instead of null Signed-off-by: Jakub Dyszkiewicz --- pkg/api-server/inspect_endpoints.go | 4 +++- pkg/api-server/inspect_endpoints_test.go | 9 +++++++++ .../testdata/inspect_dataplane_rules_empty.golden.json | 4 ++++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 pkg/api-server/testdata/inspect_dataplane_rules_empty.golden.json diff --git a/pkg/api-server/inspect_endpoints.go b/pkg/api-server/inspect_endpoints.go index b321e93cd197..c3220804cc80 100644 --- a/pkg/api-server/inspect_endpoints.go +++ b/pkg/api-server/inspect_endpoints.go @@ -575,7 +575,9 @@ func inspectRulesAttachment(cfg *kuma_cp.Config, builder xds_context.MeshContext return } rulesAttachments := inspect.BuildRulesAttachments(matchedPolicies.Dynamic, proxy.Dataplane.Spec.Networking, meshContext.VIPDomains) - resp := api_server_types.RuleInspectResponse{} + resp := api_server_types.RuleInspectResponse{ + Items: []api_server_types.RuleInspectEntry{}, + } for _, ruleAttachment := range rulesAttachments { subset := map[string]string{} for _, tag := range ruleAttachment.Rule.Subset { diff --git a/pkg/api-server/inspect_endpoints_test.go b/pkg/api-server/inspect_endpoints_test.go index 90a4c4afeb2b..4ac4f56090e4 100644 --- a/pkg/api-server/inspect_endpoints_test.go +++ b/pkg/api-server/inspect_endpoints_test.go @@ -898,6 +898,15 @@ var _ = Describe("Inspect WS", func() { }, contentType: "text/plain", }), + Entry("inspect rules empty", testCase{ + path: "/meshes/default/dataplanes/web-01/rules", + matcher: matchers.MatchGoldenJSON(path.Join("testdata", "inspect_dataplane_rules_empty.golden.json")), + resources: []core_model.Resource{ + samples2.MeshDefault(), + samples2.DataplaneWeb(), + }, + contentType: restful.MIME_JSON, + }), Entry("inspect rules basic", testCase{ path: "/meshes/default/dataplanes/web-01/rules", matcher: matchers.MatchGoldenJSON(path.Join("testdata", "inspect_dataplane_rules.golden.json")), diff --git a/pkg/api-server/testdata/inspect_dataplane_rules_empty.golden.json b/pkg/api-server/testdata/inspect_dataplane_rules_empty.golden.json new file mode 100644 index 000000000000..fda84bc68e5d --- /dev/null +++ b/pkg/api-server/testdata/inspect_dataplane_rules_empty.golden.json @@ -0,0 +1,4 @@ +{ + "total": 0, + "items": [] +}