mirror of
https://github.com/goharbor/harbor
synced 2024-09-20 16:25:37 +00:00
fix: update context to "makeCtx func() context.Context" (#15584)
Signed-off-by: Shengwen Yu <yshengwen@vmware.com> Co-authored-by: Shengwen Yu <yshengwen@vmware.com>
This commit is contained in:
parent
98cef43ead
commit
ce9bea807e
|
@ -41,6 +41,7 @@ func newScanAllAPI() *scanAllAPI {
|
||||||
scanCtl: scan.DefaultController,
|
scanCtl: scan.DefaultController,
|
||||||
scannerCtl: scanner.DefaultController,
|
scannerCtl: scanner.DefaultController,
|
||||||
scheduler: scheduler.Sched,
|
scheduler: scheduler.Sched,
|
||||||
|
makeCtx: orm.Context,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,6 +51,7 @@ type scanAllAPI struct {
|
||||||
scanCtl scan.Controller
|
scanCtl scan.Controller
|
||||||
scannerCtl scanner.Controller
|
scannerCtl scanner.Controller
|
||||||
scheduler scheduler.Scheduler
|
scheduler scheduler.Scheduler
|
||||||
|
makeCtx func() context.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *scanAllAPI) Prepare(ctx context.Context, operation string, params interface{}) middleware.Responder {
|
func (s *scanAllAPI) Prepare(ctx context.Context, operation string, params interface{}) middleware.Responder {
|
||||||
|
@ -75,7 +77,7 @@ func (s *scanAllAPI) StopScanAll(ctx context.Context, params operation.StopScanA
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("failed to stop the execution of executionID=%+v", execution.ID)
|
log.Errorf("failed to stop the execution of executionID=%+v", execution.ID)
|
||||||
}
|
}
|
||||||
}(orm.Context(), execution.ID)
|
}(s.makeCtx(), execution.ID)
|
||||||
|
|
||||||
return operation.NewStopScanAllAccepted()
|
return operation.NewStopScanAllAccepted()
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
@ -23,7 +24,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/common/dao"
|
"github.com/goharbor/harbor/src/lib/orm"
|
||||||
"github.com/goharbor/harbor/src/pkg/scan/dao/scanner"
|
"github.com/goharbor/harbor/src/pkg/scan/dao/scanner"
|
||||||
"github.com/goharbor/harbor/src/pkg/scheduler"
|
"github.com/goharbor/harbor/src/pkg/scheduler"
|
||||||
"github.com/goharbor/harbor/src/pkg/task"
|
"github.com/goharbor/harbor/src/pkg/task"
|
||||||
|
@ -32,6 +33,7 @@ import (
|
||||||
"github.com/goharbor/harbor/src/server/v2.0/restapi"
|
"github.com/goharbor/harbor/src/server/v2.0/restapi"
|
||||||
scantesting "github.com/goharbor/harbor/src/testing/controller/scan"
|
scantesting "github.com/goharbor/harbor/src/testing/controller/scan"
|
||||||
scannertesting "github.com/goharbor/harbor/src/testing/controller/scanner"
|
scannertesting "github.com/goharbor/harbor/src/testing/controller/scanner"
|
||||||
|
ormtesting "github.com/goharbor/harbor/src/testing/lib/orm"
|
||||||
"github.com/goharbor/harbor/src/testing/mock"
|
"github.com/goharbor/harbor/src/testing/mock"
|
||||||
schedulertesting "github.com/goharbor/harbor/src/testing/pkg/scheduler"
|
schedulertesting "github.com/goharbor/harbor/src/testing/pkg/scheduler"
|
||||||
tasktesting "github.com/goharbor/harbor/src/testing/pkg/task"
|
tasktesting "github.com/goharbor/harbor/src/testing/pkg/task"
|
||||||
|
@ -52,9 +54,6 @@ type ScanAllTestSuite struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *ScanAllTestSuite) SetupSuite() {
|
func (suite *ScanAllTestSuite) SetupSuite() {
|
||||||
// this is because orm.Context()
|
|
||||||
dao.PrepareTestForPostgresSQL()
|
|
||||||
|
|
||||||
suite.execution = &task.Execution{
|
suite.execution = &task.Execution{
|
||||||
Status: "Running",
|
Status: "Running",
|
||||||
Metrics: &taskdao.Metrics{
|
Metrics: &taskdao.Metrics{
|
||||||
|
@ -89,6 +88,7 @@ func (suite *ScanAllTestSuite) SetupSuite() {
|
||||||
scanCtl: suite.scanCtl,
|
scanCtl: suite.scanCtl,
|
||||||
scannerCtl: suite.scannerCtl,
|
scannerCtl: suite.scannerCtl,
|
||||||
scheduler: suite.scheduler,
|
scheduler: suite.scheduler,
|
||||||
|
makeCtx: func() context.Context { return orm.NewContext(nil, &ormtesting.FakeOrmer{}) },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user