mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
raft: add TestUnstableRestore
This commit is contained in:
parent
be60c88603
commit
7703d4942c
@ -17,6 +17,7 @@
|
||||
package raft
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
pb "github.com/coreos/etcd/raft/raftpb"
|
||||
@ -187,3 +188,23 @@ func TestUnstableMaybeTerm(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnstableRestore(t *testing.T) {
|
||||
u := unstable{
|
||||
entries: []pb.Entry{{Index: 5, Term: 1}},
|
||||
offset: 5,
|
||||
snapshot: &pb.Snapshot{Metadata: pb.SnapshotMetadata{Index: 4, Term: 1}},
|
||||
}
|
||||
s := pb.Snapshot{Metadata: pb.SnapshotMetadata{Index: 6, Term: 2}}
|
||||
u.restore(s)
|
||||
|
||||
if u.offset != s.Metadata.Index+1 {
|
||||
t.Errorf("offset = %d, want %d", u.offset != s.Metadata.Index+1)
|
||||
}
|
||||
if len(u.entries) != 0 {
|
||||
t.Errorf("len = %d, want 0", len(u.entries), 0)
|
||||
}
|
||||
if !reflect.DeepEqual(u.snapshot, &s) {
|
||||
t.Errorf("snap = %v, want %v", u.snapshot, &s)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user