Testing when we have 1 target with weight 0 and another with weight 100
@@ -68,6 +68,19 @@ func (suite *BalancerTestSuite) TestWeightBalancerZeroWeight() {
suite.Error(err)
}
+func (suite *BalancerTestSuite) TestWeightBalancerZeroWeightForOneTarget() {
+ balancer := NewWeightBalancer()
+
+ hosts := []*Target{
+ {Target: "127.0.0.1", Weight: 0},
+ {Target: "http://test.com", Weight: 100},
+ }
+
+ electedHost, err := balancer.Elect(hosts)
+ suite.NoError(err)
+ suite.Equal(hosts[1], electedHost)
+}
+
// In order for 'go test' to run this suite, we need to create
// a normal test function and pass our suite to suite.Run
func TestBalancerTestSuite(t *testing.T) {
