-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreplay_test.go
53 lines (46 loc) · 1.18 KB
/
replay_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
package xopconsole_test
import (
"bytes"
"context"
"testing"
"github.com/xoplog/xop-go"
"github.com/xoplog/xop-go/xopconsole"
"github.com/xoplog/xop-go/xoptest"
"github.com/xoplog/xop-go/xoptest/xoptestutil"
"github.com/stretchr/testify/require"
)
type buffer struct {
t *testing.T
buf []byte
}
func (buf *buffer) Write(b []byte) (int, error) {
buf.t.Log(string(b))
buf.buf = append(buf.buf, b...)
return len(b), nil
}
func TestReplayConsole(t *testing.T) {
for _, mc := range xoptestutil.MessageCases {
mc := mc
t.Run(mc.Name, func(t *testing.T) {
tLog := xoptest.New(t)
buf := &buffer{t: t}
cLog := xopconsole.New(xopconsole.WithWriter(buf))
seed := xop.NewSeed(
xop.WithBase(cLog),
xop.WithBase(tLog),
)
if len(mc.SeedMods) != 0 {
t.Logf("Applying %d extra seed mods", len(mc.SeedMods))
seed = seed.Copy(mc.SeedMods...)
}
log := seed.Request(t.Name())
mc.Do(t, log, tLog)
t.Log("Replay")
rLog := xoptest.New(t)
err := xopconsole.Replay(context.Background(), bytes.NewBuffer(buf.buf), rLog)
require.NoError(t, err, "replay")
t.Log("verify replay equals original")
xoptestutil.VerifyTestReplay(t, tLog, rLog)
})
}
}