package model import ( "reflect" "testing" ) func TestRecipeCrud(t *testing.T) { InitStorage() defer RemoveStorage() InitDatabase() defer CloseDatabase() var original, readback, update, updated, deleted Recipe recipes := RecipeTestData() original = recipes[0] update = recipes[1] err := original.Create() if err != nil { t.Fatalf("Failed to create test recipe in DB: %v\n", err) } readback.Id = original.Id err = readback.Read() if err != nil { t.Fatalf("Failed to create test recipe in DB: %v\n", err) } if !reflect.DeepEqual(original, readback) { t.Fatalf("Recipes did not match after create / read cycle") } update.Id = original.Id err = update.Update() if err != nil { t.Fatalf("Failed to update recipe: %v\n", err) } updated.Id = original.Id err = updated.Read() if err != nil { t.Fatalf("Failed to read back updated recipe: %v\n", err) } if !reflect.DeepEqual(updated, update) { t.Fatalf("Recipes did not match after update / read cycle") } if reflect.DeepEqual(updated, original) { t.Fatalf("Updated and original recipe match") } err = updated.Delete() if err != nil { t.Fatalf("Failed to delete updated recipe: %v\n", err) } deleted.Id = updated.Id err = deleted.Read() if err == nil { t.Fatalf("Was able to read back deleted recipe") } }