...

Source file src/github.com/emissary-ingress/emissary/v3/cmd/entrypoint/notify_test.go

Documentation: github.com/emissary-ingress/emissary/v3/cmd/entrypoint

     1  package entrypoint
     2  
     3  import (
     4  	"net/http"
     5  	"net/http/httptest"
     6  	"testing"
     7  
     8  	"github.com/stretchr/testify/assert"
     9  
    10  	"github.com/datawire/dlib/dlog"
    11  )
    12  
    13  // Check if we return false when we get a connection refused.
    14  func TestNotifyWebhookUrlConnectionRefused(t *testing.T) {
    15  	ctx := dlog.NewTestContext(t, false)
    16  
    17  	finished, err := notifyWebhookUrl(ctx, "test", "http://localhost:5555")
    18  	assert.NoError(t, err)
    19  	assert.False(t, finished)
    20  }
    21  
    22  // Check that we panic if we do not get a properly formed http response of some kind such as an EOF.
    23  func TestNotifyWebhookUrlEOF(t *testing.T) {
    24  	ctx := dlog.NewTestContext(t, false)
    25  
    26  	var srv *httptest.Server
    27  	srv = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
    28  		// We want to generate an EOF for the connected client. This seems to do that.
    29  		srv.CloseClientConnections()
    30  	}))
    31  
    32  	_, err := notifyWebhookUrl(ctx, "test", srv.URL)
    33  	assert.Error(t, err)
    34  }
    35  

View as plain text