From 7703d4942c0bbaf32c6700a02874edd110a7ae5a Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Wed, 3 Dec 2014 13:03:56 -0800 Subject: [PATCH] raft: add TestUnstableRestore --- raft/log_unstable_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/raft/log_unstable_test.go b/raft/log_unstable_test.go index 97685892c..119b878d3 100644 --- a/raft/log_unstable_test.go +++ b/raft/log_unstable_test.go @@ -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) + } +}