summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2024-10-23 18:41:45 +0200
committerxengineering <me@xengineering.eu>2024-10-23 18:42:20 +0200
commit9704fcb5e98ff4cfee39b9754b8fb112998e4194 (patch)
treeb5a7663a57040ab15b3d11b13cd1b6f5dcf58e8c
parente8f52156bf07a7668fb434eadb0e22f3e7dad648 (diff)
downloadceres-9704fcb5e98ff4cfee39b9754b8fb112998e4194.tar
ceres-9704fcb5e98ff4cfee39b9754b8fb112998e4194.tar.zst
ceres-9704fcb5e98ff4cfee39b9754b8fb112998e4194.zip
Fix unit tests
API changes were not adopted in the unit tests.
-rw-r--r--model/recipe_test.go28
-rw-r--r--model/recipes_test.go30
2 files changed, 48 insertions, 10 deletions
diff --git a/model/recipe_test.go b/model/recipe_test.go
index 1119d20..6bc7b54 100644
--- a/model/recipe_test.go
+++ b/model/recipe_test.go
@@ -20,11 +20,28 @@ func TestRecipeCrud(t *testing.T) {
storage := NewStorage(storagePath)
- ConnectDatabase(filepath.Join(storage.Path, "ceres.sqlite3"))
- defer DisconnectDatabase()
- MigrateDatabase("dummy_version")
+ database, err := OpenDB(filepath.Join(storage.Path, "ceres.sqlite3"))
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer func() {
+ err := database.Close()
+ if err != nil {
+ t.Fatal(err)
+ }
+ }()
+
+ err = database.Migrate()
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ err = database.CreateExamples()
+ if err != nil {
+ t.Fatal(err)
+ }
- Transaction(func(tx *sql.Tx) error {
+ err = database.Transaction(func(tx *sql.Tx) error {
var original, readback, update, updated, deleted Recipe
recipes := RecipeTestData()
@@ -82,4 +99,7 @@ func TestRecipeCrud(t *testing.T) {
return nil
})
+ if err != nil {
+ t.Fatalf("Failed to read recipes from database: %s", err)
+ }
}
diff --git a/model/recipes_test.go b/model/recipes_test.go
index ddd1543..232fec8 100644
--- a/model/recipes_test.go
+++ b/model/recipes_test.go
@@ -1,6 +1,7 @@
package model
import (
+ "database/sql"
"fmt"
"os"
"path/filepath"
@@ -18,17 +19,34 @@ func TestRecipesRead(t *testing.T) {
storage := NewStorage(storagePath)
- ConnectDatabase(filepath.Join(storage.Path, "ceres.sqlite3"))
- defer DisconnectDatabase()
- MigrateDatabase("dummy_version")
+ database, err := OpenDB(filepath.Join(storage.Path, "ceres.sqlite3"))
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer func() {
+ err := database.Close()
+ if err != nil {
+ t.Fatal(err)
+ }
+ }()
+
+ err = database.Migrate()
+ if err != nil {
+ t.Fatal(err)
+ }
- InjectExampleRecipes()
+ err = database.CreateExamples()
+ if err != nil {
+ t.Fatal(err)
+ }
r := make(Recipes, 0)
- err = r.Read()
+ err = database.Transaction(func(tx *sql.Tx) error {
+ return r.Read(tx)
+ })
if err != nil {
- t.Fatalf("Failed to read Recipes: %v\n", err)
+ t.Fatalf("Failed to read recipes from database: %s", err)
}
if len(r) != 2 { // TODO this needs to be aligned with model/testrecipes.go