Skip to content

Commit

Permalink
Fix tests once more
Browse files Browse the repository at this point in the history
  • Loading branch information
dschreij committed Jan 10, 2024
1 parent c0c58e1 commit e39adf1
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ func TestGORM(t *testing.T) {
user := User{Name: "jinzhu"}

tx := DB.Begin()
tx.Create(&user)
if err := tx.Create(&user).Error; err != nil {
t.Errorf("Failed, got error: %v", err)
}

var result User
if err := tx.First(&result, user.ID).Error; err != nil {
Expand All @@ -37,11 +39,14 @@ func TestJoinsWithoutCount(t *testing.T) {
},
}
tx := DB.Begin()
tx.Create(&users)
if err := tx.Create(&users).Error; err != nil {
t.Errorf("Failed, got error: %v", err)
}

tx.Model(&User{}).Joins("Company").Order("\"Company\".\"name\" ASC")
q := tx.Model(&User{})
q.Joins("Company").Order("\"Company\".\"name\" ASC")
var result []User
if err := tx.Find(&result).Error; err != nil {
if err := q.Find(&result).Error; err != nil {
t.Errorf("Failed, got error: %v", err)
}
if len(result) != 2 {
Expand Down Expand Up @@ -69,19 +74,21 @@ func TestJoinsWithCount(t *testing.T) {
},
}
tx := DB.Begin()
tx.Create(&users)
tx.Model(&User{}).Joins("Company").
Order("\"Company\".\"name\" ASC") // Order still works!
if err := tx.Create(&users).Error; err != nil {
t.Errorf("Failed, got error: %v", err)
}
q := tx.Model(&User{})
q.Joins("Company").Order("\"Company\".\"name\" ASC") // Order still works!

// --- Critical change
var count int64
if err := tx.Count(&count).Error; err != nil {
if err := q.Count(&count).Error; err != nil {
t.Errorf("Failed, got error: %v", err)
}
// --- End critical change

var result []User
if err := tx.Find(&result).Error; err != nil {
if err := q.Find(&result).Error; err != nil {
t.Errorf("Failed, got error: %v", err)
}
if len(result) != 2 {
Expand Down

0 comments on commit e39adf1

Please sign in to comment.