mirror of
https://gitee.com/johng/gf.git
synced 2024-12-01 19:57:40 +08:00
fix: unit test error in PgSQL and SQLite; Unified t.Assert(err, nil)
to t.AssertNil(err)
(#3356)
This commit is contained in:
parent
607f079b23
commit
3a8f246569
@ -2558,7 +2558,7 @@ func Test_Model_AllAndCount(t *testing.T) {
|
|||||||
|
|
||||||
gtest.C(t, func(t *gtest.T) {
|
gtest.C(t, func(t *gtest.T) {
|
||||||
result, total, err := db.Model(table).Order("id").Limit(0, 3).AllAndCount(false)
|
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(len(result), 3)
|
||||||
t.Assert(total, TableSize)
|
t.Assert(total, TableSize)
|
||||||
@ -2582,7 +2582,7 @@ func Test_Model_ScanAndCount(t *testing.T) {
|
|||||||
total := 0
|
total := 0
|
||||||
|
|
||||||
err := db.Model(table).Order("id").Limit(0, 3).ScanAndCount(&users, &total, false)
|
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(len(users), 3)
|
||||||
t.Assert(total, TableSize)
|
t.Assert(total, TableSize)
|
||||||
|
@ -282,12 +282,12 @@ func Test_Model_Save(t *testing.T) {
|
|||||||
"nickname": "n1",
|
"nickname": "n1",
|
||||||
"create_time": CreateTime,
|
"create_time": CreateTime,
|
||||||
}).OnConflict("id").Save()
|
}).OnConflict("id").Save()
|
||||||
t.AssertNil(nil)
|
t.AssertNil(err)
|
||||||
n, _ := result.RowsAffected()
|
n, _ := result.RowsAffected()
|
||||||
t.Assert(n, 1)
|
t.Assert(n, 1)
|
||||||
|
|
||||||
err = db.Model(table).Scan(&user)
|
err = db.Model(table).Scan(&user)
|
||||||
t.Assert(err, nil)
|
t.AssertNil(err)
|
||||||
t.Assert(user.Id, 1)
|
t.Assert(user.Id, 1)
|
||||||
t.Assert(user.Passport, "p1")
|
t.Assert(user.Passport, "p1")
|
||||||
t.Assert(user.Password, "pw1")
|
t.Assert(user.Password, "pw1")
|
||||||
@ -304,14 +304,14 @@ func Test_Model_Save(t *testing.T) {
|
|||||||
t.AssertNil(err)
|
t.AssertNil(err)
|
||||||
|
|
||||||
err = db.Model(table).Scan(&user)
|
err = db.Model(table).Scan(&user)
|
||||||
t.Assert(err, nil)
|
t.AssertNil(err)
|
||||||
t.Assert(user.Passport, "p1")
|
t.Assert(user.Passport, "p1")
|
||||||
t.Assert(user.Password, "pw2")
|
t.Assert(user.Password, "pw2")
|
||||||
t.Assert(user.NickName, "n2")
|
t.Assert(user.NickName, "n2")
|
||||||
t.Assert(user.CreateTime.String(), CreateTime)
|
t.Assert(user.CreateTime.String(), CreateTime)
|
||||||
|
|
||||||
count, err = db.Model(table).Count()
|
count, err = db.Model(table).Count()
|
||||||
t.Assert(err, nil)
|
t.AssertNil(err)
|
||||||
t.Assert(count, 1)
|
t.Assert(count, 1)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -37,12 +37,12 @@ func Test_LastInsertId(t *testing.T) {
|
|||||||
{"passport": "user2", "password": "pwd", "nickname": "nickname", "create_time": CreateTime},
|
{"passport": "user2", "password": "pwd", "nickname": "nickname", "create_time": CreateTime},
|
||||||
{"passport": "user3", "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()
|
lastInsertId, err := res.LastInsertId()
|
||||||
t.Assert(err, nil)
|
t.AssertNil(err)
|
||||||
t.Assert(lastInsertId, int64(3))
|
t.Assert(lastInsertId, int64(3))
|
||||||
rowsAffected, err := res.RowsAffected()
|
rowsAffected, err := res.RowsAffected()
|
||||||
t.Assert(err, nil)
|
t.AssertNil(err)
|
||||||
t.Assert(rowsAffected, int64(3))
|
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": "user2", "password": "pwd", "nickname": "nickname", "create_time": CreateTime},
|
||||||
{"passport": "user3", "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()
|
lastInsertId, err := res.LastInsertId()
|
||||||
t.Assert(err, nil)
|
t.AssertNil(err)
|
||||||
t.AssertEQ(lastInsertId, int64(3))
|
t.AssertEQ(lastInsertId, int64(3))
|
||||||
rowsAffected, err := res.RowsAffected()
|
rowsAffected, err := res.RowsAffected()
|
||||||
t.Assert(err, nil)
|
t.AssertNil(err)
|
||||||
t.AssertEQ(rowsAffected, int64(3))
|
t.AssertEQ(rowsAffected, int64(3))
|
||||||
|
|
||||||
res1, err := tx.Model(tableName).Insert(g.List{
|
res1, err := tx.Model(tableName).Insert(g.List{
|
||||||
{"passport": "user4", "password": "pwd", "nickname": "nickname", "create_time": CreateTime},
|
{"passport": "user4", "password": "pwd", "nickname": "nickname", "create_time": CreateTime},
|
||||||
{"passport": "user5", "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()
|
lastInsertId1, err := res1.LastInsertId()
|
||||||
t.Assert(err, nil)
|
t.AssertNil(err)
|
||||||
t.AssertEQ(lastInsertId1, int64(5))
|
t.AssertEQ(lastInsertId1, int64(5))
|
||||||
rowsAffected1, err := res1.RowsAffected()
|
rowsAffected1, err := res1.RowsAffected()
|
||||||
t.Assert(err, nil)
|
t.AssertNil(err)
|
||||||
t.AssertEQ(rowsAffected1, int64(2))
|
t.AssertEQ(rowsAffected1, int64(2))
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
})
|
})
|
||||||
t.Assert(err, nil)
|
t.AssertNil(err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -385,12 +385,12 @@ func Test_Model_Save(t *testing.T) {
|
|||||||
"nickname": "oldme",
|
"nickname": "oldme",
|
||||||
"create_time": CreateTime,
|
"create_time": CreateTime,
|
||||||
}).OnConflict("id").Save()
|
}).OnConflict("id").Save()
|
||||||
t.AssertNil(nil)
|
t.AssertNil(err)
|
||||||
n, _ := result.RowsAffected()
|
n, _ := result.RowsAffected()
|
||||||
t.Assert(n, 1)
|
t.Assert(n, 1)
|
||||||
|
|
||||||
err = db.Model(table).Scan(&user)
|
err = db.Model(table).Scan(&user)
|
||||||
t.Assert(err, nil)
|
t.AssertNil(err)
|
||||||
t.Assert(user.Id, 1)
|
t.Assert(user.Id, 1)
|
||||||
t.Assert(user.Passport, "CN")
|
t.Assert(user.Passport, "CN")
|
||||||
t.Assert(user.Password, "12345678")
|
t.Assert(user.Password, "12345678")
|
||||||
@ -407,14 +407,14 @@ func Test_Model_Save(t *testing.T) {
|
|||||||
t.AssertNil(err)
|
t.AssertNil(err)
|
||||||
|
|
||||||
err = db.Model(table).Scan(&user)
|
err = db.Model(table).Scan(&user)
|
||||||
t.Assert(err, nil)
|
t.AssertNil(err)
|
||||||
t.Assert(user.Passport, "CN")
|
t.Assert(user.Passport, "CN")
|
||||||
t.Assert(user.Password, "abc123456")
|
t.Assert(user.Password, "abc123456")
|
||||||
t.Assert(user.NickName, "to be not to be")
|
t.Assert(user.NickName, "to be not to be")
|
||||||
t.Assert(user.CreateTime.String(), CreateTime)
|
t.Assert(user.CreateTime.String(), CreateTime)
|
||||||
|
|
||||||
count, err = db.Model(table).Count()
|
count, err = db.Model(table).Count()
|
||||||
t.Assert(err, nil)
|
t.AssertNil(err)
|
||||||
t.Assert(count, 1)
|
t.Assert(count, 1)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -385,12 +385,12 @@ func Test_Model_Save(t *testing.T) {
|
|||||||
"nickname": "oldme",
|
"nickname": "oldme",
|
||||||
"create_time": CreateTime,
|
"create_time": CreateTime,
|
||||||
}).OnConflict("id").Save()
|
}).OnConflict("id").Save()
|
||||||
t.AssertNil(nil)
|
t.AssertNil(err)
|
||||||
n, _ := result.RowsAffected()
|
n, _ := result.RowsAffected()
|
||||||
t.Assert(n, 1)
|
t.Assert(n, 1)
|
||||||
|
|
||||||
err = db.Model(table).Scan(&user)
|
err = db.Model(table).Scan(&user)
|
||||||
t.Assert(err, nil)
|
t.AssertNil(err)
|
||||||
t.Assert(user.Id, 1)
|
t.Assert(user.Id, 1)
|
||||||
t.Assert(user.Passport, "CN")
|
t.Assert(user.Passport, "CN")
|
||||||
t.Assert(user.Password, "12345678")
|
t.Assert(user.Password, "12345678")
|
||||||
@ -407,14 +407,14 @@ func Test_Model_Save(t *testing.T) {
|
|||||||
t.AssertNil(err)
|
t.AssertNil(err)
|
||||||
|
|
||||||
err = db.Model(table).Scan(&user)
|
err = db.Model(table).Scan(&user)
|
||||||
t.Assert(err, nil)
|
t.AssertNil(err)
|
||||||
t.Assert(user.Passport, "CN")
|
t.Assert(user.Passport, "CN")
|
||||||
t.Assert(user.Password, "abc123456")
|
t.Assert(user.Password, "abc123456")
|
||||||
t.Assert(user.NickName, "to be not to be")
|
t.Assert(user.NickName, "to be not to be")
|
||||||
t.Assert(user.CreateTime.String(), CreateTime)
|
t.Assert(user.CreateTime.String(), CreateTime)
|
||||||
|
|
||||||
count, err = db.Model(table).Count()
|
count, err = db.Model(table).Count()
|
||||||
t.Assert(err, nil)
|
t.AssertNil(err)
|
||||||
t.Assert(count, 1)
|
t.Assert(count, 1)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -214,7 +214,7 @@ func Test_PathInResource(t *testing.T) {
|
|||||||
t.Assert(i18n.T(context.Background(), "{#hello}{#world}"), "你好世界")
|
t.Assert(i18n.T(context.Background(), "{#hello}{#world}"), "你好世界")
|
||||||
|
|
||||||
err = i18n.SetPath("i18n")
|
err = i18n.SetPath("i18n")
|
||||||
t.Assert(err, nil)
|
t.AssertNil(err)
|
||||||
i18n.SetLanguage("ja")
|
i18n.SetLanguage("ja")
|
||||||
t.Assert(i18n.T(context.Background(), "{#hello}{#world}"), "こんにちは世界")
|
t.Assert(i18n.T(context.Background(), "{#hello}{#world}"), "こんにちは世界")
|
||||||
})
|
})
|
||||||
@ -245,7 +245,7 @@ func Test_PathInNormal(t *testing.T) {
|
|||||||
i18n.SetLanguage("en")
|
i18n.SetLanguage("en")
|
||||||
t.Assert(i18n.T(context.Background(), "{#hello}{#world}{#name}"), "HelloWorld{#name}")
|
t.Assert(i18n.T(context.Background(), "{#hello}{#world}{#name}"), "HelloWorld{#name}")
|
||||||
err := gfile.PutContentsAppend(gfile.Join(gdebug.CallerDirectory(), "manifest/i18n/en.toml"), "\nname = \"GoFrame\"")
|
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.
|
// Wait for the file modification time to change.
|
||||||
time.Sleep(10 * time.Millisecond)
|
time.Sleep(10 * time.Millisecond)
|
||||||
t.Assert(i18n.T(context.Background(), "{#hello}{#world}{#name}"), "HelloWorldGoFrame")
|
t.Assert(i18n.T(context.Background(), "{#hello}{#world}{#name}"), "HelloWorldGoFrame")
|
||||||
@ -254,7 +254,7 @@ func Test_PathInNormal(t *testing.T) {
|
|||||||
// Add new language
|
// Add new language
|
||||||
gtest.C(t, func(t *gtest.T) {
|
gtest.C(t, func(t *gtest.T) {
|
||||||
err := gfile.PutContents(gfile.Join(gdebug.CallerDirectory(), "manifest/i18n/en-US.toml"), "lang = \"en-US\"")
|
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.
|
// Wait for the file modification time to change.
|
||||||
time.Sleep(10 * time.Millisecond)
|
time.Sleep(10 * time.Millisecond)
|
||||||
i18n.SetLanguage("en-US")
|
i18n.SetLanguage("en-US")
|
||||||
|
@ -258,7 +258,7 @@ func Test_Package_Option_HeadSize4(t *testing.T) {
|
|||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
data := make([]byte, 0xFFFF+1)
|
data := make([]byte, 0xFFFF+1)
|
||||||
_, err = conn.SendRecvPkg(data, gtcp.PkgOption{HeaderSize: 4})
|
_, err = conn.SendRecvPkg(data, gtcp.PkgOption{HeaderSize: 4})
|
||||||
t.Assert(err, nil)
|
t.AssertNil(err)
|
||||||
})
|
})
|
||||||
// SendRecvPkg with big data - success.
|
// SendRecvPkg with big data - success.
|
||||||
gtest.C(t, func(t *gtest.T) {
|
gtest.C(t, func(t *gtest.T) {
|
||||||
|
@ -155,14 +155,14 @@ func TestAdapterFile_Set(t *testing.T) {
|
|||||||
path = gcfg.DefaultConfigFileName
|
path = gcfg.DefaultConfigFileName
|
||||||
err = gfile.PutContents(path, config)
|
err = gfile.PutContents(path, config)
|
||||||
)
|
)
|
||||||
t.Assert(err, nil)
|
t.AssertNil(err)
|
||||||
defer gfile.Remove(path)
|
defer gfile.Remove(path)
|
||||||
|
|
||||||
c, err := gcfg.New()
|
c, err := gcfg.New()
|
||||||
t.Assert(c.MustGet(ctx, "log-path").String(), "logs")
|
t.Assert(c.MustGet(ctx, "log-path").String(), "logs")
|
||||||
|
|
||||||
err = c.GetAdapter().(*gcfg.AdapterFile).Set("log-path", "custom-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")
|
t.Assert(c.MustGet(ctx, "log-path").String(), "custom-logs")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ func Test_Datetime(t *testing.T) {
|
|||||||
})
|
})
|
||||||
gtest.C(t, func(t *gtest.T) {
|
gtest.C(t, func(t *gtest.T) {
|
||||||
timeTemp, err := gtime.StrToTime("")
|
timeTemp, err := gtime.StrToTime("")
|
||||||
t.Assert(err, nil)
|
t.AssertNil(err)
|
||||||
t.AssertLT(timeTemp.Unix(), 0)
|
t.AssertLT(timeTemp.Unix(), 0)
|
||||||
timeTemp, err = gtime.StrToTime("2006-01")
|
timeTemp, err = gtime.StrToTime("2006-01")
|
||||||
t.AssertNE(err, nil)
|
t.AssertNE(err, nil)
|
||||||
|
Loading…
Reference in New Issue
Block a user