Skip to content

Commit

Permalink
feat: raft/log_test se testify packages in tests
Browse files Browse the repository at this point in the history
Signed-off-by: jianfei.zhang <[email protected]>
  • Loading branch information
falser101 committed Nov 15, 2022
1 parent 8ac5bb0 commit 4682871
Showing 1 changed file with 11 additions and 28 deletions.
39 changes: 11 additions & 28 deletions raft/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,22 +322,6 @@ func TestHasNextCommittedEnts(t *testing.T) {
{applied: 3, snap: true, whasNext: false},
}
for i, tt := range tests {
storage := NewMemoryStorage()
storage.ApplySnapshot(snap)
raftLog := newLog(storage, raftLogger)
raftLog.append(ents...)
raftLog.maybeCommit(5, 1)
raftLog.appliedTo(tt.applied)
if tt.snap {
newSnap := snap
newSnap.Metadata.Index++
raftLog.restore(newSnap)
}

hasNext := raftLog.hasNextCommittedEnts()
if hasNext != tt.whasNext {
t.Errorf("#%d: hasNext = %v, want %v", i, hasNext, tt.whasNext)
}
t.Run(fmt.Sprint(i), func(t *testing.T) {
storage := NewMemoryStorage()
require.NoError(t, storage.ApplySnapshot(snap))
Expand All @@ -346,7 +330,12 @@ func TestHasNextCommittedEnts(t *testing.T) {
raftLog.append(ents...)
raftLog.maybeCommit(5, 1)
raftLog.appliedTo(tt.applied)
require.Equal(t, tt.hasNext, raftLog.hasNextCommittedEnts())
if tt.snap {
newSnap := snap
newSnap.Metadata.Index++
raftLog.restore(newSnap)
}
require.Equal(t, tt.whasNext, raftLog.hasNextCommittedEnts())
})
}
}
Expand All @@ -373,17 +362,6 @@ func TestNextCommittedEnts(t *testing.T) {
{applied: 3, snap: true, wents: nil},
}
for i, tt := range tests {
storage := NewMemoryStorage()
storage.ApplySnapshot(snap)
raftLog := newLog(storage, raftLogger)
raftLog.append(ents...)
raftLog.maybeCommit(5, 1)
raftLog.appliedTo(tt.applied)
if tt.snap {
newSnap := snap
newSnap.Metadata.Index++
raftLog.restore(newSnap)
}
t.Run(fmt.Sprint(i), func(t *testing.T) {
storage := NewMemoryStorage()
require.NoError(t, storage.ApplySnapshot(snap))
Expand All @@ -392,6 +370,11 @@ func TestNextCommittedEnts(t *testing.T) {
raftLog.append(ents...)
raftLog.maybeCommit(5, 1)
raftLog.appliedTo(tt.applied)
if tt.snap {
newSnap := snap
newSnap.Metadata.Index++
raftLog.restore(newSnap)
}
require.Equal(t, tt.wents, raftLog.nextCommittedEnts())
})

Expand Down

0 comments on commit 4682871

Please sign in to comment.