fix: unit test error in PgSQL and SQLite; Unified t.Assert(err, nil) to t.AssertNil(err) (#3356)

This commit is contained in:
oldme 2024-03-12 20:05:03 +08:00 committed by GitHub
parent 607f079b23
commit 3a8f246569
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 31 additions and 31 deletions

View File

@ -2558,7 +2558,7 @@ func Test_Model_AllAndCount(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
result, total, err := db.Model(table).Order("id").Limit(0, 3).AllAndCount(false)
t.Assert(err, nil)
t.AssertNil(err)
t.Assert(len(result), 3)
t.Assert(total, TableSize)
@ -2582,7 +2582,7 @@ func Test_Model_ScanAndCount(t *testing.T) {
total := 0
err := db.Model(table).Order("id").Limit(0, 3).ScanAndCount(&users, &total, false)
t.Assert(err, nil)
t.AssertNil(err)
t.Assert(len(users), 3)
t.Assert(total, TableSize)

View File

@ -282,12 +282,12 @@ func Test_Model_Save(t *testing.T) {
"nickname": "n1",
"create_time": CreateTime,
}).OnConflict("id").Save()
t.AssertNil(nil)
t.AssertNil(err)
n, _ := result.RowsAffected()
t.Assert(n, 1)
err = db.Model(table).Scan(&user)
t.Assert(err, nil)
t.AssertNil(err)
t.Assert(user.Id, 1)
t.Assert(user.Passport, "p1")
t.Assert(user.Password, "pw1")
@ -304,14 +304,14 @@ func Test_Model_Save(t *testing.T) {
t.AssertNil(err)
err = db.Model(table).Scan(&user)
t.Assert(err, nil)
t.AssertNil(err)
t.Assert(user.Passport, "p1")
t.Assert(user.Password, "pw2")
t.Assert(user.NickName, "n2")
t.Assert(user.CreateTime.String(), CreateTime)
count, err = db.Model(table).Count()
t.Assert(err, nil)
t.AssertNil(err)
t.Assert(count, 1)
})
}

View File

@ -37,12 +37,12 @@ func Test_LastInsertId(t *testing.T) {
{"passport": "user2", "password": "pwd", "nickname": "nickname", "create_time": CreateTime},
{"passport": "user3", "password": "pwd", "nickname": "nickname", "create_time": CreateTime},
})
t.Assert(err, nil)
t.AssertNil(err)
lastInsertId, err := res.LastInsertId()
t.Assert(err, nil)
t.AssertNil(err)
t.Assert(lastInsertId, int64(3))
rowsAffected, err := res.RowsAffected()
t.Assert(err, nil)
t.AssertNil(err)
t.Assert(rowsAffected, int64(3))
})
}
@ -58,29 +58,29 @@ func Test_TxLastInsertId(t *testing.T) {
{"passport": "user2", "password": "pwd", "nickname": "nickname", "create_time": CreateTime},
{"passport": "user3", "password": "pwd", "nickname": "nickname", "create_time": CreateTime},
})
t.Assert(err, nil)
t.AssertNil(err)
lastInsertId, err := res.LastInsertId()
t.Assert(err, nil)
t.AssertNil(err)
t.AssertEQ(lastInsertId, int64(3))
rowsAffected, err := res.RowsAffected()
t.Assert(err, nil)
t.AssertNil(err)
t.AssertEQ(rowsAffected, int64(3))
res1, err := tx.Model(tableName).Insert(g.List{
{"passport": "user4", "password": "pwd", "nickname": "nickname", "create_time": CreateTime},
{"passport": "user5", "password": "pwd", "nickname": "nickname", "create_time": CreateTime},
})
t.Assert(err, nil)
t.AssertNil(err)
lastInsertId1, err := res1.LastInsertId()
t.Assert(err, nil)
t.AssertNil(err)
t.AssertEQ(lastInsertId1, int64(5))
rowsAffected1, err := res1.RowsAffected()
t.Assert(err, nil)
t.AssertNil(err)
t.AssertEQ(rowsAffected1, int64(2))
return nil
})
t.Assert(err, nil)
t.AssertNil(err)
})
}

View File

@ -385,12 +385,12 @@ func Test_Model_Save(t *testing.T) {
"nickname": "oldme",
"create_time": CreateTime,
}).OnConflict("id").Save()
t.AssertNil(nil)
t.AssertNil(err)
n, _ := result.RowsAffected()
t.Assert(n, 1)
err = db.Model(table).Scan(&user)
t.Assert(err, nil)
t.AssertNil(err)
t.Assert(user.Id, 1)
t.Assert(user.Passport, "CN")
t.Assert(user.Password, "12345678")
@ -407,14 +407,14 @@ func Test_Model_Save(t *testing.T) {
t.AssertNil(err)
err = db.Model(table).Scan(&user)
t.Assert(err, nil)
t.AssertNil(err)
t.Assert(user.Passport, "CN")
t.Assert(user.Password, "abc123456")
t.Assert(user.NickName, "to be not to be")
t.Assert(user.CreateTime.String(), CreateTime)
count, err = db.Model(table).Count()
t.Assert(err, nil)
t.AssertNil(err)
t.Assert(count, 1)
})
}

