aboutsummaryrefslogtreecommitdiff
path: root/pipeln_test.go
diff options
context:
space:
mode:
authorGrégoire Duchêne <gduchene@awhk.org>2021-03-16 15:16:03 +0000
committerGrégoire Duchêne <gduchene@awhk.org>2021-03-16 15:16:03 +0000
commitf06b2f85e8b1158bd63c7ed4d918770626d99545 (patch)
tree5c3623e265e0ebc21cacc890e478f8868c63f86e /pipeln_test.go
parentae2def146399745a8dba5113d5e1b57292a258e8 (diff)
PipeListenerDialer.Close should be called once
PipeListenerDialer.Close will return unix.EINVAL if it is called more than once. This is to emulate the behavior of other standard listeners. Also: * PipeListenerDialer.Accept will return (nil, unix.EINVAL) if the listener is closed. This roughly matches with behavior described in accept(2). * PipeListenerDialer.Dial will also return (nil, unix.EINVAL) if the address passed does not match the one passed to New. It will also return (nil, unix.ECONNREFUSED) if the listener is closed. This roughly matches the behavior described in connect(2) and unix(7). * The custom errors ErrBadAddress and ErrClosed are removed.
Diffstat (limited to 'pipeln_test.go')
-rw-r--r--pipeln_test.go25
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)
+ })
}