From 962bafb7ce16b961156a3977d3d4e433201bd384 Mon Sep 17 00:00:00 2001 From: Steven Zou Date: Tue, 22 Oct 2019 18:47:18 +0800 Subject: [PATCH] fix go imports order issues Signed-off-by: Steven Zou --- src/core/api/repository.go | 8 +++----- src/core/main.go | 11 ++++------- .../notification/scan_image_handler_test.go | 17 +++++++++++++++++ src/core/service/notifications/jobs/handler.go | 3 +-- src/pkg/art/basic_controller.go | 2 +- src/pkg/art/manager.go | 1 + src/pkg/scan/api/scan/base_controller.go | 5 ++--- src/pkg/scan/api/scan/base_controller_test.go | 1 + src/pkg/scan/event/init.go | 2 +- 9 files changed, 31 insertions(+), 19 deletions(-) diff --git a/src/core/api/repository.go b/src/core/api/repository.go index 274052b5c..9372d68fa 100755 --- a/src/core/api/repository.go +++ b/src/core/api/repository.go @@ -24,11 +24,6 @@ import ( "strings" "time" - "github.com/goharbor/harbor/src/jobservice/logger" - - "github.com/goharbor/harbor/src/pkg/scan/api/scan" - v1 "github.com/goharbor/harbor/src/pkg/scan/rest/v1" - "github.com/docker/distribution/manifest/schema1" "github.com/docker/distribution/manifest/schema2" "github.com/goharbor/harbor/src/common" @@ -44,8 +39,11 @@ import ( "github.com/goharbor/harbor/src/core/config" notifierEvt "github.com/goharbor/harbor/src/core/notifier/event" coreutils "github.com/goharbor/harbor/src/core/utils" + "github.com/goharbor/harbor/src/jobservice/logger" "github.com/goharbor/harbor/src/pkg/art" "github.com/goharbor/harbor/src/pkg/immutabletag/match/rule" + "github.com/goharbor/harbor/src/pkg/scan/api/scan" + v1 "github.com/goharbor/harbor/src/pkg/scan/rest/v1" "github.com/goharbor/harbor/src/replication" "github.com/goharbor/harbor/src/replication/event" "github.com/goharbor/harbor/src/replication/model" diff --git a/src/core/main.go b/src/core/main.go index 3977557e3..244fe0c29 100755 --- a/src/core/main.go +++ b/src/core/main.go @@ -23,8 +23,6 @@ import ( "syscall" "time" - "github.com/goharbor/harbor/src/pkg/scan/event" - "github.com/astaxie/beego" _ "github.com/astaxie/beego/session/redis" "github.com/goharbor/harbor/src/common/dao" @@ -34,16 +32,14 @@ import ( "github.com/goharbor/harbor/src/common/utils" "github.com/goharbor/harbor/src/common/utils/log" "github.com/goharbor/harbor/src/core/api" + quota "github.com/goharbor/harbor/src/core/api/quota" + _ "github.com/goharbor/harbor/src/core/api/quota/chart" + _ "github.com/goharbor/harbor/src/core/api/quota/registry" _ "github.com/goharbor/harbor/src/core/auth/authproxy" _ "github.com/goharbor/harbor/src/core/auth/db" _ "github.com/goharbor/harbor/src/core/auth/ldap" _ "github.com/goharbor/harbor/src/core/auth/oidc" _ "github.com/goharbor/harbor/src/core/auth/uaa" - - quota "github.com/goharbor/harbor/src/core/api/quota" - _ "github.com/goharbor/harbor/src/core/api/quota/chart" - _ "github.com/goharbor/harbor/src/core/api/quota/registry" - "github.com/goharbor/harbor/src/core/config" "github.com/goharbor/harbor/src/core/filter" "github.com/goharbor/harbor/src/core/middlewares" @@ -52,6 +48,7 @@ import ( "github.com/goharbor/harbor/src/pkg/notification" "github.com/goharbor/harbor/src/pkg/scan" "github.com/goharbor/harbor/src/pkg/scan/dao/scanner" + "github.com/goharbor/harbor/src/pkg/scan/event" "github.com/goharbor/harbor/src/pkg/scheduler" "github.com/goharbor/harbor/src/pkg/types" "github.com/goharbor/harbor/src/replication" diff --git a/src/core/notifier/handler/notification/scan_image_handler_test.go b/src/core/notifier/handler/notification/scan_image_handler_test.go index 23914268f..aefb03a59 100644 --- a/src/core/notifier/handler/notification/scan_image_handler_test.go +++ b/src/core/notifier/handler/notification/scan_image_handler_test.go @@ -57,12 +57,19 @@ func (suite *ScanImagePreprocessHandlerSuite) SetupSuite() { Artifact: a, } + reports := []*scan.Report{ + { + Report: "{}", + }, + } + suite.c = sc.DefaultController mc := &MockScanAPIController{} var options []report.Option s := make(map[string]interface{}) mc.On("GetSummary", a, []string{v1.MimeTypeNativeReport}, options).Return(s, nil) + mc.On("GetReport", a, []string{v1.MimeTypeNativeReport}).Return(reports, nil) sc.DefaultController = mc @@ -140,6 +147,16 @@ func (msc *MockScanAPIController) HandleJobHooks(trackID string, change *job.Sta return args.Error(0) } +func (msc *MockScanAPIController) DeleteReports(digests ...string) error { + pl := make([]interface{}, 0) + for _, d := range digests { + pl = append(pl, d) + } + args := msc.Called(pl...) + + return args.Error(0) +} + // MockHTTPHandler ... type MockHTTPHandler struct{} diff --git a/src/core/service/notifications/jobs/handler.go b/src/core/service/notifications/jobs/handler.go index 3bec8ac59..743b94dfb 100755 --- a/src/core/service/notifications/jobs/handler.go +++ b/src/core/service/notifications/jobs/handler.go @@ -18,8 +18,6 @@ import ( "encoding/json" "time" - "github.com/goharbor/harbor/src/pkg/scan/api/scan" - "github.com/goharbor/harbor/src/common/job" "github.com/goharbor/harbor/src/common/models" "github.com/goharbor/harbor/src/common/utils/log" @@ -29,6 +27,7 @@ import ( "github.com/goharbor/harbor/src/pkg/notification" "github.com/goharbor/harbor/src/pkg/retention" sc "github.com/goharbor/harbor/src/pkg/scan" + "github.com/goharbor/harbor/src/pkg/scan/api/scan" "github.com/goharbor/harbor/src/replication" "github.com/goharbor/harbor/src/replication/operation/hook" "github.com/goharbor/harbor/src/replication/policy/scheduler" diff --git a/src/pkg/art/basic_controller.go b/src/pkg/art/basic_controller.go index eb51c08cf..2050185c4 100644 --- a/src/pkg/art/basic_controller.go +++ b/src/pkg/art/basic_controller.go @@ -27,7 +27,7 @@ type basicController struct { m Manager } -// NewController +// NewController ... func NewController() Controller { return &basicController{ m: NewManager(), diff --git a/src/pkg/art/manager.go b/src/pkg/art/manager.go index c4135439a..a900e0dd8 100644 --- a/src/pkg/art/manager.go +++ b/src/pkg/art/manager.go @@ -19,6 +19,7 @@ import ( "github.com/goharbor/harbor/src/pkg/q" ) +// Manager is designed to manage the artifact type Manager interface { // List the artifacts with queries // diff --git a/src/pkg/scan/api/scan/base_controller.go b/src/pkg/scan/api/scan/base_controller.go index 907ff7e18..c810fc3f8 100644 --- a/src/pkg/scan/api/scan/base_controller.go +++ b/src/pkg/scan/api/scan/base_controller.go @@ -19,11 +19,10 @@ import ( "fmt" "time" - "github.com/goharbor/harbor/src/common/utils/log" - cj "github.com/goharbor/harbor/src/common/job" jm "github.com/goharbor/harbor/src/common/job/models" "github.com/goharbor/harbor/src/common/rbac" + "github.com/goharbor/harbor/src/common/utils/log" "github.com/goharbor/harbor/src/core/config" "github.com/goharbor/harbor/src/jobservice/job" "github.com/goharbor/harbor/src/jobservice/logger" @@ -306,7 +305,7 @@ func (bc *basicController) HandleJobHooks(trackID string, change *job.StatusChan // Should not block the main flow, just logged log.Error(errors.Wrap(err, "scan controller: handle job hook")) } else { - log.Debugf("Robot account with id %d for the scan %s is removed", rid, trackID) + log.Debugf("Robot account with id %d for the scan %s is removed", int64(rid), trackID) } } } diff --git a/src/pkg/scan/api/scan/base_controller_test.go b/src/pkg/scan/api/scan/base_controller_test.go index 6fae613ce..c256c4b23 100644 --- a/src/pkg/scan/api/scan/base_controller_test.go +++ b/src/pkg/scan/api/scan/base_controller_test.go @@ -199,6 +199,7 @@ func (suite *ControllerTestSuite) SetupSuite() { params[sca.JobParamRegistration] = regJSON params[sca.JobParameterRequest] = rJSON params[sca.JobParameterMimes] = []string{v1.MimeTypeNativeReport} + params[sca.JobParameterRobotID] = int64(1) j := &jm.JobData{ Name: job.ImageScanJob, diff --git a/src/pkg/scan/event/init.go b/src/pkg/scan/event/init.go index cbb1cad86..0e63fbc85 100644 --- a/src/pkg/scan/event/init.go +++ b/src/pkg/scan/event/init.go @@ -23,7 +23,7 @@ import ( // Init the events for scan func Init() { - log.Debugf("Subscribe topic %s for cascade deletion of scan reports") + log.Debugf("Subscribe topic %s for cascade deletion of scan reports", model.DeleteImageTopic) err := notifier.Subscribe(model.DeleteImageTopic, NewOnDelImageHandler()) log.Error(errors.Wrap(err, "register on delete image handler: init: scan"))