View File

@ -385,12 +385,12 @@ func Test_Model_Save(t *testing.T) {
"nickname": "oldme",
"create_time": CreateTime,
}).OnConflict("id").Save()
t.AssertNil(nil)
t.AssertNil(err)
n, _ := result.RowsAffected()
t.Assert(n, 1)
err = db.Model(table).Scan(&user)
t.Assert(err, nil)
t.AssertNil(err)
t.Assert(user.Id, 1)
t.Assert(user.Passport, "CN")
t.Assert(user.Password, "12345678")
@ -407,14 +407,14 @@ func Test_Model_Save(t *testing.T) {
t.AssertNil(err)
err = db.Model(table).Scan(&user)
t.Assert(err, nil)
t.AssertNil(err)
t.Assert(user.Passport, "CN")
t.Assert(user.Password, "abc123456")
t.Assert(user.NickName, "to be not to be")
t.Assert(user.CreateTime.String(), CreateTime)
count, err = db.Model(table).Count()
t.Assert(err, nil)
t.AssertNil(err)
t.Assert(count, 1)
})
}

View File

@ -214,7 +214,7 @@ func Test_PathInResource(t *testing.T) {
t.Assert(i18n.T(context.Background(), "{#hello}{#world}"), "你好世界")
err = i18n.SetPath("i18n")
t.Assert(err, nil)
t.AssertNil(err)
i18n.SetLanguage("ja")
t.Assert(i18n.T(context.Background(), "{#hello}{#world}"), "こんにちは世界")
})
@ -245,7 +245,7 @@ func Test_PathInNormal(t *testing.T) {
i18n.SetLanguage("en")
t.Assert(i18n.T(context.Background(), "{#hello}{#world}{#name}"), "HelloWorld{#name}")
err := gfile.PutContentsAppend(gfile.Join(gdebug.CallerDirectory(), "manifest/i18n/en.toml"), "\nname = \"GoFrame\"")
t.Assert(err, nil)
t.AssertNil(err)
// Wait for the file modification time to change.
time.Sleep(10 * time.Millisecond)
t.Assert(i18n.T(context.Background(), "{#hello}{#world}{#name}"), "HelloWorldGoFrame")
@ -254,7 +254,7 @@ func Test_PathInNormal(t *testing.T) {
// Add new language
gtest.C(t, func(t *gtest.T) {
err := gfile.PutContents(gfile.Join(gdebug.CallerDirectory(), "manifest/i18n/en-US.toml"), "lang = \"en-US\"")
t.Assert(err, nil)
t.AssertNil(err)
// Wait for the file modification time to change.
time.Sleep(10 * time.Millisecond)
i18n.SetLanguage("en-US")

View File

@ -258,7 +258,7 @@ func Test_Package_Option_HeadSize4(t *testing.T) {
defer conn.Close()
data := make([]byte, 0xFFFF+1)
_, err = conn.SendRecvPkg(data, gtcp.PkgOption{HeaderSize: 4})
t.Assert(err, nil)
t.AssertNil(err)
})
// SendRecvPkg with big data - success.
gtest.C(t, func(t *gtest.T) {

View File

@ -155,14 +155,14 @@ func TestAdapterFile_Set(t *testing.T) {
path = gcfg.DefaultConfigFileName
err = gfile.PutContents(path, config)
)
t.Assert(err, nil)
t.AssertNil(err)
defer gfile.Remove(path)
c, err := gcfg.New()
t.Assert(c.MustGet(ctx, "log-path").String(), "logs")
err = c.GetAdapter().(*gcfg.AdapterFile).Set("log-path", "custom-logs")
t.Assert(err, nil)
t.AssertNil(err)
t.Assert(c.MustGet(ctx, "log-path").String(), "custom-logs")
})
}

View File

@ -72,7 +72,7 @@ func Test_Datetime(t *testing.T) {
})
gtest.C(t, func(t *gtest.T) {
timeTemp, err := gtime.StrToTime("")
t.Assert(err, nil)
t.AssertNil(err)
t.AssertLT(timeTemp.Unix(), 0)
timeTemp, err = gtime.StrToTime("2006-01")
t.AssertNE(err, nil)