diff options
Diffstat (limited to 'internal/quorum/quorum_test.go')
| -rw-r--r-- | internal/quorum/quorum_test.go | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/internal/quorum/quorum_test.go b/internal/quorum/quorum_test.go index d0f7ec7..9953c11 100644 --- a/internal/quorum/quorum_test.go +++ b/internal/quorum/quorum_test.go @@ -9,7 +9,7 @@ import ( ) func TestScore(t *testing.T) { - conf := config.Config{Participants: []string{"foo:1234", "bar:4321", "baz:3444"}} + conf := config.Config{Nodes: []string{"foo:1234", "bar:4321", "baz:3444"}} quo := New(conf) vote1 := vote.New(conf, "foo:334234", "foo bar\n") @@ -55,7 +55,7 @@ func TestTieScore(t *testing.T) { t.Run("First tie score test", func(t *testing.T) { // If it is a tie, the first particpant (here: "foo") will win. - conf := config.Config{Participants: []string{"foo:1234", "bar:4321", "baz:3444"}} + conf := config.Config{Nodes: []string{"foo:1234", "bar:4321", "baz:3444"}} quo := New(conf) addVotes(conf, quo) @@ -68,7 +68,7 @@ func TestTieScore(t *testing.T) { t.Errorf("Expected score[0] to be {foo,3}: %v", scores[0]) } - winner, _ := quo.winner() + winner := scores[0].ID if winner != "foo" { t.Errorf("Expected the winner to be foo but is: %s", winner) } @@ -76,7 +76,7 @@ func TestTieScore(t *testing.T) { t.Run("Second tie score test", func(t *testing.T) { // If it is a tie, the first particpant (here: "bar") will win. - conf := config.Config{Participants: []string{"bar:1234", "foo:4321", "baz:3444"}} + conf := config.Config{Nodes: []string{"bar:1234", "foo:4321", "baz:3444"}} quo := New(conf) addVotes(conf, quo) @@ -89,7 +89,7 @@ func TestTieScore(t *testing.T) { t.Errorf("Expected score[0] to be {bar,3}: %v", scores[0]) } - winner, _ := quo.winner() + winner := scores[0].ID if winner != "bar" { t.Errorf("Expected the winner to be bar but is: %s", winner) } @@ -97,7 +97,7 @@ func TestTieScore(t *testing.T) { } func TestExpire(t *testing.T) { - conf := config.Config{Participants: []string{"foo:1234", "bay:4321"}} + conf := config.Config{Nodes: []string{"foo:1234", "bay:4321"}} quo := New(conf) vote1 := vote.New(conf, "foo:334234", " foo bar baz bay\n") @@ -112,8 +112,16 @@ func TestExpire(t *testing.T) { t.Errorf("Expected to have two votes before expiry: %v", quo) } - quo.deleteExpiredVotes() + liveNodes := quo.deleteExpiredVotes() if len(quo.votes) != 1 { - t.Errorf("Expected to have only one vote after expiry: %v", quo) + t.Errorf("Expected to have one vote after expiry: %v", quo) + } + + if len(liveNodes) != 1 { + t.Errorf("Expected to have one live node after expiry: %v", quo) + } + + if liveNodes[0] != "foo" { + t.Errorf("Expected 'foo' to be the live node, but got : %v", liveNodes[0]) } } |
