fix: database tests for cache
This commit is contained in:
parent
d09b763aa7
commit
8fa74fd046
1 changed files with 9 additions and 3 deletions
12
internal/cache/cache_test.go
vendored
12
internal/cache/cache_test.go
vendored
|
@ -1,6 +1,8 @@
|
|||
package cache
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
@ -8,15 +10,16 @@ import (
|
|||
)
|
||||
|
||||
func TestCache(t *testing.T) {
|
||||
// Create temporary database for testing
|
||||
database, err := db.New("test_cache.db")
|
||||
// Create temporary database for testing with unique name
|
||||
dbFile := fmt.Sprintf("test_cache_%d.db", time.Now().UnixNano())
|
||||
database, err := db.New(dbFile)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create test database: %v", err)
|
||||
}
|
||||
defer func() {
|
||||
_ = database.Close()
|
||||
// Clean up test database file
|
||||
// os.Remove("test_cache.db")
|
||||
_ = os.Remove(dbFile)
|
||||
}()
|
||||
|
||||
// Create cache instance
|
||||
|
@ -76,6 +79,9 @@ func TestCache(t *testing.T) {
|
|||
t.Run("Exists", func(t *testing.T) {
|
||||
existsKey := "exists_key"
|
||||
|
||||
// Make sure the key doesn't exist initially by deleting it
|
||||
_ = cache.Delete(existsKey)
|
||||
|
||||
// Should not exist initially
|
||||
exists, err := cache.Exists(existsKey)
|
||||
if err != nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue