twitch-bot/internal/actors/counter/database_test.go
Knut Ahlers 1409a4bd34
[lint] Fix v2 import path not carrying version
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2022-10-23 15:06:45 +02:00

30 lines
823 B
Go

package counter
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/Luzifer/twitch-bot/v2/pkg/database"
)
func TestCounterStoreLoop(t *testing.T) {
dbc := database.GetTestDatabase(t)
dbc.DB().AutoMigrate(&counter{})
counterName := "mytestcounter"
v, err := GetCounterValue(dbc, counterName)
assert.NoError(t, err, "reading non-existent counter")
assert.Equal(t, int64(0), v, "expecting 0 counter value on non-existent counter")
err = UpdateCounter(dbc, counterName, 5, true)
assert.NoError(t, err, "inserting counter")
err = UpdateCounter(dbc, counterName, 1, false)
assert.NoError(t, err, "updating counter")
v, err = GetCounterValue(dbc, counterName)
assert.NoError(t, err, "reading existent counter")
assert.Equal(t, int64(6), v, "expecting counter value on existing counter")
}