package shell import ( "bytes" "io" "testing" ) // nopCloser wraps a ReadWriter with a no-op Close. type nopCloser struct { io.ReadWriter } func (nopCloser) Close() error { return nil } func TestRecordingChannelPassthrough(t *testing.T) { var buf bytes.Buffer rc := NewRecordingChannel(nopCloser{&buf}) // Write through the recorder. msg := []byte("hello") n, err := rc.Write(msg) if err != nil { t.Fatalf("Write: %v", err) } if n != len(msg) { t.Errorf("Write n = %d, want %d", n, len(msg)) } // Read through the recorder. out := make([]byte, 16) n, err = rc.Read(out) if err != nil { t.Fatalf("Read: %v", err) } if string(out[:n]) != "hello" { t.Errorf("Read = %q, want %q", out[:n], "hello") } if err := rc.Close(); err != nil { t.Fatalf("Close: %v", err) } }