-
Notifications
You must be signed in to change notification settings - Fork 0
/
trim_writer_test.go
64 lines (49 loc) · 1.13 KB
/
trim_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
64
package socketio
import (
"bytes"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestTrimWriter(t *testing.T) {
var inputs []string
var target string
var trim string
test := func() {
buf := bytes.NewBuffer(nil)
w := newTrimWriter(buf, trim)
for _, str := range inputs {
_, err := w.Write([]byte(str))
So(err, ShouldBeNil)
}
So(buf.String(), ShouldEqual, target)
}
Convey("Trim nothing", t, func() {
inputs = []string{"1234", "2234"}
target = "12342234"
trim = ""
test()
})
Convey("Trim something", t, func() {
trim = "34"
Convey("Something at the end of final packet", func() {
inputs = []string{"1234", "2234"}
target = "123422"
test()
})
Convey("Something at the multiple packets", func() {
inputs = []string{"1234", "3434"}
target = "12"
test()
})
Convey("Something in the middle of packets", func() {
inputs = []string{"1234", "3434", "5678"}
target = "123434345678"
test()
})
Convey("Something in the middle and end of packets", func() {
inputs = []string{"1234", "3434", "5678", "9034"}
target = "12343434567890"
test()
})
})
}