fix tests

This commit is contained in:
black 2023-05-31 17:32:33 +08:00
parent fc3b5e7de1
commit e557d273c2
5 changed files with 31 additions and 17 deletions

View File

@ -278,8 +278,6 @@ func TestBelongsToAssociationUnscoped(t *testing.T) {
t.Fatalf("failed to create items, got error: %v", err)
}
tx = tx.Debug()
// test replace
if err := tx.Model(&item).Association("ItemParent").Unscoped().Replace(&ItemParent{
Logo: "updated logo",

View File

@ -29,7 +29,7 @@ func TestCountWithGroup(t *testing.T) {
}
var count2 int64
if err := DB.Debug().Model(&Company{}).Where("name in ?", []string{"company_count_group_b", "company_count_group_c"}).Group("name").Count(&count2).Error; err != nil {
if err := DB.Model(&Company{}).Where("name in ?", []string{"company_count_group_b", "company_count_group_c"}).Group("name").Count(&count2).Error; err != nil {
t.Errorf(fmt.Sprintf("Count should work, but got err %v", err))
}
if count2 != 2 {

View File

@ -3,17 +3,17 @@ module gorm.io/gorm/tests
go 1.16
require (
github.com/go-sql-driver/mysql v1.7.1 // indirect
github.com/google/uuid v1.3.0
github.com/jackc/pgx/v5 v5.3.1 // indirect
github.com/jinzhu/now v1.1.5
github.com/lib/pq v1.10.8
github.com/mattn/go-sqlite3 v1.14.16 // indirect
golang.org/x/crypto v0.8.0 // indirect
gorm.io/driver/mysql v1.5.0
gorm.io/driver/postgres v1.5.0
gorm.io/driver/sqlite v1.5.0
gorm.io/driver/sqlserver v1.4.3
gorm.io/gorm v1.25.0
github.com/lib/pq v1.10.9
github.com/microsoft/go-mssqldb v1.0.0 // indirect
golang.org/x/crypto v0.9.0 // indirect
gorm.io/driver/mysql v1.5.1
gorm.io/driver/postgres v1.5.2
gorm.io/driver/sqlite v1.5.1
gorm.io/driver/sqlserver v1.5.0
gorm.io/gorm v1.25.1
)
replace gorm.io/gorm => ../

View File

@ -373,6 +373,9 @@ func TestMigrateIndexes(t *testing.T) {
t.Fatalf("no error should happen when rename index, but got %v", err)
}
if DB.Migrator().HasIndex(&IndexStruct{}, "idx_index_structs_name") {
t.Fatalf("Should not find index for user's name after rename")
}
if !DB.Migrator().HasIndex(&IndexStruct{}, "idx_users_name_1") {
t.Fatalf("Should find index for user's name after rename")
}
@ -393,9 +396,16 @@ func TestMigrateIndexes(t *testing.T) {
t.Fatalf("Got error when tried to create index: %+v", err)
}
if err := DB.Migrator().RenameIndex("index_structs", "idx_index_structs_name", "idx_users_name_1"); err != nil {
if DB.Dialector.Name() == "mysql" {
// mysql RenameIndex doesn't support string table
if err := DB.Debug().Migrator().RenameIndex(&IndexStruct{}, "idx_index_structs_name", "idx_users_name_1"); err != nil {
t.Fatalf("no error should happen when rename index, but got %v", err)
}
} else {
if err := DB.Debug().Migrator().RenameIndex("index_structs", "idx_index_structs_name", "idx_users_name_1"); err != nil {
t.Fatalf("no error should happen when rename index, but got %v", err)
}
}
if !DB.Migrator().HasIndex("index_structs", "idx_users_name_1") {
t.Fatalf("Should find index for user's name after rename")
@ -674,9 +684,16 @@ func TestMigrateColumns(t *testing.T) {
t.Fatalf("Failed to add column, got %v", err)
}
if DB.Dialector.Name() == "mysql" {
// mysql RenameColumn doesn't support string table
if err := DB.Migrator().RenameColumn(&NewColumnStruct{}, "new_name", "new_new_name"); err != nil {
t.Fatalf("Failed to rename column, got %v", err)
}
} else {
if err := DB.Migrator().RenameColumn("column_structs", "new_name", "new_new_name"); err != nil {
t.Fatalf("Failed to rename column, got %v", err)
}
}
if !DB.Migrator().HasColumn("column_structs", "new_new_name") {
t.Fatalf("Failed to find added column")

View File

@ -429,7 +429,6 @@ func TestEmbedPreload(t *testing.T) {
},
}
DB = DB.Debug()
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
actual := Org{}