summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2024-05-08 21:20:39 +0200
committerxengineering <me@xengineering.eu>2024-05-08 21:20:39 +0200
commit9073adf62f2fa78190c8296c5f6f6c9fb1963063 (patch)
treeab6063d46e59048cbe02bf9cf396600c752a63ae
parent5a09313066f5594ca9e3917c00821e443dcba7bc (diff)
downloadceres-9073adf62f2fa78190c8296c5f6f6c9fb1963063.tar
ceres-9073adf62f2fa78190c8296c5f6f6c9fb1963063.tar.zst
ceres-9073adf62f2fa78190c8296c5f6f6c9fb1963063.zip
Fix unit tests
-rw-r--r--model/recipe_test.go19
-rw-r--r--model/recipes_test.go21
2 files changed, 33 insertions, 7 deletions
diff --git a/model/recipe_test.go b/model/recipe_test.go
index 508cf53..7b6c14c 100644
--- a/model/recipe_test.go
+++ b/model/recipe_test.go
@@ -3,13 +3,26 @@ package model
import (
"reflect"
"testing"
+ "path/filepath"
+ "os"
+ "fmt"
)
func TestRecipeCrud(t *testing.T) {
- InitStorage()
- defer RemoveStorage()
+ storagePath, err := os.MkdirTemp("", "ceres")
+ if err != nil {
+ fmt.Println("Error creating temporary directory:", err)
+ return
+ }
+ t.Logf("Storage path: %v\n", storagePath)
+ defer os.RemoveAll(storagePath)
+
+ storage := NewStorage(storagePath)
+ if !storage.Exists() {
+ storage.Create()
+ }
- InitDatabase()
+ InitDatabase(filepath.Join(storage.Path, "ceres.sqlite3"))
defer CloseDatabase()
tx, err := NewTx()
diff --git a/model/recipes_test.go b/model/recipes_test.go
index ac5d870..15b90b6 100644
--- a/model/recipes_test.go
+++ b/model/recipes_test.go
@@ -2,20 +2,33 @@ package model
import (
"testing"
+ "os"
+ "fmt"
+ "path/filepath"
)
func TestRecipesRead(t *testing.T) {
- InitStorage()
- defer RemoveStorage()
+ storagePath, err := os.MkdirTemp("", "ceres")
+ if err != nil {
+ fmt.Println("Error creating temporary directory:", err)
+ return
+ }
+ t.Logf("Storage path: %v\n", storagePath)
+ defer os.RemoveAll(storagePath)
+
+ storage := NewStorage(storagePath)
+ if !storage.Exists() {
+ storage.Create()
+ }
- InitDatabase()
+ InitDatabase(filepath.Join(storage.Path, "ceres.sqlite3"))
defer CloseDatabase()
InjectTestRecipes()
r := make(Recipes, 0)
- err := r.Read()
+ err = r.Read()
if err != nil {
t.Fatalf("Failed to read Recipes: %v\n", err)
}