Fix unit test
If running test behide a proxy, we may get the error code 403 Forbidden which will fail line 135 for the last testcase. Detail: ``` metrics not as expected: notifications.EndpointMetrics{Pending:0, Events:0, Successes:4, Failures:0, Errors:0, Statuses:map[string]int{"307 Temporary Redirect":0, "400 Bad Request":0, "403 Forbidden":0, "200 OK":4}} != notifications.EndpointMetrics{Pending:0, Events:0, Successes:4, Failures:0, Errors:0, Statuses:map[string]int{"400 Bad Request":0, "200 OK":4, "307 Temporary Redirect":0}} ``` Immediate close will fix that Signed-off-by: Hu Keping <hukeping@huawei.com> Signed-off-by: Derek McGowan <derek@mcgstyle.net>
This commit is contained in:
parent
129ad8ea0c
commit
efc32091e7
1 changed files with 18 additions and 2 deletions
|
@ -5,6 +5,7 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"mime"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"reflect"
|
||||
|
@ -94,6 +95,21 @@ func TestHTTPSink(t *testing.T) {
|
|||
var expectedMetrics EndpointMetrics
|
||||
expectedMetrics.Statuses = make(map[string]int)
|
||||
|
||||
closeL, err := net.Listen("tcp", "localhost:0")
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error creating listener: %v", err)
|
||||
}
|
||||
defer closeL.Close()
|
||||
go func() {
|
||||
for {
|
||||
c, err := closeL.Accept()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
c.Close()
|
||||
}
|
||||
}()
|
||||
|
||||
for _, tc := range []struct {
|
||||
events []Event // events to send
|
||||
url string
|
||||
|
@ -121,8 +137,8 @@ func TestHTTPSink(t *testing.T) {
|
|||
failure: true,
|
||||
},
|
||||
{
|
||||
// Case where connection never goes through.
|
||||
url: "http://shoudlntresolve/",
|
||||
// Case where connection is immediately closed
|
||||
url: closeL.Addr().String(),
|
||||
failure: true,
|
||||
},
|
||||
} {
|
||||
|
|
Loading…
Reference in a new issue