Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions contrib/drivers/mssql/mssql_z_unit_model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions contrib/drivers/pgsql/pgsql_z_unit_model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
})
}
Expand Down
20 changes: 10 additions & 10 deletions contrib/drivers/pgsql/pgsql_z_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
}
Expand All @@ -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)
})
}

Expand Down
8 changes: 4 additions & 4 deletions contrib/drivers/sqlite/sqlite_z_unit_model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
})
}
Expand Down
8 changes: 4 additions & 4 deletions contrib/drivers/sqlitecgo/sqlitecgo_z_unit_model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
})
}
Expand Down
6 changes: 3 additions & 3 deletions i18n/gi18n/gi18n_z_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}"), "こんにちは世界")
})
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion net/gtcp/gtcp_z_unit_conn_pkg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions os/gcfg/gcfg_z_unit_adapter_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})
}
2 changes: 1 addition & 1 deletion os/gtime/gtime_z_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading