...
1 package testing
2
3 import (
4 "io"
5 "sync"
6 )
7
8
9
10 type ByteLoop struct {
11 value byte
12 closed bool
13 mu sync.RWMutex
14 }
15
16
17
18
19 func (l *ByteLoop) Read(p []byte) (size int, err error) {
20 l.mu.RLock()
21 defer l.mu.RUnlock()
22 if l.closed {
23 return 0, io.EOF
24 }
25
26 for i := 0; i < len(p); i++ {
27 p[i] = l.value
28 }
29 return len(p), nil
30 }
31
32
33 func (l *ByteLoop) Close() error {
34 l.mu.Lock()
35 defer l.mu.Unlock()
36 l.closed = true
37
38 return nil
39 }
40
View as plain text