-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmulti_writer_test.go
63 lines (44 loc) · 1.14 KB
/
multi_writer_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 peanut_test
import (
"errors"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/jimsmart/peanut"
)
var _ = Describe("MultiWriter", func() {
It("should call the methods of the writers it wraps", func() {
w1 := &peanut.MockWriter{}
w2 := &peanut.MockWriter{}
w := peanut.MultiWriter(w1, w2)
testWritesAndCloseSequential(w)
Expect(w1.CalledWrite).To(Equal(10))
Expect(w1.CalledClose).To(Equal(1))
Expect(w1.CalledCancel).To(Equal(1))
// Did it actually write to both?
Expect(w1).To(Equal(w2))
})
It("should forward errors from Close", func() {
w1 := &peanut.MockWriter{}
w2 := &failWriter{}
w := peanut.MultiWriter(w1, w2)
err := w.Close()
Expect(err).NotTo(BeNil())
})
It("should forward errors from Cancel", func() {
w1 := &peanut.MockWriter{}
w2 := &failWriter{}
w := peanut.MultiWriter(w1, w2)
err := w.Cancel()
Expect(err).NotTo(BeNil())
})
})
type failWriter struct{}
func (failWriter) Write(x interface{}) error {
return errors.New("fail")
}
func (failWriter) Close() error {
return errors.New("fail")
}
func (failWriter) Cancel() error {
return errors.New("fail")
}