mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-11-14 02:52:42 +00:00
31 lines
820 B
Go
31 lines
820 B
Go
|
package counter
|
||
|
|
||
|
import (
|
||
|
"testing"
|
||
|
|
||
|
"github.com/stretchr/testify/assert"
|
||
|
|
||
|
"github.com/Luzifer/twitch-bot/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")
|
||
|
}
|