Test Preload won't panic when nothing found

This commit is contained in:
Jinzhu 2015-12-16 10:35:22 +08:00
parent b2a66e79e8
commit 861c477a33
1 changed files with 14 additions and 0 deletions

View File

@ -6,6 +6,8 @@ import (
"os"
"reflect"
"testing"
"github.com/jinzhu/gorm"
)
func getPreloadUser(name string) *User {
@ -130,6 +132,10 @@ func TestNestedPreload1(t *testing.T) {
if !reflect.DeepEqual(got, want) {
t.Errorf("got %s; want %s", toJSONString(got), toJSONString(want))
}
if err := DB.Preload("Level2").Preload("Level2.Level1").Find(&got, "name = ?", "not_found").Error; err != gorm.RecordNotFound {
panic(err)
}
}
func TestNestedPreload2(t *testing.T) {
@ -836,6 +842,10 @@ func TestNestedManyToManyPreload(t *testing.T) {
if !reflect.DeepEqual(got, want) {
t.Errorf("got %s; want %s", toJSONString(got), toJSONString(want))
}
if err := DB.Preload("Level2s.Level1s").Find(&got, "value = ?", "not_found").Error; err != gorm.RecordNotFound {
panic(err)
}
}
func TestNestedManyToManyPreload2(t *testing.T) {
@ -889,6 +899,10 @@ func TestNestedManyToManyPreload2(t *testing.T) {
if !reflect.DeepEqual(got, want) {
t.Errorf("got %s; want %s", toJSONString(got), toJSONString(want))
}
if err := DB.Preload("Level2.Level1s").Find(&got, "value = ?", "not_found").Error; err != gorm.RecordNotFound {
panic(err)
}
}
func TestNilPointerSlice(t *testing.T) {