mirror of https://github.com/go-gorm/gorm.git
Rename anonymous_struct_test.go to embedded_struct_test.go
This commit is contained in:
parent
b3b87d9c45
commit
e615aab232
|
@ -5,7 +5,7 @@ import "testing"
|
||||||
type BasePost struct {
|
type BasePost struct {
|
||||||
Id int64
|
Id int64
|
||||||
Title string
|
Title string
|
||||||
Url string
|
URL string
|
||||||
}
|
}
|
||||||
|
|
||||||
type HNPost struct {
|
type HNPost struct {
|
||||||
|
@ -24,19 +24,15 @@ func TestSaveAndQueryEmbeddedStruct(t *testing.T) {
|
||||||
var news HNPost
|
var news HNPost
|
||||||
if err := DB.First(&news, "title = ?", "hn_news").Error; err != nil {
|
if err := DB.First(&news, "title = ?", "hn_news").Error; err != nil {
|
||||||
t.Errorf("no error should happen when query with embedded struct, but got %v", err)
|
t.Errorf("no error should happen when query with embedded struct, but got %v", err)
|
||||||
} else {
|
} else if news.Title != "hn_news" {
|
||||||
if news.BasePost.Title != "hn_news" {
|
|
||||||
t.Errorf("embedded struct's value should be scanned correctly")
|
t.Errorf("embedded struct's value should be scanned correctly")
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
DB.Save(&EngadgetPost{BasePost: BasePost{Title: "engadget_news"}})
|
DB.Save(&EngadgetPost{BasePost: BasePost{Title: "engadget_news"}})
|
||||||
var egNews EngadgetPost
|
var egNews EngadgetPost
|
||||||
if err := DB.First(&egNews, "title = ?", "engadget_news").Error; err != nil {
|
if err := DB.First(&egNews, "title = ?", "engadget_news").Error; err != nil {
|
||||||
t.Errorf("no error should happen when query with embedded struct, but got %v", err)
|
t.Errorf("no error should happen when query with embedded struct, but got %v", err)
|
||||||
} else {
|
} else if egNews.BasePost.Title != "engadget_news" {
|
||||||
if egNews.BasePost.Title != "engadget_news" {
|
|
||||||
t.Errorf("embedded struct's value should be scanned correctly")
|
t.Errorf("embedded struct's value should be scanned correctly")
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue