-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
73 lines (48 loc) · 1.14 KB
/
main_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
65
66
67
68
69
70
71
72
73
package main
import (
"gossip-gloomers/testutils"
"testing"
"github.com/gkampitakis/go-snaps/snaps"
maelstrom "github.com/jepsen-io/maelstrom/demo/go"
"github.com/stretchr/testify/require"
)
func Test(t *testing.T) {
require := require.New(t)
node = maelstrom.NewNode()
link := testutils.NewLink(node)
client := testutils.NewClient("c0", link)
node1 := testutils.NewClient("n1", link)
go main()
err := client.InitNode("n0", []string{"n0", "n1"})
require.NoError(err)
err = client.Write(AddRequest{
MessageBody: maelstrom.MessageBody{
Type: "add",
MsgID: 2,
},
Delta: 1,
})
require.NoError(err)
output, err := client.Read()
require.NoError(err)
snaps.MatchSnapshot(t, output)
propagateOutput, err := node1.Read()
require.NoError(err)
snaps.MatchSnapshot(t, propagateOutput)
err = node1.Write(PropagateRequest{
MessageBody: maelstrom.MessageBody{
Type: "propagate",
MsgID: 4,
},
Count: 1,
})
require.NoError(err)
err = client.Write(maelstrom.MessageBody{
Type: "read",
MsgID: 3,
})
require.NoError(err)
output, err = client.Read()
require.NoError(err)
snaps.MatchSnapshot(t, output)
}