mirror of
https://github.com/zrepl/zrepl.git
synced 2024-11-22 16:34:32 +01:00
796c5ad42d
transport/ssh: update go-netssh to new version => supports CloseWrite and Deadlines => build: require Go 1.11 (netssh requires it)
39 lines
791 B
Go
39 lines
791 B
Go
package bytecounter
|
|
|
|
import (
|
|
"io"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/zrepl/zrepl/zfs"
|
|
)
|
|
|
|
type mockStreamCopierAndReader struct {
|
|
zfs.StreamCopier // to satisfy interface
|
|
reads int
|
|
}
|
|
|
|
func (r *mockStreamCopierAndReader) Read(p []byte) (int, error) {
|
|
r.reads++
|
|
return len(p), nil
|
|
}
|
|
|
|
var _ io.Reader = &mockStreamCopierAndReader{}
|
|
|
|
func TestNewStreamCopierReexportsReader(t *testing.T) {
|
|
mock := &mockStreamCopierAndReader{}
|
|
x := NewStreamCopier(mock)
|
|
|
|
r, ok := x.(io.Reader)
|
|
if !ok {
|
|
t.Fatalf("%T does not implement io.Reader, hence reader cannout have been wrapped", x)
|
|
}
|
|
|
|
var buf [23]byte
|
|
n, err := r.Read(buf[:])
|
|
assert.True(t, mock.reads == 1)
|
|
assert.True(t, n == len(buf))
|
|
assert.NoError(t, err)
|
|
assert.True(t, x.Count() == 23)
|
|
}
|