tests: Fix failed notify webhook test (#5528)

TestNewWebHookNotify wasn't passing in my local machine. The reason is
that the test expects the POST handler (as a webhook endpoint) is always
running on port 80, which is not always the case.
master
A. Elleuch 7 years ago committed by kannappanr
parent 03923947c4
commit 1e7e41fada
  1. 8
      cmd/notify-webhook_test.go

@ -54,12 +54,15 @@ func TestNewWebHookNotify(t *testing.T) {
} }
defer os.RemoveAll(root) defer os.RemoveAll(root)
server := httptest.NewServer(postHandler{})
defer server.Close()
_, err = newWebhookNotify("1") _, err = newWebhookNotify("1")
if err == nil { if err == nil {
t.Fatal("Unexpected should fail") t.Fatal("Unexpected should fail")
} }
globalServerConfig.Notify.SetWebhookByID("10", webhookNotify{Enable: true, Endpoint: "http://127.0.0.1:80"}) globalServerConfig.Notify.SetWebhookByID("10", webhookNotify{Enable: true, Endpoint: server.URL})
_, err = newWebhookNotify("10") _, err = newWebhookNotify("10")
if err != nil { if err != nil {
t.Fatal("Unexpected should not fail with lookupEndpoint", err) t.Fatal("Unexpected should not fail with lookupEndpoint", err)
@ -71,9 +74,6 @@ func TestNewWebHookNotify(t *testing.T) {
t.Fatal("Unexpected should fail with invalid URL escape") t.Fatal("Unexpected should fail with invalid URL escape")
} }
server := httptest.NewServer(postHandler{})
defer server.Close()
globalServerConfig.Notify.SetWebhookByID("20", webhookNotify{Enable: true, Endpoint: server.URL}) globalServerConfig.Notify.SetWebhookByID("20", webhookNotify{Enable: true, Endpoint: server.URL})
webhook, err := newWebhookNotify("20") webhook, err := newWebhookNotify("20")
if err != nil { if err != nil {

Loading…
Cancel
Save