From e0821942c17049483ffb1233096015e108916b50 Mon Sep 17 00:00:00 2001 From: biju-kalissery Date: Tue, 8 Sep 2015 14:13:18 -0400 Subject: [PATCH] error handling refinements ref: https://github.com/jinzhu/gorm/issues/647 --- multi_primary_keys_test.go | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/multi_primary_keys_test.go b/multi_primary_keys_test.go index 9ca68d13..5e5bf6eb 100644 --- a/multi_primary_keys_test.go +++ b/multi_primary_keys_test.go @@ -34,13 +34,24 @@ func TestManyToManyWithMultiPrimaryKeys(t *testing.T) { }, } - DB.Save(&blog) - DB.Model(&blog).Association("Tags").Append([]Tag{{Locale: "ZH", Value: "tag3"}}) - + res := DB.Save(&blog) + if nil != res.Error { + t.Errorf("Error while saving blog:%v", res.Error) + } + res2 := DB.Model(&blog).Association("Tags").Append([]Tag{{Locale: "ZH", Value: "tag3"}}) + if nil != res2.Error { + t.Errorf("Error while appending tag to blog:%v", res2.Error) + } + var tags []Tag - DB.Model(&blog).Related(&tags, "Tags") - if len(tags) != 3 { - t.Errorf("should found 3 tags with blog") + res = DB.Model(&blog).Related(&tags, "Tags") + if nil != res.Error { + t.Errorf("Error while reading tags related to blog:%v", res.Error) + } + + tagsCount := len(tags) + if tagsCount != 3 { + t.Errorf("should found 3 tags with blog, found:%v", tagsCount) } } }