Browse Source

raft: add TestUnstableRestore

Xiang Li 11 years ago
parent
commit
7703d4942c
1 changed files with 21 additions and 0 deletions
  1. 21 0
      raft/log_unstable_test.go

+ 21 - 0
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)
+	}
+}