This repository has been archived by the owner on Mar 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes_test.go
109 lines (91 loc) · 2.63 KB
/
types_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package raftify
import "testing"
func TestStateToString(t *testing.T) {
state := Bootstrap
if state.toString() != "Bootstrap" {
t.Logf("Expected to get \"Bootstrap\", instead got %v", state.toString())
t.Fail()
}
state = Rejoin
if state.toString() != "Rejoin" {
t.Logf("Expected to get \"Rejoin\", instead got %v", state.toString())
t.Fail()
}
state = Follower
if state.toString() != "Follower" {
t.Logf("Expected to get \"Follower\", instead got %v", state.toString())
t.Fail()
}
state = PreCandidate
if state.toString() != "PreCandidate" {
t.Logf("Expected to get \"PreCandidate\", instead got %v", state.toString())
t.Fail()
}
state = Candidate
if state.toString() != "Candidate" {
t.Logf("Expected to get \"Candidate\", instead got %v", state.toString())
t.Fail()
}
state = Leader
if state.toString() != "Leader" {
t.Logf("Expected to get \"Leader\", instead got %v", state.toString())
t.Fail()
}
state = PreShutdown
if state.toString() != "PreShutdown" {
t.Logf("Expected to get \"PreShutdown\", instead got %v", state.toString())
t.Fail()
}
state = Shutdown
if state.toString() != "Shutdown" {
t.Logf("Expected to get \"Shutdown\", instead got %v", state.toString())
t.Fail()
}
state = 100
if state.toString() != "unknown" {
t.Logf("Expected to get \"unknown\", instead got %v", state.toString())
t.Fail()
}
}
func TestMessageTypeToString(t *testing.T) {
msg := HeartbeatMsg
if msg.toString() != "HeartbeatMsg" {
t.Logf("Expected to get \"HeartbeatMsg\", instead got %v", msg.toString())
t.Fail()
}
msg = HeartbeatResponseMsg
if msg.toString() != "HeartbeatResponseMsg" {
t.Logf("Expected to get \"HeartbeatResponseMsg\", instead got %v", msg.toString())
t.Fail()
}
msg = PreVoteRequestMsg
if msg.toString() != "PreVoteRequestMsg" {
t.Logf("Expected to get \"PreVoteRequestMsg\", instead got %v", msg.toString())
t.Fail()
}
msg = PreVoteResponseMsg
if msg.toString() != "PreVoteResponseMsg" {
t.Logf("Expected to get \"PreVoteResponseMsg\", instead got %v", msg.toString())
t.Fail()
}
msg = VoteRequestMsg
if msg.toString() != "VoteRequestMsg" {
t.Logf("Expected to get \"VoteRequestMsg\", instead got %v", msg.toString())
t.Fail()
}
msg = VoteResponseMsg
if msg.toString() != "VoteResponseMsg" {
t.Logf("Expected to get \"VoteResponseMsg\", instead got %v", msg.toString())
t.Fail()
}
msg = NewQuorumMsg
if msg.toString() != "NewQuorumMsg" {
t.Logf("Expected to get \"NewQuorumMsg\", instead got %v", msg.toString())
t.Fail()
}
msg = 100
if msg.toString() != "unknown" {
t.Logf("Expected to get \"unknown\", instead got %v", msg.toString())
t.Fail()
}
}