mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-23 08:48:32 +02:00
refactor(api): restructured API for type safety, maintainability and docs generation
- These changes makes the API incombatible with previous versions - Added new types for error handling, success responses, and health checks. - Updated health check logic to utilize the new types for better clarity and structure. - Refactored existing handlers to improve response consistency and error handling. - Updated Makefile to include a new target for generating API types from Swagger. - Updated "new agent" API to respond an encrypted cert pair
This commit is contained in:
@@ -3,40 +3,40 @@ package loadbalancer
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/yusing/go-proxy/internal/net/gphttp/loadbalancer/types"
|
||||
"github.com/yusing/go-proxy/internal/types"
|
||||
. "github.com/yusing/go-proxy/internal/utils/testing"
|
||||
)
|
||||
|
||||
func TestRebalance(t *testing.T) {
|
||||
t.Parallel()
|
||||
t.Run("zero", func(t *testing.T) {
|
||||
lb := New(new(types.Config))
|
||||
lb := New(new(types.LoadBalancerConfig))
|
||||
for range 10 {
|
||||
lb.AddServer(types.TestNewServer(0))
|
||||
lb.AddServer(TestNewServer(0))
|
||||
}
|
||||
lb.rebalance()
|
||||
ExpectEqual(t, lb.sumWeight, maxWeight)
|
||||
})
|
||||
t.Run("less", func(t *testing.T) {
|
||||
lb := New(new(types.Config))
|
||||
lb.AddServer(types.TestNewServer(float64(maxWeight) * .1))
|
||||
lb.AddServer(types.TestNewServer(float64(maxWeight) * .2))
|
||||
lb.AddServer(types.TestNewServer(float64(maxWeight) * .3))
|
||||
lb.AddServer(types.TestNewServer(float64(maxWeight) * .2))
|
||||
lb.AddServer(types.TestNewServer(float64(maxWeight) * .1))
|
||||
lb := New(new(types.LoadBalancerConfig))
|
||||
lb.AddServer(TestNewServer(float64(maxWeight) * .1))
|
||||
lb.AddServer(TestNewServer(float64(maxWeight) * .2))
|
||||
lb.AddServer(TestNewServer(float64(maxWeight) * .3))
|
||||
lb.AddServer(TestNewServer(float64(maxWeight) * .2))
|
||||
lb.AddServer(TestNewServer(float64(maxWeight) * .1))
|
||||
lb.rebalance()
|
||||
// t.Logf("%s", U.Must(json.MarshalIndent(lb.pool, "", " ")))
|
||||
ExpectEqual(t, lb.sumWeight, maxWeight)
|
||||
})
|
||||
t.Run("more", func(t *testing.T) {
|
||||
lb := New(new(types.Config))
|
||||
lb.AddServer(types.TestNewServer(float64(maxWeight) * .1))
|
||||
lb.AddServer(types.TestNewServer(float64(maxWeight) * .2))
|
||||
lb.AddServer(types.TestNewServer(float64(maxWeight) * .3))
|
||||
lb.AddServer(types.TestNewServer(float64(maxWeight) * .4))
|
||||
lb.AddServer(types.TestNewServer(float64(maxWeight) * .3))
|
||||
lb.AddServer(types.TestNewServer(float64(maxWeight) * .2))
|
||||
lb.AddServer(types.TestNewServer(float64(maxWeight) * .1))
|
||||
lb := New(new(types.LoadBalancerConfig))
|
||||
lb.AddServer(TestNewServer(float64(maxWeight) * .1))
|
||||
lb.AddServer(TestNewServer(float64(maxWeight) * .2))
|
||||
lb.AddServer(TestNewServer(float64(maxWeight) * .3))
|
||||
lb.AddServer(TestNewServer(float64(maxWeight) * .4))
|
||||
lb.AddServer(TestNewServer(float64(maxWeight) * .3))
|
||||
lb.AddServer(TestNewServer(float64(maxWeight) * .2))
|
||||
lb.AddServer(TestNewServer(float64(maxWeight) * .1))
|
||||
lb.rebalance()
|
||||
// t.Logf("%s", U.Must(json.MarshalIndent(lb.pool, "", " ")))
|
||||
ExpectEqual(t, lb.sumWeight, maxWeight)
|
||||
|
||||
Reference in New Issue
Block a user