-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathgossamr_test.go
63 lines (52 loc) · 1002 Bytes
/
gossamr_test.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package gossamr
import (
"bufio"
"bytes"
"github.com/markchadwick/spec"
"io"
"log"
"testing"
)
func init() {
log.SetFlags(log.Lshortfile | log.Ldate | log.Ltime)
}
func Test(t *testing.T) {
spec.Run(t)
}
type BufCloser struct {
*bytes.Buffer
}
func NewBufCloser() *BufCloser {
return &BufCloser{new(bytes.Buffer)}
}
func (bc *BufCloser) Close() error {
return nil
}
// An in-memory buffer to block while input is pending and it is not closed.
type TestBuffer struct {
r *io.PipeReader
w *io.PipeWriter
br *bufio.Reader
bw *bufio.Writer
}
func NewTestBuffer() *TestBuffer {
r, w := io.Pipe()
return &TestBuffer{
r: r,
w: w,
br: bufio.NewReader(r),
bw: bufio.NewWriter(w),
}
}
func (tb *TestBuffer) Read(p []byte) (int, error) {
return tb.br.Read(p)
}
func (tb *TestBuffer) Write(p []byte) (int, error) {
return tb.bw.Write(p)
}
func (tb *TestBuffer) Close() (err error) {
if err = tb.bw.Flush(); err != nil {
return
}
return tb.w.CloseWithError(io.EOF)
}