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 pathlists_test.go
80 lines (66 loc) · 1.85 KB
/
lists_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
package raftify
import (
"testing"
"github.com/hashicorp/memberlist"
)
func TestHeartbeatIDList(t *testing.T) {
list := HeartbeatIDList{
pending: []uint64{},
}
list.add(0)
list.add(1)
list.add(2)
if len(list.pending) != 3 {
t.Logf("Expected list length of 3, instead got %v", len(list.pending))
t.Fail()
}
if err := list.remove(0); err != nil {
t.Logf("Expected heartbeatid 0 to be removed, instead got error: %v", err.Error())
t.Fail()
}
if len(list.pending) != 2 {
t.Logf("Expected list length of 2, instead got %v", len(list.pending))
t.Fail()
}
if err := list.remove(0); err == nil {
t.Log("Expected removal of heartbeatid 0 to fail, instead passed as valid")
t.Fail()
}
list.reset()
if len(list.pending) != 0 {
t.Logf("Expected list length of 0, instead got %v", len(list.pending))
t.Fail()
}
}
func TestVoteList(t *testing.T) {
initPending := []*memberlist.Node{
{Name: "1-One"},
{Name: "2-Two"},
}
initPendingCopy := make([]*memberlist.Node, len(initPending))
copy(initPendingCopy, initPending)
list := VoteList{
pending: initPendingCopy,
}
if err := list.remove("1-One"); err != nil {
t.Logf("Expected to remove 1-One from vote list, instead got error: %v", err.Error())
t.Fail()
}
if len(list.pending) != len(initPending)-1 {
t.Logf("Expected list length of %v, instead got %v", len(initPending), len(list.pending))
t.Fail()
}
if err := list.remove("2-Two"); err != nil {
t.Logf("Expected to remove 2-Two from vote list, instead got error: %v", err.Error())
t.Fail()
}
if len(list.pending) != len(initPending)-2 {
t.Logf("Expected list length of %v, instead got %v", len(initPending), len(list.pending))
t.Fail()
}
list.reset(initPending)
if len(list.pending) != len(initPending) {
t.Logf("Expected list to be reset to initial size, instead go size %v", len(initPending))
t.Fail()
}
}