pull/10/head
isthisnagee 3 years ago
parent 326ffebd24
commit 597972a5f1

@ -3,28 +3,33 @@ package model
import ( import (
"git.nagee.dev/isthisnagee/diary/db" "git.nagee.dev/isthisnagee/diary/db"
"testing" "testing"
"runtime/debug"
) )
func assert_string(t *testing.T, expected string, actual string) { func assert_string(t *testing.T, expected string, actual string) {
if actual != expected { if actual != expected {
t.Log(string(debug.Stack()))
t.Fatalf("(%v, %v)", expected, actual) t.Fatalf("(%v, %v)", expected, actual)
} }
} }
func assert_int(t *testing.T, expected int64, actual int64) { func assert_int(t *testing.T, expected int64, actual int64) {
if actual != expected { if actual != expected {
t.Log(string(debug.Stack()))
t.Fatalf("(%v, %v)", expected, actual) t.Fatalf("(%v, %v)", expected, actual)
} }
} }
func assert_bool(t *testing.T, expected bool, actual bool) { func assert_bool(t *testing.T, expected bool, actual bool) {
if actual != expected { if actual != expected {
t.Log(string(debug.Stack()))
t.Fatalf("(%v, %v)", expected, actual) t.Fatalf("(%v, %v)", expected, actual)
} }
} }
func assert_exists(t *testing.T, actual interface{}) { func assert_exists(t *testing.T, actual interface{}) {
if actual == nil { if actual == nil {
t.Log(string(debug.Stack()))
t.Fatalf("Unexpected nil: %s", actual) t.Fatalf("Unexpected nil: %s", actual)
} }
} }
@ -103,15 +108,30 @@ func DeleteDiaryEntryNotFound(t *testing.T) {
func TestGetDiaryEntries(t *testing.T) { func TestGetDiaryEntries(t *testing.T) {
var app = setup() var app = setup()
var result_1 = app.NewDiaryEntry("Met with Nagee @ 1PM") var result_1 = app.NewDiaryEntry("Met with Nagee @ 1PM")
var result_2 = app.NewDiaryEntry("Met with Nagee @ 2PM") var result_2 = app.NewDiaryEntry("Met with Nagee @ 2PM")
queried_result, _ := app.GetDiaryEntries(inserted_result.Id)
assert_int(t, inserted_result.Id, queried_result.Id) // no numEntries
assert_int(t, inserted_result.CreatedAt, queried_result.CreatedAt) entries := app.GetDiaryEntries(
assert_int(t, inserted_result.Version, queried_result.Version) GetDiaryEntriesQuery{},
assert_string(t, inserted_result.Title, queried_result.Title) )
assert_int(t, int64(len(entries)), 2)
assert_int(t, result_2.Id, entries[0].Id)
assert_int(t, result_1.Id, entries[1].Id)
var numEntries = new(int64)
*numEntries = 1
entries = app.GetDiaryEntries(
GetDiaryEntriesQuery{
NumEntries: numEntries,
},
)
assert_int(t, int64(len(entries)), 1)
assert_int(t, result_2.Id, entries[0].Id)
teardown(app) teardown(app)
} }

Loading…
Cancel
Save