|
|
@ -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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -98,5 +103,35 @@ func DeleteDiaryEntryNotFound(t *testing.T) {
|
|
|
|
t.Fatalf("Expected NotFoundError, got %s", err_type)
|
|
|
|
t.Fatalf("Expected NotFoundError, got %s", err_type)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
teardown(app)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestGetDiaryEntries(t *testing.T) {
|
|
|
|
|
|
|
|
var app = setup()
|
|
|
|
|
|
|
|
var result_1 = app.NewDiaryEntry("Met with Nagee @ 1PM")
|
|
|
|
|
|
|
|
var result_2 = app.NewDiaryEntry("Met with Nagee @ 2PM")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// no numEntries
|
|
|
|
|
|
|
|
entries := app.GetDiaryEntries(
|
|
|
|
|
|
|
|
GetDiaryEntriesQuery{},
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|