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
|
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 {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue