diff --git a/cache/cache.go b/cache/cache.go index 53e1730..00394d0 100644 --- a/cache/cache.go +++ b/cache/cache.go @@ -1,11 +1,8 @@ -// Package cache provides an interface to the local Redis cache. +// Package cache provides an interface to a cache. package cache import ( - "context" "time" - - "github.com/valkey-io/valkey-go" ) // A Cache stores and retrieves simple key-value data quickly. @@ -44,63 +41,3 @@ const ( func GlobalSlowmodeKey(platformName string) string { return "global_slowmode_" + platformName } - -// NewValkey creates a new Valkey-backed Cache. -func NewValkey() (Valkey, error) { - c, err := valkey.NewClient(valkey.ClientOption{InitAddress: []string{"cache:6379"}}) - if err != nil { - return Valkey{}, err - } - return Valkey{c: c}, nil -} - -// Valkey implements Cache for a real Valkey database. -type Valkey struct { - c valkey.Client -} - -func (v *Valkey) StoreBool(key string, value bool) error { - return v.c.Do(context.TODO(), v.c.B().Set().Key(key).Value(strFromBool(value)).Build()).Error() -} - -func (v *Valkey) StoreExpiringBool(key string, value bool, expiration time.Duration) error { - return v.c.Do(context.TODO(), v.c.B().Set().Key(key).Value(strFromBool(value)).Ex(expiration).Build()).Error() -} - -func (v *Valkey) FetchBool(key string) (bool, error) { - resp, err := v.c.Do(context.TODO(), v.c.B().Get().Key(key).Build()).ToString() - if err != nil { - if valkey.IsValkeyNil(err) { - return false, nil - } - return false, err - } - return boolFromStr(resp), nil -} - -func (v *Valkey) StoreString(key, value string) error { - return v.c.Do(context.TODO(), v.c.B().Set().Key(key).Value(value).Build()).Error() -} - -func (v *Valkey) StoreExpiringString(key, value string, expiration time.Duration) error { - return v.c.Do(context.TODO(), v.c.B().Set().Key(key).Value(value).Ex(expiration).Build()).Error() -} - -func (v *Valkey) FetchString(key string) (string, error) { - val, err := v.c.Do(context.TODO(), v.c.B().Get().Key(key).Build()).ToString() - if valkey.IsValkeyNil(err) { - return "", nil - } - return val, err -} - -func strFromBool(b bool) string { - if b { - return "true" - } - return "false" -} - -func boolFromStr(s string) bool { - return s == "true" -} diff --git a/cache/cachetest/cachetest.go b/cache/cachetest/cachetest.go index 6784421..40ede50 100644 --- a/cache/cachetest/cachetest.go +++ b/cache/cachetest/cachetest.go @@ -2,54 +2,18 @@ package cachetest import ( - "sync" - "time" -) - -// NewInMemory creates a new InMemoryCache for test. -func NewInMemory() *InMemory { - return &InMemory{d: map[string]any{}} -} + "testing" -// InMemory implements a simple map-based cache for testing. -type InMemory struct { - mtx sync.Mutex // protects writes to d - d map[string]any -} + "github.com/airforce270/airbot/cache" + "gorm.io/gorm" +) -func (c *InMemory) StoreBool(key string, value bool) error { - c.store(key, value) - return nil -} -func (c *InMemory) StoreExpiringBool(key string, value bool, expiration time.Duration) error { - c.store(key, value) - return nil -} -func (c *InMemory) FetchBool(key string) (bool, error) { - val, found := c.d[key] - if !found { - return false, nil +// NewSQLite creates a new cache for test. +func NewSQLite(t *testing.T, db *gorm.DB) cache.Cache { + t.Helper() + c, err := cache.NewSQLite(db) + if err != nil { + t.Fatalf("Failed to create cache for test: %v", err) } - return val.(bool), nil -} -func (c *InMemory) StoreString(key, value string) error { - c.store(key, value) - return nil -} -func (c *InMemory) StoreExpiringString(key, value string, expiration time.Duration) error { - c.store(key, value) - return nil -} -func (c *InMemory) FetchString(key string) (string, error) { - val, found := c.d[key] - if !found { - return "", nil - } - return val.(string), nil -} - -func (c *InMemory) store(key string, value any) { - c.mtx.Lock() - c.d[key] = value - c.mtx.Unlock() + return &c } diff --git a/cache/sqlite.go b/cache/sqlite.go new file mode 100644 index 0000000..2cecac8 --- /dev/null +++ b/cache/sqlite.go @@ -0,0 +1,101 @@ +package cache + +import ( + "fmt" + "time" + + "github.com/airforce270/airbot/database/models" + "gorm.io/gorm" +) + +// NewSQLite creates a new SQLite-backed Cache. +func NewSQLite(db *gorm.DB) (SQLite, error) { + return SQLite{db}, nil +} + +// SQLite implements Cache for a SQLite database. +type SQLite struct { + db *gorm.DB +} + +func (v *SQLite) StoreBool(key string, value bool) error { + item := models.CacheBoolItem{ + Key: key, + Value: value, + } + + if err := v.db.Save(&item).Error; err != nil { + return fmt.Errorf("failed to store %s=%v: %w", key, value, err) + } + + return nil +} + +func (v *SQLite) StoreExpiringBool(key string, value bool, expiration time.Duration) error { + item := models.CacheBoolItem{ + Key: key, + Value: value, + ExpiresAt: time.Now().Add(expiration), + } + + if err := v.db.Save(&item).Error; err != nil { + return fmt.Errorf("failed to store %q=%t: %w", key, value, err) + } + + return nil +} + +func (v *SQLite) FetchBool(key string) (bool, error) { + var item models.CacheBoolItem + + if err := v.db.First(&item, "key = ?", key).Error; err != nil { + return false, fmt.Errorf("failed to fetch %q: %w", key, err) + } + + if !item.ExpiresAt.IsZero() && item.ExpiresAt.Before(time.Now()) { + return false, nil + } + + return item.Value, nil +} + +func (v *SQLite) StoreString(key, value string) error { + item := models.CacheStringItem{ + Key: key, + Value: value, + } + + if err := v.db.Save(&item).Error; err != nil { + return fmt.Errorf("failed to store %q=%q: %w", key, value, err) + } + + return nil +} + +func (v *SQLite) StoreExpiringString(key, value string, expiration time.Duration) error { + item := models.CacheStringItem{ + Key: key, + Value: value, + ExpiresAt: time.Now().Add(expiration), + } + + if err := v.db.Save(&item).Error; err != nil { + return fmt.Errorf("failed to store %q=%q: %w", key, value, err) + } + + return nil +} + +func (v *SQLite) FetchString(key string) (string, error) { + var item models.CacheStringItem + + if err := v.db.First(&item, "key = ?", key).Error; err != nil { + return "", fmt.Errorf("failed to fetch %q: %w", key, err) + } + + if !item.ExpiresAt.IsZero() && item.ExpiresAt.Before(time.Now()) { + return "", nil + } + + return item.Value, nil +} diff --git a/commands/admin/admin_test.go b/commands/admin/admin_test.go index 47599ca..1a8dd58 100644 --- a/commands/admin/admin_test.go +++ b/commands/admin/admin_test.go @@ -546,9 +546,9 @@ func TestReloadConfig(t *testing.T) { ctx := context.Background() db := databasetest.New(t) - cdb := cachetest.NewInMemory() + cdb := cachetest.NewSQLite(t, db) - platform := twitch.NewForTesting(server.URL(t).String(), db) + platform := twitch.NewForTesting(t, server.URL(t).String(), db) const want = "something-specific" cfg := func() string { diff --git a/commands/botinfo/botinfo_test.go b/commands/botinfo/botinfo_test.go index 9b617e1..f64bf19 100644 --- a/commands/botinfo/botinfo_test.go +++ b/commands/botinfo/botinfo_test.go @@ -26,7 +26,7 @@ func TestEchoCommands(t *testing.T) { Prefix: "$", PermissionLevel: permission.Normal, Resources: base.Resources{ - Platform: twitch.NewForTesting("forsen", databasetest.New(t)), + Platform: twitch.NewForTesting(t, "forsen", databasetest.New(t)), }, }, Platform: commandtest.TwitchPlatform, @@ -54,7 +54,7 @@ func TestEchoCommands(t *testing.T) { Prefix: "$", PermissionLevel: permission.Normal, Resources: base.Resources{ - Platform: twitch.NewForTesting("forsen", databasetest.New(t)), + Platform: twitch.NewForTesting(t, "forsen", databasetest.New(t)), }, }, Platform: commandtest.TwitchPlatform, @@ -77,7 +77,7 @@ func TestEchoCommands(t *testing.T) { Prefix: "$", PermissionLevel: permission.Normal, Resources: base.Resources{ - Platform: twitch.NewForTesting("forsen", databasetest.New(t)), + Platform: twitch.NewForTesting(t, "forsen", databasetest.New(t)), }, }, Platform: commandtest.TwitchPlatform, @@ -100,7 +100,7 @@ func TestEchoCommands(t *testing.T) { Prefix: "$", PermissionLevel: permission.Normal, Resources: base.Resources{ - Platform: twitch.NewForTesting("forsen", databasetest.New(t)), + Platform: twitch.NewForTesting(t, "forsen", databasetest.New(t)), }, }, Platform: commandtest.TwitchPlatform, @@ -123,7 +123,7 @@ func TestEchoCommands(t *testing.T) { Prefix: "$", PermissionLevel: permission.Normal, Resources: base.Resources{ - Platform: twitch.NewForTesting("forsen", databasetest.New(t)), + Platform: twitch.NewForTesting(t, "forsen", databasetest.New(t)), }, }, Platform: commandtest.TwitchPlatform, @@ -146,7 +146,7 @@ func TestEchoCommands(t *testing.T) { Prefix: "??", PermissionLevel: permission.Normal, Resources: base.Resources{ - Platform: twitch.NewForTesting("forsen", databasetest.New(t)), + Platform: twitch.NewForTesting(t, "forsen", databasetest.New(t)), }, }, Platform: commandtest.TwitchPlatform, @@ -190,7 +190,7 @@ func TestEchoCommands(t *testing.T) { Prefix: "$", PermissionLevel: permission.Normal, Resources: base.Resources{ - Platform: twitch.NewForTesting("forsen", databasetest.New(t)), + Platform: twitch.NewForTesting(t, "forsen", databasetest.New(t)), }, }, Platform: commandtest.TwitchPlatform, diff --git a/commands/bulk/bulk_test.go b/commands/bulk/bulk_test.go index 9124ec9..87fff84 100644 --- a/commands/bulk/bulk_test.go +++ b/commands/bulk/bulk_test.go @@ -27,7 +27,7 @@ func TestBulkCommands(t *testing.T) { Prefix: "$", PermissionLevel: permission.Mod, Resources: base.Resources{ - Platform: twitch.NewForTesting("forsen", databasetest.New(t)), + Platform: twitch.NewForTesting(t, "forsen", databasetest.New(t)), }, }, Platform: commandtest.TwitchPlatform, @@ -75,7 +75,7 @@ func TestBulkCommands(t *testing.T) { Prefix: "$", PermissionLevel: permission.Mod, Resources: base.Resources{ - Platform: twitch.NewForTesting("forsen", databasetest.New(t)), + Platform: twitch.NewForTesting(t, "forsen", databasetest.New(t)), }, }, Platform: commandtest.TwitchPlatform, diff --git a/commands/commandtest/commandtest.go b/commands/commandtest/commandtest.go index cc5d5fb..b48366e 100644 --- a/commands/commandtest/commandtest.go +++ b/commands/commandtest/commandtest.go @@ -49,12 +49,12 @@ func Run(t *testing.T, tests []Case) { server.Resps = tc.apiResps db := databasetest.New(t) - cdb := cachetest.NewInMemory() + cdb := cachetest.NewSQLite(t, db) var platform base.Platform switch tc.platform { case TwitchPlatform: - platform = twitch.NewForTesting(server.URL(t).String(), db) + platform = twitch.NewForTesting(t, server.URL(t).String(), db) default: t.Fatal("Platform must be set.") } diff --git a/commands/echo/echo_test.go b/commands/echo/echo_test.go index ff70eb0..1144c88 100644 --- a/commands/echo/echo_test.go +++ b/commands/echo/echo_test.go @@ -26,7 +26,7 @@ func TestEchoCommands(t *testing.T) { Prefix: "$", PermissionLevel: permission.Normal, Resources: base.Resources{ - Platform: twitch.NewForTesting("forsen", databasetest.New(t)), + Platform: twitch.NewForTesting(t, "forsen", databasetest.New(t)), }, }, Platform: commandtest.TwitchPlatform, @@ -49,7 +49,7 @@ func TestEchoCommands(t *testing.T) { Prefix: "$", PermissionLevel: permission.Normal, Resources: base.Resources{ - Platform: twitch.NewForTesting("forsen", databasetest.New(t)), + Platform: twitch.NewForTesting(t, "forsen", databasetest.New(t)), }, }, Platform: commandtest.TwitchPlatform, @@ -72,7 +72,7 @@ func TestEchoCommands(t *testing.T) { Prefix: "$", PermissionLevel: permission.Mod, Resources: base.Resources{ - Platform: twitch.NewForTesting("forsen", databasetest.New(t)), + Platform: twitch.NewForTesting(t, "forsen", databasetest.New(t)), }, }, Platform: commandtest.TwitchPlatform, @@ -118,7 +118,7 @@ func TestEchoCommands(t *testing.T) { Prefix: "$", PermissionLevel: permission.Mod, Resources: base.Resources{ - Platform: twitch.NewForTesting("forsen", databasetest.New(t)), + Platform: twitch.NewForTesting(t, "forsen", databasetest.New(t)), }, }, Platform: commandtest.TwitchPlatform, @@ -173,7 +173,7 @@ func TestEchoCommands(t *testing.T) { Prefix: "$", PermissionLevel: permission.Mod, Resources: base.Resources{ - Platform: twitch.NewForTesting("forsen", databasetest.New(t)), + Platform: twitch.NewForTesting(t, "forsen", databasetest.New(t)), }, }, Platform: commandtest.TwitchPlatform, @@ -211,7 +211,7 @@ func TestEchoCommands(t *testing.T) { Prefix: "$", PermissionLevel: permission.Normal, Resources: base.Resources{ - Platform: twitch.NewForTesting("forsen", databasetest.New(t)), + Platform: twitch.NewForTesting(t, "forsen", databasetest.New(t)), }, }, Platform: commandtest.TwitchPlatform, @@ -235,7 +235,7 @@ func TestEchoCommands(t *testing.T) { Prefix: "$", PermissionLevel: permission.Normal, Resources: base.Resources{ - Platform: twitch.NewForTesting("forsen", databasetest.New(t)), + Platform: twitch.NewForTesting(t, "forsen", databasetest.New(t)), }, }, Platform: commandtest.TwitchPlatform, @@ -258,7 +258,7 @@ func TestEchoCommands(t *testing.T) { Prefix: "$", PermissionLevel: permission.Normal, Resources: base.Resources{ - Platform: twitch.NewForTesting("forsen", databasetest.New(t)), + Platform: twitch.NewForTesting(t, "forsen", databasetest.New(t)), }, }, Platform: commandtest.TwitchPlatform, diff --git a/commands/fun/fun_test.go b/commands/fun/fun_test.go index 0913982..f3e3199 100644 --- a/commands/fun/fun_test.go +++ b/commands/fun/fun_test.go @@ -28,7 +28,7 @@ func TestFunCommands(t *testing.T) { Prefix: "$", PermissionLevel: permission.Normal, Resources: base.Resources{ - Platform: twitch.NewForTesting("forsen", databasetest.New(t)), + Platform: twitch.NewForTesting(t, "forsen", databasetest.New(t)), }, }, Platform: commandtest.TwitchPlatform, @@ -53,7 +53,7 @@ func TestFunCommands(t *testing.T) { Prefix: "$", PermissionLevel: permission.Normal, Resources: base.Resources{ - Platform: twitch.NewForTesting("forsen", databasetest.New(t)), + Platform: twitch.NewForTesting(t, "forsen", databasetest.New(t)), }, }, Platform: commandtest.TwitchPlatform, @@ -78,7 +78,7 @@ func TestFunCommands(t *testing.T) { Prefix: "$", PermissionLevel: permission.Normal, Resources: base.Resources{ - Platform: twitch.NewForTesting("forsen", databasetest.New(t)), + Platform: twitch.NewForTesting(t, "forsen", databasetest.New(t)), }, }, Platform: commandtest.TwitchPlatform, diff --git a/database/models/models.go b/database/models/models.go index 9d14b2f..e880c39 100644 --- a/database/models/models.go +++ b/database/models/models.go @@ -10,6 +10,8 @@ import ( // AllModels contains one of each defined data model, for auto-migrations. var AllModels = []any{ BotBan{}, + CacheBoolItem{}, + CacheStringItem{}, ChannelCommandCooldown{}, Duel{}, GambaTransaction{}, @@ -31,6 +33,34 @@ type BotBan struct { BannedAt time.Time } +// CacheBoolItem is a cache item of type bool. +type CacheBoolItem struct { + CreatedAt time.Time + UpdatedAt time.Time + + // Key is the item's key. + Key string `gorm:"primarykey"` + // Value is the item's value. + Value bool + // ExpiresAt is when the item expires. + // If 0, the item never expires. + ExpiresAt time.Time +} + +// CacheBoolItem is a cache item of type string. +type CacheStringItem struct { + CreatedAt time.Time + UpdatedAt time.Time + + // Key is the item's key. + Key string `gorm:"primarykey"` + // Value is the item's value. + Value string + // ExpiresAt is when the item expires. + // If 0, the item never expires. + ExpiresAt time.Time +} + // ChannelCommandCooldown contains a record of a command cooldown in a channel. type ChannelCommandCooldown struct { gorm.Model diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index 21a9dce..39c10fe 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -4,9 +4,6 @@ services: env_file: .env environment: - RUNNING_IN_DOCKER=true - depends_on: - cache: - condition: service_healthy stdin_open: true tty: true volumes: diff --git a/docker-compose.yml b/docker-compose.yml index 9d84036..c9909e4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,22 +2,6 @@ # https://github.com/docker/awesome-compose services: - cache: - image: valkey/valkey:7.2-alpine - restart: always - environment: - - ALLOW_EMPTY_PASSWORD=yes - expose: - - 6379 - command: valkey-server --save 30 1 - volumes: - - redis-data:/data - healthcheck: - test: [ "CMD", "valkey-cli", "ping" ] - interval: 1s - timeout: 5s - retries: 10 - server: build: context: . @@ -29,14 +13,10 @@ services: env_file: .env environment: - RUNNING_IN_DOCKER=true - depends_on: - cache: - condition: service_healthy volumes: - sqlite-data:/data - type: bind source: ./config.toml target: /config.toml volumes: - redis-data: sqlite-data: diff --git a/gamba/gamba_test.go b/gamba/gamba_test.go index 60ada7b..46ba761 100644 --- a/gamba/gamba_test.go +++ b/gamba/gamba_test.go @@ -170,7 +170,7 @@ func TestGrantPoints(t *testing.T) { } ps := map[string]base.Platform{ - "FakeTwitch": twitch.NewForTesting(server.URL, db), + "FakeTwitch": twitch.NewForTesting(t, server.URL, db), } grantPoints(ps, db) @@ -216,7 +216,7 @@ func TestGetInactiveUsers(t *testing.T) { } ps := map[string]base.Platform{ - "FakeTwitch": twitch.NewForTesting(server.URL, db), + "FakeTwitch": twitch.NewForTesting(t, server.URL, db), } got := getInactiveUsers(ps, db) diff --git a/go.mod b/go.mod index 8963245..7bb5365 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,6 @@ require ( github.com/nicklaw5/helix/v2 v2.30.0 github.com/pelletier/go-toml/v2 v2.2.2 github.com/shirou/gopsutil/v3 v3.24.5 - github.com/valkey-io/valkey-go v1.0.44 golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa golang.org/x/oauth2 v0.22.0 golang.org/x/sync v0.8.0 diff --git a/go.sum b/go.sum index d867901..8626f44 100644 --- a/go.sum +++ b/go.sum @@ -169,8 +169,6 @@ github.com/onsi/gomega v1.27.1/go.mod h1:aHX5xOykVYzWOV4WqQy0sy8BQptgukenXpCXfad github.com/onsi/gomega v1.27.3/go.mod h1:5vG284IBtfDAmDyrK+eGyZmUgUlmi+Wngqo557cZ6Gw= github.com/onsi/gomega v1.27.4/go.mod h1:riYq/GJKh8hhoM01HN6Vmuy93AarCXCBGpvFDK3q3fQ= github.com/onsi/gomega v1.27.6/go.mod h1:PIQNjfQwkP3aQAH7lf7j87O/5FiNr+ZR8+ipb+qQlhg= -github.com/onsi/gomega v1.31.1 h1:KYppCUK+bUgAZwHOu7EXVBKyQA6ILvOESHkn/tgoqvo= -github.com/onsi/gomega v1.31.1/go.mod h1:y40C95dwAD1Nz36SsEnxvfFe8FFfNxzI5eJ0EYGyAy0= github.com/openzipkin/zipkin-go v0.1.1/go.mod h1:NtoC/o8u3JlF1lSlyPNswIbeQH9bJTmOf0Erfk+hxe8= github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM= github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= @@ -242,8 +240,6 @@ github.com/tklauser/go-sysconf v0.3.14 h1:g5vzr9iPFFz24v2KZXs/pvpvh8/V9Fw6vQK5ZZ github.com/tklauser/go-sysconf v0.3.14/go.mod h1:1ym4lWMLUOhuBOPGtRcJm7tEGX4SCYNEEEtghGG/8uY= github.com/tklauser/numcpus v0.8.0 h1:Mx4Wwe/FjZLeQsK/6kt2EOepwwSl7SmJrK5bV/dXYgY= github.com/tklauser/numcpus v0.8.0/go.mod h1:ZJZlAY+dmR4eut8epnzf0u/VwodKmryxR8txiloSqBE= -github.com/valkey-io/valkey-go v1.0.44 h1:j3wPHiGLX2wQ0Jwe/hWODbEEj2dGLMx+Qoc8aAHOO2o= -github.com/valkey-io/valkey-go v1.0.44/go.mod h1:LXqAbjygRuA1YRocojTslAGx2dQB4p8feaseGviWka4= github.com/viant/assertly v0.4.8/go.mod h1:aGifi++jvCrUaklKEKT0BU95igDNaqkvz+49uaYMPRU= github.com/viant/toolbox v0.24.0/go.mod h1:OxMCG57V0PXuIP2HNQrtJf2CjqdmbrOx5EkMILuUhzM= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= diff --git a/main.go b/main.go index ec7a4ee..be6ca6b 100644 --- a/main.go +++ b/main.go @@ -71,7 +71,7 @@ func start(ctx context.Context) (cleanup.Cleaner, postStartupResources, error) { } log.Printf("Connecting to cache...") - cdb, err := cache.NewValkey() + cdb, err := cache.NewSQLite(db) if err != nil { return nil, postStartupResources{}, fmt.Errorf("failed to connect to cache: %w", err) } diff --git a/platforms/twitch/twitch.go b/platforms/twitch/twitch.go index 70e74a1..c9939e7 100644 --- a/platforms/twitch/twitch.go +++ b/platforms/twitch/twitch.go @@ -12,6 +12,7 @@ import ( "strconv" "strings" "sync" + "testing" "time" "github.com/airforce270/airbot/apiclients/ivr" @@ -728,15 +729,17 @@ func New(username string, owners []string, clientID, clientSecret, accessToken, } // New creates a new Twitch connection for testing. -func NewForTesting(url string, db *gorm.DB) *Twitch { +func NewForTesting(t *testing.T, url string, db *gorm.DB) *Twitch { + t.Helper() helixClient, err := helix.NewClient(&helix.Options{ ClientID: "fake-client-id", UserAccessToken: "fake-access-token", APIBaseURL: url, }) if err != nil { - panic(err) + t.Fatalf("Failed to create Helix client for test: %v", err) } + return &Twitch{ username: "fake-username", id: "", @@ -751,7 +754,7 @@ func NewForTesting(url string, db *gorm.DB) *Twitch { irc: nil, helix: helixClient, db: db, - cdb: cachetest.NewInMemory(), + cdb: cachetest.NewSQLite(t, db), } } diff --git a/platforms/twitch/twitch_test.go b/platforms/twitch/twitch_test.go index bf52d2d..6dea7f9 100644 --- a/platforms/twitch/twitch_test.go +++ b/platforms/twitch/twitch_test.go @@ -17,7 +17,7 @@ func TestTwitch_CurrentUsers(t *testing.T) { t.Parallel() db := databasetest.New(t) server := newTestServer() - tw := NewForTesting(server.URL, db) + tw := NewForTesting(t, server.URL, db) got, err := tw.CurrentUsers() if err != nil {