package model import ( "database/sql" "fmt" "os" "path/filepath" "testing" ) func TestRecipesRead(t *testing.T) { 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) 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) } r := make(Recipes, 0) err = database.Transaction(func(tx *sql.Tx) error { return r.Read(tx) }) if err != nil { t.Fatalf("Failed to read recipes from database: %s", err) } if len(r) != 2 { // TODO this needs to be aligned with model/testrecipes.go t.Fatalf("Expected a list of one recipe but got %d", len(r)) } }