diff options
Diffstat (limited to 'pipeln_test.go')
| -rw-r--r-- | pipeln_test.go | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/pipeln_test.go b/pipeln_test.go index e5de8d0..9673fcc 100644 --- a/pipeln_test.go +++ b/pipeln_test.go @@ -9,6 +9,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "golang.org/x/sys/unix" ) func Test(t *testing.T) { @@ -22,9 +23,27 @@ func Test(t *testing.T) { go srv.Serve(ln) client := http.Client{Transport: &http.Transport{Dial: ln.Dial}} - resp, err := client.Get("http://test/endpoint") - require.NoError(t, err) - assert.Equal(t, http.StatusOK, resp.StatusCode) + + t.Run("OK", func(t *testing.T) { + resp, err := client.Get("http://test/endpoint") + require.NoError(t, err) + assert.Equal(t, http.StatusOK, resp.StatusCode) + }) + + t.Run("Address Mismatch", func(t *testing.T) { + _, err := client.Get("http://other-test/endpoint") + assert.ErrorIs(t, err, unix.EINVAL) + }) srv.Shutdown(context.Background()) + + t.Run("Remote Connection Closed", func(t *testing.T) { + _, err := client.Get("http://test/endpoint") + assert.ErrorIs(t, err, unix.ECONNREFUSED) + }) + + t.Run("Already-closed Listener", func(t *testing.T) { + srv = http.Server{Handler: mux} + assert.ErrorIs(t, srv.Serve(ln), unix.EINVAL) + }) } |
