mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-11-14 02:52:42 +00:00
38 lines
1,021 B
Go
38 lines
1,021 B
Go
|
package timer
|
||
|
|
||
|
import (
|
||
|
"testing"
|
||
|
"time"
|
||
|
|
||
|
"github.com/stretchr/testify/assert"
|
||
|
"github.com/stretchr/testify/require"
|
||
|
|
||
|
"github.com/Luzifer/twitch-bot/pkg/database"
|
||
|
)
|
||
|
|
||
|
func TestTimerRoundtrip(t *testing.T) {
|
||
|
dbc := database.GetTestDatabase(t)
|
||
|
ts, err := New(dbc)
|
||
|
require.NoError(t, err, "creating timer service")
|
||
|
|
||
|
id := "78c0176a-938e-497b-bed4-83d5bdec6caf"
|
||
|
|
||
|
has, err := ts.HasTimer(id)
|
||
|
require.NoError(t, err, "checking for non-existent timer")
|
||
|
assert.False(t, has, "checking existence of non-existing timer")
|
||
|
|
||
|
err = ts.SetTimer(id, time.Now().Add(500*time.Millisecond))
|
||
|
require.NoError(t, err, "setting timer")
|
||
|
|
||
|
has, err = ts.HasTimer(id)
|
||
|
require.NoError(t, err, "checking for existent timer")
|
||
|
assert.True(t, has, "checking existence of existing timer")
|
||
|
|
||
|
err = ts.SetTimer(id, time.Now().Add(-time.Millisecond))
|
||
|
require.NoError(t, err, "updating timer")
|
||
|
|
||
|
has, err = ts.HasTimer(id)
|
||
|
require.NoError(t, err, "checking for expired timer")
|
||
|
assert.False(t, has, "checking existence of expired timer")
|
||
|
}
|