syncthing/protocol/common_test.go

53 lines
926 B
Go
Raw Normal View History

2013-12-19 16:01:34 -07:00
package protocol
import "io"
type TestModel struct {
data []byte
repo string
2013-12-19 16:01:34 -07:00
name string
offset int64
2014-02-23 05:58:10 -07:00
size int
2013-12-19 16:01:34 -07:00
closed bool
}
func (t *TestModel) Index(nodeID string, files []FileInfo) {
}
2013-12-28 08:30:02 -07:00
func (t *TestModel) IndexUpdate(nodeID string, files []FileInfo) {
}
2014-02-23 05:58:10 -07:00
func (t *TestModel) Request(nodeID, repo, name string, offset int64, size int) ([]byte, error) {
t.repo = repo
2013-12-19 16:01:34 -07:00
t.name = name
t.offset = offset
t.size = size
return t.data, nil
}
func (t *TestModel) Close(nodeID string, err error) {
2013-12-19 16:01:34 -07:00
t.closed = true
}
type ErrPipe struct {
io.PipeWriter
written int
max int
err error
closed bool
}
func (e *ErrPipe) Write(data []byte) (int, error) {
if e.closed {
return 0, e.err
}
if e.written+len(data) > e.max {
n, _ := e.PipeWriter.Write(data[:e.max-e.written])
e.PipeWriter.CloseWithError(e.err)
e.closed = true
return n, e.err
} else {
return e.PipeWriter.Write(data)
}
}