Browse Source

raft: add tests for IsLocalMsg (#6357)

* raft: add tests for IsLocalMsg

* report index of failed tests
goroutine 9 years ago
parent
commit
ce49fb6ec4
1 changed files with 32 additions and 0 deletions
  1. 32 0
      raft/util_test.go

+ 32 - 0
raft/util_test.go

@@ -70,3 +70,35 @@ func TestLimitSize(t *testing.T) {
 		}
 	}
 }
+
+func TestIsLocalMsg(t *testing.T) {
+	tests := []struct {
+		msgt    pb.MessageType
+		isLocal bool
+	}{
+		{pb.MsgHup, true},
+		{pb.MsgBeat, true},
+		{pb.MsgUnreachable, true},
+		{pb.MsgSnapStatus, true},
+		{pb.MsgCheckQuorum, true},
+		{pb.MsgTransferLeader, false},
+		{pb.MsgProp, false},
+		{pb.MsgApp, false},
+		{pb.MsgAppResp, false},
+		{pb.MsgVote, false},
+		{pb.MsgVoteResp, false},
+		{pb.MsgSnap, false},
+		{pb.MsgHeartbeat, false},
+		{pb.MsgHeartbeatResp, false},
+		{pb.MsgTimeoutNow, false},
+		{pb.MsgReadIndex, false},
+		{pb.MsgReadIndexResp, false},
+	}
+
+	for i, tt := range tests {
+		got := IsLocalMsg(tt.msgt)
+		if got != tt.isLocal {
+			t.Errorf("#%d: got %v, want %v", i, got, tt.isLocal)
+		}
+	}
+}