From fb15db7e05444eec0bbf9e5a4831f7d8d1dfedb2 Mon Sep 17 00:00:00 2001 From: dongmen <414110582@qq.com> Date: Thu, 14 Dec 2023 10:00:05 +0800 Subject: [PATCH] fix failed unit test cases --- .../pkg/meta/internal/sqlkv/sql_impl_test.go | 6 +-- engine/pkg/orm/util_test.go | 49 +++++++++---------- 2 files changed, 26 insertions(+), 29 deletions(-) diff --git a/engine/pkg/meta/internal/sqlkv/sql_impl_test.go b/engine/pkg/meta/internal/sqlkv/sql_impl_test.go index 14e6ffeba56..7c7682a96f4 100644 --- a/engine/pkg/meta/internal/sqlkv/sql_impl_test.go +++ b/engine/pkg/meta/internal/sqlkv/sql_impl_test.go @@ -58,9 +58,9 @@ func mockGetDBConn(t *testing.T, table string) (*sql.DB, sqlmock.Sqlmock) { mock.ExpectQuery("SELECT VERSION()"). WillReturnRows(sqlmock.NewRows([]string{"VERSION()"}). AddRow("5.7.35-log")) - mock.ExpectQuery(regexp.QuoteMeta("SELECT SCHEMA_NAME from Information_schema.SCHEMATA " + - "where SCHEMA_NAME LIKE ? ORDER BY SCHEMA_NAME=? DESC limit 1")). - WillReturnRows(sqlmock.NewRows([]string{"SCHEMA_NAME"})) + // mock.ExpectQuery(regexp.QuoteMeta("SELECT SCHEMA_NAME from Information_schema.SCHEMATA " + + // "where SCHEMA_NAME LIKE ? ORDER BY SCHEMA_NAME=? DESC limit 1")). + // WillReturnRows(sqlmock.NewRows([]string{"SCHEMA_NAME"})) mock.ExpectExec(regexp.QuoteMeta(fmt.Sprintf("CREATE TABLE `%s` (`seq_id` bigint unsigned AUTO_INCREMENT,"+ "`created_at` datetime(3) NULL,`updated_at` datetime(3) NULL,`meta_key` varbinary(2048) not null,`meta_value` longblob,"+ "`job_id` varchar(64) not null,PRIMARY KEY (`seq_id`),UNIQUE INDEX `uidx_jk` (`job_id`,`meta_key`))", table))). diff --git a/engine/pkg/orm/util_test.go b/engine/pkg/orm/util_test.go index 81fd23e51ed..86fed2dba41 100644 --- a/engine/pkg/orm/util_test.go +++ b/engine/pkg/orm/util_test.go @@ -54,21 +54,21 @@ func TestInitialize(t *testing.T) { mock.ExpectQuery("SELECT VERSION()"). WillReturnRows(sqlmock.NewRows([]string{"VERSION()"}).AddRow("5.7.35-log")) - mock.ExpectQuery(regexp.QuoteMeta("SELECT SCHEMA_NAME from Information_schema.SCHEMATA where SCHEMA_NAME LIKE ? ORDER BY SCHEMA_NAME=? DESC limit 1")).WillReturnRows( - sqlmock.NewRows([]string{"SCHEMA_NAME"})) + // mock.ExpectQuery(regexp.QuoteMeta("SELECT SCHEMA_NAME from Information_schema.SCHEMATA where SCHEMA_NAME LIKE ? ORDER BY SCHEMA_NAME=? DESC limit 1")).WillReturnRows( + // sqlmock.NewRows([]string{"SCHEMA_NAME"})) mock.ExpectExec(regexp.QuoteMeta("CREATE TABLE `project_infos` (`seq_id` bigint unsigned AUTO_INCREMENT," + "`created_at` datetime(3) NULL,`updated_at` datetime(3) NULL," + "`id` varchar(128) not null,`name` varchar(128) not null,PRIMARY KEY (`seq_id`)," + "UNIQUE INDEX `uidx_id` (`id`))")).WillReturnResult(sqlmock.NewResult(1, 1)) - mock.ExpectQuery(regexp.QuoteMeta("SELECT SCHEMA_NAME from Information_schema.SCHEMATA where SCHEMA_NAME LIKE ? ORDER BY SCHEMA_NAME=? DESC limit 1")).WillReturnRows( - sqlmock.NewRows([]string{"SCHEMA_NAME"})) + // mock.ExpectQuery(regexp.QuoteMeta("SELECT SCHEMA_NAME from Information_schema.SCHEMATA where SCHEMA_NAME LIKE ? ORDER BY SCHEMA_NAME=? DESC limit 1")).WillReturnRows( + // sqlmock.NewRows([]string{"SCHEMA_NAME"})) mock.ExpectExec(regexp.QuoteMeta("CREATE TABLE `project_operations` (`seq_id` bigint unsigned AUTO_INCREMENT," + "`project_id` varchar(128) not null,`operation` varchar(16) not null,`job_id` varchar(128) not null," + "`created_at` datetime(3) NULL,PRIMARY KEY (`seq_id`),INDEX `idx_op` (`project_id`,`created_at`))")).WillReturnResult(sqlmock.NewResult(1, 1)) - mock.ExpectQuery(regexp.QuoteMeta("SELECT SCHEMA_NAME from Information_schema.SCHEMATA where SCHEMA_NAME LIKE ? ORDER BY SCHEMA_NAME=? DESC limit 1")).WillReturnRows( - sqlmock.NewRows([]string{"SCHEMA_NAME"})) + // mock.ExpectQuery(regexp.QuoteMeta("SELECT SCHEMA_NAME from Information_schema.SCHEMATA where SCHEMA_NAME LIKE ? ORDER BY SCHEMA_NAME=? DESC limit 1")).WillReturnRows( + // sqlmock.NewRows([]string{"SCHEMA_NAME"})) mock.ExpectExec(regexp.QuoteMeta( "CREATE TABLE `master_meta` (`seq_id` bigint unsigned AUTO_INCREMENT,"+ "`created_at` datetime(3) NULL,`updated_at` datetime(3) NULL,"+ @@ -84,8 +84,8 @@ func TestInitialize(t *testing.T) { ".*", // sequence of indexes are nondeterministic ).WillReturnResult(sqlmock.NewResult(1, 1)) - mock.ExpectQuery(regexp.QuoteMeta("SELECT SCHEMA_NAME from Information_schema.SCHEMATA where SCHEMA_NAME LIKE ? ORDER BY SCHEMA_NAME=? DESC limit 1")).WillReturnRows( - sqlmock.NewRows([]string{"SCHEMA_NAME"})) + // mock.ExpectQuery(regexp.QuoteMeta("SELECT SCHEMA_NAME from Information_schema.SCHEMATA where SCHEMA_NAME LIKE ? ORDER BY SCHEMA_NAME=? DESC limit 1")).WillReturnRows( + // sqlmock.NewRows([]string{"SCHEMA_NAME"})) mock.ExpectExec(regexp.QuoteMeta( "CREATE TABLE `worker_statuses` (`seq_id` bigint unsigned AUTO_INCREMENT,"+ "`created_at` datetime(3) NULL,`updated_at` datetime(3) NULL,"+ @@ -101,8 +101,8 @@ func TestInitialize(t *testing.T) { ".*", // sequence of indexes are nondeterministic ).WillReturnResult(sqlmock.NewResult(1, 1)) - mock.ExpectQuery(regexp.QuoteMeta("SELECT SCHEMA_NAME from Information_schema.SCHEMATA where SCHEMA_NAME LIKE ? ORDER BY SCHEMA_NAME=? DESC limit 1")).WillReturnRows( - sqlmock.NewRows([]string{"SCHEMA_NAME"})) + // mock.ExpectQuery(regexp.QuoteMeta("SELECT SCHEMA_NAME from Information_schema.SCHEMATA where SCHEMA_NAME LIKE ? ORDER BY SCHEMA_NAME=? DESC limit 1")).WillReturnRows( + // sqlmock.NewRows([]string{"SCHEMA_NAME"})) mock.ExpectExec(regexp.QuoteMeta( "CREATE TABLE `resource_meta` (`seq_id` bigint unsigned AUTO_INCREMENT,"+ "`created_at` datetime(3) NULL,`updated_at` datetime(3) NULL,"+ @@ -113,16 +113,16 @@ func TestInitialize(t *testing.T) { ".*", // sequence of indexes are nondeterministic ).WillReturnResult(sqlmock.NewResult(1, 1)) - mock.ExpectQuery(regexp.QuoteMeta("SELECT SCHEMA_NAME from Information_schema.SCHEMATA where SCHEMA_NAME LIKE ? ORDER BY SCHEMA_NAME=? DESC limit 1")). - WillReturnRows(sqlmock.NewRows([]string{"SCHEMA_NAME"})) + // mock.ExpectQuery(regexp.QuoteMeta("SELECT SCHEMA_NAME from Information_schema.SCHEMATA where SCHEMA_NAME LIKE ? ORDER BY SCHEMA_NAME=? DESC limit 1")). + // WillReturnRows(sqlmock.NewRows([]string{"SCHEMA_NAME"})) mock.ExpectExec(regexp.QuoteMeta("CREATE TABLE `logic_epoches` (`seq_id` bigint unsigned AUTO_INCREMENT,`created_at` datetime(3) NULL," + "`updated_at` datetime(3) NULL,`job_id` varchar(128) not null,`epoch` bigint not null default 1,PRIMARY KEY (`seq_id`),UNIQUE INDEX `uidx_jk` (`job_id`))")). WillReturnResult(sqlmock.NewResult(1, 1)) - mock.ExpectQuery(regexp.QuoteMeta( - "SELECT SCHEMA_NAME from Information_schema.SCHEMATA " + - "where SCHEMA_NAME LIKE ? ORDER BY SCHEMA_NAME=? DESC limit 1"), - ).WillReturnRows(sqlmock.NewRows([]string{"SCHEMA_NAME"})) + // mock.ExpectQuery(regexp.QuoteMeta( + // "SELECT SCHEMA_NAME from Information_schema.SCHEMATA " + + // "where SCHEMA_NAME LIKE ? ORDER BY SCHEMA_NAME=? DESC limit 1"), + // ).WillReturnRows(sqlmock.NewRows([]string{"SCHEMA_NAME"})) mock.ExpectExec(regexp.QuoteMeta( "CREATE TABLE `job_ops` (`seq_id` bigint unsigned AUTO_INCREMENT,"+ "`created_at` datetime(3) NULL,`updated_at` datetime(3) NULL,"+ @@ -131,10 +131,10 @@ func TestInitialize(t *testing.T) { ".*", // sequence of indexes are nondeterministic ).WillReturnResult(sqlmock.NewResult(1, 1)) - mock.ExpectQuery(regexp.QuoteMeta( - "SELECT SCHEMA_NAME from Information_schema.SCHEMATA " + - "where SCHEMA_NAME LIKE ? ORDER BY SCHEMA_NAME=? DESC limit 1"), - ).WillReturnRows(sqlmock.NewRows([]string{"SCHEMA_NAME"})) + // mock.ExpectQuery(regexp.QuoteMeta( + // "SELECT SCHEMA_NAME from Information_schema.SCHEMATA " + + // "where SCHEMA_NAME LIKE ? ORDER BY SCHEMA_NAME=? DESC limit 1"), + // ).WillReturnRows(sqlmock.NewRows([]string{"SCHEMA_NAME"})) mock.ExpectExec(regexp.QuoteMeta( "CREATE TABLE `executors` (`seq_id` bigint unsigned AUTO_INCREMENT," + "`created_at` datetime(3) NULL,`updated_at` datetime(3) NULL," + @@ -143,9 +143,9 @@ func TestInitialize(t *testing.T) { "UNIQUE INDEX `uni_id` (`id`))"), ).WillReturnResult(sqlmock.NewResult(1, 1)) - mock.ExpectQuery(regexp.QuoteMeta("SELECT SCHEMA_NAME from Information_schema.SCHEMATA " + - "where SCHEMA_NAME LIKE ? ORDER BY SCHEMA_NAME=? DESC limit 1")).WillReturnRows( - sqlmock.NewRows([]string{"SCHEMA_NAME"})) + // mock.ExpectQuery(regexp.QuoteMeta("SELECT SCHEMA_NAME from Information_schema.SCHEMATA " + + // "where SCHEMA_NAME LIKE ? ORDER BY SCHEMA_NAME=? DESC limit 1")).WillReturnRows( + // sqlmock.NewRows([]string{"SCHEMA_NAME"})) mock.ExpectExec(regexp.QuoteMeta("CREATE TABLE `logic_epoches` (`seq_id` bigint unsigned AUTO_INCREMENT," + "`created_at` datetime(3) NULL,`updated_at` datetime(3) NULL,`job_id` varchar(128) not null,`epoch` bigint not null default 1," + "PRIMARY KEY (`seq_id`),UNIQUE INDEX `uidx_jk` (`job_id`))")). @@ -175,9 +175,6 @@ func TestInitEpochModel(t *testing.T) { mock.ExpectQuery("SELECT VERSION()"). WillReturnRows(sqlmock.NewRows([]string{"VERSION()"}).AddRow("5.7.35-log")) - mock.ExpectQuery(regexp.QuoteMeta("SELECT SCHEMA_NAME from Information_schema.SCHEMATA " + - "where SCHEMA_NAME LIKE ? ORDER BY SCHEMA_NAME=? DESC limit 1")).WillReturnRows( - sqlmock.NewRows([]string{"SCHEMA_NAME"})) mock.ExpectExec(regexp.QuoteMeta("CREATE TABLE `logic_epoches` (`seq_id` bigint unsigned AUTO_INCREMENT," + "`created_at` datetime(3) NULL,`updated_at` datetime(3) NULL,`job_id` varchar(128) not null,`epoch` bigint not null default 1," + "PRIMARY KEY (`seq_id`),UNIQUE INDEX `uidx_jk` (`job_id`))")).