@@ -42,7 +42,6 @@ func TestNewLeastAlgorithmWithoutAlgorithmType(t *testing.T) {
42
42
}
43
43
44
44
func TestNext (t * testing.T ) {
45
-
46
45
t .Run ("least-connection" , func (t * testing.T ) {
47
46
t .Run ("with zero pending requests" , func (t * testing.T ) {
48
47
caseFour := mocks .TestCases [4 ]
@@ -73,8 +72,36 @@ func TestNext(t *testing.T) {
73
72
})
74
73
})
75
74
76
- // TODO least-response-time test
75
+ t .Run ("least-response-time" , func (t * testing.T ) {
76
+ t .Run ("with zero avg response time" , func (t * testing.T ) {
77
+ caseFive := mocks .TestCases [4 ]
78
+ caseFive .Config .Type = "least-response-time"
79
+ balancer := NewLeastAlgorithm (& caseFive .Config , caseFive .ProxyFunc )
80
+ assert .NotNil (t , balancer )
81
+
82
+ leastResponseTime := balancer .(* LeastAlgorithm )
83
+ proxy := leastResponseTime .nextFunc ()
77
84
85
+ assert .IsType (t , & mocks.MockProxy {}, proxy )
86
+ mProxy := proxy .(* mocks.MockProxy )
87
+ assert .Equal (t , caseFive .Config .Backends [1 ].Url , mProxy .Addr )
88
+ })
89
+
90
+ t .Run ("with non zero avg response time" , func (t * testing.T ) {
91
+ caseOne := mocks .TestCases [0 ]
92
+ caseOne .Config .Type = "least-response-time"
93
+ balancer := NewLeastAlgorithm (& caseOne .Config , caseOne .ProxyFunc )
94
+ assert .NotNil (t , balancer )
95
+
96
+ leastResponseTime := balancer .(* LeastAlgorithm )
97
+ proxy := leastResponseTime .nextFunc ()
98
+
99
+ assert .IsType (t , & mocks.MockProxy {}, proxy )
100
+ mProxy := proxy .(* mocks.MockProxy )
101
+ assert .Equal (t , caseOne .Config .Backends [0 ].Url , mProxy .Addr )
102
+
103
+ })
104
+ })
78
105
}
79
106
80
107
func TestServe (t * testing.T ) {
0 commit comments