fix tests
This commit is contained in:
parent
fc3b5e7de1
commit
e557d273c2
@ -278,8 +278,6 @@ func TestBelongsToAssociationUnscoped(t *testing.T) {
|
|||||||
t.Fatalf("failed to create items, got error: %v", err)
|
t.Fatalf("failed to create items, got error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
tx = tx.Debug()
|
|
||||||
|
|
||||||
// test replace
|
// test replace
|
||||||
if err := tx.Model(&item).Association("ItemParent").Unscoped().Replace(&ItemParent{
|
if err := tx.Model(&item).Association("ItemParent").Unscoped().Replace(&ItemParent{
|
||||||
Logo: "updated logo",
|
Logo: "updated logo",
|
||||||
|
@ -29,7 +29,7 @@ func TestCountWithGroup(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var count2 int64
|
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))
|
t.Errorf(fmt.Sprintf("Count should work, but got err %v", err))
|
||||||
}
|
}
|
||||||
if count2 != 2 {
|
if count2 != 2 {
|
||||||
|
18
tests/go.mod
18
tests/go.mod
@ -3,17 +3,17 @@ module gorm.io/gorm/tests
|
|||||||
go 1.16
|
go 1.16
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/go-sql-driver/mysql v1.7.1 // indirect
|
||||||
github.com/google/uuid v1.3.0
|
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/jinzhu/now v1.1.5
|
||||||
github.com/lib/pq v1.10.8
|
github.com/lib/pq v1.10.9
|
||||||
github.com/mattn/go-sqlite3 v1.14.16 // indirect
|
github.com/microsoft/go-mssqldb v1.0.0 // indirect
|
||||||
golang.org/x/crypto v0.8.0 // indirect
|
golang.org/x/crypto v0.9.0 // indirect
|
||||||
gorm.io/driver/mysql v1.5.0
|
gorm.io/driver/mysql v1.5.1
|
||||||
gorm.io/driver/postgres v1.5.0
|
gorm.io/driver/postgres v1.5.2
|
||||||
gorm.io/driver/sqlite v1.5.0
|
gorm.io/driver/sqlite v1.5.1
|
||||||
gorm.io/driver/sqlserver v1.4.3
|
gorm.io/driver/sqlserver v1.5.0
|
||||||
gorm.io/gorm v1.25.0
|
gorm.io/gorm v1.25.1
|
||||||
)
|
)
|
||||||
|
|
||||||
replace gorm.io/gorm => ../
|
replace gorm.io/gorm => ../
|
||||||
|
@ -373,6 +373,9 @@ func TestMigrateIndexes(t *testing.T) {
|
|||||||
t.Fatalf("no error should happen when rename index, but got %v", err)
|
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") {
|
if !DB.Migrator().HasIndex(&IndexStruct{}, "idx_users_name_1") {
|
||||||
t.Fatalf("Should find index for user's name after rename")
|
t.Fatalf("Should find index for user's name after rename")
|
||||||
}
|
}
|
||||||
@ -393,8 +396,15 @@ func TestMigrateIndexes(t *testing.T) {
|
|||||||
t.Fatalf("Got error when tried to create index: %+v", err)
|
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" {
|
||||||
t.Fatalf("no error should happen when rename index, but got %v", err)
|
// 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") {
|
if !DB.Migrator().HasIndex("index_structs", "idx_users_name_1") {
|
||||||
@ -674,8 +684,15 @@ func TestMigrateColumns(t *testing.T) {
|
|||||||
t.Fatalf("Failed to add column, got %v", err)
|
t.Fatalf("Failed to add column, got %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := DB.Migrator().RenameColumn("column_structs", "new_name", "new_new_name"); err != nil {
|
if DB.Dialector.Name() == "mysql" {
|
||||||
t.Fatalf("Failed to rename column, got %v", err)
|
// 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") {
|
if !DB.Migrator().HasColumn("column_structs", "new_new_name") {
|
||||||
|
@ -429,7 +429,6 @@ func TestEmbedPreload(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
DB = DB.Debug()
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
actual := Org{}
|
actual := Org{}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user