From 861c477a3331754c3bf45fc13965793ce295d186 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Wed, 16 Dec 2015 10:35:22 +0800 Subject: [PATCH] Test Preload won't panic when nothing found --- preload_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/preload_test.go b/preload_test.go index e1b4efe2..36bfaae5 100644 --- a/preload_test.go +++ b/preload_test.go @@ -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) {