-
Notifications
You must be signed in to change notification settings - Fork 13
/
event_test.go
40 lines (35 loc) · 827 Bytes
/
event_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
package oplog
import "testing"
// Version of bytes.Buffer that checks whether WriteTo was called or not
type writeChecker struct {
written []byte
called bool
}
func (wt *writeChecker) Write(b []byte) (int, error) {
wt.written = b
wt.called = true
return len(b), nil
}
func TestOplogEventOutput(t *testing.T) {
e := Event{"a", "b"}
w := &writeChecker{}
n, err := e.WriteTo(w)
if err != nil {
t.Fatal(err)
}
if !w.called {
t.Fatal("writer not called")
}
if string(w.written) != "id: a\nevent: b\n\n" {
t.Fatalf("invalid output: %s", string(w.written))
}
if n != int64(len(w.written)) {
t.Fatalf("returned length doesn't match written string length: %d != %d", n, len(w.written))
}
}
func TestOplogEventId(t *testing.T) {
e := Event{"a", "b"}
if e.GetEventID().String() != "a" {
t.FailNow()
}
}