@@ -25,32 +25,30 @@ import (
2525
2626func TestFindConflict (t * testing.T ) {
2727 previousEnts := index (1 ).terms (1 , 2 , 3 )
28- tests := []struct {
29- ents []pb.Entry
30- wconflict uint64
28+ for _ , tt := range []struct {
29+ ents []pb.Entry
30+ want uint64
3131 }{
32- // no conflict, empty ent
33- {nil , 0 },
32+ // no conflict, empty entries
33+ {ents : nil , want : 0 },
3434 // no conflict
35- {index (1 ).terms (1 , 2 , 3 ), 0 },
36- {index (2 ).terms (2 , 3 ), 0 },
37- {index (3 ).terms (3 ), 0 },
35+ {ents : index (1 ).terms (1 , 2 , 3 ), want : 0 },
36+ {ents : index (2 ).terms (2 , 3 ), want : 0 },
37+ {ents : index (3 ).terms (3 ), want : 0 },
3838 // no conflict, but has new entries
39- {index (1 ).terms (1 , 2 , 3 , 4 , 4 ), 4 },
40- {index (2 ).terms (2 , 3 , 4 , 5 ), 4 },
41- {index (3 ).terms (3 , 4 , 4 ), 4 },
42- {index (4 ).terms (4 , 4 ), 4 },
39+ {ents : index (1 ).terms (1 , 2 , 3 , 4 , 4 ), want : 4 },
40+ {ents : index (2 ).terms (2 , 3 , 4 , 5 ), want : 4 },
41+ {ents : index (3 ).terms (3 , 4 , 4 ), want : 4 },
42+ {ents : index (4 ).terms (4 , 4 ), want : 4 },
4343 // conflicts with existing entries
44- {index (1 ).terms (4 , 4 ), 1 },
45- {index (2 ).terms (1 , 4 , 4 ), 2 },
46- {index (3 ).terms (1 , 2 , 4 , 4 ), 3 },
47- }
48-
49- for i , tt := range tests {
50- t .Run (fmt .Sprint (i ), func (t * testing.T ) {
51- raftLog := newLog (NewMemoryStorage (), raftLogger )
52- raftLog .append (previousEnts ... )
53- require .Equal (t , tt .wconflict , raftLog .findConflict (tt .ents ))
44+ {ents : index (1 ).terms (4 , 4 ), want : 1 },
45+ {ents : index (2 ).terms (1 , 4 , 4 ), want : 2 },
46+ {ents : index (3 ).terms (1 , 2 , 4 , 4 ), want : 3 },
47+ } {
48+ t .Run ("" , func (t * testing.T ) {
49+ log := newLog (NewMemoryStorage (), discardLogger )
50+ log .append (previousEnts ... )
51+ require .Equal (t , tt .want , log .findConflict (tt .ents ))
5452 })
5553 }
5654}
0 commit comments