2024-10-08 09:40:49 +00:00
|
|
|
package multinet
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2024-10-09 12:39:16 +00:00
|
|
|
"net/netip"
|
2024-10-08 09:40:49 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2024-10-09 12:39:16 +00:00
|
|
|
func TestNoSourceIPs(t *testing.T) {
|
2024-10-08 09:40:49 +00:00
|
|
|
t.Run("noop balancer", func(t *testing.T) {
|
|
|
|
d, err := NewDialer(Config{
|
2024-10-09 12:39:16 +00:00
|
|
|
Subnets: []Subnet{
|
|
|
|
{
|
|
|
|
Prefix: netip.MustParsePrefix("10.11.12.0/24"),
|
|
|
|
},
|
|
|
|
},
|
2024-10-08 09:40:49 +00:00
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
conn, err := d.DialContext(context.Background(), "tcp", "10.11.12.254:8080")
|
|
|
|
require.ErrorIs(t, err, errNoSuitableNodeFound)
|
|
|
|
require.Nil(t, conn)
|
|
|
|
})
|
|
|
|
t.Run("round robin balancer", func(t *testing.T) {
|
|
|
|
d, err := NewDialer(Config{
|
2024-10-09 12:39:16 +00:00
|
|
|
Subnets: []Subnet{
|
|
|
|
{
|
|
|
|
Prefix: netip.MustParsePrefix("10.11.12.0/24"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Balancer: BalancerTypeRoundRobin,
|
2024-10-08 09:40:49 +00:00
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
conn, err := d.DialContext(context.Background(), "tcp", "10.11.12.254:8080")
|
|
|
|
require.ErrorIs(t, err, errNoSuitableNodeFound)
|
|
|
|
require.Nil(t, conn)
|
|
|
|
})
|
|
|
|
}
|