You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
diary/model/model_test.go

44 lines
780 B

3 years ago
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)
}