1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package raftpb
16
17 import (
18 "testing"
19 )
20
21 func TestConfState_Equivalent(t *testing.T) {
22 type testCase struct {
23 cs, cs2 ConfState
24 ok bool
25 }
26
27 testCases := []testCase{
28
29 {ConfState{
30 Voters: []uint64{1, 2, 3},
31 Learners: []uint64{5, 4, 6},
32 VotersOutgoing: []uint64{9, 8, 7},
33 LearnersNext: []uint64{10, 20, 15},
34 }, ConfState{
35 Voters: []uint64{1, 2, 3},
36 Learners: []uint64{4, 5, 6},
37 VotersOutgoing: []uint64{7, 9, 8},
38 LearnersNext: []uint64{20, 10, 15},
39 }, true},
40
41 {ConfState{Voters: []uint64{}}, ConfState{Voters: []uint64(nil)}, true},
42
43 {ConfState{Voters: []uint64{1, 2, 3, 4}}, ConfState{Voters: []uint64{2, 1, 3}}, false},
44 {ConfState{Voters: []uint64{1, 4, 3}}, ConfState{Voters: []uint64{2, 1, 3}}, false},
45
46 {ConfState{Voters: []uint64{1, 2, 3, 4}}, ConfState{Voters: []uint64{2, 1, 3}}, false},
47
48 {ConfState{AutoLeave: true}, ConfState{}, false},
49 }
50
51 for _, tc := range testCases {
52 t.Run("", func(t *testing.T) {
53 if err := tc.cs.Equivalent(tc.cs2); (err == nil) != tc.ok {
54 t.Fatalf("wanted error: %t, got:\n%s", tc.ok, err)
55 }
56 })
57 }
58 }
59
View as plain text