diff options
| author | Paul Buetow <paul@buetow.org> | 2023-07-02 20:14:25 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2023-07-02 20:14:25 +0300 |
| commit | baa44274ced7476e0243b30f93493cb1c06a9b40 (patch) | |
| tree | e3acaace7f2d9cc0f466f20c916da7aabf9c7f25 /internal | |
| parent | 9e099d15bd31f80751b9b2ac38c31bf130528329 (diff) | |
refactor vote.New to use var arg
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/quorum/quorum.go | 2 | ||||
| -rw-r--r-- | internal/quorum/quorum_test.go | 22 | ||||
| -rw-r--r-- | internal/vote/vote.go | 2 | ||||
| -rw-r--r-- | internal/vote/vote_test.go | 6 |
4 files changed, 16 insertions, 16 deletions
diff --git a/internal/quorum/quorum.go b/internal/quorum/quorum.go index bbdc640..04e41ce 100644 --- a/internal/quorum/quorum.go +++ b/internal/quorum/quorum.go @@ -211,5 +211,5 @@ func (quo Quorum) expireOldVotes() (vote.Vote, error) { delete(quo.votes, e) } - return vote.New(quo.conf, live) + return vote.New(quo.conf, live...) } diff --git a/internal/quorum/quorum_test.go b/internal/quorum/quorum_test.go index 5bf6834..7ddcdb2 100644 --- a/internal/quorum/quorum_test.go +++ b/internal/quorum/quorum_test.go @@ -16,22 +16,22 @@ func TestScore(t *testing.T) { conf, _ := config.New(config.WithNodes("foo:1234", "bar:4321", "baz:3444")) quo := New(conf) - vote1, _ := vote.New(conf, []string{"foo", "bar"}) + vote1, _ := vote.New(conf, "foo", "bar") vote1.FromID = "foo" vote1.ExpiresAt = inOneHour quo.vote(vote1) - vote2, _ := vote.New(conf, []string{"bar", "baz"}) + vote2, _ := vote.New(conf, "bar", "baz") vote2.FromID = "bar" vote2.ExpiresAt = inOneHour quo.vote(vote2) - vote3_dup, _ := vote.New(conf, []string{"bar", "baz"}) + vote3_dup, _ := vote.New(conf, "bar", "baz") vote3_dup.FromID = "bar" vote3_dup.ExpiresAt = inOneHour quo.vote(vote3_dup) - vote4, _ := vote.New(conf, []string{"foo", "bar", "baz"}) + vote4, _ := vote.New(conf, "foo", "bar", "baz") vote4.FromID = "baz" vote4.ExpiresAt = inOneHour quo.vote(vote4) @@ -49,17 +49,17 @@ func TestScore(t *testing.T) { func TestTieScore(t *testing.T) { addVotes := func(conf config.Config, quo Quorum) { - vote1, _ := vote.New(conf, []string{"foo", "bar", "baz"}) + vote1, _ := vote.New(conf, "foo", "bar", "baz") vote1.FromID = "foo" vote1.ExpiresAt = inOneHour quo.vote(vote1) - vote2, _ := vote.New(conf, []string{"foo", "bar", "baz"}) + vote2, _ := vote.New(conf, "foo", "bar", "baz") vote2.FromID = "bar" vote2.ExpiresAt = inOneHour quo.vote(vote2) - vote3, _ := vote.New(conf, []string{"foo", "bar", "baz"}) + vote3, _ := vote.New(conf, "foo", "bar", "baz") vote3.FromID = "baz" vote3.ExpiresAt = inOneHour quo.vote(vote3) @@ -112,12 +112,12 @@ func TestExpire(t *testing.T) { conf, _ := config.New(config.WithNodes("foo:1234", "bar:4321", "bay:2212")) quo := New(conf) - vote1, _ := vote.New(conf, []string{"bar", "baz", "bay"}) + vote1, _ := vote.New(conf, "bar", "baz", "bay") vote1.FromID = "foo" vote1.ExpiresAt = inOneHour quo.vote(vote1) - vote2, _ := vote.New(conf, []string{"foo", "bar", "baz"}) + vote2, _ := vote.New(conf, "foo", "bar", "baz") vote2.FromID = "bar" vote2.ExpiresAt = time.Now() quo.vote(vote2) @@ -144,11 +144,11 @@ func TestLiveNodes(t *testing.T) { conf, _ := config.New(config.WithNodes("foo:1234", "bay:4321")) quo := New(conf) - vote1, _ := vote.New(conf, []string{"bar", "baz", "bay"}) + vote1, _ := vote.New(conf, "bar", "baz", "bay") vote1.ExpiresAt = inOneHour quo.vote(vote1) - vote2, _ := vote.New(conf, []string{"foo", "bar", "baz"}) + vote2, _ := vote.New(conf, "foo", "bar", "baz") vote2.ExpiresAt = inOneHour quo.vote(vote2) diff --git a/internal/vote/vote.go b/internal/vote/vote.go index 5378655..4772703 100644 --- a/internal/vote/vote.go +++ b/internal/vote/vote.go @@ -15,7 +15,7 @@ type Vote struct { ExpiresAt time.Time `json:"-"` } -func New(conf config.Config, ids []string) (Vote, error) { +func New(conf config.Config, ids ...string) (Vote, error) { var v Vote v.FromID = conf.MyID diff --git a/internal/vote/vote_test.go b/internal/vote/vote_test.go index f1221b2..df05da0 100644 --- a/internal/vote/vote_test.go +++ b/internal/vote/vote_test.go @@ -11,7 +11,7 @@ func TestVote(t *testing.T) { t.Parallel() conf, _ := config.New(config.WithMyID("foo.zone")) - v, _ := New(conf, []string{"foo", "bar", "baz", "bay"}) + v, _ := New(conf, "foo", "bar", "baz", "bay") if v.FromID != "foo.zone" { t.Errorf("Expected vote to come from foo.zone but came from %s", v.FromID) @@ -34,7 +34,7 @@ func TestVoteExpiry(t *testing.T) { t.Parallel() conf, _ := config.New(config.WithMyID("foo.zone")) - v, _ := New(conf, []string{"foo", "bar", "baz", "bay"}) + v, _ := New(conf, "foo", "bar", "baz", "bay") // Set expiry 1h into the future v.ExpiresAt = time.Now().Add(1 * time.Hour) @@ -53,7 +53,7 @@ func TestMarshalling(t *testing.T) { t.Parallel() conf, _ := config.New(config.WithMyID("foo.zone")) - v, _ := New(conf, []string{"foo", "bar", "baz", "bay"}) + v, _ := New(conf, "foo", "bar", "baz", "bay") jsonStr, err := v.ToJSON() if err != nil { |
