syncthing/protocol/common_test.go

52 lines
915 B
Go
Raw Normal View History

2013-12-19 23:01:34 +00:00
package protocol
import "io"
type TestModel struct {
data []byte
repo string
2013-12-19 23:01:34 +00:00
name string
offset int64
2014-02-23 12:58:10 +00:00
size int
2013-12-19 23:01:34 +00:00
closed bool
}
func (t *TestModel) Index(nodeID string, files []FileInfo) {
}
2013-12-28 15:30:02 +00:00
func (t *TestModel) IndexUpdate(nodeID string, files []FileInfo) {
}
2014-02-23 12:58:10 +00:00
func (t *TestModel) Request(nodeID, repo, name string, offset int64, size int) ([]byte, error) {
t.repo = repo
2013-12-19 23:01:34 +00: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 23:01:34 +00: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
}
2014-02-24 12:29:30 +00:00
return e.PipeWriter.Write(data)
2013-12-19 23:01:34 +00:00
}