-
Notifications
You must be signed in to change notification settings - Fork 0
/
writer.go
49 lines (41 loc) · 798 Bytes
/
writer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package mock
func NewWriter() *writer {
return &writer{}
}
func NewWriteCloser() *writeCloser {
return &writeCloser{
writer: NewWriter(),
closer: NewCloser(),
}
}
type writer struct {
data []byte
returnN interface{}
returnErr error
log func(v ...interface{})
}
type writeCloser struct {
*writer
*closer
}
func (w *writer) Write(p []byte) (n int, err error) {
w.data = append(w.data, p...)
n = len(p)
if w.returnN != nil {
n = w.returnN.(int)
}
return n, w.returnErr
}
func (w *writer) WriteShouldReturn(n interface{}, err error) {
if n != nil {
if _, ok := n.(int); !ok {
w.log("method SeekShouldReturn expects 'n' to be int or nil")
return
}
}
w.returnN = n
w.returnErr = err
}
func (w writer) WrittenData() string {
return string(w.data)
}