From 1e1c7e1cac0f020dbb89013e6ee75d7fe3993f07 Mon Sep 17 00:00:00 2001 From: rocky114 <934313141@qq.com> Date: Tue, 24 Oct 2023 17:55:36 +0800 Subject: [PATCH 1/4] fix: unit test(TestManager) --- sqle/server/auditplan/manager_test.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/sqle/server/auditplan/manager_test.go b/sqle/server/auditplan/manager_test.go index ff0d0c9679..f8978a32c3 100644 --- a/sqle/server/auditplan/manager_test.go +++ b/sqle/server/auditplan/manager_test.go @@ -26,16 +26,16 @@ func TestManager(t *testing.T) { nextTime := m.lastSyncTime.Add(5 * time.Second) // test init - mockHandle.ExpectQuery("SELECT `audit_plans`.* FROM `audit_plans` LEFT JOIN projects ON projects.id = audit_plans.project_id WHERE `audit_plans`.`deleted_at` IS NULL AND ((projects.status = 'active'))"). - WithArgs(). + mockHandle.ExpectQuery("SELECT * FROM `audit_plans` WHERE `audit_plans`.`deleted_at` IS NULL AND ((project_status = ?))"). + WithArgs("active"). WillReturnRows(sqlmock.NewRows([]string{"id", "name", "type", "cron_expression"}).AddRow(1, "test_ap_1", "default", "*/1 * * * *")) mockHandle.ExpectQuery("SELECT id, updated_at FROM `audit_plans` WHERE (updated_at > ?) ORDER BY updated_at"). WithArgs(m.lastSyncTime). WillReturnRows(sqlmock.NewRows([]string{"id", "updated_at"}).AddRow(2, nextTime)) - mockHandle.ExpectQuery("SELECT `audit_plans`.* FROM `audit_plans` LEFT JOIN projects ON projects.id = audit_plans.project_id WHERE `audit_plans`.`deleted_at` IS NULL AND ((projects.status = 'active') AND (audit_plans.id = ?))"). - WithArgs(2). + mockHandle.ExpectQuery("SELECT * FROM `audit_plans` WHERE `audit_plans`.`deleted_at` IS NULL AND ((project_status = ?) AND (id = ?)) "). + WithArgs("active", 2). WillReturnRows(sqlmock.NewRows([]string{"id", "name", "type", "cron_expression"}).AddRow(2, "test_ap_2", "default", "*/2 * * * *")) assert.NoError(t, m.sync()) @@ -65,8 +65,8 @@ func TestManager(t *testing.T) { WithArgs(nextTime). WillReturnRows(sqlmock.NewRows([]string{"id", "updated_at"}).AddRow(3, nextTimeMore)) - mockHandle.ExpectQuery("SELECT `audit_plans`.* FROM `audit_plans` LEFT JOIN projects ON projects.id = audit_plans.project_id WHERE `audit_plans`.`deleted_at` IS NULL AND ((projects.status = 'active') AND (audit_plans.id = ?))"). - WithArgs(3). + mockHandle.ExpectQuery("SELECT * FROM `audit_plans` WHERE `audit_plans`.`deleted_at` IS NULL AND ((project_status = ?) AND (id = ?))"). + WithArgs("active", 3). WillReturnRows(sqlmock.NewRows([]string{"id", "name", "type", "cron_expression"}).AddRow(3, "test_ap_3", "default", "*/3 * * * *")) m.sync() @@ -87,8 +87,8 @@ func TestManager(t *testing.T) { WithArgs(nextTimeMore). WillReturnRows(sqlmock.NewRows([]string{"id", "updated_at"}).AddRow(3, nextTimeMore2)) - mockHandle.ExpectQuery("SELECT `audit_plans`.* FROM `audit_plans` LEFT JOIN projects ON projects.id = audit_plans.project_id WHERE `audit_plans`.`deleted_at` IS NULL AND ((projects.status = 'active') AND (audit_plans.id = ?))"). - WithArgs(3). + mockHandle.ExpectQuery("SELECT * FROM `audit_plans` WHERE `audit_plans`.`deleted_at` IS NULL AND ((project_status = ?) AND (id = ?))"). + WithArgs("active", 3). WillReturnRows(sqlmock.NewRows([]string{"id", "name", "type", "cron_expression"})) m.sync() From 15b28539d18ecfc20d38c09afbc2bb8fd69ed656 Mon Sep 17 00:00:00 2001 From: rocky114 <934313141@qq.com> Date: Tue, 24 Oct 2023 18:58:02 +0800 Subject: [PATCH 2/4] fix: unit test (sqled_test.go) --- sqle/server/sqled_test.go | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/sqle/server/sqled_test.go b/sqle/server/sqled_test.go index 6683038e3e..a71047ad5c 100644 --- a/sqle/server/sqled_test.go +++ b/sqle/server/sqled_test.go @@ -25,7 +25,6 @@ func getAction(sqls []string, typ int, p driver.Plugin) *action { Model: model.Model{ID: 1}, SQLSource: model.TaskSQLSourceFromMyBatisXMLFile, InstanceId: 1, - Instance: &model.Instance{}, } for _, sql := range sqls { @@ -36,12 +35,11 @@ func getAction(sqls []string, typ int, p driver.Plugin) *action { entry := log.NewEntry().WithField("task_id", task.ID) return &action{ - task: task, - plugin: p, - typ: typ, - entry: entry, - done: make(chan struct{}), - customRules: []*model.CustomRule{}, + task: task, + plugin: p, + typ: typ, + entry: entry, + done: make(chan struct{}), } } @@ -166,8 +164,8 @@ func Test_action_audit_UpdateTask(t *testing.T) { } act := getAction([]string{"select * from t1"}, ActionTypeAudit, &mockDriver{}) - mock.ExpectQuery(regexp.QuoteMeta("SELECT `sql_whitelist`.* FROM `sql_whitelist` WHERE `sql_whitelist`.`deleted_at` IS NULL")). - WithArgs(1). + mock.ExpectQuery(regexp.QuoteMeta("SELECT * FROM `sql_whitelist` WHERE `sql_whitelist`.`deleted_at` IS NULL AND ((sql_whitelist.project_id = ?))")). + WithArgs(""). WillReturnRows(sqlmock.NewRows([]string{"value", "match_type"}).AddRow(whitelist.Value, whitelist.MatchType)) mock.ExpectBegin() @@ -210,7 +208,7 @@ func Test_action_execute(t *testing.T) { return nil }) - gomonkey.ApplyMethod(reflect.TypeOf(&model.Storage{}), "GetRulesFromRuleTemplateByName", func(_ *model.Storage, _ []uint, _ string) ([]*model.Rule, []*model.CustomRule, error) { + gomonkey.ApplyMethod(reflect.TypeOf(&model.Storage{}), "GetRulesFromRuleTemplateByName", func(_ *model.Storage, _ []string, _ string) ([]*model.Rule, []*model.CustomRule, error) { return nil, nil, nil }) } From ea3cc2e2f1e548afefccff087613a522a62c639b Mon Sep 17 00:00:00 2001 From: yangzhongjiao Date: Wed, 25 Oct 2023 09:48:18 +0000 Subject: [PATCH 3/4] fix: unit test --- sqle/api/controller/v1/oauth2_ce.go | 4 +- sqle/api/controller/v1/sync_instance_ce.go | 4 +- sqle/api/middleware/jwt.go | 3 +- sqle/api/middleware/jwt_test.go | 55 ++++++++++++++++++---- sqle/api/middleware/license_qa.go | 4 +- sqle/model/audit_plan_list_test.go | 47 +++++++++--------- 6 files changed, 75 insertions(+), 42 deletions(-) diff --git a/sqle/api/controller/v1/oauth2_ce.go b/sqle/api/controller/v1/oauth2_ce.go index ea911f9141..9f16e560ea 100644 --- a/sqle/api/controller/v1/oauth2_ce.go +++ b/sqle/api/controller/v1/oauth2_ce.go @@ -1,5 +1,5 @@ -// //go:build !enterprise -// // +build !enterprise +//go:build !enterprise +// +build !enterprise package v1 diff --git a/sqle/api/controller/v1/sync_instance_ce.go b/sqle/api/controller/v1/sync_instance_ce.go index e778234102..8cba4285a1 100644 --- a/sqle/api/controller/v1/sync_instance_ce.go +++ b/sqle/api/controller/v1/sync_instance_ce.go @@ -1,5 +1,5 @@ -// //go:build !enterprise -// // +build !enterprise +//go:build !enterprise +// +build !enterprise package v1 diff --git a/sqle/api/middleware/jwt.go b/sqle/api/middleware/jwt.go index 750e499d6c..38d3b6a790 100644 --- a/sqle/api/middleware/jwt.go +++ b/sqle/api/middleware/jwt.go @@ -8,7 +8,6 @@ import ( "strings" dmsCommonJwt "github.com/actiontech/dms/pkg/dms-common/api/jwt" - "github.com/actiontech/sqle/sqle/api/controller" "github.com/actiontech/sqle/sqle/dms" "github.com/actiontech/sqle/sqle/model" "github.com/labstack/echo/v4" @@ -66,7 +65,7 @@ func ScannerVerifier() echo.MiddlewareFunc { projectUid, err := dms.GetPorjectUIDByName(context.TODO(), c.Param("project_name")) if err != nil { - return controller.JSONBaseErrorReq(c, err) + return echo.NewHTTPError(http.StatusInternalServerError, err.Error()) } apnInParam := c.Param("audit_plan_name") if apnInToken != apnInParam { diff --git a/sqle/api/middleware/jwt_test.go b/sqle/api/middleware/jwt_test.go index c515f55cac..7fef0868dd 100644 --- a/sqle/api/middleware/jwt_test.go +++ b/sqle/api/middleware/jwt_test.go @@ -2,14 +2,18 @@ package middleware import ( "database/sql/driver" + "encoding/json" "fmt" + "log" "net/http" "net/http/httptest" "testing" "time" sqlmock "github.com/DATA-DOG/go-sqlmock" + dmsCommon "github.com/actiontech/dms/pkg/dms-common/api/dms/v1" dmsCommonJwt "github.com/actiontech/dms/pkg/dms-common/api/jwt" + "github.com/actiontech/sqle/sqle/api/controller" "github.com/actiontech/sqle/sqle/model" "github.com/jinzhu/gorm" "github.com/labstack/echo/v4" @@ -17,11 +21,42 @@ import ( "github.com/stretchr/testify/assert" ) +func mockServer() *httptest.Server { + f := func(w http.ResponseWriter, r *http.Request) { + response := dmsCommon.ListProjectReply{ + Data: []*dmsCommon.ListProject{{ + ProjectUid: "700300", + Name: "default", + Archived: false, + }}, + Total: 1, + } + res, err := json.Marshal(response) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + log.Printf("reponse err ") + return + } + w.WriteHeader(http.StatusOK) + w.Header().Set("Content-Type", "application/json") + + _, err = w.Write(res) + if err != nil { + log.Printf("reponse err ") + } + } + return httptest.NewServer(http.HandlerFunc(f)) +} + func TestScannerVerifier(t *testing.T) { + server := mockServer() + defer server.Close() + controller.InitDMSServerAddress(server.URL) + e := echo.New() apName := "test_audit_plan" - projectName := "test_project" + projectUID := "700300" testUser := "test_user" h := func(c echo.Context) error { @@ -36,7 +71,7 @@ func TestScannerVerifier(t *testing.T) { res := httptest.NewRecorder() ctx := e.NewContext(req, res) ctx.SetParamNames("audit_plan_name", "project_name") - ctx.SetParamValues(apName, projectName) + ctx.SetParamValues(apName, projectUID) return ctx, res } @@ -63,8 +98,8 @@ func TestScannerVerifier(t *testing.T) { mockDB, mock, err := sqlmock.New(sqlmock.QueryMatcherOption(sqlmock.QueryMatcherEqual)) assert.NoError(t, err) model.InitMockStorage(mockDB) - mock.ExpectQuery("SELECT `audit_plans`.* FROM `audit_plans` LEFT JOIN projects ON projects.id = audit_plans.project_id WHERE `audit_plans`.`deleted_at` IS NULL AND ((projects.name = ? AND audit_plans.name = ?))"). - WithArgs(projectName, apName). + mock.ExpectQuery("SELECT * FROM `audit_plans` WHERE `audit_plans`.`deleted_at` IS NULL AND ((project_id = ? AND name = ?))"). + WithArgs(projectUID, apName). WillReturnRows(sqlmock.NewRows([]string{"name", "token"}).AddRow(driver.Value(testUser), "test-token")) mock.ExpectClose() @@ -84,8 +119,8 @@ func TestScannerVerifier(t *testing.T) { mockDB, mock, err := sqlmock.New(sqlmock.QueryMatcherOption(sqlmock.QueryMatcherEqual)) assert.NoError(t, err) model.InitMockStorage(mockDB) - mock.ExpectQuery("SELECT `audit_plans`.* FROM `audit_plans` LEFT JOIN projects ON projects.id = audit_plans.project_id WHERE `audit_plans`.`deleted_at` IS NULL AND ((projects.name = ? AND audit_plans.name = ?))"). - WithArgs(projectName, apName). + mock.ExpectQuery("SELECT * FROM `audit_plans` WHERE `audit_plans`.`deleted_at` IS NULL AND ((project_id = ? AND name = ?))"). + WithArgs(projectUID, apName). WillReturnError(gorm.ErrRecordNotFound) assert.NoError(t, err) model.InitMockStorage(mockDB) @@ -107,8 +142,8 @@ func TestScannerVerifier(t *testing.T) { mockDB, mock, err := sqlmock.New(sqlmock.QueryMatcherOption(sqlmock.QueryMatcherEqual)) assert.NoError(t, err) model.InitMockStorage(mockDB) - mock.ExpectQuery("SELECT `audit_plans`.* FROM `audit_plans` LEFT JOIN projects ON projects.id = audit_plans.project_id WHERE `audit_plans`.`deleted_at` IS NULL AND ((projects.name = ? AND audit_plans.name = ?))"). - WithArgs(projectName, apName). + mock.ExpectQuery("SELECT * FROM `audit_plans` WHERE `audit_plans`.`deleted_at` IS NULL AND ((project_id = ? AND name = ?))"). + WithArgs(projectUID, apName). WillReturnRows(sqlmock.NewRows([]string{"name", "token"}).AddRow(testUser, token)) mock.ExpectClose() @@ -129,8 +164,8 @@ func TestScannerVerifier(t *testing.T) { mockDB, mock, err := sqlmock.New(sqlmock.QueryMatcherOption(sqlmock.QueryMatcherEqual)) assert.NoError(t, err) model.InitMockStorage(mockDB) - mock.ExpectQuery("SELECT `audit_plans`.* FROM `audit_plans` LEFT JOIN projects ON projects.id = audit_plans.project_id WHERE `audit_plans`.`deleted_at` IS NULL AND ((projects.name = ? AND audit_plans.name = ?))"). - WithArgs(projectName, apName). + mock.ExpectQuery("SELECT * FROM `audit_plans` WHERE `audit_plans`.`deleted_at` IS NULL AND ((project_id = ? AND name = ?))"). + WithArgs(projectUID, apName). WillReturnRows(sqlmock.NewRows([]string{"name", "token"}).AddRow(testUser, token)) mock.ExpectClose() diff --git a/sqle/api/middleware/license_qa.go b/sqle/api/middleware/license_qa.go index 52b169ea6d..f076d0d493 100644 --- a/sqle/api/middleware/license_qa.go +++ b/sqle/api/middleware/license_qa.go @@ -1,5 +1,5 @@ -// //go:build !release -// // +build !release +//go:build !release +// +build !release package middleware diff --git a/sqle/model/audit_plan_list_test.go b/sqle/model/audit_plan_list_test.go index 724cccbd5b..71f3483d26 100644 --- a/sqle/model/audit_plan_list_test.go +++ b/sqle/model/audit_plan_list_test.go @@ -12,14 +12,11 @@ import ( func TestStorage_GetAuditPlansByReq(t *testing.T) { // 1. test for common user tableAndRowOfSQL := ` - FROM audit_plans - LEFT JOIN users ON audit_plans.create_user_id = users.id - LEFT JOIN projects ON audit_plans.project_id = projects.id - WHERE audit_plans.deleted_at IS NULL - AND users.deleted_at IS NULL - AND ( - users.login_name = ? - ) + FROM + audit_plans +WHERE + audit_plans.deleted_at IS NULL + AND ( audit_plans.create_user_id = ? ) AND audit_plans.db_type = ? ` mockDB, mock, err := sqlmock.New(sqlmock.QueryMatcherOption(sqlmock.QueryMatcherEqual)) @@ -47,11 +44,10 @@ func TestStorage_GetAuditPlansByReq(t *testing.T) { // 2. test for admin user tableAndRowOfSQL1 := ` - FROM audit_plans - LEFT JOIN users ON audit_plans.create_user_id = users.id - LEFT JOIN projects ON audit_plans.project_id = projects.id - WHERE audit_plans.deleted_at IS NULL - AND users.deleted_at IS NULL + FROM + audit_plans +WHERE + audit_plans.deleted_at IS NULL ` mockDB, mock, err = sqlmock.New(sqlmock.QueryMatcherOption(sqlmock.QueryMatcherEqual)) assert.NoError(t, err) @@ -111,29 +107,32 @@ func TestStorage_GetAuditPlanSQLsByReq(t *testing.T) { func TestStorage_GetAuditPlanReportsByReq(t *testing.T) { tableAndRowOfSQL := ` - FROM audit_plan_reports_v2 AS reports - JOIN audit_plans ON audit_plans.id = reports.audit_plan_id - JOIN projects ON projects.id = audit_plans.project_id - WHERE reports.deleted_at IS NULL - AND audit_plans.deleted_at IS NULL - AND audit_plans.name = ? - AND projects.name = ? - ORDER BY reports.created_at DESC , reports.id DESC + FROM + audit_plan_reports_v2 AS reports + JOIN audit_plans ON audit_plans.id = reports.audit_plan_id +WHERE + reports.deleted_at IS NULL + AND audit_plans.deleted_at IS NULL + AND audit_plans.name = ? + AND audit_plans.project_id = ? +ORDER BY + reports.created_at DESC , + reports.id DESC ` mockDB, mock, err := sqlmock.New(sqlmock.QueryMatcherOption(sqlmock.QueryMatcherEqual)) assert.NoError(t, err) defer mockDB.Close() InitMockStorage(mockDB) mock.ExpectPrepare(fmt.Sprintf(`SELECT reports.id, reports.score , reports.pass_rate, reports.audit_level, reports.created_at %v LIMIT ? OFFSET ?`, tableAndRowOfSQL)). - ExpectQuery().WithArgs("audit_plan_for_jave_repo", "project_1", 100, 10).WillReturnRows(sqlmock.NewRows([]string{ + ExpectQuery().WithArgs("audit_plan_for_jave_repo", "1", 100, 10).WillReturnRows(sqlmock.NewRows([]string{ "id", "score", "pass_rate", "audit_level", "created_at"}). AddRow("1", 100, 1, "normal", "2021-09-01T13:46:13+08:00")) mock.ExpectPrepare(fmt.Sprintf(`SELECT COUNT(*) %v`, tableAndRowOfSQL)). - ExpectQuery().WithArgs("audit_plan_for_jave_repo", "project_1").WillReturnRows(sqlmock.NewRows([]string{"COUNT(*)"}).AddRow("2")) + ExpectQuery().WithArgs("audit_plan_for_jave_repo", "1").WillReturnRows(sqlmock.NewRows([]string{"COUNT(*)"}).AddRow("2")) nameFields := map[string]interface{}{ "audit_plan_name": "audit_plan_for_jave_repo", - "project_name": "project_1", + "project_id": "1", "limit": 100, "offset": 10} result, count, err := GetStorage().GetAuditPlanReportsByReq(nameFields) From 1aa8a21b343573ec31404295e1d386bfc7ad7ddd Mon Sep 17 00:00:00 2001 From: yangzhongjiao Date: Thu, 26 Oct 2023 04:39:57 +0000 Subject: [PATCH 4/4] fix: golang lint --- sqle/api/controller/v1/statistic_ce.go | 4 ---- sqle/api/controller/v1/task.go | 13 ++----------- sqle/api/middleware/jwt_test.go | 4 ++-- sqle/dms/instance.go | 4 ++-- sqle/model/instance.go | 2 +- 5 files changed, 7 insertions(+), 20 deletions(-) diff --git a/sqle/api/controller/v1/statistic_ce.go b/sqle/api/controller/v1/statistic_ce.go index 736a85784c..37e082287c 100644 --- a/sqle/api/controller/v1/statistic_ce.go +++ b/sqle/api/controller/v1/statistic_ce.go @@ -17,10 +17,6 @@ func getInstancesTypePercentV1(c echo.Context) error { return controller.JSONBaseErrorReq(c, errCommunityEditionDoesNotSupportStatistic) } -func getLicenseUsageV1(c echo.Context) error { - return controller.JSONBaseErrorReq(c, errCommunityEditionDoesNotSupportStatistic) -} - func getWorkflowRejectedPercentGroupByCreatorV1(c echo.Context) error { return controller.JSONBaseErrorReq(c, errCommunityEditionDoesNotSupportStatistic) } diff --git a/sqle/api/controller/v1/task.go b/sqle/api/controller/v1/task.go index 73d1c4c92d..8f9a6b2497 100644 --- a/sqle/api/controller/v1/task.go +++ b/sqle/api/controller/v1/task.go @@ -171,7 +171,7 @@ func CreateAndAuditTask(c echo.Context) error { } task := &model.Task{ Schema: req.InstanceSchema, - InstanceId: uint64(instance.ID), + InstanceId: instance.ID, Instance: instance, CreateUserId: uint64(user.ID), ExecuteSQLs: []*model.ExecuteSQL{}, @@ -702,7 +702,7 @@ func CreateAuditTasksGroupV1(c echo.Context) error { for i, reqInstance := range req.Instances { tasks[i] = &model.Task{ Schema: reqInstance.InstanceSchema, - InstanceId: uint64(nameInstanceMap[reqInstance.InstanceName].ID), + InstanceId: nameInstanceMap[reqInstance.InstanceName].ID, CreateUserId: uint64(user.ID), DBType: nameInstanceMap[reqInstance.InstanceName].DbType, } @@ -722,15 +722,6 @@ func CreateAuditTasksGroupV1(c echo.Context) error { }) } -func getDistinctInstNameList(instList []*InstanceForCreatingTask) []string { - instNames := make([]string, len(instList)) - for i, inst := range instList { - instNames[i] = inst.InstanceName - } - - return utils.RemoveDuplicate(instNames) -} - type AuditTaskGroupReqV1 struct { TaskGroupId uint `json:"task_group_id" form:"task_group_id" valid:"required"` Sql string `json:"sql" form:"sql" example:"alter table tb1 drop columns c1"` diff --git a/sqle/api/middleware/jwt_test.go b/sqle/api/middleware/jwt_test.go index 7fef0868dd..723eaf92b0 100644 --- a/sqle/api/middleware/jwt_test.go +++ b/sqle/api/middleware/jwt_test.go @@ -34,7 +34,7 @@ func mockServer() *httptest.Server { res, err := json.Marshal(response) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) - log.Printf("reponse err ") + log.Printf("response err %v", err) return } w.WriteHeader(http.StatusOK) @@ -42,7 +42,7 @@ func mockServer() *httptest.Server { _, err = w.Write(res) if err != nil { - log.Printf("reponse err ") + log.Printf("response err %v ", err) } } return httptest.NewServer(http.HandlerFunc(f)) diff --git a/sqle/dms/instance.go b/sqle/dms/instance.go index d44cd0f6b5..937e8e4f46 100644 --- a/sqle/dms/instance.go +++ b/sqle/dms/instance.go @@ -126,7 +126,7 @@ func convertInstance(instance *dmsV1.ListDBService) (*model.Instance, error) { return &model.Instance{ ID: uint64(instanceId), Name: instance.Name, - DbType: string(instance.DBType), + DbType: instance.DBType, RuleTemplateId: uint64(ruleTemplateId), RuleTemplateName: instance.SQLEConfig.RuleTemplateName, ProjectId: instance.ProjectUID, @@ -292,7 +292,7 @@ func GetInstancesByIds(ctx context.Context, instanceIds []uint64) ([]*model.Inst func GetInstanceIdNameMapByIds(ctx context.Context, instanceIds []uint64) (map[uint64]string, error) { // todo: remove duplicate instance id - ret := make(map[uint64]string, 0) + ret := make(map[uint64]string) for _, instanceId := range instanceIds { instance, exist, err := getInstance(ctx, dmsV1.ListDBServiceReq{ PageSize: 1, diff --git a/sqle/model/instance.go b/sqle/model/instance.go index e7fe3af113..06edf54d90 100644 --- a/sqle/model/instance.go +++ b/sqle/model/instance.go @@ -324,7 +324,7 @@ type InstanceWorkFlowStatusCount struct { func (s *Storage) GetInstanceWorkFlowStatusCountByProject(instances []*Instance, queryStatus []string) ([]*InstanceWorkFlowStatusCount, error) { var instanceWorkFlowStatusCount []*InstanceWorkFlowStatusCount - var instanceIds []uint64 + instanceIds := make([]uint64, 0) var instanceMap = make(map[uint64]InstanceWorkFlowStatusCount) for _, instance := range instances { instanceMap[instance.ID] = InstanceWorkFlowStatusCount{