This commit is contained in:
Lunny Xiao 2023-12-31 22:00:44 +08:00
parent 97bf025984
commit 43f38242f8
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A
1 changed files with 22 additions and 25 deletions

View File

@ -26,8 +26,7 @@ const (
dbName = "testdb.sqlite3"
)
var (
migrations = []*Migration{
var migrations = []*Migration{
{
ID: "201608301400",
Migrate: func(tx *xorm.Engine) error {
@ -46,8 +45,7 @@ var (
return tx.DropTables(&Pet{})
},
},
}
)
}
func TestMigration(t *testing.T) {
_ = os.Remove(dbName)
@ -58,7 +56,7 @@ func TestMigration(t *testing.T) {
}
defer db.Close()
if err = db.DB().Ping(); err != nil {
if err = db.Ping(); err != nil {
log.Fatal(err)
}
@ -97,7 +95,7 @@ func TestInitSchema(t *testing.T) {
log.Fatal(err)
}
defer db.Close()
if err = db.DB().Ping(); err != nil {
if err = db.Ping(); err != nil {
log.Fatal(err)
}
@ -126,7 +124,7 @@ func TestMissingID(t *testing.T) {
if db != nil {
defer db.Close()
}
assert.NoError(t, db.DB().Ping())
assert.NoError(t, db.Ping())
migrationsMissingID := []*Migration{
{
@ -141,7 +139,6 @@ func TestMissingID(t *testing.T) {
}
func tableCount(db *xorm.Engine, tableName string) (count int) {
row := db.DB().QueryRow(fmt.Sprintf("SELECT COUNT(*) FROM %s", tableName))
_ = row.Scan(&count)
_, _ = db.SQL(fmt.Sprintf("SELECT COUNT(*) FROM %s", tableName)).Get(&count)
return
}