package model import ( "isthisnagee.com/tools/diary/db" "testing" ) func assert_string(t *testing.T, expected string, actual string) { if actual != expected { t.Fatalf("(%s, %s)", expected, actual) } } func assert_exists(t *testing.T, actual interface{}) { if actual == nil { t.Fatalf("Unexpected nil: %s", actual) } } func setup() App { var db_ctx, err = db.Init(":memory:") if err != nil { panic(err) } return App{db_ctx} } func teardown(app App) { app.Db.Close() } func TestNewDiaryEntry(t *testing.T) { var app = setup() var result = app.NewDiaryEntry("Met with Nagee @ 1PM") assert_string(t, "Met with Nagee @ 1PM", result.Title) assert_exists(t, result.Id) assert_exists(t, result.CreatedAt) assert_exists(t, result.Version) teardown(app) }