From 3a8f246569c81dc2d2ac154dbd7e377c7a9e767d Mon Sep 17 00:00:00 2001 From: oldme <45782393+oldme-git@users.noreply.github.com> Date: Tue, 12 Mar 2024 20:05:03 +0800 Subject: [PATCH] fix: unit test error in PgSQL and SQLite; Unified `t.Assert(err, nil)` to `t.AssertNil(err)` (#3356) --- .../drivers/mssql/mssql_z_unit_model_test.go | 4 ++-- .../drivers/pgsql/pgsql_z_unit_model_test.go | 8 ++++---- contrib/drivers/pgsql/pgsql_z_unit_test.go | 20 +++++++++---------- .../sqlite/sqlite_z_unit_model_test.go | 8 ++++---- .../sqlitecgo/sqlitecgo_z_unit_model_test.go | 8 ++++---- i18n/gi18n/gi18n_z_unit_test.go | 6 +++--- net/gtcp/gtcp_z_unit_conn_pkg_test.go | 2 +- os/gcfg/gcfg_z_unit_adapter_file_test.go | 4 ++-- os/gtime/gtime_z_unit_test.go | 2 +- 9 files changed, 31 insertions(+), 31 deletions(-) diff --git a/contrib/drivers/mssql/mssql_z_unit_model_test.go b/contrib/drivers/mssql/mssql_z_unit_model_test.go index 7a809039f..fe092043b 100644 --- a/contrib/drivers/mssql/mssql_z_unit_model_test.go +++ b/contrib/drivers/mssql/mssql_z_unit_model_test.go @@ -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) diff --git a/contrib/drivers/pgsql/pgsql_z_unit_model_test.go b/contrib/drivers/pgsql/pgsql_z_unit_model_test.go index 4c9d6e906..781438b76 100644 --- a/contrib/drivers/pgsql/pgsql_z_unit_model_test.go +++ b/contrib/drivers/pgsql/pgsql_z_unit_model_test.go @@ -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) }) } diff --git a/contrib/drivers/pgsql/pgsql_z_unit_test.go b/contrib/drivers/pgsql/pgsql_z_unit_test.go index 6d9a6f981..4cdfdabd5 100644 --- a/contrib/drivers/pgsql/pgsql_z_unit_test.go +++ b/contrib/drivers/pgsql/pgsql_z_unit_test.go @@ -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) }) } diff --git a/contrib/drivers/sqlite/sqlite_z_unit_model_test.go b/contrib/drivers/sqlite/sqlite_z_unit_model_test.go index 95473ff40..7734bb5b7 100644 --- a/contrib/drivers/sqlite/sqlite_z_unit_model_test.go +++ b/contrib/drivers/sqlite/sqlite_z_unit_model_test.go @@ -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) }) } diff --git a/contrib/drivers/sqlitecgo/sqlitecgo_z_unit_model_test.go b/contrib/drivers/sqlitecgo/sqlitecgo_z_unit_model_test.go index 610e46a94..b84141ca8 100644 --- a/contrib/drivers/sqlitecgo/sqlitecgo_z_unit_model_test.go +++ b/contrib/drivers/sqlitecgo/sqlitecgo_z_unit_model_test.go @@ -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) }) } diff --git a/i18n/gi18n/gi18n_z_unit_test.go b/i18n/gi18n/gi18n_z_unit_test.go index 5ef6fc86f..af44d226b 100644 --- a/i18n/gi18n/gi18n_z_unit_test.go +++ b/i18n/gi18n/gi18n_z_unit_test.go @@ -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") diff --git a/net/gtcp/gtcp_z_unit_conn_pkg_test.go b/net/gtcp/gtcp_z_unit_conn_pkg_test.go index 8b171abe4..19479e3cc 100644 --- a/net/gtcp/gtcp_z_unit_conn_pkg_test.go +++ b/net/gtcp/gtcp_z_unit_conn_pkg_test.go @@ -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) { diff --git a/os/gcfg/gcfg_z_unit_adapter_file_test.go b/os/gcfg/gcfg_z_unit_adapter_file_test.go index d44c1f2fc..4f46e44ea 100644 --- a/os/gcfg/gcfg_z_unit_adapter_file_test.go +++ b/os/gcfg/gcfg_z_unit_adapter_file_test.go @@ -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") }) } diff --git a/os/gtime/gtime_z_unit_test.go b/os/gtime/gtime_z_unit_test.go index d7479ff98..4765f8349 100644 --- a/os/gtime/gtime_z_unit_test.go +++ b/os/gtime/gtime_z_unit_test.go @@ -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)