From bffdd7d4993bac71dad681f7a38a8fabcb5ebac1 Mon Sep 17 00:00:00 2001 From: sinadarbouy Date: Sun, 28 Jul 2024 21:55:41 +0200 Subject: [PATCH] Enhance GetServers API to include load balancer config and update tests - Modified the GetServers endpoint to return the current load balancer configuration for each server. - Added a new field "loadBalancer" to the server details, including the load balancer strategy name. - Updated unit tests to validate the new "loadBalancer" field in the API response. - Adjusted test setup to include the default load balancer strategy configuration. --- api/api.go | 5 +++-- api/api_test.go | 14 +++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/api/api.go b/api/api.go index 256f0957..b457f047 100644 --- a/api/api.go +++ b/api/api.go @@ -281,13 +281,14 @@ func (a *API) GetServers(context.Context, *emptypb.Empty) (*structpb.Struct, err _, span := otel.Tracer(config.TracerName).Start(a.ctx, "Get Servers") defer span.End() - servers := make(map[string]interface{}) + servers := make(map[string]any) for name, server := range a.Servers { - servers[name] = map[string]interface{}{ + servers[name] = map[string]any{ "network": server.Network, "address": server.Address, "status": uint(server.Status), "tickInterval": server.TickInterval.Nanoseconds(), + "loadBalancer": map[string]any{"strategy": server.LoadbalancerStrategyName}, } } diff --git a/api/api_test.go b/api/api_test.go index a6717ab8..9f8253dd 100644 --- a/api/api_test.go +++ b/api/api_test.go @@ -342,11 +342,12 @@ func TestGetServers(t *testing.T) { Options: network.Option{ EnableTicker: false, }, - Proxies: []network.IProxy{proxy}, - Logger: zerolog.Logger{}, - PluginRegistry: pluginRegistry, - PluginTimeout: config.DefaultPluginTimeout, - HandshakeTimeout: config.DefaultHandshakeTimeout, + Proxies: []network.IProxy{proxy}, + Logger: zerolog.Logger{}, + PluginRegistry: pluginRegistry, + PluginTimeout: config.DefaultPluginTimeout, + HandshakeTimeout: config.DefaultHandshakeTimeout, + LoadbalancerStrategyName: config.DefaultLoadBalancerStrategy, }, ) @@ -376,6 +377,9 @@ func TestGetServers(t *testing.T) { tickInterval, ok := defaultServer["tickInterval"].(float64) assert.True(t, ok) assert.Equal(t, config.DefaultTickInterval.Nanoseconds(), int64(tickInterval)) + loadBalancer, ok := defaultServer["loadBalancer"].(map[string]interface{}) + assert.True(t, ok) + assert.Equal(t, config.DefaultLoadBalancerStrategy, loadBalancer["strategy"]) } else { t.Errorf("servers.default is not found or not a map") }