aboutsummaryrefslogtreecommitdiff
path: root/ssh/mempipe_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'ssh/mempipe_test.go')
-rw-r--r--ssh/mempipe_test.go20
1 files changed, 17 insertions, 3 deletions
diff --git a/ssh/mempipe_test.go b/ssh/mempipe_test.go
index 8697cd6..f27339c 100644
--- a/ssh/mempipe_test.go
+++ b/ssh/mempipe_test.go
@@ -13,9 +13,10 @@ import (
// An in-memory packetConn. It is safe to call Close and writePacket
// from different goroutines.
type memTransport struct {
- eof bool
- pending [][]byte
- write *memTransport
+ eof bool
+ pending [][]byte
+ write *memTransport
+ writeCount uint64
sync.Mutex
*sync.Cond
}
@@ -63,9 +64,16 @@ func (t *memTransport) writePacket(p []byte) error {
copy(c, p)
t.write.pending = append(t.write.pending, c)
t.write.Cond.Signal()
+ t.writeCount++
return nil
}
+func (t *memTransport) getWriteCount() uint64 {
+ t.write.Lock()
+ defer t.write.Unlock()
+ return t.writeCount
+}
+
func memPipe() (a, b packetConn) {
t1 := memTransport{}
t2 := memTransport{}
@@ -81,6 +89,9 @@ func TestMemPipe(t *testing.T) {
if err := a.writePacket([]byte{42}); err != nil {
t.Fatalf("writePacket: %v", err)
}
+ if wc := a.(*memTransport).getWriteCount(); wc != 1 {
+ t.Fatalf("got %v, want 1", wc)
+ }
if err := a.Close(); err != nil {
t.Fatal("Close: ", err)
}
@@ -95,6 +106,9 @@ func TestMemPipe(t *testing.T) {
if err != io.EOF {
t.Fatalf("got %v, %v, want EOF", p, err)
}
+ if wc := b.(*memTransport).getWriteCount(); wc != 0 {
+ t.Fatalf("got %v, want 0", wc)
+ }
}
func TestDoubleClose(t *testing.T) {