github.com/epfl-dcsl/gotee@v0.0.0-20200909122901-014b35f5e5e9/src/net/pipe_test.go (about) 1 // Copyright 2010 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package net_test 6 7 import ( 8 "io" 9 "net" 10 "testing" 11 "time" 12 13 "golang_org/x/net/nettest" 14 ) 15 16 func TestPipe(t *testing.T) { 17 nettest.TestConn(t, func() (c1, c2 net.Conn, stop func(), err error) { 18 c1, c2 = net.Pipe() 19 stop = func() { 20 c1.Close() 21 c2.Close() 22 } 23 return 24 }) 25 } 26 27 func TestPipeCloseError(t *testing.T) { 28 c1, c2 := net.Pipe() 29 c1.Close() 30 31 if _, err := c1.Read(nil); err != io.ErrClosedPipe { 32 t.Errorf("c1.Read() = %v, want io.ErrClosedPipe", err) 33 } 34 if _, err := c1.Write(nil); err != io.ErrClosedPipe { 35 t.Errorf("c1.Write() = %v, want io.ErrClosedPipe", err) 36 } 37 if err := c1.SetDeadline(time.Time{}); err != io.ErrClosedPipe { 38 t.Errorf("c1.SetDeadline() = %v, want io.ErrClosedPipe", err) 39 } 40 if _, err := c2.Read(nil); err != io.EOF { 41 t.Errorf("c2.Read() = %v, want io.EOF", err) 42 } 43 if _, err := c2.Write(nil); err != io.ErrClosedPipe { 44 t.Errorf("c2.Write() = %v, want io.ErrClosedPipe", err) 45 } 46 if err := c2.SetDeadline(time.Time{}); err != io.ErrClosedPipe { 47 t.Errorf("c2.SetDeadline() = %v, want io.ErrClosedPipe", err) 48 } 49 }