mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-11-09 00:30:02 +00:00
30 lines
823 B
Go
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")
|
|
}
|