From 22bffdadc1daaf3f03dab04622fdbe835d9901fa Mon Sep 17 00:00:00 2001 From: John Guo Date: Thu, 21 Mar 2024 21:57:33 +0800 Subject: [PATCH] fix: unit testing cases of `contrib/drivers` occasionally failed by using now time assertion (#3410) --- contrib/drivers/mssql/mssql_z_unit_basic_test.go | 2 +- contrib/drivers/mysql/mysql_z_unit_core_test.go | 10 +++++----- contrib/drivers/oracle/oracle_z_unit_basic_test.go | 6 +++--- contrib/drivers/sqlite/sqlite_z_unit_core_test.go | 8 ++++---- .../drivers/sqlitecgo/sqlitecgo_z_unit_core_test.go | 8 ++++---- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/contrib/drivers/mssql/mssql_z_unit_basic_test.go b/contrib/drivers/mssql/mssql_z_unit_basic_test.go index 6b61a7dba32..87bb85fe448 100644 --- a/contrib/drivers/mssql/mssql_z_unit_basic_test.go +++ b/contrib/drivers/mssql/mssql_z_unit_basic_test.go @@ -217,7 +217,7 @@ func Test_DB_Insert(t *testing.T) { Nickname string `gconv:"nickname"` CreateTime *gtime.Time `json:"create_time"` } - timeNow := gtime.Now() + timeNow := gtime.New("2024-10-01 12:01:01") result, err = db.Insert(ctx, table, User{ Id: 3, Passport: "user_3", diff --git a/contrib/drivers/mysql/mysql_z_unit_core_test.go b/contrib/drivers/mysql/mysql_z_unit_core_test.go index 87405624527..41fcf475c62 100644 --- a/contrib/drivers/mysql/mysql_z_unit_core_test.go +++ b/contrib/drivers/mysql/mysql_z_unit_core_test.go @@ -127,7 +127,7 @@ func Test_DB_Insert(t *testing.T) { Nickname string `gconv:"nickname"` CreateTime string `json:"create_time"` } - timeStr := gtime.Now().String() + timeStr := gtime.New("2024-10-01 12:01:01").String() result, err = db.Insert(ctx, table, User{ Id: 3, Passport: "user_3", @@ -149,7 +149,7 @@ func Test_DB_Insert(t *testing.T) { t.Assert(one["create_time"].GTime().String(), timeStr) // *struct - timeStr = gtime.Now().String() + timeStr = gtime.New("2024-10-01 12:01:01").String() result, err = db.Insert(ctx, table, &User{ Id: 4, Passport: "t4", @@ -170,7 +170,7 @@ func Test_DB_Insert(t *testing.T) { t.Assert(one["create_time"].GTime().String(), timeStr) // batch with Insert - timeStr = gtime.Now().String() + timeStr = gtime.New("2024-10-01 12:01:01").String() r, err := db.Insert(ctx, table, g.Slice{ g.Map{ "id": 200, @@ -487,7 +487,7 @@ func Test_DB_Save(t *testing.T) { defer dropTable(table) gtest.C(t, func(t *gtest.T) { - timeStr := gtime.Now().String() + timeStr := gtime.New("2024-10-01 12:01:01").String() _, err := db.Save(ctx, table, g.Map{ "id": 1, "passport": "t1", @@ -512,7 +512,7 @@ func Test_DB_Replace(t *testing.T) { defer dropTable(table) gtest.C(t, func(t *gtest.T) { - timeStr := gtime.Now().String() + timeStr := gtime.New("2024-10-01 12:01:01").String() _, err := db.Replace(ctx, table, g.Map{ "id": 1, "passport": "t1", diff --git a/contrib/drivers/oracle/oracle_z_unit_basic_test.go b/contrib/drivers/oracle/oracle_z_unit_basic_test.go index 4b97fb79b54..d54a13c43b2 100644 --- a/contrib/drivers/oracle/oracle_z_unit_basic_test.go +++ b/contrib/drivers/oracle/oracle_z_unit_basic_test.go @@ -219,7 +219,7 @@ func Test_DB_Insert(t *testing.T) { Salary float64 `gconv:"SALARY"` CreateTime string `json:"CREATE_TIME"` } - timeStr := gtime.Now().String() + timeStr := gtime.New("2024-10-01 12:01:01").String() result, err = db.Insert(ctx, table, User{ Id: 3, Passport: "user_3", @@ -243,7 +243,7 @@ func Test_DB_Insert(t *testing.T) { t.Assert(one["CREATE_TIME"].GTime().String(), timeStr) // *struct - timeStr = gtime.Now().String() + timeStr = gtime.New("2024-10-01 12:01:01").String() result, err = db.Insert(ctx, table, &User{ Id: 4, Passport: "t4", @@ -266,7 +266,7 @@ func Test_DB_Insert(t *testing.T) { t.Assert(one["CREATE_TIME"].GTime().String(), timeStr) // batch with Insert - timeStr = gtime.Now().String() + timeStr = gtime.New("2024-10-01 12:01:01").String() r, err := db.Insert(ctx, table, g.Slice{ g.Map{ "ID": 200, diff --git a/contrib/drivers/sqlite/sqlite_z_unit_core_test.go b/contrib/drivers/sqlite/sqlite_z_unit_core_test.go index a8a4b232ff8..95c5cd68d63 100644 --- a/contrib/drivers/sqlite/sqlite_z_unit_core_test.go +++ b/contrib/drivers/sqlite/sqlite_z_unit_core_test.go @@ -140,7 +140,7 @@ func Test_DB_Insert(t *testing.T) { Nickname string `gconv:"nickname"` CreateTime string `json:"create_time"` } - timeStr := gtime.Now().String() + timeStr := gtime.New("2024-10-01 12:01:01").String() result, err = db.Insert(ctx, table, User{ Id: 3, Passport: "user_3", @@ -162,7 +162,7 @@ func Test_DB_Insert(t *testing.T) { t.Assert(one["create_time"].GTime().String(), timeStr) // *struct - timeStr = gtime.Now().String() + timeStr = gtime.New("2024-10-01 12:01:01").String() result, err = db.Insert(ctx, table, &User{ Id: 4, Passport: "t4", @@ -183,7 +183,7 @@ func Test_DB_Insert(t *testing.T) { t.Assert(one["create_time"].GTime().String(), timeStr) // batch with Insert - timeStr = gtime.Now().String() + timeStr = gtime.New("2024-10-01 12:01:01").String() r, err := db.Insert(ctx, table, g.Slice{ g.Map{ "id": 200, @@ -449,7 +449,7 @@ func Test_DB_Replace(t *testing.T) { defer dropTable(table) gtest.C(t, func(t *gtest.T) { - timeStr := gtime.Now().String() + timeStr := gtime.New("2024-10-01 12:01:01").String() _, err := db.Replace(ctx, table, g.Map{ "id": 1, "passport": "t1", diff --git a/contrib/drivers/sqlitecgo/sqlitecgo_z_unit_core_test.go b/contrib/drivers/sqlitecgo/sqlitecgo_z_unit_core_test.go index dbfdb23def1..fee914add0a 100644 --- a/contrib/drivers/sqlitecgo/sqlitecgo_z_unit_core_test.go +++ b/contrib/drivers/sqlitecgo/sqlitecgo_z_unit_core_test.go @@ -140,7 +140,7 @@ func Test_DB_Insert(t *testing.T) { Nickname string `gconv:"nickname"` CreateTime string `json:"create_time"` } - timeStr := gtime.Now().String() + timeStr := gtime.New("2024-10-01 12:01:01").String() result, err = db.Insert(ctx, table, User{ Id: 3, Passport: "user_3", @@ -162,7 +162,7 @@ func Test_DB_Insert(t *testing.T) { t.Assert(one["create_time"].GTime().String(), timeStr) // *struct - timeStr = gtime.Now().String() + timeStr = gtime.New("2024-10-01 12:01:01").String() result, err = db.Insert(ctx, table, &User{ Id: 4, Passport: "t4", @@ -183,7 +183,7 @@ func Test_DB_Insert(t *testing.T) { t.Assert(one["create_time"].GTime().String(), timeStr) // batch with Insert - timeStr = gtime.Now().String() + timeStr = gtime.New("2024-10-01 12:01:01").String() r, err := db.Insert(ctx, table, g.Slice{ g.Map{ "id": 200, @@ -449,7 +449,7 @@ func Test_DB_Replace(t *testing.T) { defer dropTable(table) gtest.C(t, func(t *gtest.T) { - timeStr := gtime.Now().String() + timeStr := gtime.New("2024-10-01 12:01:01").String() _, err := db.Replace(ctx, table, g.Map{ "id": 1, "passport": "t1",