diff options
Diffstat (limited to 'internal/vote/vote_test.go')
| -rw-r--r-- | internal/vote/vote_test.go | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/internal/vote/vote_test.go b/internal/vote/vote_test.go new file mode 100644 index 0000000..0986e00 --- /dev/null +++ b/internal/vote/vote_test.go @@ -0,0 +1,46 @@ +package vote + +import ( + "testing" + "time" + + "codeberg.org/snonux/gorum/internal/config" +) + +func TestVote(t *testing.T) { + conf := config.Config{Participants: []string{"foo:1234", "bay:4321"}} + v := New(conf, "earth:334234", " foo bar baz bay\n") + + if v.From != "earth" { + t.Errorf("Expected vote to come from earth but came from %s", v.From) + } + + if len(v.IDs) != 2 { + t.Errorf("Expected vote length to be 2 but is %d", len(v.IDs)) + } + + if v.IDs[0] != "foo" { + t.Errorf("Expected vote 1 to be foo but is %s", v.IDs[0]) + } + + if v.IDs[1] != "bay" { + t.Errorf("Expected vote 2 to be bay but is %s", v.IDs[1]) + } +} + +func TestVoteExpiry(t *testing.T) { + conf := config.Config{Participants: []string{"foo:1234", "bay:4321"}} + v := New(conf, "earth:334234", " foo bar baz bay\n") + + // Set expiry 1h into the future + v.ExpiresAt = time.Now().Add(1 * time.Hour) + if v.Expired() { + t.Errorf("Didn't expect vote to be expired") + } + + // Set expiry to now + v.ExpiresAt = time.Now() + if !v.Expired() { + t.Errorf("Expected vote to be expired") + } +} |
