fix: database tests for cache

This commit is contained in:
Felipe M 2025-06-13 09:26:49 +02:00
parent d09b763aa7
commit 8fa74fd046
Signed by: fmartingr
GPG key ID: CCFBC5637D4000A8

View file

@ -1,6 +1,8 @@
package cache package cache
import ( import (
"fmt"
"os"
"testing" "testing"
"time" "time"
@ -8,15 +10,16 @@ import (
) )
func TestCache(t *testing.T) { func TestCache(t *testing.T) {
// Create temporary database for testing // Create temporary database for testing with unique name
database, err := db.New("test_cache.db") dbFile := fmt.Sprintf("test_cache_%d.db", time.Now().UnixNano())
database, err := db.New(dbFile)
if err != nil { if err != nil {
t.Fatalf("Failed to create test database: %v", err) t.Fatalf("Failed to create test database: %v", err)
} }
defer func() { defer func() {
_ = database.Close() _ = database.Close()
// Clean up test database file // Clean up test database file
// os.Remove("test_cache.db") _ = os.Remove(dbFile)
}() }()
// Create cache instance // Create cache instance
@ -76,6 +79,9 @@ func TestCache(t *testing.T) {
t.Run("Exists", func(t *testing.T) { t.Run("Exists", func(t *testing.T) {
existsKey := "exists_key" existsKey := "exists_key"
// Make sure the key doesn't exist initially by deleting it
_ = cache.Delete(existsKey)
// Should not exist initially // Should not exist initially
exists, err := cache.Exists(existsKey) exists, err := cache.Exists(existsKey)
if err != nil { if err != nil {