api: Ensure the internal/ui/gateway-service-nodes endpoint responds with an array (#9593)
In some circumstances this endpoint will have no results in it (dues to ACLs, Namespaces, filtering or missing configuration). This ensures that the response is at least an empty array (`[]`) rather than `null`
This commit is contained in:
parent
d871a6f260
commit
82a5e6d6fc
|
@ -261,7 +261,12 @@ RPC:
|
||||||
}
|
}
|
||||||
|
|
||||||
summaries, _ := summarizeServices(out.Dump, s.agent.config, args.Datacenter)
|
summaries, _ := summarizeServices(out.Dump, s.agent.config, args.Datacenter)
|
||||||
return prepSummaryOutput(summaries, false), nil
|
|
||||||
|
prepped := prepSummaryOutput(summaries, false)
|
||||||
|
if prepped == nil {
|
||||||
|
prepped = make([]*ServiceSummary, 0)
|
||||||
|
}
|
||||||
|
return prepped, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// UIServiceTopology returns the list of upstreams and downstreams for a Connect enabled service.
|
// UIServiceTopology returns the list of upstreams and downstreams for a Connect enabled service.
|
||||||
|
@ -449,6 +454,8 @@ func summarizeServices(dump structs.ServiceDump, cfg *config.RuntimeConfig, dc s
|
||||||
|
|
||||||
func prepSummaryOutput(summaries map[structs.ServiceName]*ServiceSummary, excludeSidecars bool) []*ServiceSummary {
|
func prepSummaryOutput(summaries map[structs.ServiceName]*ServiceSummary, excludeSidecars bool) []*ServiceSummary {
|
||||||
var resp []*ServiceSummary
|
var resp []*ServiceSummary
|
||||||
|
// Ensure at least a zero length slice
|
||||||
|
resp = make([]*ServiceSummary, 0)
|
||||||
|
|
||||||
// Collect and sort resp for display
|
// Collect and sort resp for display
|
||||||
for _, sum := range summaries {
|
for _, sum := range summaries {
|
||||||
|
|
|
@ -629,7 +629,18 @@ func TestUIGatewayServiceNodes_Terminating(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
require.NoError(t, a.RPC("Catalog.Register", &arg, ®Output))
|
require.NoError(t, a.RPC("Catalog.Register", &arg, ®Output))
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
// Request without having registered the config-entry, shouldn't respond with null
|
||||||
|
req, _ := http.NewRequest("GET", "/v1/internal/ui/gateway-services-nodes/terminating-gateway", nil)
|
||||||
|
resp := httptest.NewRecorder()
|
||||||
|
obj, err := a.srv.UIGatewayServicesNodes(resp, req)
|
||||||
|
require.Nil(t, err)
|
||||||
|
require.NotNil(t, obj)
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
// Register terminating-gateway config entry, linking it to db and redis (does not exist)
|
// Register terminating-gateway config entry, linking it to db and redis (does not exist)
|
||||||
args := &structs.TerminatingGatewayConfigEntry{
|
args := &structs.TerminatingGatewayConfigEntry{
|
||||||
Name: "terminating-gateway",
|
Name: "terminating-gateway",
|
||||||
|
|
Loading…
Reference in a new issue