Skip to content

Commit

Permalink
fix failed unit test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
asddongmen committed Dec 14, 2023
1 parent ac6a1fc commit fb15db7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 29 deletions.
6 changes: 3 additions & 3 deletions engine/pkg/meta/internal/sqlkv/sql_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))).
Expand Down
49 changes: 23 additions & 26 deletions engine/pkg/orm/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,"+
Expand All @@ -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,"+
Expand All @@ -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,"+
Expand All @@ -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,"+
Expand All @@ -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," +
Expand All @@ -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`))")).
Expand Down Expand Up @@ -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`))")).
Expand Down

0 comments on commit fb15db7

Please sign in to comment.