Skip to content

Commit

Permalink
Enhance GetServers API to include load balancer config and update tests
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
sinadarbouy committed Jul 28, 2024
1 parent d309592 commit bffdd7d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
5 changes: 3 additions & 2 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
}
}

Expand Down
14 changes: 9 additions & 5 deletions api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
)

Expand Down Expand Up @@ -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")
}
Expand Down

0 comments on commit bffdd7d

Please sign in to comment.