[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update context to "makeCtx func() context.Context" #15584

Merged
merged 1 commit into from
Sep 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/server/v2.0/handler/scan_all.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func newScanAllAPI() *scanAllAPI {
scanCtl: scan.DefaultController,
scannerCtl: scanner.DefaultController,
scheduler: scheduler.Sched,
makeCtx: orm.Context,
}
}

Expand All @@ -50,6 +51,7 @@ type scanAllAPI struct {
scanCtl scan.Controller
scannerCtl scanner.Controller
scheduler scheduler.Scheduler
makeCtx func() context.Context
}

func (s *scanAllAPI) Prepare(ctx context.Context, operation string, params interface{}) middleware.Responder {
Expand All @@ -75,7 +77,7 @@ func (s *scanAllAPI) StopScanAll(ctx context.Context, params operation.StopScanA
if err != nil {
log.Errorf("failed to stop the execution of executionID=%+v", execution.ID)
}
}(orm.Context(), execution.ID)
}(s.makeCtx(), execution.ID)

return operation.NewStopScanAllAccepted()
}
Expand Down
8 changes: 4 additions & 4 deletions src/server/v2.0/handler/scan_all_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ package handler

import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
"net/http"
"testing"
"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/scheduler"
"github.com/goharbor/harbor/src/pkg/task"
Expand All @@ -32,6 +33,7 @@ import (
"github.com/goharbor/harbor/src/server/v2.0/restapi"
scantesting "github.com/goharbor/harbor/src/testing/controller/scan"
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"
schedulertesting "github.com/goharbor/harbor/src/testing/pkg/scheduler"
tasktesting "github.com/goharbor/harbor/src/testing/pkg/task"
Expand All @@ -52,9 +54,6 @@ type ScanAllTestSuite struct {
}

func (suite *ScanAllTestSuite) SetupSuite() {
// this is because orm.Context()
dao.PrepareTestForPostgresSQL()

suite.execution = &task.Execution{
Status: "Running",
Metrics: &taskdao.Metrics{
Expand Down Expand Up @@ -89,6 +88,7 @@ func (suite *ScanAllTestSuite) SetupSuite() {
scanCtl: suite.scanCtl,
scannerCtl: suite.scannerCtl,
scheduler: suite.scheduler,
makeCtx: func() context.Context { return orm.NewContext(nil, &ormtesting.FakeOrmer{}) },
},
}

Expand Down