diff --git a/.golangci.yml b/.golangci.yml index 37674f9f..a3976d8a 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -36,7 +36,7 @@ linters: - unparam - unused - whitespace - - wsl + - wsl_v5 settings: dupl: threshold: 100 @@ -51,6 +51,10 @@ linters: require-explanation: true require-specific: true allow-unused: false + wsl_v5: + allow-first-in-block: true + allow-whole-block: false + branch-max-lines: 2 exclusions: generated: lax presets: diff --git a/cmd/vela-worker/exec.go b/cmd/vela-worker/exec.go index 4fe04051..e877d3ba 100644 --- a/cmd/vela-worker/exec.go +++ b/cmd/vela-worker/exec.go @@ -25,7 +25,7 @@ import ( // exec is a helper function to poll the queue // and execute Vela pipelines for the Worker. // -//nolint:nilerr,funlen // ignore returning nil - don't want to crash worker +//nolint:gocyclo,funlen // ignore cyclomatic complexity and function length func (w *Worker) exec(index int, config *api.Worker) error { var err error @@ -347,6 +347,7 @@ func (w *Worker) exec(index int, config *api.Worker) error { // log/event streaming uses buildCtx so that it is not subject to the timeout. go func() { defer wg.Done() + logger.Info("streaming build logs") // execute the build with the executor err = _executor.StreamBuild(buildCtx) @@ -372,9 +373,9 @@ func (w *Worker) getWorkerStatusFromConfig(config *api.Worker) string { switch rb := len(config.GetRunningBuilds()); { case rb == 0: return constants.WorkerStatusIdle - case rb < w.Config.Build.Limit: + case rb < int(w.Config.Build.Limit): return constants.WorkerStatusAvailable - case rb == w.Config.Build.Limit: + case rb == int(w.Config.Build.Limit): return constants.WorkerStatusBusy default: return constants.WorkerStatusError diff --git a/cmd/vela-worker/flags.go b/cmd/vela-worker/flags.go index 8f94d8f7..23fde260 100644 --- a/cmd/vela-worker/flags.go +++ b/cmd/vela-worker/flags.go @@ -49,7 +49,7 @@ func flags() []cli.Flag { // Build Flags - &cli.IntFlag{ + &cli.Int32Flag{ Name: "build.limit", Usage: "maximum amount of builds that can run concurrently", Sources: cli.EnvVars("WORKER_BUILD_LIMIT", "VELA_BUILD_LIMIT", "BUILD_LIMIT"), diff --git a/cmd/vela-worker/operate.go b/cmd/vela-worker/operate.go index bc7d853f..148d4029 100644 --- a/cmd/vela-worker/operate.go +++ b/cmd/vela-worker/operate.go @@ -31,7 +31,7 @@ func (w *Worker) operate(ctx context.Context) error { registryWorker.SetHostname(w.Config.API.Address.Hostname()) registryWorker.SetAddress(w.Config.API.Address.String()) registryWorker.SetActive(true) - registryWorker.SetBuildLimit(int32(w.Config.Build.Limit)) + registryWorker.SetBuildLimit(w.Config.Build.Limit) // set routes from config if set or defaulted to `vela` if (len(w.Config.Queue.Routes) > 0) && (w.Config.Queue.Routes[0] != "NONE" && w.Config.Queue.Routes[0] != "") { @@ -131,7 +131,6 @@ func (w *Worker) operate(ctx context.Context) error { } w.QueueCheckedIn, err = w.queueCheckIn(gctx, registryWorker) - if err != nil { // queue check in failed, retry logrus.Errorf("unable to ping queue %v", err) @@ -162,7 +161,7 @@ func (w *Worker) operate(ctx context.Context) error { }) // iterate till the configured build limit - for i := 0; i < w.Config.Build.Limit; i++ { + for i := 0; i < int(w.Config.Build.Limit); i++ { // evaluate and capture i at each iteration // // https://github.com/golang/go/wiki/CommonMistakes#using-goroutines-on-loop-iterator-variables @@ -193,6 +192,7 @@ func (w *Worker) operate(ctx context.Context) error { continue } + select { case <-gctx.Done(): logrus.WithFields(logrus.Fields{ diff --git a/cmd/vela-worker/run.go b/cmd/vela-worker/run.go index fa0fdc17..6d1e419d 100644 --- a/cmd/vela-worker/run.go +++ b/cmd/vela-worker/run.go @@ -96,7 +96,7 @@ func run(ctx context.Context, c *cli.Command) error { }, // build configuration Build: &Build{ - Limit: int(c.Int("build.limit")), + Limit: c.Int32("build.limit"), Timeout: c.Duration("build.timeout"), }, // build configuration @@ -104,7 +104,7 @@ func run(ctx context.Context, c *cli.Command) error { // executor configuration Executor: &executor.Setup{ Driver: c.String("executor.driver"), - MaxLogSize: uint(c.Uint("executor.max_log_size")), + MaxLogSize: c.Uint("executor.max_log_size"), LogStreamingTimeout: c.Duration("executor.log_streaming_timeout"), EnforceTrustedRepos: c.Bool("executor.enforce-trusted-repos"), OutputCtn: outputsCtn, @@ -172,5 +172,5 @@ func run(ctx context.Context, c *cli.Command) error { } // start the worker - return w.Start() + return w.Start(ctx) } diff --git a/cmd/vela-worker/start.go b/cmd/vela-worker/start.go index 4cf15d5f..8c7a9032 100644 --- a/cmd/vela-worker/start.go +++ b/cmd/vela-worker/start.go @@ -22,9 +22,9 @@ import ( // serve traffic for web and API requests. The // operator subprocess enables the Worker to // poll the queue and execute Vela pipelines. -func (w *Worker) Start() error { +func (w *Worker) Start(ctx context.Context) error { // create the context for controlling the worker subprocesses - ctx, done := context.WithCancel(context.Background()) + ctx, done := context.WithCancel(ctx) // create the errgroup for managing worker subprocesses // // https://pkg.go.dev/golang.org/x/sync/errgroup#Group @@ -47,17 +47,21 @@ func (w *Worker) Start() error { select { case sig := <-signalChannel: logrus.Infof("Received signal: %s", sig) + err := server.Shutdown(ctx) if err != nil { logrus.Error(err) } + done() case <-gctx.Done(): logrus.Info("Closing signal goroutine") + err := server.Shutdown(ctx) if err != nil { logrus.Error(err) } + return gctx.Err() } @@ -67,7 +71,9 @@ func (w *Worker) Start() error { // spawn goroutine for starting the server g.Go(func() error { var err error + logrus.Info("starting worker server") + if tlsCfg != nil { if err := server.ListenAndServeTLS(w.Config.Certificate.Cert, w.Config.Certificate.Key); !errors.Is(err, http.ErrServerClosed) { // log a message indicating the start of the server diff --git a/cmd/vela-worker/worker.go b/cmd/vela-worker/worker.go index 834a88b0..ec6fcae4 100644 --- a/cmd/vela-worker/worker.go +++ b/cmd/vela-worker/worker.go @@ -22,7 +22,7 @@ type ( // Build represents the worker configuration for build information. Build struct { - Limit int + Limit int32 Timeout time.Duration } diff --git a/executor/executor_test.go b/executor/executor_test.go index 48b0c6a5..9540a52f 100644 --- a/executor/executor_test.go +++ b/executor/executor_test.go @@ -197,7 +197,7 @@ var ( ID: "step_github_octocat_1_init", Directory: "/home/github/octocat", Image: "#init", - Name: "init", + Name: constants.InitName, Number: 1, Pull: "always", }, diff --git a/executor/linux/api.go b/executor/linux/api.go index 44478794..dd8de021 100644 --- a/executor/linux/api.go +++ b/executor/linux/api.go @@ -35,8 +35,6 @@ func (c *client) GetPipeline() (*pipeline.Build, error) { } // CancelBuild cancels the current build in execution. -// -//nolint:funlen // process of going through steps/services/stages is verbose and could be funcitonalized func (c *client) CancelBuild() (*api.Build, error) { // get the current build from the client b, err := c.GetBuild() @@ -76,16 +74,12 @@ func (c *client) CancelBuild() (*api.Build, error) { switch s.GetStatus() { // service is in a error state case constants.StatusError: - break // service is in a failure state case constants.StatusFailure: - break // service is in a killed state case constants.StatusKilled: - break // service is in a success state case constants.StatusSuccess: - break default: // update the service with a canceled state s.SetStatus(constants.StatusCanceled) @@ -117,16 +111,12 @@ func (c *client) CancelBuild() (*api.Build, error) { switch s.GetStatus() { // step is in a error state case constants.StatusError: - break // step is in a failure state case constants.StatusFailure: - break // step is in a killed state case constants.StatusKilled: - break // step is in a success state case constants.StatusSuccess: - break default: // update the step with a canceled state s.SetStatus(constants.StatusCanceled) @@ -160,16 +150,12 @@ func (c *client) CancelBuild() (*api.Build, error) { switch s.GetStatus() { // stage is in a error state case constants.StatusError: - break // stage is in a failure state case constants.StatusFailure: - break // stage is in a killed state case constants.StatusKilled: - break // stage is in a success state case constants.StatusSuccess: - break default: // update the step with a canceled state s.SetStatus(constants.StatusCanceled) diff --git a/executor/linux/build.go b/executor/linux/build.go index 0b10eee8..f2e4deaf 100644 --- a/executor/linux/build.go +++ b/executor/linux/build.go @@ -288,10 +288,8 @@ func (c *client) AssembleBuild(ctx context.Context) error { // create the stages for the pipeline for _, s := range c.pipeline.Stages { - // TODO: remove hardcoded reference // - //nolint:goconst // ignore making a constant for now - if s.Name == "init" { + if s.Name == constants.InitName { continue } @@ -308,8 +306,7 @@ func (c *client) AssembleBuild(ctx context.Context) error { // create the steps for the pipeline for _, s := range c.pipeline.Steps { - // TODO: remove hardcoded reference - if s.Name == "init" { + if s.Name == constants.InitName { continue } @@ -480,8 +477,7 @@ func (c *client) ExecBuild(ctx context.Context) error { // execute the steps for the pipeline for _, _step := range c.pipeline.Steps { - // TODO: remove hardcoded reference - if _step.Name == "init" { + if _step.Name == constants.InitName { continue } @@ -573,8 +569,7 @@ func (c *client) ExecBuild(ctx context.Context) error { // iterate through each stage in the pipeline for _, _stage := range c.pipeline.Stages { - // TODO: remove hardcoded reference - if _stage.Name == "init" { + if _stage.Name == constants.InitName { continue } @@ -691,7 +686,7 @@ func (c *client) StreamBuild(ctx context.Context) error { // into the container right before execution, rather than // during build planning. It is only available for the Docker runtime. // -//nolint:funlen // explanation takes up a lot of lines + func loadLazySecrets(c *client, _step *pipeline.Container) error { _log := new(api.Log) @@ -872,8 +867,7 @@ func (c *client) DestroyBuild(ctx context.Context) error { // destroy the steps for the pipeline for _, _step := range c.pipeline.Steps { - // TODO: remove hardcoded reference - if _step.Name == "init" { + if _step.Name == constants.InitName { continue } @@ -887,8 +881,7 @@ func (c *client) DestroyBuild(ctx context.Context) error { // destroy the stages for the pipeline for _, _stage := range c.pipeline.Stages { - // TODO: remove hardcoded reference - if _stage.Name == "init" { + if _stage.Name == constants.InitName { continue } diff --git a/executor/linux/build_test.go b/executor/linux/build_test.go index 56446428..59140560 100644 --- a/executor/linux/build_test.go +++ b/executor/linux/build_test.go @@ -37,7 +37,11 @@ func TestLinux_CreateBuild(t *testing.T) { Usage: "doc", }, } + compiler, err := native.FromCLICommand(context.Background(), cmd) + if err != nil { + t.Errorf("unable to create pipeline compiler: %v", err) + } _build := testBuild() @@ -147,6 +151,7 @@ func TestLinux_CreateBuild(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { logger := testLogger.WithFields(logrus.Fields{"test": test.name}) + defer loggerHook.Reset() _pipeline, _, err := compiler. @@ -166,6 +171,7 @@ func TestLinux_CreateBuild(t *testing.T) { switch test.runtime { case constants.DriverKubernetes: _pod := testPodFor(_pipeline) + _runtime, err = kubernetes.NewMock(_pod) if err != nil { t.Errorf("unable to create kubernetes runtime engine: %v", err) @@ -204,16 +210,19 @@ func TestLinux_CreateBuild(t *testing.T) { } loggedError := false + for _, logEntry := range loggerHook.AllEntries() { // Many errors during StreamBuild get logged and ignored. // So, Make sure there are no errors logged during StreamBuild. if logEntry.Level == logrus.ErrorLevel { loggedError = true + if !test.logError { t.Errorf("%s StreamBuild for %s logged an Error: %v", test.name, test.pipeline, logEntry.Message) } } } + if test.logError && !loggedError { t.Errorf("%s StreamBuild for %s did not log an Error but should have", test.name, test.pipeline) } @@ -231,7 +240,11 @@ func TestLinux_PlanBuild(t *testing.T) { Usage: "doc", }, } + compiler, err := native.FromCLICommand(context.Background(), cmd) + if err != nil { + t.Errorf("unable to create pipeline compiler: %v", err) + } _build := testBuild() @@ -330,6 +343,7 @@ func TestLinux_PlanBuild(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { logger := testLogger.WithFields(logrus.Fields{"test": test.name}) + defer loggerHook.Reset() _pipeline, _, err := compiler. @@ -349,6 +363,7 @@ func TestLinux_PlanBuild(t *testing.T) { switch test.runtime { case constants.DriverKubernetes: _pod := testPodFor(_pipeline) + _runtime, err = kubernetes.NewMock(_pod) if err != nil { t.Errorf("unable to create kubernetes runtime engine: %v", err) @@ -392,16 +407,19 @@ func TestLinux_PlanBuild(t *testing.T) { } loggedError := false + for _, logEntry := range loggerHook.AllEntries() { // Many errors during StreamBuild get logged and ignored. // So, Make sure there are no errors logged during StreamBuild. if logEntry.Level == logrus.ErrorLevel { loggedError = true + if !test.logError { t.Errorf("%s StreamBuild for %s logged an Error: %v", test.name, test.pipeline, logEntry.Message) } } } + if test.logError && !loggedError { t.Errorf("%s StreamBuild for %s did not log an Error but should have", test.name, test.pipeline) } @@ -419,7 +437,11 @@ func TestLinux_AssembleBuild(t *testing.T) { Usage: "doc", }, } + compiler, err := native.FromCLICommand(context.Background(), cmd) + if err != nil { + t.Errorf("unable to create pipeline compiler: %v", err) + } _build := testBuild() @@ -619,6 +641,7 @@ func TestLinux_AssembleBuild(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { logger := testLogger.WithFields(logrus.Fields{"test": test.name}) + defer loggerHook.Reset() _pipeline, _, err := compiler. @@ -706,16 +729,19 @@ func TestLinux_AssembleBuild(t *testing.T) { } loggedError := false + for _, logEntry := range loggerHook.AllEntries() { // Many errors during StreamBuild get logged and ignored. // So, Make sure there are no errors logged during StreamBuild. if logEntry.Level == logrus.ErrorLevel { loggedError = true + if !test.logError { t.Errorf("%s StreamBuild for %s logged an Error: %v", test.name, test.pipeline, logEntry.Message) } } } + if test.logError && !loggedError { t.Errorf("%s StreamBuild for %s did not log an Error but should have", test.name, test.pipeline) } @@ -733,7 +759,11 @@ func TestLinux_ExecBuild(t *testing.T) { Usage: "doc", }, } + compiler, err := native.FromCLICommand(context.Background(), cmd) + if err != nil { + t.Errorf("unable to create compiler from CLI command: %v", err) + } _build := testBuild() @@ -860,6 +890,7 @@ func TestLinux_ExecBuild(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { logger := testLogger.WithFields(logrus.Fields{"test": test.name}) + defer loggerHook.Reset() _pipeline, _, err := compiler. @@ -882,6 +913,7 @@ func TestLinux_ExecBuild(t *testing.T) { switch test.runtime { case constants.DriverKubernetes: _pod = testPodFor(_pipeline) + _runtime, err = kubernetes.NewMock(_pod) if err != nil { t.Errorf("unable to create kubernetes runtime engine: %v", err) @@ -965,6 +997,7 @@ func TestLinux_ExecBuild(t *testing.T) { percents := []int{0, 0, 50, 100} lastIndex := len(percents) - 1 + for index, stepsCompletedPercent := range percents { if index == 0 || index == lastIndex { stepsRunningCount = 0 @@ -1002,16 +1035,19 @@ func TestLinux_ExecBuild(t *testing.T) { } loggedError := false + for _, logEntry := range loggerHook.AllEntries() { // Many errors during StreamBuild get logged and ignored. // So, Make sure there are no errors logged during StreamBuild. if logEntry.Level == logrus.ErrorLevel { loggedError = true + if !test.logError { t.Errorf("%s StreamBuild for %s logged an Error: %v", test.name, test.pipeline, logEntry.Message) } } } + if test.logError && !loggedError { t.Errorf("%s StreamBuild for %s did not log an Error but should have", test.name, test.pipeline) } @@ -1029,7 +1065,11 @@ func TestLinux_StreamBuild(t *testing.T) { Usage: "doc", }, } + compiler, err := native.FromCLICommand(context.Background(), cmd) + if err != nil { + t.Errorf("unable to create compiler from CLI command: %v", err) + } _build := testBuild() @@ -1048,7 +1088,7 @@ func TestLinux_StreamBuild(t *testing.T) { type planFuncType = func(context.Context, *pipeline.Container) error // planNothing is a planFuncType that does nothing - planNothing := func(ctx context.Context, container *pipeline.Container) error { + planNothing := func(_ context.Context, _ *pipeline.Container) error { return nil } @@ -1126,7 +1166,7 @@ func TestLinux_StreamBuild(t *testing.T) { streamFunc: func(c *client) message.StreamFunc { return c.StreamService }, - planFunc: func(c *client) planFuncType { + planFunc: func(_ *client) planFuncType { // simulate failure to call PlanService return planNothing }, @@ -1152,7 +1192,7 @@ func TestLinux_StreamBuild(t *testing.T) { streamFunc: func(c *client) message.StreamFunc { return c.StreamService }, - planFunc: func(c *client) planFuncType { + planFunc: func(_ *client) planFuncType { // simulate failure to call PlanService return planNothing }, @@ -1224,7 +1264,7 @@ func TestLinux_StreamBuild(t *testing.T) { streamFunc: func(c *client) message.StreamFunc { return c.StreamStep }, - planFunc: func(c *client) planFuncType { + planFunc: func(_ *client) planFuncType { // simulate failure to call PlanStep return planNothing }, @@ -1248,7 +1288,7 @@ func TestLinux_StreamBuild(t *testing.T) { streamFunc: func(c *client) message.StreamFunc { return c.StreamStep }, - planFunc: func(c *client) planFuncType { + planFunc: func(_ *client) planFuncType { // simulate failure to call PlanStep return planNothing }, @@ -1318,7 +1358,7 @@ func TestLinux_StreamBuild(t *testing.T) { streamFunc: func(c *client) message.StreamFunc { return c.secret.stream }, - planFunc: func(c *client) planFuncType { + planFunc: func(_ *client) planFuncType { // no plan function equivalent for secret containers return planNothing }, @@ -1342,7 +1382,7 @@ func TestLinux_StreamBuild(t *testing.T) { streamFunc: func(c *client) message.StreamFunc { return c.secret.stream }, - planFunc: func(c *client) planFuncType { + planFunc: func(_ *client) planFuncType { // no plan function equivalent for secret containers return planNothing }, @@ -1509,6 +1549,7 @@ func TestLinux_StreamBuild(t *testing.T) { streamRequests := make(chan message.StreamRequest) logger := testLogger.WithFields(logrus.Fields{"test": test.name}) + defer loggerHook.Reset() _pipeline, _, err := compiler. @@ -1528,6 +1569,7 @@ func TestLinux_StreamBuild(t *testing.T) { switch test.runtime { case constants.DriverKubernetes: _pod := testPodFor(_pipeline) + _runtime, err = kubernetes.NewMock(_pod) if err != nil { t.Errorf("unable to create kubernetes runtime engine: %v", err) @@ -1575,10 +1617,12 @@ func TestLinux_StreamBuild(t *testing.T) { // imitate build getting canceled or otherwise finishing before ExecBuild gets called. done() } + if test.earlyExecExit { // imitate a failure after ExecBuild starts and before it sends a StreamRequest. close(streamRequests) } + if test.earlyBuildDone || test.earlyExecExit { return } @@ -1621,16 +1665,19 @@ func TestLinux_StreamBuild(t *testing.T) { } loggedError := false + for _, logEntry := range loggerHook.AllEntries() { // Many errors during StreamBuild get logged and ignored. // So, Make sure there are no errors logged during StreamBuild. if logEntry.Level == logrus.ErrorLevel { loggedError = true + if !test.logError { t.Errorf("%s StreamBuild for %s logged an Error: %v", test.name, test.pipeline, logEntry.Message) } } } + if test.logError && !loggedError { t.Errorf("%s StreamBuild for %s did not log an Error but should have", test.name, test.pipeline) } @@ -1648,7 +1695,11 @@ func TestLinux_DestroyBuild(t *testing.T) { Usage: "doc", }, } + compiler, err := native.FromCLICommand(context.Background(), cmd) + if err != nil { + t.Errorf("unable to create compiler from CLI command: %v", err) + } _build := testBuild() @@ -1789,6 +1840,7 @@ func TestLinux_DestroyBuild(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { logger := testLogger.WithFields(logrus.Fields{"test": test.name}) + defer loggerHook.Reset() _pipeline, _, err := compiler. @@ -1808,6 +1860,7 @@ func TestLinux_DestroyBuild(t *testing.T) { switch test.runtime { case constants.DriverKubernetes: _pod := testPodFor(_pipeline) + _runtime, err = kubernetes.NewMock(_pod) if err != nil { t.Errorf("unable to create kubernetes runtime engine: %v", err) @@ -1860,6 +1913,7 @@ func TestLinux_DestroyBuild(t *testing.T) { } loggedError := false + for _, logEntry := range loggerHook.AllEntries() { // Many errors during StreamBuild get logged and ignored. // So, Make sure there are no errors logged during StreamBuild. @@ -1879,11 +1933,13 @@ func TestLinux_DestroyBuild(t *testing.T) { } loggedError = true + if !test.logError { t.Errorf("%s StreamBuild for %s logged an Error: %v", test.name, test.pipeline, logEntry.Message) } } } + if test.logError && !loggedError { t.Errorf("%s StreamBuild for %s did not log an Error but should have", test.name, test.pipeline) } diff --git a/executor/linux/linux_test.go b/executor/linux/linux_test.go index 9a026c87..083b0516 100644 --- a/executor/linux/linux_test.go +++ b/executor/linux/linux_test.go @@ -252,7 +252,7 @@ func testSteps(runtime string) *pipeline.Build { Directory: "/home/github/octocat", Environment: map[string]string{"FOO": "bar"}, Image: "#init", - Name: "init", + Name: constants.InitName, Number: 1, Pull: "always", }, @@ -458,7 +458,7 @@ func testPodFor(build *pipeline.Build) *v1.Pod { for _, stage := range build.Stages { for _, step := range stage.Steps { - if step.Name == "init" { + if step.Name == constants.InitName { continue } @@ -473,7 +473,7 @@ func testPodFor(build *pipeline.Build) *v1.Pod { } for _, step := range build.Steps { - if step.Name == "init" { + if step.Name == constants.InitName { continue } @@ -512,7 +512,7 @@ func countBuildSteps(build *pipeline.Build) int { for _, stage := range build.Stages { for _, step := range stage.Steps { - if step.Name == "init" { + if step.Name == constants.InitName { continue } @@ -521,7 +521,7 @@ func countBuildSteps(build *pipeline.Build) int { } for _, step := range build.Steps { - if step.Name == "init" { + if step.Name == constants.InitName { continue } @@ -582,7 +582,7 @@ func testContainerStatuses(build *pipeline.Build, servicesRunning bool, stepsRun for _, stage := range build.Stages { for _, step := range stage.Steps { - if step.Name == "init" { + if step.Name == constants.InitName { continue } @@ -615,7 +615,7 @@ func testContainerStatuses(build *pipeline.Build, servicesRunning bool, stepsRun } for _, step := range build.Steps { - if step.Name == "init" { + if step.Name == constants.InitName { continue } diff --git a/executor/linux/outputs_test.go b/executor/linux/outputs_test.go index d8965d6d..34fc5374 100644 --- a/executor/linux/outputs_test.go +++ b/executor/linux/outputs_test.go @@ -284,7 +284,11 @@ func TestLinux_Outputs_exec(t *testing.T) { Usage: "doc", }, } + compiler, err := native.FromCLICommand(context.Background(), cmd) + if err != nil { + t.Errorf("unable to create pipeline compiler: %v", err) + } _build := testBuild() diff --git a/executor/linux/secret.go b/executor/linux/secret.go index c1d7c47b..c938615b 100644 --- a/executor/linux/secret.go +++ b/executor/linux/secret.go @@ -235,7 +235,7 @@ func (s *secretSvc) pull(secret *pipeline.Secret) (*api.Secret, error) { // https://pkg.go.dev/github.com/go-vela/sdk-go/vela#SecretService.Get _secret, _, err = s.client.Vela.Secret.Get(secret.Engine, secret.Type, org, "*", key) if err != nil { - return nil, fmt.Errorf("%s: %w", ErrUnableToRetrieve, err) + return nil, fmt.Errorf("%w: %w", ErrUnableToRetrieve, err) } secret.Value = _secret.GetValue() @@ -252,7 +252,7 @@ func (s *secretSvc) pull(secret *pipeline.Secret) (*api.Secret, error) { // https://pkg.go.dev/github.com/go-vela/sdk-go/vela#SecretService.Get _secret, _, err = s.client.Vela.Secret.Get(secret.Engine, secret.Type, org, repo, key) if err != nil { - return nil, fmt.Errorf("%s: %w", ErrUnableToRetrieve, err) + return nil, fmt.Errorf("%w: %w", ErrUnableToRetrieve, err) } secret.Value = _secret.GetValue() @@ -269,7 +269,7 @@ func (s *secretSvc) pull(secret *pipeline.Secret) (*api.Secret, error) { // https://pkg.go.dev/github.com/go-vela/sdk-go/vela#SecretService.Get _secret, _, err = s.client.Vela.Secret.Get(secret.Engine, secret.Type, org, team, key) if err != nil { - return nil, fmt.Errorf("%s: %w", ErrUnableToRetrieve, err) + return nil, fmt.Errorf("%w: %w", ErrUnableToRetrieve, err) } secret.Value = _secret.GetValue() @@ -387,7 +387,7 @@ func escapeNewlineSecrets(m map[string]*api.Secret) { for i, secret := range m { // only double-escape secrets that have been manually escaped if !strings.Contains(secret.GetValue(), "\\\\n") { - s := strings.Replace(secret.GetValue(), "\\n", "\\\n", -1) + s := strings.ReplaceAll(secret.GetValue(), "\\n", "\\\n") m[i].Value = &s } } diff --git a/executor/linux/secret_test.go b/executor/linux/secret_test.go index fdaf0f7a..b8844c11 100644 --- a/executor/linux/secret_test.go +++ b/executor/linux/secret_test.go @@ -366,7 +366,11 @@ func TestLinux_Secret_exec(t *testing.T) { Usage: "doc", }, } + compiler, err := native.FromCLICommand(context.Background(), cmd) + if err != nil { + t.Errorf("unable to create pipeline compiler: %v", err) + } _build := testBuild() @@ -438,6 +442,7 @@ func TestLinux_Secret_exec(t *testing.T) { switch test.runtime { case constants.DriverKubernetes: _pod := testPodFor(p) + _runtime, err = kubernetes.NewMock(_pod) if err != nil { t.Errorf("unable to create kubernetes runtime engine: %v", err) @@ -841,7 +846,7 @@ func TestLinux_Secret_stream(t *testing.T) { Directory: "/home/github/octocat", Environment: map[string]string{"FOO": "bar"}, Image: "#init", - Name: "init", + Name: constants.InitName, Number: 1, Pull: "always", }, @@ -856,7 +861,7 @@ func TestLinux_Secret_stream(t *testing.T) { Directory: "/home/github/octocat", Environment: map[string]string{"FOO": "bar"}, Image: "#init", - Name: "init", + Name: constants.InitName, Number: 1, Pull: "always", }, diff --git a/executor/linux/service.go b/executor/linux/service.go index 923320bd..e60b2e97 100644 --- a/executor/linux/service.go +++ b/executor/linux/service.go @@ -65,7 +65,7 @@ func (c *client) CreateService(ctx context.Context, ctn *pipeline.Container) err } // PlanService prepares the service for execution. -func (c *client) PlanService(ctx context.Context, ctn *pipeline.Container) error { +func (c *client) PlanService(_ context.Context, ctn *pipeline.Container) error { var err error // update engine logger with service metadata // diff --git a/executor/linux/stage_test.go b/executor/linux/stage_test.go index 043f6cda..1a3e7750 100644 --- a/executor/linux/stage_test.go +++ b/executor/linux/stage_test.go @@ -35,7 +35,11 @@ func TestLinux_CreateStage(t *testing.T) { Usage: "doc", }, } + compiler, err := native.FromCLICommand(context.Background(), cmd) + if err != nil { + t.Errorf("unable to create pipeline compiler: %v", err) + } _pipeline, _, err := compiler. Duplicate(). @@ -229,6 +233,7 @@ func TestLinux_PlanStage(t *testing.T) { dtm, _ := dockerTestMap.Load("foo") dtm.(chan error) <- nil + close(dtm.(chan error)) kubernetesTestMap := new(sync.Map) @@ -236,6 +241,7 @@ func TestLinux_PlanStage(t *testing.T) { ktm, _ := kubernetesTestMap.Load("foo") ktm.(chan error) <- nil + close(ktm.(chan error)) dockerErrMap := new(sync.Map) @@ -243,6 +249,7 @@ func TestLinux_PlanStage(t *testing.T) { dem, _ := dockerErrMap.Load("foo") dem.(chan error) <- errors.New("bar") + close(dem.(chan error)) kubernetesErrMap := new(sync.Map) @@ -250,6 +257,7 @@ func TestLinux_PlanStage(t *testing.T) { kem, _ := kubernetesErrMap.Load("foo") kem.(chan error) <- errors.New("bar") + close(kem.(chan error)) // setup tests diff --git a/executor/linux/step.go b/executor/linux/step.go index 8568bc06..5e4eaa56 100644 --- a/executor/linux/step.go +++ b/executor/linux/step.go @@ -27,8 +27,7 @@ func (c *client) CreateStep(ctx context.Context, ctn *pipeline.Container) error // https://pkg.go.dev/github.com/sirupsen/logrus#Entry.WithField logger := c.Logger.WithField("step", ctn.Name) - // TODO: remove hardcoded reference - if ctn.Name == "init" { + if ctn.Name == constants.InitName { return nil } @@ -79,7 +78,7 @@ func (c *client) CreateStep(ctx context.Context, ctn *pipeline.Container) error } // PlanStep prepares the step for execution. -func (c *client) PlanStep(ctx context.Context, ctn *pipeline.Container) error { +func (c *client) PlanStep(_ context.Context, ctn *pipeline.Container) error { var err error // update engine logger with step metadata @@ -147,8 +146,7 @@ func (c *client) PlanStep(ctx context.Context, ctn *pipeline.Container) error { // ExecStep runs a step. func (c *client) ExecStep(ctx context.Context, ctn *pipeline.Container) error { - // TODO: remove hardcoded reference - if ctn.Name == "init" { + if ctn.Name == constants.InitName { return nil } @@ -228,8 +226,7 @@ func (c *client) ExecStep(ctx context.Context, ctn *pipeline.Container) error { // StreamStep tails the output for a step. func (c *client) StreamStep(ctx context.Context, ctn *pipeline.Container) error { - // TODO: remove hardcoded reference - if ctn.Name == "init" { + if ctn.Name == constants.InitName { return nil } @@ -383,8 +380,7 @@ func (c *client) StreamStep(ctx context.Context, ctn *pipeline.Container) error // DestroyStep cleans up steps after execution. func (c *client) DestroyStep(ctx context.Context, ctn *pipeline.Container) error { - // TODO: remove hardcoded reference - if ctn.Name == "init" { + if ctn.Name == constants.InitName { return nil } diff --git a/executor/linux/step_test.go b/executor/linux/step_test.go index 30aaee0e..96c5476e 100644 --- a/executor/linux/step_test.go +++ b/executor/linux/step_test.go @@ -14,6 +14,7 @@ import ( "github.com/go-vela/sdk-go/vela" api "github.com/go-vela/server/api/types" "github.com/go-vela/server/compiler/types/pipeline" + "github.com/go-vela/server/constants" "github.com/go-vela/server/mock/server" "github.com/go-vela/worker/internal/message" "github.com/go-vela/worker/runtime" @@ -60,7 +61,7 @@ func TestLinux_CreateStep(t *testing.T) { Directory: "/vela/src/github.com/github/octocat", Environment: map[string]string{"FOO": "bar"}, Image: "#init", - Name: "init", + Name: constants.InitName, Number: 1, Pull: "not_present", }, @@ -74,7 +75,7 @@ func TestLinux_CreateStep(t *testing.T) { Directory: "/vela/src/github.com/github/octocat", Environment: map[string]string{"FOO": "bar"}, Image: "#init", - Name: "init", + Name: constants.InitName, Number: 1, Pull: "not_present", }, @@ -353,7 +354,7 @@ func TestLinux_ExecStep(t *testing.T) { Directory: "/vela/src/github.com/github/octocat", Environment: map[string]string{"FOO": "bar"}, Image: "#init", - Name: "init", + Name: constants.InitName, Number: 1, Pull: "not_present", }, @@ -367,7 +368,7 @@ func TestLinux_ExecStep(t *testing.T) { Directory: "/vela/src/github.com/github/octocat", Environment: map[string]string{"FOO": "bar"}, Image: "#init", - Name: "init", + Name: constants.InitName, Number: 1, Pull: "not_present", }, @@ -569,7 +570,7 @@ func TestLinux_StreamStep(t *testing.T) { Directory: "/vela/src/github.com/github/octocat", Environment: map[string]string{"FOO": "bar"}, Image: "#init", - Name: "init", + Name: constants.InitName, Number: 1, Pull: "not_present", }, @@ -584,7 +585,7 @@ func TestLinux_StreamStep(t *testing.T) { Directory: "/vela/src/github.com/github/octocat", Environment: map[string]string{"FOO": "bar"}, Image: "#init", - Name: "init", + Name: constants.InitName, Number: 1, Pull: "not_present", }, @@ -740,7 +741,7 @@ func TestLinux_DestroyStep(t *testing.T) { Directory: "/vela/src/github.com/github/octocat", Environment: map[string]string{"FOO": "bar"}, Image: "#init", - Name: "init", + Name: constants.InitName, Number: 1, Pull: "not_present", }, @@ -754,7 +755,7 @@ func TestLinux_DestroyStep(t *testing.T) { Directory: "/vela/src/github.com/github/octocat", Environment: map[string]string{"FOO": "bar"}, Image: "#init", - Name: "init", + Name: constants.InitName, Number: 1, Pull: "not_present", }, @@ -866,7 +867,7 @@ func TestLinux_getSecretValues(t *testing.T) { Directory: "/vela/src/github.com/github/octocat", Environment: map[string]string{"FOO": "bar"}, Image: "#init", - Name: "init", + Name: constants.InitName, Number: 1, Pull: "not_present", }, diff --git a/executor/local/api.go b/executor/local/api.go index 9fa40647..d533deaf 100644 --- a/executor/local/api.go +++ b/executor/local/api.go @@ -35,8 +35,6 @@ func (c *client) GetPipeline() (*pipeline.Build, error) { } // CancelBuild cancels the current build in execution. -// -//nolint:funlen // process of going through steps/services/stages is verbose and could be funcitonalized func (c *client) CancelBuild() (*api.Build, error) { // get the current build from the client b, err := c.GetBuild() @@ -76,16 +74,12 @@ func (c *client) CancelBuild() (*api.Build, error) { switch s.GetStatus() { // service is in a error state case constants.StatusError: - break // service is in a failure state case constants.StatusFailure: - break // service is in a killed state case constants.StatusKilled: - break // service is in a success state case constants.StatusSuccess: - break default: // update the service with a canceled state s.SetStatus(constants.StatusCanceled) @@ -117,16 +111,12 @@ func (c *client) CancelBuild() (*api.Build, error) { switch s.GetStatus() { // step is in a error state case constants.StatusError: - break // step is in a failure state case constants.StatusFailure: - break // step is in a killed state case constants.StatusKilled: - break // step is in a success state case constants.StatusSuccess: - break default: // update the step with a canceled state s.SetStatus(constants.StatusCanceled) @@ -160,16 +150,12 @@ func (c *client) CancelBuild() (*api.Build, error) { switch s.GetStatus() { // stage is in a error state case constants.StatusError: - break // stage is in a failure state case constants.StatusFailure: - break // stage is in a killed state case constants.StatusKilled: - break // stage is in a success state case constants.StatusSuccess: - break default: // update the step with a canceled state s.SetStatus(constants.StatusCanceled) diff --git a/executor/local/build.go b/executor/local/build.go index 796cb131..9dc56e21 100644 --- a/executor/local/build.go +++ b/executor/local/build.go @@ -192,10 +192,8 @@ func (c *client) AssembleBuild(ctx context.Context) error { // create the stages for the pipeline for _, _stage := range c.pipeline.Stages { - // TODO: remove hardcoded reference // - //nolint:goconst // ignore making a constant for now - if _stage.Name == "init" { + if _stage.Name == constants.InitName { continue } @@ -211,8 +209,7 @@ func (c *client) AssembleBuild(ctx context.Context) error { // create the steps for the pipeline for _, _step := range c.pipeline.Steps { - // TODO: remove hardcoded reference - if _step.Name == "init" { + if _step.Name == constants.InitName { continue } @@ -285,8 +282,7 @@ func (c *client) ExecBuild(ctx context.Context) error { // execute the steps for the pipeline for _, _step := range c.pipeline.Steps { - // TODO: remove hardcoded reference - if _step.Name == "init" { + if _step.Name == constants.InitName { continue } @@ -344,8 +340,7 @@ func (c *client) ExecBuild(ctx context.Context) error { // iterate through each stage in the pipeline for _, _stage := range c.pipeline.Stages { - // TODO: remove hardcoded reference - if _stage.Name == "init" { + if _stage.Name == constants.InitName { continue } @@ -447,8 +442,7 @@ func (c *client) DestroyBuild(ctx context.Context) error { // destroy the steps for the pipeline for _, _step := range c.pipeline.Steps { - // TODO: remove hardcoded reference - if _step.Name == "init" { + if _step.Name == constants.InitName { continue } @@ -462,8 +456,7 @@ func (c *client) DestroyBuild(ctx context.Context) error { // destroy the stages for the pipeline for _, _stage := range c.pipeline.Stages { - // TODO: remove hardcoded reference - if _stage.Name == "init" { + if _stage.Name == constants.InitName { continue } diff --git a/executor/local/build_test.go b/executor/local/build_test.go index 71b98039..a403f769 100644 --- a/executor/local/build_test.go +++ b/executor/local/build_test.go @@ -25,6 +25,7 @@ func TestLocal_CreateBuild(t *testing.T) { Usage: "doc", }, } + compiler, err := native.FromCLICommand(context.Background(), cmd) if err != nil { t.Errorf("unable to create compiler engine: %v", err) @@ -110,6 +111,7 @@ func TestLocal_PlanBuild(t *testing.T) { Usage: "doc", }, } + compiler, err := native.FromCLICommand(context.Background(), cmd) if err != nil { t.Errorf("unable to create compiler engine: %v", err) @@ -201,6 +203,7 @@ func TestLocal_AssembleBuild(t *testing.T) { Usage: "doc", }, } + compiler, err := native.FromCLICommand(context.Background(), cmd) if err != nil { t.Errorf("unable to create compiler engine: %v", err) @@ -326,6 +329,7 @@ func TestLocal_ExecBuild(t *testing.T) { Usage: "doc", }, } + compiler, err := native.FromCLICommand(context.Background(), cmd) if err != nil { t.Errorf("unable to create compiler engine: %v", err) @@ -436,6 +440,7 @@ func TestLocal_StreamBuild(t *testing.T) { Usage: "doc", }, } + compiler, err := native.FromCLICommand(context.Background(), cmd) if err != nil { t.Errorf("unable to create compiler engine: %v", err) @@ -451,7 +456,7 @@ func TestLocal_StreamBuild(t *testing.T) { type planFuncType = func(context.Context, *pipeline.Container) error // planNothing is a planFuncType that does nothing - planNothing := func(ctx context.Context, container *pipeline.Container) error { + planNothing := func(_ context.Context, _ *pipeline.Container) error { return nil } @@ -495,7 +500,7 @@ func TestLocal_StreamBuild(t *testing.T) { streamFunc: func(c *client) message.StreamFunc { return c.StreamService }, - planFunc: func(c *client) planFuncType { + planFunc: func(_ *client) planFuncType { // simulate failure to call PlanService return planNothing }, @@ -540,7 +545,7 @@ func TestLocal_StreamBuild(t *testing.T) { streamFunc: func(c *client) message.StreamFunc { return c.StreamStep }, - planFunc: func(c *client) planFuncType { + planFunc: func(_ *client) planFuncType { // simulate failure to call PlanStep return planNothing }, @@ -658,6 +663,7 @@ func TestLocal_DestroyBuild(t *testing.T) { Usage: "doc", }, } + compiler, err := native.FromCLICommand(context.Background(), cmd) if err != nil { t.Errorf("unable to create compiler engine: %v", err) diff --git a/executor/local/local.go b/executor/local/local.go index dca23942..33f88a55 100644 --- a/executor/local/local.go +++ b/executor/local/local.go @@ -3,6 +3,7 @@ package local import ( + "errors" "os" "reflect" "sync" @@ -71,7 +72,7 @@ func Equal(a, b *client) bool { reflect.DeepEqual(a.pipeline, b.pipeline) && reflect.DeepEqual(&a.services, &b.services) && reflect.DeepEqual(&a.steps, &b.steps) && - reflect.DeepEqual(a.err, b.err) + errors.Is(a.err, b.err) } // New returns an Executor implementation that integrates with the local system. diff --git a/executor/local/local_test.go b/executor/local/local_test.go index 4479920b..8c27577e 100644 --- a/executor/local/local_test.go +++ b/executor/local/local_test.go @@ -11,6 +11,7 @@ import ( "github.com/go-vela/sdk-go/vela" api "github.com/go-vela/server/api/types" "github.com/go-vela/server/compiler/types/pipeline" + "github.com/go-vela/server/constants" "github.com/go-vela/server/mock/server" "github.com/go-vela/worker/runtime/docker" ) @@ -248,7 +249,7 @@ func testSteps() *pipeline.Build { Directory: "/home/github/octocat", Environment: map[string]string{"FOO": "bar"}, Image: "#init", - Name: "init", + Name: constants.InitName, Number: 1, Pull: "always", }, diff --git a/executor/local/opts_test.go b/executor/local/opts_test.go index 89b70d07..893ebfb0 100644 --- a/executor/local/opts_test.go +++ b/executor/local/opts_test.go @@ -38,7 +38,6 @@ func TestLocal_Opt_WithBuild(t *testing.T) { _engine, err := New( WithBuild(test.build), ) - if err != nil { t.Errorf("WithBuild returned err: %v", err) } @@ -213,7 +212,6 @@ func TestLocal_Opt_WithVelaClient(t *testing.T) { _engine, err := New( WithVelaClient(test.client), ) - if err != nil { t.Errorf("WithVelaClient returned err: %v", err) } diff --git a/executor/local/outputs_test.go b/executor/local/outputs_test.go index a794adbc..43649744 100644 --- a/executor/local/outputs_test.go +++ b/executor/local/outputs_test.go @@ -284,7 +284,12 @@ func TestLinux_Outputs_exec(t *testing.T) { Usage: "doc", }, } + compiler, err := native.FromCLICommand(context.Background(), cmd) + if err != nil { + t.Errorf("unable to create pipeline compiler: %v", err) + } + _build := testBuild() gin.SetMode(gin.TestMode) diff --git a/executor/local/service.go b/executor/local/service.go index c1417a24..a7affb90 100644 --- a/executor/local/service.go +++ b/executor/local/service.go @@ -44,7 +44,7 @@ func (c *client) CreateService(ctx context.Context, ctn *pipeline.Container) err } // PlanService prepares the service for execution. -func (c *client) PlanService(ctx context.Context, ctn *pipeline.Container) error { +func (c *client) PlanService(_ context.Context, ctn *pipeline.Container) error { // update the engine service object _service := new(api.Service) _service.SetName(ctn.Name) diff --git a/executor/local/stage_test.go b/executor/local/stage_test.go index dadae0c1..2c880b7c 100644 --- a/executor/local/stage_test.go +++ b/executor/local/stage_test.go @@ -29,6 +29,7 @@ func TestLocal_CreateStage(t *testing.T) { Usage: "doc", }, } + compiler, err := native.FromCLICommand(context.Background(), cmd) if err != nil { t.Errorf("unable to create compiler from CLI context: %v", err) @@ -144,6 +145,7 @@ func TestLocal_PlanStage(t *testing.T) { tm, _ := testMap.Load("foo") tm.(chan error) <- nil + close(tm.(chan error)) errMap := new(sync.Map) @@ -151,6 +153,7 @@ func TestLocal_PlanStage(t *testing.T) { em, _ := errMap.Load("foo") em.(chan error) <- errors.New("bar") + close(em.(chan error)) // setup tests diff --git a/executor/local/step.go b/executor/local/step.go index b097aed9..cd1e1ffc 100644 --- a/executor/local/step.go +++ b/executor/local/step.go @@ -20,8 +20,7 @@ const stepPattern = "[step: %s]" // CreateStep configures the step for execution. func (c *client) CreateStep(ctx context.Context, ctn *pipeline.Container) error { - // TODO: remove hardcoded reference - if ctn.Name == "init" { + if ctn.Name == constants.InitName { return nil } @@ -49,7 +48,7 @@ func (c *client) CreateStep(ctx context.Context, ctn *pipeline.Container) error } // PlanStep prepares the step for execution. -func (c *client) PlanStep(ctx context.Context, ctn *pipeline.Container) error { +func (c *client) PlanStep(_ context.Context, ctn *pipeline.Container) error { // early exit if container is nil if ctn.Empty() { return fmt.Errorf("empty container provided") @@ -68,8 +67,7 @@ func (c *client) PlanStep(ctx context.Context, ctn *pipeline.Container) error { // ExecStep runs a step. func (c *client) ExecStep(ctx context.Context, ctn *pipeline.Container) error { - // TODO: remove hardcoded reference - if ctn.Name == "init" { + if ctn.Name == constants.InitName { return nil } @@ -125,8 +123,7 @@ func (c *client) ExecStep(ctx context.Context, ctn *pipeline.Container) error { // StreamStep tails the output for a step. func (c *client) StreamStep(ctx context.Context, ctn *pipeline.Container) error { - // TODO: remove hardcoded reference - if ctn.Name == "init" { + if ctn.Name == constants.InitName { return nil } @@ -164,8 +161,7 @@ func (c *client) StreamStep(ctx context.Context, ctn *pipeline.Container) error // DestroyStep cleans up steps after execution. func (c *client) DestroyStep(ctx context.Context, ctn *pipeline.Container) error { - // TODO: remove hardcoded reference - if ctn.Name == "init" { + if ctn.Name == constants.InitName { return nil } diff --git a/executor/local/step_test.go b/executor/local/step_test.go index 5916b174..3ad1c3c9 100644 --- a/executor/local/step_test.go +++ b/executor/local/step_test.go @@ -8,6 +8,7 @@ import ( api "github.com/go-vela/server/api/types" "github.com/go-vela/server/compiler/types/pipeline" + "github.com/go-vela/server/constants" "github.com/go-vela/worker/internal/message" "github.com/go-vela/worker/runtime/docker" ) @@ -35,7 +36,7 @@ func TestLocal_CreateStep(t *testing.T) { Directory: "/vela/src/github.com/github/octocat", Environment: map[string]string{"FOO": "bar"}, Image: "#init", - Name: "init", + Name: constants.InitName, Number: 1, Pull: "not_present", }, @@ -192,7 +193,7 @@ func TestLocal_ExecStep(t *testing.T) { Directory: "/vela/src/github.com/github/octocat", Environment: map[string]string{"FOO": "bar"}, Image: "#init", - Name: "init", + Name: constants.InitName, Number: 1, Pull: "not_present", }, @@ -301,7 +302,7 @@ func TestLocal_StreamStep(t *testing.T) { Directory: "/vela/src/github.com/github/octocat", Environment: map[string]string{"FOO": "bar"}, Image: "#init", - Name: "init", + Name: constants.InitName, Number: 1, Pull: "not_present", }, @@ -391,7 +392,7 @@ func TestLocal_DestroyStep(t *testing.T) { Directory: "/vela/src/github.com/github/octocat", Environment: map[string]string{"FOO": "bar"}, Image: "#init", - Name: "init", + Name: constants.InitName, Number: 1, Pull: "not_present", }, diff --git a/go.mod b/go.mod index c21abc28..c50d81c9 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.24.4 require ( github.com/Masterminds/semver/v3 v3.4.0 + github.com/containerd/errdefs v1.0.0 github.com/distribution/reference v0.6.0 github.com/docker/docker v28.5.1+incompatible github.com/docker/go-units v0.5.0 @@ -33,7 +34,6 @@ require ( github.com/buger/jsonparser v1.1.1 // indirect github.com/cenkalti/backoff/v5 v5.0.2 // indirect github.com/containerd/containerd/v2 v2.1.3 // indirect - github.com/containerd/errdefs v1.0.0 // indirect github.com/containerd/errdefs/pkg v0.3.0 // indirect github.com/expr-lang/expr v1.17.6 // indirect github.com/fxamacker/cbor/v2 v2.9.0 // indirect diff --git a/internal/context/context_test.go b/internal/context/context_test.go index 4e1ba5d3..4c89c5d6 100644 --- a/internal/context/context_test.go +++ b/internal/context/context_test.go @@ -129,6 +129,7 @@ func TestWithDelayedCancelPropagation(t *testing.T) { if d := ctx.Done(); d == nil { t.Errorf("ctx.Done() == %v want non-nil", d) } + if e := ctx.Err(); e != nil { t.Errorf("ctx.Err() == %v want nil", e) } @@ -145,6 +146,7 @@ func TestWithDelayedCancelPropagation(t *testing.T) { testCancelPropagated(ctx, "WithDelayedCancelPropagation", t) time.Sleep(shortDuration) + lastLogEntry := loggerHook.LastEntry() if lastLogEntry.Message != test.lastLogMessage { t.Errorf("unexpected last log entry: want = %s ; got = %s", test.lastLogMessage, lastLogEntry.Message) diff --git a/internal/outputs/sanitize_test.go b/internal/outputs/sanitize_test.go index 4bea4520..6f0c79fd 100644 --- a/internal/outputs/sanitize_test.go +++ b/internal/outputs/sanitize_test.go @@ -9,6 +9,7 @@ import ( api "github.com/go-vela/server/api/types" "github.com/go-vela/server/compiler/types/pipeline" "github.com/go-vela/server/compiler/types/raw" + "github.com/go-vela/server/constants" "github.com/go-vela/worker/internal/step" ) @@ -90,7 +91,7 @@ func TestOutputs_Sanitize(t *testing.T) { Directory: "/home/github/octocat", Environment: map[string]string{"FOO": "bar"}, Image: "#init", - Name: "init", + Name: constants.InitName, Number: 1, Pull: "always", }, @@ -110,7 +111,7 @@ func TestOutputs_Sanitize(t *testing.T) { Directory: "/home/github/octocat", Environment: map[string]string{}, Image: "#init", - Name: "init", + Name: constants.InitName, Number: 1, Pull: "always", }, @@ -129,7 +130,7 @@ func TestOutputs_Sanitize(t *testing.T) { Directory: "/home/github/octocat", Environment: map[string]string{"FOO": "bar"}, Image: "#init", - Name: "init", + Name: constants.InitName, Number: 1, Pull: "always", }, @@ -153,7 +154,7 @@ func TestOutputs_Sanitize(t *testing.T) { Directory: "/home/github/octocat", Environment: map[string]string{"FOO": "bar"}, Image: "#init", - Name: "init", + Name: constants.InitName, Number: 1, Pull: "always", }, diff --git a/internal/service/snapshot_test.go b/internal/service/snapshot_test.go index b763630b..0dcecafc 100644 --- a/internal/service/snapshot_test.go +++ b/internal/service/snapshot_test.go @@ -134,7 +134,7 @@ func TestService_Snapshot(t *testing.T) { // run test for _, test := range tests { - t.Run(test.name, func(t *testing.T) { + t.Run(test.name, func(_ *testing.T) { Snapshot(test.container, test.build, test.client, nil, test.service) }) } diff --git a/internal/service/upload_test.go b/internal/service/upload_test.go index 41619bed..c9d5011d 100644 --- a/internal/service/upload_test.go +++ b/internal/service/upload_test.go @@ -11,6 +11,7 @@ import ( "github.com/go-vela/sdk-go/vela" api "github.com/go-vela/server/api/types" "github.com/go-vela/server/compiler/types/pipeline" + "github.com/go-vela/server/constants" "github.com/go-vela/server/mock/server" ) @@ -65,7 +66,7 @@ func TestService_Upload(t *testing.T) { Directory: "/home/github/octocat", Environment: map[string]string{"FOO": "bar"}, Image: "#init", - Name: "init", + Name: constants.InitName, Number: 1, Pull: "always", } @@ -76,7 +77,7 @@ func TestService_Upload(t *testing.T) { Environment: map[string]string{"FOO": "bar"}, ExitCode: 137, Image: "#init", - Name: "init", + Name: constants.InitName, Number: 1, Pull: "always", } @@ -162,7 +163,7 @@ func TestService_Upload(t *testing.T) { // run test for _, test := range tests { - t.Run(test.name, func(t *testing.T) { + t.Run(test.name, func(_ *testing.T) { Upload(test.container, test.build, test.client, nil, test.service) }) } diff --git a/internal/step/environment_test.go b/internal/step/environment_test.go index 75dfc4f0..ea00b2b0 100644 --- a/internal/step/environment_test.go +++ b/internal/step/environment_test.go @@ -8,6 +8,7 @@ import ( api "github.com/go-vela/server/api/types" "github.com/go-vela/server/compiler/types/pipeline" "github.com/go-vela/server/compiler/types/raw" + "github.com/go-vela/server/constants" ) func TestStep_Environment(t *testing.T) { @@ -63,7 +64,7 @@ func TestStep_Environment(t *testing.T) { Directory: "/home/github/octocat", Environment: map[string]string{"FOO": "bar"}, Image: "#init", - Name: "init", + Name: constants.InitName, Number: 1, Pull: "always", } diff --git a/internal/step/load_test.go b/internal/step/load_test.go index 03534975..1ae7a5b1 100644 --- a/internal/step/load_test.go +++ b/internal/step/load_test.go @@ -9,6 +9,7 @@ import ( api "github.com/go-vela/server/api/types" "github.com/go-vela/server/compiler/types/pipeline" + "github.com/go-vela/server/constants" ) func TestStep_Load(t *testing.T) { @@ -18,7 +19,7 @@ func TestStep_Load(t *testing.T) { Directory: "/home/github/octocat", Environment: map[string]string{"FOO": "bar"}, Image: "#init", - Name: "init", + Name: constants.InitName, Number: 1, Pull: "always", } @@ -107,14 +108,14 @@ func TestStep_LoadInit(t *testing.T) { ID: "github_octocat_1", Stages: pipeline.StageSlice{ { - Name: "init", + Name: constants.InitName, Steps: pipeline.ContainerSlice{ { ID: "github_octocat_1_init_init", Directory: "/vela/src/github.com/github/octocat", Environment: map[string]string{"FOO": "bar"}, Image: "#init", - Name: "init", + Name: constants.InitName, Number: 1, Pull: "always", }, @@ -127,7 +128,7 @@ func TestStep_LoadInit(t *testing.T) { Directory: "/vela/src/github.com/github/octocat", Environment: map[string]string{"FOO": "bar"}, Image: "#init", - Name: "init", + Name: constants.InitName, Number: 1, Pull: "always", }, @@ -144,7 +145,7 @@ func TestStep_LoadInit(t *testing.T) { Directory: "/vela/src/github.com/github/octocat", Environment: map[string]string{"FOO": "bar"}, Image: "#init", - Name: "init", + Name: constants.InitName, Number: 1, Pull: "always", }, @@ -155,7 +156,7 @@ func TestStep_LoadInit(t *testing.T) { Directory: "/vela/src/github.com/github/octocat", Environment: map[string]string{"FOO": "bar"}, Image: "#init", - Name: "init", + Name: constants.InitName, Number: 1, Pull: "always", }, @@ -199,7 +200,7 @@ func TestStep_LoadLogs(t *testing.T) { Directory: "/home/github/octocat", Environment: map[string]string{"FOO": "bar"}, Image: "#init", - Name: "init", + Name: constants.InitName, Number: 1, Pull: "always", } diff --git a/internal/step/skip_test.go b/internal/step/skip_test.go index 696f5df6..e23eca2f 100644 --- a/internal/step/skip_test.go +++ b/internal/step/skip_test.go @@ -8,6 +8,7 @@ import ( "github.com/go-vela/sdk-go/vela" api "github.com/go-vela/server/api/types" "github.com/go-vela/server/compiler/types/pipeline" + "github.com/go-vela/server/constants" ) func TestStep_Skip(t *testing.T) { @@ -207,7 +208,7 @@ func TestStep_Skip(t *testing.T) { Directory: "/home/github/octocat", Environment: map[string]string{"FOO": "bar"}, Image: "#init", - Name: "init", + Name: constants.InitName, Number: 1, Pull: "always", } diff --git a/internal/step/snapshot_test.go b/internal/step/snapshot_test.go index 348eb6e6..9faa17a7 100644 --- a/internal/step/snapshot_test.go +++ b/internal/step/snapshot_test.go @@ -11,6 +11,7 @@ import ( "github.com/go-vela/sdk-go/vela" api "github.com/go-vela/server/api/types" "github.com/go-vela/server/compiler/types/pipeline" + "github.com/go-vela/server/constants" "github.com/go-vela/server/mock/server" ) @@ -65,7 +66,7 @@ func TestStep_Snapshot(t *testing.T) { Directory: "/home/github/octocat", Environment: map[string]string{"FOO": "bar"}, Image: "#init", - Name: "init", + Name: constants.InitName, Number: 1, Pull: "always", } @@ -76,7 +77,7 @@ func TestStep_Snapshot(t *testing.T) { Environment: map[string]string{"FOO": "bar"}, ExitCode: 137, Image: "#init", - Name: "init", + Name: constants.InitName, Number: 1, Pull: "always", } @@ -189,7 +190,7 @@ func TestStep_SnapshotInit(t *testing.T) { Directory: "/home/github/octocat", Environment: map[string]string{"FOO": "bar"}, Image: "#init", - Name: "init", + Name: constants.InitName, Number: 1, Pull: "always", } @@ -200,7 +201,7 @@ func TestStep_SnapshotInit(t *testing.T) { Environment: map[string]string{"FOO": "bar"}, ExitCode: 137, Image: "#init", - Name: "init", + Name: constants.InitName, Number: 1, Pull: "always", } diff --git a/internal/step/upload_test.go b/internal/step/upload_test.go index 5d527f19..fc285592 100644 --- a/internal/step/upload_test.go +++ b/internal/step/upload_test.go @@ -11,6 +11,7 @@ import ( "github.com/go-vela/sdk-go/vela" api "github.com/go-vela/server/api/types" "github.com/go-vela/server/compiler/types/pipeline" + "github.com/go-vela/server/constants" "github.com/go-vela/server/mock/server" ) @@ -65,7 +66,7 @@ func TestStep_Upload(t *testing.T) { Directory: "/home/github/octocat", Environment: map[string]string{"FOO": "bar"}, Image: "#init", - Name: "init", + Name: constants.InitName, Number: 1, Pull: "always", } @@ -76,7 +77,7 @@ func TestStep_Upload(t *testing.T) { Environment: map[string]string{"FOO": "bar"}, ExitCode: 137, Image: "#init", - Name: "init", + Name: constants.InitName, Number: 1, Pull: "always", } diff --git a/mock/docker/checkpoint.go b/mock/docker/checkpoint.go new file mode 100644 index 00000000..27572c43 --- /dev/null +++ b/mock/docker/checkpoint.go @@ -0,0 +1,25 @@ +// SPDX-License-Identifier: Apache-2.0 + +package docker + +import ( + "context" + + "github.com/docker/docker/api/types/checkpoint" +) + +// CheckpointService implements all the checkpoint +// related functions for the Docker mock. +type CheckpointService struct{} + +func (cp *CheckpointService) CheckpointCreate(_ context.Context, _ string, _ checkpoint.CreateOptions) error { + return nil +} + +func (cp *CheckpointService) CheckpointDelete(_ context.Context, _ string, _ checkpoint.DeleteOptions) error { + return nil +} + +func (cp *CheckpointService) CheckpointList(_ context.Context, _ string, _ checkpoint.ListOptions) ([]checkpoint.Summary, error) { + return nil, nil +} diff --git a/mock/docker/config.go b/mock/docker/config.go index 78b63b4c..04d2fc58 100644 --- a/mock/docker/config.go +++ b/mock/docker/config.go @@ -17,33 +17,33 @@ type ConfigService struct{} // ConfigCreate is a helper function to simulate // a mocked call to create a config for a // Docker swarm cluster. -func (c *ConfigService) ConfigCreate(ctx context.Context, config swarm.ConfigSpec) (swarm.ConfigCreateResponse, error) { +func (c *ConfigService) ConfigCreate(_ context.Context, _ swarm.ConfigSpec) (swarm.ConfigCreateResponse, error) { return swarm.ConfigCreateResponse{}, nil } // ConfigInspectWithRaw is a helper function to simulate // a mocked call to inspect a config for a Docker swarm // cluster and return the raw body received from the API. -func (c *ConfigService) ConfigInspectWithRaw(ctx context.Context, name string) (swarm.Config, []byte, error) { +func (c *ConfigService) ConfigInspectWithRaw(_ context.Context, _ string) (swarm.Config, []byte, error) { return swarm.Config{}, nil, nil } // ConfigList is a helper function to simulate // a mocked call to list the configs for a // Docker swarm cluster. -func (c *ConfigService) ConfigList(ctx context.Context, options swarm.ConfigListOptions) ([]swarm.Config, error) { +func (c *ConfigService) ConfigList(_ context.Context, _ swarm.ConfigListOptions) ([]swarm.Config, error) { return nil, nil } // ConfigRemove is a helper function to simulate // a mocked call to remove a config for a // Docker swarm cluster. -func (c *ConfigService) ConfigRemove(ctx context.Context, id string) error { return nil } +func (c *ConfigService) ConfigRemove(_ context.Context, _ string) error { return nil } // ConfigUpdate is a helper function to simulate // a mocked call to update a config for a // Docker swarm cluster. -func (c *ConfigService) ConfigUpdate(ctx context.Context, id string, version swarm.Version, config swarm.ConfigSpec) error { +func (c *ConfigService) ConfigUpdate(_ context.Context, _ string, _ swarm.Version, _ swarm.ConfigSpec) error { return nil } diff --git a/mock/docker/container.go b/mock/docker/container.go index e1df4360..46ead632 100644 --- a/mock/docker/container.go +++ b/mock/docker/container.go @@ -32,7 +32,7 @@ type ContainerService struct{} // Docker container. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerAttach -func (c *ContainerService) ContainerAttach(ctx context.Context, ctn string, options container.AttachOptions) (types.HijackedResponse, error) { +func (c *ContainerService) ContainerAttach(_ context.Context, _ string, _ container.AttachOptions) (types.HijackedResponse, error) { return types.HijackedResponse{}, nil } @@ -40,7 +40,7 @@ func (c *ContainerService) ContainerAttach(ctx context.Context, ctn string, opti // a mocked call to apply changes to a Docker container. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerCommit -func (c *ContainerService) ContainerCommit(ctx context.Context, ctn string, options container.CommitOptions) (container.CommitResponse, error) { +func (c *ContainerService) ContainerCommit(_ context.Context, _ string, _ container.CommitOptions) (container.CommitResponse, error) { return container.CommitResponse{}, nil } @@ -48,7 +48,7 @@ func (c *ContainerService) ContainerCommit(ctx context.Context, ctn string, opti // a mocked call to create a Docker container. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerCreate -func (c *ContainerService) ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, p *v1.Platform, ctn string) (container.CreateResponse, error) { +func (c *ContainerService) ContainerCreate(_ context.Context, config *container.Config, _ *container.HostConfig, _ *network.NetworkingConfig, _ *v1.Platform, ctn string) (container.CreateResponse, error) { // verify a container was provided if len(ctn) == 0 { return container.CreateResponse{}, @@ -60,7 +60,7 @@ func (c *ContainerService) ContainerCreate(ctx context.Context, config *containe if strings.Contains(ctn, "notfound") && !strings.Contains(ctn, "ignorenotfound") { return container.CreateResponse{}, - //nolint:stylecheck // messsage is capitalized to match Docker messages + //nolint:staticcheck // messsage is capitalized to match Docker messages errdefs.NotFound(fmt.Errorf("Error: No such container: %s", ctn)) } @@ -69,7 +69,7 @@ func (c *ContainerService) ContainerCreate(ctx context.Context, config *containe if strings.Contains(ctn, "not-found") && !strings.Contains(ctn, "ignore-not-found") { return container.CreateResponse{}, - //nolint:stylecheck // messsage is capitalized to match Docker messages + //nolint:staticcheck // messsage is capitalized to match Docker messages errdefs.NotFound(fmt.Errorf("Error: No such container: %s", ctn)) } @@ -78,7 +78,7 @@ func (c *ContainerService) ContainerCreate(ctx context.Context, config *containe strings.Contains(config.Image, "not-found") { return container.CreateResponse{}, errdefs.NotFound( - //nolint:stylecheck // messsage is capitalized to match Docker messages + //nolint:staticcheck // messsage is capitalized to match Docker messages fmt.Errorf("Error response from daemon: manifest for %s not found: manifest unknown", config.Image), ) } @@ -96,7 +96,7 @@ func (c *ContainerService) ContainerCreate(ctx context.Context, config *containe // filesystem between two Docker containers. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerDiff -func (c *ContainerService) ContainerDiff(ctx context.Context, ctn string) ([]container.FilesystemChange, error) { +func (c *ContainerService) ContainerDiff(_ context.Context, _ string) ([]container.FilesystemChange, error) { return nil, nil } @@ -105,7 +105,7 @@ func (c *ContainerService) ContainerDiff(ctx context.Context, ctn string) ([]con // running inside a Docker container. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerExecAttach -func (c *ContainerService) ContainerExecAttach(ctx context.Context, execID string, config container.ExecAttachOptions) (types.HijackedResponse, error) { +func (c *ContainerService) ContainerExecAttach(_ context.Context, _ string, _ container.ExecAttachOptions) (types.HijackedResponse, error) { return types.HijackedResponse{}, nil } @@ -114,7 +114,7 @@ func (c *ContainerService) ContainerExecAttach(ctx context.Context, execID strin // Docker container. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerExecCreate -func (c *ContainerService) ContainerExecCreate(ctx context.Context, ctn string, config container.ExecOptions) (container.ExecCreateResponse, error) { +func (c *ContainerService) ContainerExecCreate(_ context.Context, _ string, _ container.ExecOptions) (container.ExecCreateResponse, error) { return container.ExecCreateResponse{}, nil } @@ -123,7 +123,7 @@ func (c *ContainerService) ContainerExecCreate(ctx context.Context, ctn string, // Docker container. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerExecInspect -func (c *ContainerService) ContainerExecInspect(ctx context.Context, execID string) (container.ExecInspect, error) { +func (c *ContainerService) ContainerExecInspect(_ context.Context, _ string) (container.ExecInspect, error) { return container.ExecInspect{}, nil } @@ -132,7 +132,7 @@ func (c *ContainerService) ContainerExecInspect(ctx context.Context, execID stri // inside a Docker container. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerExecResize -func (c *ContainerService) ContainerExecResize(ctx context.Context, execID string, options container.ResizeOptions) error { +func (c *ContainerService) ContainerExecResize(_ context.Context, _ string, _ container.ResizeOptions) error { return nil } @@ -141,7 +141,7 @@ func (c *ContainerService) ContainerExecResize(ctx context.Context, execID strin // container. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerExecStart -func (c *ContainerService) ContainerExecStart(ctx context.Context, execID string, config container.ExecStartOptions) error { +func (c *ContainerService) ContainerExecStart(_ context.Context, _ string, _ container.ExecStartOptions) error { return nil } @@ -150,7 +150,7 @@ func (c *ContainerService) ContainerExecStart(ctx context.Context, execID string // container. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerExport -func (c *ContainerService) ContainerExport(ctx context.Context, ctn string) (io.ReadCloser, error) { +func (c *ContainerService) ContainerExport(_ context.Context, _ string) (io.ReadCloser, error) { return nil, nil } @@ -158,7 +158,7 @@ func (c *ContainerService) ContainerExport(ctx context.Context, ctn string) (io. // a mocked call to inspect a Docker container. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerInspect -func (c *ContainerService) ContainerInspect(ctx context.Context, ctn string) (container.InspectResponse, error) { +func (c *ContainerService) ContainerInspect(_ context.Context, ctn string) (container.InspectResponse, error) { // verify a container was provided if len(ctn) == 0 { return container.InspectResponse{}, errors.New("no container provided") @@ -169,7 +169,7 @@ func (c *ContainerService) ContainerInspect(ctx context.Context, ctn string) (co if strings.Contains(ctn, "notfound") && !strings.Contains(ctn, "ignorenotfound") { return container.InspectResponse{}, - //nolint:stylecheck // messsage is capitalized to match Docker messages + //nolint:staticcheck // messsage is capitalized to match Docker messages errdefs.NotFound(fmt.Errorf("Error: No such container: %s", ctn)) } @@ -178,7 +178,7 @@ func (c *ContainerService) ContainerInspect(ctx context.Context, ctn string) (co if strings.Contains(ctn, "not-found") && !strings.Contains(ctn, "ignore-not-found") { return container.InspectResponse{}, - //nolint:stylecheck // messsage is capitalized to match Docker messages + //nolint:staticcheck // messsage is capitalized to match Docker messages errdefs.NotFound(fmt.Errorf("Error: No such container: %s", ctn)) } @@ -203,7 +203,7 @@ func (c *ContainerService) ContainerInspect(ctx context.Context, ctn string) (co // the raw body received from the API. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerInspectWithRaw -func (c *ContainerService) ContainerInspectWithRaw(ctx context.Context, ctn string, getSize bool) (container.InspectResponse, []byte, error) { +func (c *ContainerService) ContainerInspectWithRaw(_ context.Context, ctn string, _ bool) (container.InspectResponse, []byte, error) { // verify a container was provided if len(ctn) == 0 { return container.InspectResponse{}, nil, errors.New("no container provided") @@ -214,7 +214,7 @@ func (c *ContainerService) ContainerInspectWithRaw(ctx context.Context, ctn stri strings.Contains(ctn, "not-found") { return container.InspectResponse{}, nil, - //nolint:stylecheck // messsage is capitalized to match Docker messages + //nolint:staticcheck // messsage is capitalized to match Docker messages errdefs.NotFound(fmt.Errorf("Error: No such container: %s", ctn)) } @@ -244,7 +244,7 @@ func (c *ContainerService) ContainerInspectWithRaw(ctx context.Context, ctn stri // a mocked call to kill a Docker container. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerKill -func (c *ContainerService) ContainerKill(ctx context.Context, ctn, signal string) error { +func (c *ContainerService) ContainerKill(_ context.Context, ctn, _ string) error { // verify a container was provided if len(ctn) == 0 { return errors.New("no container provided") @@ -253,7 +253,7 @@ func (c *ContainerService) ContainerKill(ctx context.Context, ctn, signal string // check if the container is not found if strings.Contains(ctn, "notfound") || strings.Contains(ctn, "not-found") { - //nolint:stylecheck // messsage is capitalized to match Docker messages + //nolint:staticcheck // messsage is capitalized to match Docker messages return errdefs.NotFound(fmt.Errorf("Error: No such container: %s", ctn)) } @@ -264,7 +264,7 @@ func (c *ContainerService) ContainerKill(ctx context.Context, ctn, signal string // a mocked call to list Docker containers. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerList -func (c *ContainerService) ContainerList(ctx context.Context, options container.ListOptions) ([]container.Summary, error) { +func (c *ContainerService) ContainerList(_ context.Context, _ container.ListOptions) ([]container.Summary, error) { return nil, nil } @@ -273,7 +273,7 @@ func (c *ContainerService) ContainerList(ctx context.Context, options container. // Docker container. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerLogs -func (c *ContainerService) ContainerLogs(ctx context.Context, ctn string, options container.LogsOptions) (io.ReadCloser, error) { +func (c *ContainerService) ContainerLogs(_ context.Context, ctn string, _ container.LogsOptions) (io.ReadCloser, error) { // verify a container was provided if len(ctn) == 0 { return nil, errors.New("no container provided") @@ -282,7 +282,7 @@ func (c *ContainerService) ContainerLogs(ctx context.Context, ctn string, option // check if the container is not found if strings.Contains(ctn, "notfound") || strings.Contains(ctn, "not-found") { - //nolint:stylecheck // messsage is capitalized to match Docker messages + //nolint:staticcheck // messsage is capitalized to match Docker messages return nil, errdefs.NotFound(fmt.Errorf("Error: No such container: %s", ctn)) } @@ -312,7 +312,7 @@ func (c *ContainerService) ContainerLogs(ctx context.Context, ctn string, option // a mocked call to pause a running Docker container. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerPause -func (c *ContainerService) ContainerPause(ctx context.Context, ctn string) error { +func (c *ContainerService) ContainerPause(_ context.Context, _ string) error { return nil } @@ -320,7 +320,7 @@ func (c *ContainerService) ContainerPause(ctx context.Context, ctn string) error // a mocked call to remove a Docker container. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerRemove -func (c *ContainerService) ContainerRemove(ctx context.Context, ctn string, options container.RemoveOptions) error { +func (c *ContainerService) ContainerRemove(_ context.Context, ctn string, _ container.RemoveOptions) error { // verify a container was provided if len(ctn) == 0 { return errors.New("no container provided") @@ -328,7 +328,7 @@ func (c *ContainerService) ContainerRemove(ctx context.Context, ctn string, opti // check if the container is not found if strings.Contains(ctn, "notfound") || strings.Contains(ctn, "not-found") { - //nolint:stylecheck // messsage is capitalized to match Docker messages + //nolint:staticcheck // messsage is capitalized to match Docker messages return errdefs.NotFound(fmt.Errorf("Error: No such container: %s", ctn)) } @@ -339,7 +339,7 @@ func (c *ContainerService) ContainerRemove(ctx context.Context, ctn string, opti // a mocked call to rename a Docker container. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerRename -func (c *ContainerService) ContainerRename(ctx context.Context, container, newContainerName string) error { +func (c *ContainerService) ContainerRename(_ context.Context, _ string, _ string) error { return nil } @@ -347,7 +347,7 @@ func (c *ContainerService) ContainerRename(ctx context.Context, container, newCo // a mocked call to resize a Docker container. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerResize -func (c *ContainerService) ContainerResize(ctx context.Context, ctn string, options container.ResizeOptions) error { +func (c *ContainerService) ContainerResize(_ context.Context, _ string, _ container.ResizeOptions) error { return nil } @@ -355,7 +355,7 @@ func (c *ContainerService) ContainerResize(ctx context.Context, ctn string, opti // a mocked call to restart a Docker container. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerRestart -func (c *ContainerService) ContainerRestart(ctx context.Context, ctn string, options container.StopOptions) error { +func (c *ContainerService) ContainerRestart(_ context.Context, _ string, _ container.StopOptions) error { return nil } @@ -363,7 +363,7 @@ func (c *ContainerService) ContainerRestart(ctx context.Context, ctn string, opt // a mocked call to start a Docker container. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerStart -func (c *ContainerService) ContainerStart(ctx context.Context, ctn string, options container.StartOptions) error { +func (c *ContainerService) ContainerStart(_ context.Context, ctn string, _ container.StartOptions) error { // verify a container was provided if len(ctn) == 0 { return errors.New("no container provided") @@ -372,7 +372,7 @@ func (c *ContainerService) ContainerStart(ctx context.Context, ctn string, optio // check if the container is not found if strings.Contains(ctn, "notfound") || strings.Contains(ctn, "not-found") { - //nolint:stylecheck // messsage is capitalized to match Docker messages + //nolint:staticcheck // messsage is capitalized to match Docker messages return errdefs.NotFound(fmt.Errorf("Error: No such container: %s", ctn)) } @@ -384,7 +384,7 @@ func (c *ContainerService) ContainerStart(ctx context.Context, ctn string, optio // inside a Docker container. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerStatPath -func (c *ContainerService) ContainerStatPath(ctx context.Context, containerID, path string) (container.PathStat, error) { +func (c *ContainerService) ContainerStatPath(_ context.Context, _ string, _ string) (container.PathStat, error) { return container.PathStat{}, nil } @@ -393,7 +393,7 @@ func (c *ContainerService) ContainerStatPath(ctx context.Context, containerID, p // Docker container. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerStats -func (c *ContainerService) ContainerStats(ctx context.Context, ctn string, stream bool) (container.StatsResponseReader, error) { +func (c *ContainerService) ContainerStats(_ context.Context, _ string, _ bool) (container.StatsResponseReader, error) { return container.StatsResponseReader{}, nil } @@ -401,7 +401,7 @@ func (c *ContainerService) ContainerStats(ctx context.Context, ctn string, strea // a mocked call to stop a Docker container. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerStop -func (c *ContainerService) ContainerStop(ctx context.Context, ctn string, options container.StopOptions) error { +func (c *ContainerService) ContainerStop(_ context.Context, ctn string, _ container.StopOptions) error { // verify a container was provided if len(ctn) == 0 { return errors.New("no container provided") @@ -409,7 +409,7 @@ func (c *ContainerService) ContainerStop(ctx context.Context, ctn string, option // check if the container is not found if strings.Contains(ctn, "notfound") || strings.Contains(ctn, "not-found") { - //nolint:stylecheck // messsage is capitalized to match Docker messages + //nolint:staticcheck // messsage is capitalized to match Docker messages return errdefs.NotFound(fmt.Errorf("Error: No such container: %s", ctn)) } @@ -421,7 +421,7 @@ func (c *ContainerService) ContainerStop(ctx context.Context, ctn string, option // a Docker container. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerTop -func (c *ContainerService) ContainerTop(ctx context.Context, ctn string, arguments []string) (container.TopResponse, error) { +func (c *ContainerService) ContainerTop(_ context.Context, _ string, _ []string) (container.TopResponse, error) { return container.TopResponse{}, nil } @@ -429,7 +429,7 @@ func (c *ContainerService) ContainerTop(ctx context.Context, ctn string, argumen // a mocked call to unpause a Docker container. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerUnpause -func (c *ContainerService) ContainerUnpause(ctx context.Context, ctn string) error { +func (c *ContainerService) ContainerUnpause(_ context.Context, _ string) error { return nil } @@ -437,7 +437,7 @@ func (c *ContainerService) ContainerUnpause(ctx context.Context, ctn string) err // a mocked call to update a Docker container. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerUpdate -func (c *ContainerService) ContainerUpdate(ctx context.Context, ctn string, updateConfig container.UpdateConfig) (container.UpdateResponse, error) { +func (c *ContainerService) ContainerUpdate(_ context.Context, _ string, _ container.UpdateConfig) (container.UpdateResponse, error) { return container.UpdateResponse{}, nil } @@ -446,7 +446,7 @@ func (c *ContainerService) ContainerUpdate(ctx context.Context, ctn string, upda // container to finish. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerWait -func (c *ContainerService) ContainerWait(ctx context.Context, ctn string, condition container.WaitCondition) (<-chan container.WaitResponse, <-chan error) { +func (c *ContainerService) ContainerWait(_ context.Context, ctn string, _ container.WaitCondition) (<-chan container.WaitResponse, <-chan error) { ctnCh := make(chan container.WaitResponse, 1) errCh := make(chan error, 1) @@ -461,7 +461,7 @@ func (c *ContainerService) ContainerWait(ctx context.Context, ctn string, condit // check if the container is not found if strings.Contains(ctn, "notfound") || strings.Contains(ctn, "not-found") { // propagate the error to the error channel - //nolint:stylecheck // messsage is capitalized to match Docker messages + //nolint:staticcheck // messsage is capitalized to match Docker messages errCh <- errdefs.NotFound(fmt.Errorf("Error: No such container: %s", ctn)) return ctnCh, errCh @@ -491,15 +491,15 @@ func (c *ContainerService) ContainerWait(ctx context.Context, ctn string, condit // a mocked call to prune Docker containers. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ContainersPrune -func (c *ContainerService) ContainersPrune(ctx context.Context, pruneFilters filters.Args) (container.PruneReport, error) { +func (c *ContainerService) ContainersPrune(_ context.Context, _ filters.Args) (container.PruneReport, error) { return container.PruneReport{}, nil } // ContainerStatsOneShot is a helper function to simulate // a mocked call to return near realtime stats for a given container. // -// https://pkg.go.dev/github.com/docker/docker/client#Client.CoontainerStatsOneShot -func (c *ContainerService) ContainerStatsOneShot(ctx context.Context, containerID string) (container.StatsResponseReader, error) { +// https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerStatsOneShot +func (c *ContainerService) ContainerStatsOneShot(_ context.Context, _ string) (container.StatsResponseReader, error) { return container.StatsResponseReader{}, nil } @@ -507,7 +507,7 @@ func (c *ContainerService) ContainerStatsOneShot(ctx context.Context, containerI // a mocked call to copy content from a Docker container. // // https://pkg.go.dev/github.com/docker/docker/client#Client.CopyFromContainer -func (c *ContainerService) CopyFromContainer(ctx context.Context, containerID, srcPath string) (io.ReadCloser, container.PathStat, error) { +func (c *ContainerService) CopyFromContainer(_ context.Context, _ string, _ string) (io.ReadCloser, container.PathStat, error) { return nil, container.PathStat{}, nil } @@ -515,7 +515,7 @@ func (c *ContainerService) CopyFromContainer(ctx context.Context, containerID, s // a mocked call to copy content to a Docker container. // // https://pkg.go.dev/github.com/docker/docker/client#Client.CopyToContainer -func (c *ContainerService) CopyToContainer(ctx context.Context, container, path string, content io.Reader, options container.CopyToContainerOptions) error { +func (c *ContainerService) CopyToContainer(_ context.Context, _ string, _ string, _ io.Reader, _ container.CopyToContainerOptions) error { return nil } diff --git a/mock/docker/distribution.go b/mock/docker/distribution.go index 3c134434..2247baeb 100644 --- a/mock/docker/distribution.go +++ b/mock/docker/distribution.go @@ -16,7 +16,7 @@ type DistributionService struct{} // DistributionInspect is a helper function to simulate // a mocked call to inspect a Docker image and return // the digest and manifest. -func (d *DistributionService) DistributionInspect(ctx context.Context, image, encodedRegistryAuth string) (registry.DistributionInspect, error) { +func (d *DistributionService) DistributionInspect(_ context.Context, _ string, _ string) (registry.DistributionInspect, error) { return registry.DistributionInspect{}, nil } diff --git a/mock/docker/image.go b/mock/docker/image.go index dbac4848..cf70eb6b 100644 --- a/mock/docker/image.go +++ b/mock/docker/image.go @@ -5,7 +5,6 @@ package docker import ( "bytes" "context" - "encoding/json" "errors" "fmt" "io" @@ -29,13 +28,13 @@ type ImageService struct{} // BuildCachePrune is a helper function to simulate // a mocked call to prune the build cache for the // Docker daemon. -func (i *ImageService) BuildCachePrune(ctx context.Context, options build.CachePruneOptions) (*build.CachePruneReport, error) { +func (i *ImageService) BuildCachePrune(_ context.Context, _ build.CachePruneOptions) (*build.CachePruneReport, error) { return nil, nil } // BuildCancel is a helper function to simulate // a mocked call to cancel building a Docker image. -func (i *ImageService) BuildCancel(ctx context.Context, id string) error { +func (i *ImageService) BuildCancel(_ context.Context, _ string) error { return nil } @@ -43,7 +42,7 @@ func (i *ImageService) BuildCancel(ctx context.Context, id string) error { // a mocked call to build a Docker image. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ImageBuild -func (i *ImageService) ImageBuild(ctx context.Context, context io.Reader, options build.ImageBuildOptions) (build.ImageBuildResponse, error) { +func (i *ImageService) ImageBuild(_ context.Context, _ io.Reader, _ build.ImageBuildOptions) (build.ImageBuildResponse, error) { return build.ImageBuildResponse{}, nil } @@ -51,7 +50,7 @@ func (i *ImageService) ImageBuild(ctx context.Context, context io.Reader, option // a mocked call to create a Docker image. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ImageCreate -func (i *ImageService) ImageCreate(ctx context.Context, parentReference string, options image.CreateOptions) (io.ReadCloser, error) { +func (i *ImageService) ImageCreate(_ context.Context, _ string, _ image.CreateOptions) (io.ReadCloser, error) { return nil, nil } @@ -60,7 +59,7 @@ func (i *ImageService) ImageCreate(ctx context.Context, parentReference string, // Docker image. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ImageHistory -func (i *ImageService) ImageHistory(ctx context.Context, image string, options ...client.ImageHistoryOption) ([]image.HistoryResponseItem, error) { +func (i *ImageService) ImageHistory(_ context.Context, _ string, _ ...client.ImageHistoryOption) ([]image.HistoryResponseItem, error) { return nil, nil } @@ -68,7 +67,7 @@ func (i *ImageService) ImageHistory(ctx context.Context, image string, options . // a mocked call to import a Docker image. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ImageImport -func (i *ImageService) ImageImport(ctx context.Context, source image.ImportSource, ref string, options image.ImportOptions) (io.ReadCloser, error) { +func (i *ImageService) ImageImport(_ context.Context, _ image.ImportSource, _ string, _ image.ImportOptions) (io.ReadCloser, error) { return nil, nil } @@ -76,8 +75,8 @@ func (i *ImageService) ImageImport(ctx context.Context, source image.ImportSourc // a mocked call to inspect a Docker image. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ImageInspect -func (i *ImageService) ImageInspect(ctx context.Context, imageID string, inspectOpts ...client.ImageInspectOption) (image.InspectResponse, error) { - return image.InspectResponse{}, nil +func (i *ImageService) ImageInspectWithRaw(_ context.Context, _ string) (image.InspectResponse, []byte, error) { + return image.InspectResponse{}, nil, nil } // ImageInspectWithRaw is a helper function to simulate @@ -85,18 +84,17 @@ func (i *ImageService) ImageInspect(ctx context.Context, imageID string, inspect // the raw body received from the API. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ImageInspectWithRaw -func (i *ImageService) ImageInspectWithRaw(ctx context.Context, img string) (image.InspectResponse, []byte, error) { +func (i *ImageService) ImageInspect(_ context.Context, img string, _ ...client.ImageInspectOption) (image.InspectResponse, error) { // verify an image was provided if len(img) == 0 { - return image.InspectResponse{}, nil, errors.New("no image provided") + return image.InspectResponse{}, errors.New("no image provided") } // check if the image is not found if strings.Contains(img, "notfound") || strings.Contains(img, "not-found") { return image.InspectResponse{}, - nil, errdefs.NotFound( - //nolint:stylecheck // messsage is capitalized to match Docker messages + //nolint:staticcheck // messsage is capitalized to match Docker messages fmt.Errorf("Error response from daemon: manifest for %s not found: manifest unknown", img), ) } @@ -130,20 +128,14 @@ func (i *ImageService) ImageInspectWithRaw(ctx context.Context, img string) (ima Metadata: image.Metadata{LastTagTime: time.Now()}, } - // marshal response into raw bytes - b, err := json.Marshal(response) - if err != nil { - return image.InspectResponse{}, nil, err - } - - return response, b, nil + return response, nil } // ImageList is a helper function to simulate // a mocked call to list Docker images. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ImageList -func (i *ImageService) ImageList(ctx context.Context, options image.ListOptions) ([]image.Summary, error) { +func (i *ImageService) ImageList(_ context.Context, _ image.ListOptions) ([]image.Summary, error) { return nil, nil } @@ -151,7 +143,7 @@ func (i *ImageService) ImageList(ctx context.Context, options image.ListOptions) // a mocked call to load a Docker image. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ImageLoad -func (i *ImageService) ImageLoad(ctx context.Context, input io.Reader, options ...client.ImageLoadOption) (image.LoadResponse, error) { +func (i *ImageService) ImageLoad(_ context.Context, _ io.Reader, _ ...client.ImageLoadOption) (image.LoadResponse, error) { return image.LoadResponse{}, nil } @@ -159,7 +151,7 @@ func (i *ImageService) ImageLoad(ctx context.Context, input io.Reader, options . // a mocked call to pull a Docker image. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ImagePull -func (i *ImageService) ImagePull(ctx context.Context, image string, options image.PullOptions) (io.ReadCloser, error) { +func (i *ImageService) ImagePull(_ context.Context, image string, _ image.PullOptions) (io.ReadCloser, error) { // verify an image was provided if len(image) == 0 { return nil, errors.New("no container provided") @@ -171,7 +163,7 @@ func (i *ImageService) ImagePull(ctx context.Context, image string, options imag !strings.Contains(image, "ignorenotfound") { return nil, errdefs.NotFound( - //nolint:stylecheck // messsage is capitalized to match Docker messages + //nolint:staticcheck // messsage is capitalized to match Docker messages fmt.Errorf("Error response from daemon: manifest for %s not found: manifest unknown", image), ) } @@ -182,7 +174,7 @@ func (i *ImageService) ImagePull(ctx context.Context, image string, options imag !strings.Contains(image, "ignore-not-found") { return nil, errdefs.NotFound( - //nolint:stylecheck // messsage is capitalized to match Docker messages + //nolint:staticcheck // messsage is capitalized to match Docker messages fmt.Errorf("Error response from daemon: manifest for %s not found: manifest unknown", image), ) } @@ -208,7 +200,7 @@ func (i *ImageService) ImagePull(ctx context.Context, image string, options imag // a mocked call to push a Docker image. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ImagePush -func (i *ImageService) ImagePush(ctx context.Context, ref string, options image.PushOptions) (io.ReadCloser, error) { +func (i *ImageService) ImagePush(_ context.Context, _ string, _ image.PushOptions) (io.ReadCloser, error) { return nil, nil } @@ -216,7 +208,7 @@ func (i *ImageService) ImagePush(ctx context.Context, ref string, options image. // a mocked call to remove a Docker image. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ImageRemove -func (i *ImageService) ImageRemove(ctx context.Context, image string, options image.RemoveOptions) ([]image.DeleteResponse, error) { +func (i *ImageService) ImageRemove(_ context.Context, _ string, _ image.RemoveOptions) ([]image.DeleteResponse, error) { return nil, nil } @@ -224,7 +216,7 @@ func (i *ImageService) ImageRemove(ctx context.Context, image string, options im // a mocked call to save a Docker image. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ImageSave -func (i *ImageService) ImageSave(ctx context.Context, images []string, options ...client.ImageSaveOption) (io.ReadCloser, error) { +func (i *ImageService) ImageSave(_ context.Context, _ []string, _ ...client.ImageSaveOption) (io.ReadCloser, error) { return nil, nil } @@ -232,7 +224,7 @@ func (i *ImageService) ImageSave(ctx context.Context, images []string, options . // a mocked call to search for a Docker image. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ImageSearch -func (i *ImageService) ImageSearch(ctx context.Context, term string, options registry.SearchOptions) ([]registry.SearchResult, error) { +func (i *ImageService) ImageSearch(_ context.Context, _ string, _ registry.SearchOptions) ([]registry.SearchResult, error) { return nil, nil } @@ -240,7 +232,7 @@ func (i *ImageService) ImageSearch(ctx context.Context, term string, options reg // a mocked call to tag a Docker image. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ImageTag -func (i *ImageService) ImageTag(ctx context.Context, image, ref string) error { +func (i *ImageService) ImageTag(_ context.Context, _ string, _ string) error { return nil } @@ -248,7 +240,7 @@ func (i *ImageService) ImageTag(ctx context.Context, image, ref string) error { // a mocked call to prune Docker images. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ImagesPrune -func (i *ImageService) ImagesPrune(ctx context.Context, pruneFilter filters.Args) (image.PruneReport, error) { +func (i *ImageService) ImagesPrune(_ context.Context, _ filters.Args) (image.PruneReport, error) { return image.PruneReport{}, nil } diff --git a/mock/docker/mock.go b/mock/docker/mock.go index ecbb426a..2b1ba546 100644 --- a/mock/docker/mock.go +++ b/mock/docker/mock.go @@ -13,6 +13,7 @@ import ( type mock struct { // Services + CheckpointService ConfigService ContainerService DistributionService @@ -55,14 +56,14 @@ func (m *mock) DaemonHost() string { // DialSession is a helper function to simulate // returning a connection that can be used // for communication with daemon. -func (m *mock) DialSession(ctx context.Context, proto string, meta map[string][]string) (net.Conn, error) { +func (m *mock) DialSession(_ context.Context, _ string, _ map[string][]string) (net.Conn, error) { return nil, nil } // DialHijack is a helper function to simulate // returning a hijacked connection with // negotiated protocol proto. -func (m *mock) DialHijack(ctx context.Context, url, proto string, meta map[string][]string) (net.Conn, error) { +func (m *mock) DialHijack(_ context.Context, _ string, _ string, _ map[string][]string) (net.Conn, error) { return nil, nil } @@ -84,7 +85,7 @@ func (m *mock) HTTPClient() *http.Client { // NegotiateAPIVersion is a helper function to simulate // a mocked call to query the API and update the client // version to match the API version. -func (m *mock) NegotiateAPIVersion(ctx context.Context) {} +func (m *mock) NegotiateAPIVersion(_ context.Context) {} // NegotiateAPIVersionPing is a helper function to simulate // a mocked call to update the client version to match @@ -96,7 +97,7 @@ func (m *mock) NegotiateAPIVersionPing(types.Ping) {} // Docker client and server host. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ServerVersion -func (m *mock) ServerVersion(ctx context.Context) (types.Version, error) { +func (m *mock) ServerVersion(_ context.Context) (types.Version, error) { return types.Version{}, nil } @@ -107,4 +108,4 @@ func (m *mock) ServerVersion(ctx context.Context) (types.Version, error) { // Docker client expects. // // https://pkg.go.dev/github.com/docker/docker/client#CommonAPIClient -var _ client.CommonAPIClient = (*mock)(nil) +var _ client.APIClient = (*mock)(nil) diff --git a/mock/docker/network.go b/mock/docker/network.go index a7776885..d8df185e 100644 --- a/mock/docker/network.go +++ b/mock/docker/network.go @@ -25,7 +25,7 @@ type NetworkService struct{} // a mocked call to connect to a Docker network. // // https://pkg.go.dev/github.com/docker/docker/client#Client.NetworkConnect -func (n *NetworkService) NetworkConnect(ctx context.Context, network, container string, config *network.EndpointSettings) error { +func (n *NetworkService) NetworkConnect(_ context.Context, _, _ string, _ *network.EndpointSettings) error { return nil } @@ -33,7 +33,7 @@ func (n *NetworkService) NetworkConnect(ctx context.Context, network, container // a mocked call to create a Docker network. // // https://pkg.go.dev/github.com/docker/docker/client#Client.NetworkCreate -func (n *NetworkService) NetworkCreate(ctx context.Context, name string, options network.CreateOptions) (network.CreateResponse, error) { +func (n *NetworkService) NetworkCreate(_ context.Context, name string, _ network.CreateOptions) (network.CreateResponse, error) { // verify a network was provided if len(name) == 0 { return network.CreateResponse{}, errors.New("no network provided") @@ -44,7 +44,7 @@ func (n *NetworkService) NetworkCreate(ctx context.Context, name string, options if strings.Contains(name, "notfound") && !strings.Contains(name, "ignorenotfound") { return network.CreateResponse{}, - //nolint:stylecheck // messsage is capitalized to match Docker messages + //nolint:staticcheck // messsage is capitalized to match Docker messages errdefs.NotFound(fmt.Errorf("Error: No such network: %s", name)) } @@ -53,7 +53,7 @@ func (n *NetworkService) NetworkCreate(ctx context.Context, name string, options if strings.Contains(name, "not-found") && !strings.Contains(name, "ignore-not-found") { return network.CreateResponse{}, - //nolint:stylecheck // messsage is capitalized to match Docker messages + //nolint:staticcheck // messsage is capitalized to match Docker messages errdefs.NotFound(fmt.Errorf("Error: No such network: %s", name)) } @@ -69,7 +69,7 @@ func (n *NetworkService) NetworkCreate(ctx context.Context, name string, options // a mocked call to disconnect from a Docker network. // // https://pkg.go.dev/github.com/docker/docker/client#Client.NetworkDisconnect -func (n *NetworkService) NetworkDisconnect(ctx context.Context, network, container string, force bool) error { +func (n *NetworkService) NetworkDisconnect(_ context.Context, _, _ string, _ bool) error { return nil } @@ -77,7 +77,7 @@ func (n *NetworkService) NetworkDisconnect(ctx context.Context, network, contain // a mocked call to inspect a Docker network. // // https://pkg.go.dev/github.com/docker/docker/client#Client.NetworkInspect -func (n *NetworkService) NetworkInspect(ctx context.Context, networkID string, options network.InspectOptions) (network.Inspect, error) { +func (n *NetworkService) NetworkInspect(_ context.Context, networkID string, _ network.InspectOptions) (network.Inspect, error) { // verify a network was provided if len(networkID) == 0 { return network.Inspect{}, errors.New("no network provided") @@ -86,14 +86,14 @@ func (n *NetworkService) NetworkInspect(ctx context.Context, networkID string, o // check if the network is notfound if strings.Contains(networkID, "notfound") { return network.Inspect{}, - //nolint:stylecheck // messsage is capitalized to match Docker messages + //nolint:staticcheck // messsage is capitalized to match Docker messages errdefs.NotFound(fmt.Errorf("Error: No such network: %s", networkID)) } // check if the network is not-found if strings.Contains(networkID, "not-found") { return network.Inspect{}, - //nolint:stylecheck // messsage is capitalized to match Docker messages + //nolint:staticcheck // messsage is capitalized to match Docker messages errdefs.NotFound(fmt.Errorf("Error: No such network: %s", networkID)) } @@ -118,7 +118,7 @@ func (n *NetworkService) NetworkInspect(ctx context.Context, networkID string, o // the raw body received from the API. // // https://pkg.go.dev/github.com/docker/docker/client#Client.NetworkInspectWithRaw -func (n *NetworkService) NetworkInspectWithRaw(ctx context.Context, networkID string, options network.InspectOptions) (network.Inspect, []byte, error) { +func (n *NetworkService) NetworkInspectWithRaw(_ context.Context, networkID string, _ network.InspectOptions) (network.Inspect, []byte, error) { // verify a network was provided if len(networkID) == 0 { return network.Inspect{}, nil, errors.New("no network provided") @@ -150,7 +150,7 @@ func (n *NetworkService) NetworkInspectWithRaw(ctx context.Context, networkID st // a mocked call to list Docker networks. // // https://pkg.go.dev/github.com/docker/docker/client#Client.NetworkList -func (n *NetworkService) NetworkList(ctx context.Context, options network.ListOptions) ([]network.Summary, error) { +func (n *NetworkService) NetworkList(_ context.Context, _ network.ListOptions) ([]network.Summary, error) { return nil, nil } @@ -158,7 +158,7 @@ func (n *NetworkService) NetworkList(ctx context.Context, options network.ListOp // a mocked call to remove Docker a network. // // https://pkg.go.dev/github.com/docker/docker/client#Client.NetworkRemove -func (n *NetworkService) NetworkRemove(ctx context.Context, network string) error { +func (n *NetworkService) NetworkRemove(_ context.Context, network string) error { // verify a network was provided if len(network) == 0 { return errors.New("no network provided") @@ -171,7 +171,7 @@ func (n *NetworkService) NetworkRemove(ctx context.Context, network string) erro // a mocked call to prune Docker networks. // // https://pkg.go.dev/github.com/docker/docker/client#Client.NetworksPrune -func (n *NetworkService) NetworksPrune(ctx context.Context, pruneFilter filters.Args) (network.PruneReport, error) { +func (n *NetworkService) NetworksPrune(_ context.Context, _ filters.Args) (network.PruneReport, error) { return network.PruneReport{}, nil } diff --git a/mock/docker/node.go b/mock/docker/node.go index c8258065..fcdb1c20 100644 --- a/mock/docker/node.go +++ b/mock/docker/node.go @@ -18,7 +18,7 @@ type NodeService struct{} // cluster and return the raw body received from the API. // // https://pkg.go.dev/github.com/docker/docker/client#Client.NodeInspectWithRaw -func (n *NodeService) NodeInspectWithRaw(ctx context.Context, nodeID string) (swarm.Node, []byte, error) { +func (n *NodeService) NodeInspectWithRaw(_ context.Context, _ string) (swarm.Node, []byte, error) { return swarm.Node{}, nil, nil } @@ -27,7 +27,7 @@ func (n *NodeService) NodeInspectWithRaw(ctx context.Context, nodeID string) (sw // Docker swarm cluster. // // https://pkg.go.dev/github.com/docker/docker/client#Client.NodeList -func (n *NodeService) NodeList(ctx context.Context, options swarm.NodeListOptions) ([]swarm.Node, error) { +func (n *NodeService) NodeList(_ context.Context, _ swarm.NodeListOptions) ([]swarm.Node, error) { return nil, nil } @@ -36,7 +36,7 @@ func (n *NodeService) NodeList(ctx context.Context, options swarm.NodeListOption // Docker swarm cluster. // // https://pkg.go.dev/github.com/docker/docker/client#Client.NodeRemove -func (n *NodeService) NodeRemove(ctx context.Context, nodeID string, options swarm.NodeRemoveOptions) error { +func (n *NodeService) NodeRemove(_ context.Context, _ string, _ swarm.NodeRemoveOptions) error { return nil } @@ -45,7 +45,7 @@ func (n *NodeService) NodeRemove(ctx context.Context, nodeID string, options swa // Docker swarm cluster. // // https://pkg.go.dev/github.com/docker/docker/client#Client.NodeUpdate -func (n *NodeService) NodeUpdate(ctx context.Context, nodeID string, version swarm.Version, node swarm.NodeSpec) error { +func (n *NodeService) NodeUpdate(_ context.Context, _ string, _ swarm.Version, _ swarm.NodeSpec) error { return nil } diff --git a/mock/docker/plugin.go b/mock/docker/plugin.go index 796afded..96fe0b94 100644 --- a/mock/docker/plugin.go +++ b/mock/docker/plugin.go @@ -19,7 +19,7 @@ type PluginService struct{} // a mocked call to create a Docker plugin. // // https://pkg.go.dev/github.com/docker/docker/client#Client.PluginCreate -func (p *PluginService) PluginCreate(ctx context.Context, createContext io.Reader, options types.PluginCreateOptions) error { +func (p *PluginService) PluginCreate(_ context.Context, _ io.Reader, _ types.PluginCreateOptions) error { return nil } @@ -27,7 +27,7 @@ func (p *PluginService) PluginCreate(ctx context.Context, createContext io.Reade // a mocked call to disable a Docker plugin. // // https://pkg.go.dev/github.com/docker/docker/client#Client.PluginDisable -func (p *PluginService) PluginDisable(ctx context.Context, name string, options types.PluginDisableOptions) error { +func (p *PluginService) PluginDisable(_ context.Context, _ string, _ types.PluginDisableOptions) error { return nil } @@ -35,7 +35,7 @@ func (p *PluginService) PluginDisable(ctx context.Context, name string, options // a mocked call to enable a Docker plugin. // // https://pkg.go.dev/github.com/docker/docker/client#Client.PluginEnable -func (p *PluginService) PluginEnable(ctx context.Context, name string, options types.PluginEnableOptions) error { +func (p *PluginService) PluginEnable(_ context.Context, _ string, _ types.PluginEnableOptions) error { return nil } @@ -44,7 +44,7 @@ func (p *PluginService) PluginEnable(ctx context.Context, name string, options t // the raw body received from the API. // // https://pkg.go.dev/github.com/docker/docker/client#Client.PluginInspectWithRaw -func (p *PluginService) PluginInspectWithRaw(ctx context.Context, name string) (*types.Plugin, []byte, error) { +func (p *PluginService) PluginInspectWithRaw(_ context.Context, _ string) (*types.Plugin, []byte, error) { return nil, nil, nil } @@ -52,7 +52,7 @@ func (p *PluginService) PluginInspectWithRaw(ctx context.Context, name string) ( // a mocked call to install a Docker plugin. // // https://pkg.go.dev/github.com/docker/docker/client#Client.PluginInstall -func (p *PluginService) PluginInstall(ctx context.Context, name string, options types.PluginInstallOptions) (io.ReadCloser, error) { +func (p *PluginService) PluginInstall(_ context.Context, _ string, _ types.PluginInstallOptions) (io.ReadCloser, error) { return nil, nil } @@ -60,7 +60,7 @@ func (p *PluginService) PluginInstall(ctx context.Context, name string, options // a mocked call to list Docker plugins. // // https://pkg.go.dev/github.com/docker/docker/client#Client.PluginList -func (p *PluginService) PluginList(ctx context.Context, filter filters.Args) (types.PluginsListResponse, error) { +func (p *PluginService) PluginList(_ context.Context, _ filters.Args) (types.PluginsListResponse, error) { return types.PluginsListResponse{}, nil } @@ -68,7 +68,7 @@ func (p *PluginService) PluginList(ctx context.Context, filter filters.Args) (ty // a mocked call to push a Docker plugin. // // https://pkg.go.dev/github.com/docker/docker/client#Client.PluginPush -func (p *PluginService) PluginPush(ctx context.Context, name string, registryAuth string) (io.ReadCloser, error) { +func (p *PluginService) PluginPush(_ context.Context, _ string, _ string) (io.ReadCloser, error) { return nil, nil } @@ -76,7 +76,7 @@ func (p *PluginService) PluginPush(ctx context.Context, name string, registryAut // a mocked call to remove a Docker plugin. // // https://pkg.go.dev/github.com/docker/docker/client#Client.PluginRemove -func (p *PluginService) PluginRemove(ctx context.Context, name string, options types.PluginRemoveOptions) error { +func (p *PluginService) PluginRemove(_ context.Context, _ string, _ types.PluginRemoveOptions) error { return nil } @@ -85,7 +85,7 @@ func (p *PluginService) PluginRemove(ctx context.Context, name string, options t // Docker plugin. // // https://pkg.go.dev/github.com/docker/docker/client#Client.PluginSet -func (p *PluginService) PluginSet(ctx context.Context, name string, args []string) error { +func (p *PluginService) PluginSet(_ context.Context, _ string, _ []string) error { return nil } @@ -93,7 +93,7 @@ func (p *PluginService) PluginSet(ctx context.Context, name string, args []strin // a mocked call to upgrade a Docker plugin. // // https://pkg.go.dev/github.com/docker/docker/client#Client.PluginUpgrade -func (p *PluginService) PluginUpgrade(ctx context.Context, name string, options types.PluginInstallOptions) (io.ReadCloser, error) { +func (p *PluginService) PluginUpgrade(_ context.Context, _ string, _ types.PluginInstallOptions) (io.ReadCloser, error) { return nil, nil } diff --git a/mock/docker/secret.go b/mock/docker/secret.go index 7ff8c40c..f2d42f8b 100644 --- a/mock/docker/secret.go +++ b/mock/docker/secret.go @@ -19,7 +19,7 @@ type SecretService struct{} // Docker swarm cluster. // // https://pkg.go.dev/github.com/docker/docker/client#Client.SecretCreate -func (s *SecretService) SecretCreate(ctx context.Context, secret swarm.SecretSpec) (swarm.SecretCreateResponse, error) { +func (s *SecretService) SecretCreate(_ context.Context, _ swarm.SecretSpec) (swarm.SecretCreateResponse, error) { return swarm.SecretCreateResponse{}, nil } @@ -28,7 +28,7 @@ func (s *SecretService) SecretCreate(ctx context.Context, secret swarm.SecretSpe // the raw body received from the API. // // https://pkg.go.dev/github.com/docker/docker/client#Client.SecretInspectWithRaw -func (s *SecretService) SecretInspectWithRaw(ctx context.Context, name string) (swarm.Secret, []byte, error) { +func (s *SecretService) SecretInspectWithRaw(_ context.Context, _ string) (swarm.Secret, []byte, error) { return swarm.Secret{}, nil, nil } @@ -37,7 +37,7 @@ func (s *SecretService) SecretInspectWithRaw(ctx context.Context, name string) ( // Docker swarm cluster. // // https://pkg.go.dev/github.com/docker/docker/client#Client.SecretList -func (s *SecretService) SecretList(ctx context.Context, options swarm.SecretListOptions) ([]swarm.Secret, error) { +func (s *SecretService) SecretList(_ context.Context, _ swarm.SecretListOptions) ([]swarm.Secret, error) { return nil, nil } @@ -46,7 +46,7 @@ func (s *SecretService) SecretList(ctx context.Context, options swarm.SecretList // Docker swarm cluster. // // https://pkg.go.dev/github.com/docker/docker/client#Client.SecretRemove -func (s *SecretService) SecretRemove(ctx context.Context, id string) error { +func (s *SecretService) SecretRemove(_ context.Context, _ string) error { return nil } @@ -55,7 +55,7 @@ func (s *SecretService) SecretRemove(ctx context.Context, id string) error { // Docker swarm cluster. // // https://pkg.go.dev/github.com/docker/docker/client#Client.SecretUpdate -func (s *SecretService) SecretUpdate(ctx context.Context, id string, version swarm.Version, secret swarm.SecretSpec) error { +func (s *SecretService) SecretUpdate(_ context.Context, _ string, _ swarm.Version, _ swarm.SecretSpec) error { return nil } diff --git a/mock/docker/service.go b/mock/docker/service.go index 67c0502e..496710ab 100644 --- a/mock/docker/service.go +++ b/mock/docker/service.go @@ -20,7 +20,7 @@ type ServiceService struct{} // Docker swarm cluster. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ServiceCreate -func (s *ServiceService) ServiceCreate(ctx context.Context, service swarm.ServiceSpec, options swarm.ServiceCreateOptions) (swarm.ServiceCreateResponse, error) { +func (s *ServiceService) ServiceCreate(_ context.Context, _ swarm.ServiceSpec, _ swarm.ServiceCreateOptions) (swarm.ServiceCreateResponse, error) { return swarm.ServiceCreateResponse{}, nil } @@ -29,7 +29,7 @@ func (s *ServiceService) ServiceCreate(ctx context.Context, service swarm.Servic // the raw body received from the API. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ServiceInspectWithRaw -func (s *ServiceService) ServiceInspectWithRaw(ctx context.Context, serviceID string, options swarm.ServiceInspectOptions) (swarm.Service, []byte, error) { +func (s *ServiceService) ServiceInspectWithRaw(_ context.Context, _ string, _ swarm.ServiceInspectOptions) (swarm.Service, []byte, error) { return swarm.Service{}, nil, nil } @@ -38,7 +38,7 @@ func (s *ServiceService) ServiceInspectWithRaw(ctx context.Context, serviceID st // Docker swarm cluster. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ServiceList -func (s *ServiceService) ServiceList(ctx context.Context, options swarm.ServiceListOptions) ([]swarm.Service, error) { +func (s *ServiceService) ServiceList(_ context.Context, _ swarm.ServiceListOptions) ([]swarm.Service, error) { return nil, nil } @@ -47,7 +47,7 @@ func (s *ServiceService) ServiceList(ctx context.Context, options swarm.ServiceL // service for a Docker swarm cluster. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ServiceLogs -func (s *ServiceService) ServiceLogs(ctx context.Context, serviceID string, options container.LogsOptions) (io.ReadCloser, error) { +func (s *ServiceService) ServiceLogs(_ context.Context, _ string, _ container.LogsOptions) (io.ReadCloser, error) { return nil, nil } @@ -56,7 +56,7 @@ func (s *ServiceService) ServiceLogs(ctx context.Context, serviceID string, opti // Docker swarm cluster. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ServiceRemove -func (s *ServiceService) ServiceRemove(ctx context.Context, serviceID string) error { +func (s *ServiceService) ServiceRemove(_ context.Context, _ string) error { return nil } @@ -65,7 +65,7 @@ func (s *ServiceService) ServiceRemove(ctx context.Context, serviceID string) er // Docker swarm cluster. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ServiceUpdate -func (s *ServiceService) ServiceUpdate(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options swarm.ServiceUpdateOptions) (swarm.ServiceUpdateResponse, error) { +func (s *ServiceService) ServiceUpdate(_ context.Context, _ string, _ swarm.Version, _ swarm.ServiceSpec, _ swarm.ServiceUpdateOptions) (swarm.ServiceUpdateResponse, error) { return swarm.ServiceUpdateResponse{}, nil } @@ -74,7 +74,7 @@ func (s *ServiceService) ServiceUpdate(ctx context.Context, serviceID string, ve // cluster and return the raw body received from the API. // // https://pkg.go.dev/github.com/docker/docker/client#Client.TaskInspectWithRaw -func (s *ServiceService) TaskInspectWithRaw(ctx context.Context, taskID string) (swarm.Task, []byte, error) { +func (s *ServiceService) TaskInspectWithRaw(_ context.Context, _ string) (swarm.Task, []byte, error) { return swarm.Task{}, nil, nil } @@ -83,14 +83,14 @@ func (s *ServiceService) TaskInspectWithRaw(ctx context.Context, taskID string) // Docker swarm cluster. // // https://pkg.go.dev/github.com/docker/docker/client#Client.TaskList -func (s *ServiceService) TaskList(ctx context.Context, options swarm.TaskListOptions) ([]swarm.Task, error) { +func (s *ServiceService) TaskList(_ context.Context, _ swarm.TaskListOptions) ([]swarm.Task, error) { return nil, nil } // TaskLogs is a helper function to simulate // a mocked call to capture the logs from a // task for a Docker swarm cluster. -func (s *ServiceService) TaskLogs(ctx context.Context, taskID string, options container.LogsOptions) (io.ReadCloser, error) { +func (s *ServiceService) TaskLogs(_ context.Context, _ string, _ container.LogsOptions) (io.ReadCloser, error) { return nil, nil } diff --git a/mock/docker/swarm.go b/mock/docker/swarm.go index e7eba363..ab055a09 100644 --- a/mock/docker/swarm.go +++ b/mock/docker/swarm.go @@ -18,7 +18,7 @@ type SwarmService struct{} // Docker swarm cluster. // // https://pkg.go.dev/github.com/docker/docker/client#Client.SwarmGetUnlockKey -func (s *SwarmService) SwarmGetUnlockKey(ctx context.Context) (swarm.UnlockKeyResponse, error) { +func (s *SwarmService) SwarmGetUnlockKey(_ context.Context) (swarm.UnlockKeyResponse, error) { return swarm.UnlockKeyResponse{}, nil } @@ -27,7 +27,7 @@ func (s *SwarmService) SwarmGetUnlockKey(ctx context.Context) (swarm.UnlockKeyRe // swarm cluster. // // https://pkg.go.dev/github.com/docker/docker/client#Client.SwarmInit -func (s *SwarmService) SwarmInit(ctx context.Context, req swarm.InitRequest) (string, error) { +func (s *SwarmService) SwarmInit(_ context.Context, _ swarm.InitRequest) (string, error) { return "", nil } @@ -36,7 +36,7 @@ func (s *SwarmService) SwarmInit(ctx context.Context, req swarm.InitRequest) (st // cluster. // // https://pkg.go.dev/github.com/docker/docker/client#Client.SwarmInspect -func (s *SwarmService) SwarmInspect(ctx context.Context) (swarm.Swarm, error) { +func (s *SwarmService) SwarmInspect(_ context.Context) (swarm.Swarm, error) { return swarm.Swarm{}, nil } @@ -45,7 +45,7 @@ func (s *SwarmService) SwarmInspect(ctx context.Context) (swarm.Swarm, error) { // cluster. // // https://pkg.go.dev/github.com/docker/docker/client#Client.SwarmJoin -func (s *SwarmService) SwarmJoin(ctx context.Context, req swarm.JoinRequest) error { +func (s *SwarmService) SwarmJoin(_ context.Context, _ swarm.JoinRequest) error { return nil } @@ -54,7 +54,7 @@ func (s *SwarmService) SwarmJoin(ctx context.Context, req swarm.JoinRequest) err // cluster. // // https://pkg.go.dev/github.com/docker/docker/client#Client.SwarmLeave -func (s *SwarmService) SwarmLeave(ctx context.Context, force bool) error { +func (s *SwarmService) SwarmLeave(_ context.Context, _ bool) error { return nil } @@ -63,7 +63,7 @@ func (s *SwarmService) SwarmLeave(ctx context.Context, force bool) error { // cluster. // // https://pkg.go.dev/github.com/docker/docker/client#Client.SwarmUnlock -func (s *SwarmService) SwarmUnlock(ctx context.Context, req swarm.UnlockRequest) error { +func (s *SwarmService) SwarmUnlock(_ context.Context, _ swarm.UnlockRequest) error { return nil } @@ -72,7 +72,7 @@ func (s *SwarmService) SwarmUnlock(ctx context.Context, req swarm.UnlockRequest) // cluster. // // https://pkg.go.dev/github.com/docker/docker/client#Client.SwarmUpdate -func (s *SwarmService) SwarmUpdate(ctx context.Context, version swarm.Version, swarm swarm.Spec, flags swarm.UpdateFlags) error { +func (s *SwarmService) SwarmUpdate(_ context.Context, _ swarm.Version, _ swarm.Spec, _ swarm.UpdateFlags) error { return nil } diff --git a/mock/docker/system.go b/mock/docker/system.go index 1030d81a..58b781d4 100644 --- a/mock/docker/system.go +++ b/mock/docker/system.go @@ -21,7 +21,7 @@ type SystemService struct{} // from the Docker daemon. // // https://pkg.go.dev/github.com/docker/docker/client#Client.DiskUsage -func (s *SystemService) DiskUsage(ctx context.Context, options types.DiskUsageOptions) (types.DiskUsage, error) { +func (s *SystemService) DiskUsage(_ context.Context, _ types.DiskUsageOptions) (types.DiskUsage, error) { return types.DiskUsage{}, nil } @@ -30,7 +30,7 @@ func (s *SystemService) DiskUsage(ctx context.Context, options types.DiskUsageOp // from the Docker daemon. // // https://pkg.go.dev/github.com/docker/docker/client#Client.Events -func (s *SystemService) Events(ctx context.Context, options events.ListOptions) (<-chan events.Message, <-chan error) { +func (s *SystemService) Events(_ context.Context, _ events.ListOptions) (<-chan events.Message, <-chan error) { return nil, nil } @@ -39,7 +39,7 @@ func (s *SystemService) Events(ctx context.Context, options events.ListOptions) // information from the Docker daemon. // // https://pkg.go.dev/github.com/docker/docker/client#Client.Info -func (s *SystemService) Info(ctx context.Context) (system.Info, error) { +func (s *SystemService) Info(_ context.Context) (system.Info, error) { return system.Info{}, nil } @@ -48,7 +48,7 @@ func (s *SystemService) Info(ctx context.Context) (system.Info, error) { // daemon and return version information. // // https://pkg.go.dev/github.com/docker/docker/client#Client.Ping -func (s *SystemService) Ping(ctx context.Context) (types.Ping, error) { +func (s *SystemService) Ping(_ context.Context) (types.Ping, error) { return types.Ping{}, nil } @@ -57,7 +57,7 @@ func (s *SystemService) Ping(ctx context.Context) (types.Ping, error) { // daemon against a Docker registry. // // https://pkg.go.dev/github.com/docker/docker/client#Client.RegistryLogin -func (s *SystemService) RegistryLogin(ctx context.Context, auth registry.AuthConfig) (registry.AuthenticateOKBody, error) { +func (s *SystemService) RegistryLogin(_ context.Context, _ registry.AuthConfig) (registry.AuthenticateOKBody, error) { return registry.AuthenticateOKBody{}, nil } diff --git a/mock/docker/volume.go b/mock/docker/volume.go index be447b3d..2c18ea49 100644 --- a/mock/docker/volume.go +++ b/mock/docker/volume.go @@ -26,7 +26,7 @@ type VolumeService struct{} // a mocked call to create a Docker volume. // // https://pkg.go.dev/github.com/docker/docker/client#Client.VolumeCreate -func (v *VolumeService) VolumeCreate(ctx context.Context, options volume.CreateOptions) (volume.Volume, error) { +func (v *VolumeService) VolumeCreate(_ context.Context, options volume.CreateOptions) (volume.Volume, error) { // verify a volume was provided if len(options.Name) == 0 { return volume.Volume{}, errors.New("no volume provided") @@ -37,7 +37,7 @@ func (v *VolumeService) VolumeCreate(ctx context.Context, options volume.CreateO if strings.Contains(options.Name, "notfound") && !strings.Contains(options.Name, "ignorenotfound") { return volume.Volume{}, - //nolint:stylecheck // messsage is capitalized to match Docker messages + //nolint:staticcheck // messsage is capitalized to match Docker messages errdefs.NotFound(fmt.Errorf("Error: No such volume: %s", options.Name)) } @@ -46,7 +46,7 @@ func (v *VolumeService) VolumeCreate(ctx context.Context, options volume.CreateO if strings.Contains(options.Name, "not-found") && !strings.Contains(options.Name, "ignore-not-found") { return volume.Volume{}, - //nolint:stylecheck // messsage is capitalized to match Docker messages + //nolint:staticcheck // messsage is capitalized to match Docker messages errdefs.NotFound(fmt.Errorf("Error: No such volume: %s", options.Name)) } @@ -68,7 +68,7 @@ func (v *VolumeService) VolumeCreate(ctx context.Context, options volume.CreateO // a mocked call to inspect a Docker volume. // // https://pkg.go.dev/github.com/docker/docker/client#Client.VolumeInspect -func (v *VolumeService) VolumeInspect(ctx context.Context, volumeID string) (volume.Volume, error) { +func (v *VolumeService) VolumeInspect(_ context.Context, volumeID string) (volume.Volume, error) { // verify a volume was provided if len(volumeID) == 0 { return volume.Volume{}, errors.New("no volume provided") @@ -77,14 +77,14 @@ func (v *VolumeService) VolumeInspect(ctx context.Context, volumeID string) (vol // check if the volume is notfound if strings.Contains(volumeID, "notfound") { return volume.Volume{}, - //nolint:stylecheck // messsage is capitalized to match Docker messages + //nolint:staticcheck // messsage is capitalized to match Docker messages errdefs.NotFound(fmt.Errorf("Error: No such volume: %s", volumeID)) } // check if the volume is not-found if strings.Contains(volumeID, "not-found") { return volume.Volume{}, - //nolint:stylecheck // messsage is capitalized to match Docker messages + //nolint:staticcheck // messsage is capitalized to match Docker messages errdefs.NotFound(fmt.Errorf("Error: No such volume: %s", volumeID)) } @@ -105,7 +105,7 @@ func (v *VolumeService) VolumeInspect(ctx context.Context, volumeID string) (vol // the raw body received from the API. // // https://pkg.go.dev/github.com/docker/docker/client#Client.VolumeInspectWithRaw -func (v *VolumeService) VolumeInspectWithRaw(ctx context.Context, volumeID string) (volume.Volume, []byte, error) { +func (v *VolumeService) VolumeInspectWithRaw(_ context.Context, volumeID string) (volume.Volume, []byte, error) { // verify a volume was provided if len(volumeID) == 0 { return volume.Volume{}, nil, errors.New("no volume provided") @@ -114,14 +114,14 @@ func (v *VolumeService) VolumeInspectWithRaw(ctx context.Context, volumeID strin // check if the volume is notfound if strings.Contains(volumeID, "notfound") { return volume.Volume{}, nil, - //nolint:stylecheck // messsage is capitalized to match Docker messages + //nolint:staticcheck // messsage is capitalized to match Docker messages errdefs.NotFound(fmt.Errorf("Error: No such volume: %s", volumeID)) } // check if the volume is not-found if strings.Contains(volumeID, "not-found") { return volume.Volume{}, nil, - //nolint:stylecheck // messsage is capitalized to match Docker messages + //nolint:staticcheck // messsage is capitalized to match Docker messages errdefs.NotFound(fmt.Errorf("Error: No such volume: %s", volumeID)) } @@ -147,7 +147,7 @@ func (v *VolumeService) VolumeInspectWithRaw(ctx context.Context, volumeID strin // a mocked call to list Docker volumes. // // https://pkg.go.dev/github.com/docker/docker/client#Client.VolumeList -func (v *VolumeService) VolumeList(ctx context.Context, options volume.ListOptions) (volume.ListResponse, error) { +func (v *VolumeService) VolumeList(_ context.Context, _ volume.ListOptions) (volume.ListResponse, error) { return volume.ListResponse{}, nil } @@ -155,7 +155,7 @@ func (v *VolumeService) VolumeList(ctx context.Context, options volume.ListOptio // a mocked call to remove Docker a volume. // // https://pkg.go.dev/github.com/docker/docker/client#Client.VolumeRemove -func (v *VolumeService) VolumeRemove(ctx context.Context, volumeID string, force bool) error { +func (v *VolumeService) VolumeRemove(_ context.Context, volumeID string, _ bool) error { // verify a volume was provided if len(volumeID) == 0 { return errors.New("no volume provided") @@ -168,7 +168,7 @@ func (v *VolumeService) VolumeRemove(ctx context.Context, volumeID string, force // a mocked call to prune Docker volumes. // // https://pkg.go.dev/github.com/docker/docker/client#Client.VolumesPrune -func (v *VolumeService) VolumesPrune(ctx context.Context, pruneFilter filters.Args) (volume.PruneReport, error) { +func (v *VolumeService) VolumesPrune(_ context.Context, _ filters.Args) (volume.PruneReport, error) { return volume.PruneReport{}, nil } @@ -176,7 +176,7 @@ func (v *VolumeService) VolumesPrune(ctx context.Context, pruneFilter filters.Ar // a mocked call to update Docker volumes. // // https://pkg.go.dev/github.com/docker/docker/client#Client.VolumeUpdate -func (v *VolumeService) VolumeUpdate(ctx context.Context, volumeID string, version swarm.Version, options volume.UpdateOptions) error { +func (v *VolumeService) VolumeUpdate(_ context.Context, _ string, _ swarm.Version, _ volume.UpdateOptions) error { return nil } diff --git a/mock/worker/build.go b/mock/worker/build.go index eea3e1ba..ac12a520 100644 --- a/mock/worker/build.go +++ b/mock/worker/build.go @@ -112,6 +112,7 @@ func getBuild(c *gin.Context) { data := []byte(BuildResp) var body api.Build + _ = json.Unmarshal(data, &body) c.JSON(http.StatusOK, body) diff --git a/mock/worker/executor.go b/mock/worker/executor.go index b66ed1f4..8bfa7ceb 100644 --- a/mock/worker/executor.go +++ b/mock/worker/executor.go @@ -35,6 +35,7 @@ func getExecutors(c *gin.Context) { data := []byte(ExecutorsResp) var body []api.Executor + _ = json.Unmarshal(data, &body) c.JSON(http.StatusOK, body) @@ -55,6 +56,7 @@ func getExecutor(c *gin.Context) { data := []byte(ExecutorResp) var body api.Executor + _ = json.Unmarshal(data, &body) c.JSON(http.StatusOK, body) diff --git a/mock/worker/pipeline.go b/mock/worker/pipeline.go index e9de0e51..5df3a1e0 100644 --- a/mock/worker/pipeline.go +++ b/mock/worker/pipeline.go @@ -51,6 +51,7 @@ func getPipeline(c *gin.Context) { data := []byte(PipelineResp) var body api.Pipeline + _ = json.Unmarshal(data, &body) c.JSON(http.StatusOK, body) diff --git a/mock/worker/repo.go b/mock/worker/repo.go index 49c4cd00..54c420d2 100644 --- a/mock/worker/repo.go +++ b/mock/worker/repo.go @@ -54,6 +54,7 @@ func getRepo(c *gin.Context) { data := []byte(RepoResp) var body api.Repo + _ = json.Unmarshal(data, &body) c.JSON(http.StatusOK, body) diff --git a/router/middleware/executor/executor_test.go b/router/middleware/executor/executor_test.go index e522af22..ced87338 100644 --- a/router/middleware/executor/executor_test.go +++ b/router/middleware/executor/executor_test.go @@ -92,7 +92,7 @@ func TestExecutor_Establish(t *testing.T) { // setup context resp := httptest.NewRecorder() context, engine := gin.CreateTestContext(resp) - context.Request, _ = http.NewRequest(http.MethodGet, "/executors/0", nil) + context.Request, _ = http.NewRequestWithContext(t.Context(), http.MethodGet, "/executors/0", nil) // setup mock server engine.Use(func(c *gin.Context) { c.Set("executors", _executors) }) @@ -122,7 +122,7 @@ func TestExecutor_Establish_NoParam(t *testing.T) { // setup context resp := httptest.NewRecorder() context, engine := gin.CreateTestContext(resp) - context.Request, _ = http.NewRequest(http.MethodGet, "/executors/", nil) + context.Request, _ = http.NewRequestWithContext(t.Context(), http.MethodGet, "/executors/", nil) // setup mock server engine.Use(Establish()) @@ -145,7 +145,7 @@ func TestExecutor_Establish_InvalidParam(t *testing.T) { // setup context resp := httptest.NewRecorder() context, engine := gin.CreateTestContext(resp) - context.Request, _ = http.NewRequest(http.MethodGet, "/executors/foo", nil) + context.Request, _ = http.NewRequestWithContext(t.Context(), http.MethodGet, "/executors/foo", nil) // setup mock server engine.Use(Establish()) @@ -168,7 +168,7 @@ func TestExecutor_Establish_NoExecutors(t *testing.T) { // setup context resp := httptest.NewRecorder() context, engine := gin.CreateTestContext(resp) - context.Request, _ = http.NewRequest(http.MethodGet, "/executors/0", nil) + context.Request, _ = http.NewRequestWithContext(t.Context(), http.MethodGet, "/executors/0", nil) // setup mock server engine.Use(Establish()) @@ -191,7 +191,7 @@ func TestExecutor_Establish_InvalidExecutors(t *testing.T) { // setup context resp := httptest.NewRecorder() context, engine := gin.CreateTestContext(resp) - context.Request, _ = http.NewRequest(http.MethodGet, "/executors/0", nil) + context.Request, _ = http.NewRequestWithContext(t.Context(), http.MethodGet, "/executors/0", nil) // setup mock server engine.Use(func(c *gin.Context) { c.Set("executors", "invalid") }) @@ -215,7 +215,7 @@ func TestExecutor_Establish_ExecutorNotFound(t *testing.T) { // setup context resp := httptest.NewRecorder() context, engine := gin.CreateTestContext(resp) - context.Request, _ = http.NewRequest(http.MethodGet, "/executors/0", nil) + context.Request, _ = http.NewRequestWithContext(t.Context(), http.MethodGet, "/executors/0", nil) // setup mock server engine.Use(func(c *gin.Context) { c.Set("executors", make(map[int]executor.Engine)) }) diff --git a/router/middleware/executor_test.go b/router/middleware/executor_test.go index 81d8a6a1..677a2523 100644 --- a/router/middleware/executor_test.go +++ b/router/middleware/executor_test.go @@ -23,7 +23,7 @@ func TestMiddleware_Executors(t *testing.T) { resp := httptest.NewRecorder() context, engine := gin.CreateTestContext(resp) - context.Request, _ = http.NewRequest(http.MethodGet, "/health", nil) + context.Request, _ = http.NewRequestWithContext(t.Context(), http.MethodGet, "/health", nil) // setup mock server engine.Use(Executors(want)) diff --git a/router/middleware/header_test.go b/router/middleware/header_test.go index c11af88e..ae8b4ed1 100644 --- a/router/middleware/header_test.go +++ b/router/middleware/header_test.go @@ -24,7 +24,7 @@ func TestMiddleware_NoCache(t *testing.T) { resp := httptest.NewRecorder() context, engine := gin.CreateTestContext(resp) - context.Request, _ = http.NewRequest(http.MethodGet, "/health", nil) + context.Request, _ = http.NewRequestWithContext(t.Context(), http.MethodGet, "/health", nil) // setup mock server engine.Use(NoCache) @@ -69,7 +69,7 @@ func TestMiddleware_Options(t *testing.T) { resp := httptest.NewRecorder() context, engine := gin.CreateTestContext(resp) - context.Request, _ = http.NewRequest(http.MethodOptions, "/health", nil) + context.Request, _ = http.NewRequestWithContext(t.Context(), http.MethodOptions, "/health", nil) // setup mock server engine.Use(Options) @@ -117,7 +117,7 @@ func TestMiddleware_Options_InvalidMethod(t *testing.T) { resp := httptest.NewRecorder() context, engine := gin.CreateTestContext(resp) - context.Request, _ = http.NewRequest(http.MethodGet, "/health", nil) + context.Request, _ = http.NewRequestWithContext(t.Context(), http.MethodGet, "/health", nil) // setup mock server engine.Use(Options) @@ -170,7 +170,7 @@ func TestMiddleware_Secure(t *testing.T) { resp := httptest.NewRecorder() context, engine := gin.CreateTestContext(resp) - context.Request, _ = http.NewRequest(http.MethodGet, "/health", nil) + context.Request, _ = http.NewRequestWithContext(t.Context(), http.MethodGet, "/health", nil) // setup mock server engine.Use(Secure) @@ -214,7 +214,7 @@ func TestMiddleware_Secure_TLS(t *testing.T) { resp := httptest.NewRecorder() context, engine := gin.CreateTestContext(resp) - context.Request, _ = http.NewRequest(http.MethodGet, "/health", nil) + context.Request, _ = http.NewRequestWithContext(t.Context(), http.MethodGet, "/health", nil) context.Request.TLS = new(tls.ConnectionState) // setup mock server diff --git a/router/middleware/logger_test.go b/router/middleware/logger_test.go index 2e80ad4f..8018bbfe 100644 --- a/router/middleware/logger_test.go +++ b/router/middleware/logger_test.go @@ -31,7 +31,7 @@ func TestMiddleware_Logger(t *testing.T) { resp := httptest.NewRecorder() context, engine := gin.CreateTestContext(resp) - context.Request, _ = http.NewRequest(http.MethodPost, "/foobar", bytes.NewBuffer(payload)) + context.Request, _ = http.NewRequestWithContext(t.Context(), http.MethodPost, "/foobar", bytes.NewBuffer(payload)) // setup mock server engine.Use(Payload()) @@ -72,7 +72,7 @@ func TestMiddleware_Logger_Error(t *testing.T) { resp := httptest.NewRecorder() context, engine := gin.CreateTestContext(resp) - context.Request, _ = http.NewRequest(http.MethodGet, "/foobar", nil) + context.Request, _ = http.NewRequestWithContext(t.Context(), http.MethodGet, "/foobar", nil) // setup mock server engine.Use(Logger(logger, time.RFC3339, true)) diff --git a/router/middleware/payload.go b/router/middleware/payload.go index fff9b226..c362002e 100644 --- a/router/middleware/payload.go +++ b/router/middleware/payload.go @@ -16,6 +16,7 @@ func Payload() gin.HandlerFunc { return func(c *gin.Context) { // bind JSON payload from request to be added to context var payload interface{} + _ = c.BindJSON(&payload) body, _ := json.Marshal(&payload) diff --git a/router/middleware/payload_test.go b/router/middleware/payload_test.go index 6b9bc180..0ad676fb 100644 --- a/router/middleware/payload_test.go +++ b/router/middleware/payload_test.go @@ -25,7 +25,7 @@ func TestMiddleware_Payload(t *testing.T) { resp := httptest.NewRecorder() context, engine := gin.CreateTestContext(resp) - context.Request, _ = http.NewRequest(http.MethodPost, "/health", bytes.NewBuffer(jsonBody)) + context.Request, _ = http.NewRequestWithContext(t.Context(), http.MethodPost, "/health", bytes.NewBuffer(jsonBody)) // setup mock server engine.Use(Payload()) diff --git a/router/middleware/perm/perm_test.go b/router/middleware/perm/perm_test.go index 41cb0cdc..923ec3a5 100644 --- a/router/middleware/perm/perm_test.go +++ b/router/middleware/perm/perm_test.go @@ -23,7 +23,7 @@ func TestPerm_MustServer_ValidateToken200(t *testing.T) { workerCtx, workerEngine := gin.CreateTestContext(workerResp) // fake request made to the worker router - workerCtx.Request, _ = http.NewRequest(http.MethodGet, "/build/cancel", nil) + workerCtx.Request, _ = http.NewRequestWithContext(t.Context(), http.MethodGet, "/build/cancel", nil) workerCtx.Request.Header.Add("Authorization", fmt.Sprintf("Bearer %s", tkn)) // setup mock server router @@ -71,7 +71,7 @@ func TestPerm_MustServer_ValidateToken401(t *testing.T) { workerCtx, workerEngine := gin.CreateTestContext(workerResp) // fake request made to the worker router - workerCtx.Request, _ = http.NewRequest(http.MethodGet, "/build/cancel", nil) + workerCtx.Request, _ = http.NewRequestWithContext(t.Context(), http.MethodGet, "/build/cancel", nil) workerCtx.Request.Header.Add("Authorization", fmt.Sprintf("Bearer %s", tkn)) // setup mock server router @@ -119,7 +119,7 @@ func TestPerm_MustServer_ValidateToken404(t *testing.T) { workerCtx, workerEngine := gin.CreateTestContext(workerResp) // fake request made to the worker router - workerCtx.Request, _ = http.NewRequest(http.MethodGet, "/build/cancel", nil) + workerCtx.Request, _ = http.NewRequestWithContext(t.Context(), http.MethodGet, "/build/cancel", nil) workerCtx.Request.Header.Add("Authorization", fmt.Sprintf("Bearer %s", tkn)) // setup mock server router @@ -164,7 +164,7 @@ func TestPerm_MustServer_ValidateToken500(t *testing.T) { workerCtx, workerEngine := gin.CreateTestContext(workerResp) // fake request made to the worker router - workerCtx.Request, _ = http.NewRequest(http.MethodGet, "/build/cancel", nil) + workerCtx.Request, _ = http.NewRequestWithContext(t.Context(), http.MethodGet, "/build/cancel", nil) workerCtx.Request.Header.Add("Authorization", fmt.Sprintf("Bearer %s", tkn)) // setup mock server router @@ -213,7 +213,7 @@ func TestPerm_MustServer_BadServerAddress(t *testing.T) { workerCtx, workerEngine := gin.CreateTestContext(workerResp) // fake request made to the worker router - workerCtx.Request, _ = http.NewRequest(http.MethodGet, "/build/cancel", nil) + workerCtx.Request, _ = http.NewRequestWithContext(t.Context(), http.MethodGet, "/build/cancel", nil) workerCtx.Request.Header.Add("Authorization", fmt.Sprintf("Bearer %s", tkn)) // setup mock server router @@ -260,7 +260,7 @@ func TestPerm_MustServer_NoToken(t *testing.T) { workerCtx, workerEngine := gin.CreateTestContext(workerResp) // fake request made to the worker router - workerCtx.Request, _ = http.NewRequest(http.MethodGet, "/build/cancel", nil) + workerCtx.Request, _ = http.NewRequestWithContext(t.Context(), http.MethodGet, "/build/cancel", nil) workerCtx.Request.Header.Add("Authorization", fmt.Sprintf("Bearer %s", tkn)) // setup mock server router @@ -304,7 +304,7 @@ func TestPerm_MustServer_NoAuth(t *testing.T) { workerCtx, workerEngine := gin.CreateTestContext(workerResp) // fake request made to the worker router - workerCtx.Request, _ = http.NewRequest(http.MethodGet, "/build/cancel", nil) + workerCtx.Request, _ = http.NewRequestWithContext(t.Context(), http.MethodGet, "/build/cancel", nil) // test that skipping adding an authorization header is handled properly // setup mock server router diff --git a/router/middleware/register_token_test.go b/router/middleware/register_token_test.go index a924d359..bcf8d0fc 100644 --- a/router/middleware/register_token_test.go +++ b/router/middleware/register_token_test.go @@ -23,7 +23,7 @@ func TestMiddleware_RegisterToken(t *testing.T) { resp := httptest.NewRecorder() context, engine := gin.CreateTestContext(resp) - context.Request, _ = http.NewRequest(http.MethodGet, "/health", nil) + context.Request, _ = http.NewRequestWithContext(t.Context(), http.MethodGet, "/health", nil) // setup mock server engine.Use(RegisterToken(want)) diff --git a/router/middleware/server_test.go b/router/middleware/server_test.go index 3eae66f8..a80686b7 100644 --- a/router/middleware/server_test.go +++ b/router/middleware/server_test.go @@ -21,7 +21,7 @@ func TestMiddleware_ServerAddress(t *testing.T) { resp := httptest.NewRecorder() context, engine := gin.CreateTestContext(resp) - context.Request, _ = http.NewRequest(http.MethodGet, "/health", nil) + context.Request, _ = http.NewRequestWithContext(t.Context(), http.MethodGet, "/health", nil) // setup mock server engine.Use(ServerAddress(want)) diff --git a/router/middleware/worker_test.go b/router/middleware/worker_test.go index 44df42ba..2973f6cb 100644 --- a/router/middleware/worker_test.go +++ b/router/middleware/worker_test.go @@ -21,7 +21,7 @@ func TestMiddleware_WorkerHostname(t *testing.T) { resp := httptest.NewRecorder() context, engine := gin.CreateTestContext(resp) - context.Request, _ = http.NewRequest(http.MethodGet, "/health", nil) + context.Request, _ = http.NewRequestWithContext(t.Context(), http.MethodGet, "/health", nil) // setup mock server engine.Use(WorkerHostname(want)) diff --git a/runtime/docker/build.go b/runtime/docker/build.go index dfe3571d..1604ca11 100644 --- a/runtime/docker/build.go +++ b/runtime/docker/build.go @@ -10,7 +10,7 @@ import ( // InspectBuild displays details about the pod for the init step. // This is a no-op for docker. -func (c *client) InspectBuild(ctx context.Context, b *pipeline.Build) ([]byte, error) { +func (c *client) InspectBuild(_ context.Context, b *pipeline.Build) ([]byte, error) { c.Logger.Tracef("no-op: inspecting build for pipeline %s", b.ID) return []byte{}, nil @@ -18,7 +18,7 @@ func (c *client) InspectBuild(ctx context.Context, b *pipeline.Build) ([]byte, e // SetupBuild prepares the pipeline build. // This is a no-op for docker. -func (c *client) SetupBuild(ctx context.Context, b *pipeline.Build) error { +func (c *client) SetupBuild(_ context.Context, b *pipeline.Build) error { c.Logger.Tracef("no-op: setting up for build %s", b.ID) return nil @@ -26,7 +26,7 @@ func (c *client) SetupBuild(ctx context.Context, b *pipeline.Build) error { // StreamBuild initializes log/event streaming for build. // This is a no-op for docker. -func (c *client) StreamBuild(ctx context.Context, b *pipeline.Build) error { +func (c *client) StreamBuild(_ context.Context, b *pipeline.Build) error { c.Logger.Tracef("no-op: streaming build %s", b.ID) return nil @@ -34,7 +34,7 @@ func (c *client) StreamBuild(ctx context.Context, b *pipeline.Build) error { // AssembleBuild finalizes pipeline build setup. // This is a no-op for docker. -func (c *client) AssembleBuild(ctx context.Context, b *pipeline.Build) error { +func (c *client) AssembleBuild(_ context.Context, b *pipeline.Build) error { c.Logger.Tracef("no-op: assembling build %s", b.ID) return nil @@ -42,7 +42,7 @@ func (c *client) AssembleBuild(ctx context.Context, b *pipeline.Build) error { // RemoveBuild deletes (kill, remove) the pipeline build metadata. // This is a no-op for docker. -func (c *client) RemoveBuild(ctx context.Context, b *pipeline.Build) error { +func (c *client) RemoveBuild(_ context.Context, b *pipeline.Build) error { c.Logger.Tracef("no-op: removing build %s", b.ID) return nil diff --git a/runtime/docker/container.go b/runtime/docker/container.go index 20e773d9..3f0650d3 100644 --- a/runtime/docker/container.go +++ b/runtime/docker/container.go @@ -9,8 +9,8 @@ import ( "io" "strings" + "github.com/containerd/errdefs" dockerContainerTypes "github.com/docker/docker/api/types/container" - docker "github.com/docker/docker/client" "github.com/docker/docker/pkg/stdcopy" "github.com/go-vela/server/compiler/types/pipeline" @@ -33,6 +33,7 @@ func (c *client) InspectContainer(ctx context.Context, ctn *pipeline.Container) // capture the container exit code // // https://pkg.go.dev/github.com/docker/docker/api/types#ContainerState + //nolint:gosec // exit codes are truncated by OS ctn.ExitCode = int32(container.State.ExitCode) return nil @@ -210,7 +211,7 @@ func (c *client) SetupContainer(ctx context.Context, ctn *pipeline.Container) er // check if the container image exists on the host // // https://pkg.go.dev/github.com/docker/docker/client#Client.ImageInspectWithRaw - _, _, err = c.Docker.ImageInspectWithRaw(ctx, _image) + _, err = c.Docker.ImageInspect(ctx, _image) if err == nil { return nil } @@ -219,7 +220,7 @@ func (c *client) SetupContainer(ctx context.Context, ctn *pipeline.Container) er // we attempt to capture it for executing the pipeline // // https://pkg.go.dev/github.com/docker/docker/client#IsErrNotFound - if docker.IsErrNotFound(err) { + if errdefs.IsNotFound(err) { // send API call to create the image return c.CreateImage(ctx, ctn) } diff --git a/runtime/docker/docker.go b/runtime/docker/docker.go index af74bb4a..c2dc7537 100644 --- a/runtime/docker/docker.go +++ b/runtime/docker/docker.go @@ -37,7 +37,7 @@ type config struct { type client struct { config *config // https://pkg.go.dev/github.com/docker/docker/client#CommonAPIClient - Docker docker.CommonAPIClient + Docker docker.APIClient // https://pkg.go.dev/github.com/sirupsen/logrus#Entry Logger *logrus.Entry } diff --git a/runtime/docker/docker_test.go b/runtime/docker/docker_test.go index ad603199..fac56c2a 100644 --- a/runtime/docker/docker_test.go +++ b/runtime/docker/docker_test.go @@ -8,6 +8,7 @@ import ( "gotest.tools/v3/env" "github.com/go-vela/server/compiler/types/pipeline" + "github.com/go-vela/server/constants" ) func TestDocker_New(t *testing.T) { @@ -92,7 +93,7 @@ var ( Directory: "/vela/src/github.com/octocat/helloworld", Environment: map[string]string{"FOO": "bar"}, Image: "#init", - Name: "init", + Name: constants.InitName, Number: 1, Pull: "always", }, diff --git a/runtime/docker/image.go b/runtime/docker/image.go index 67888873..2f489c9d 100644 --- a/runtime/docker/image.go +++ b/runtime/docker/image.go @@ -88,7 +88,7 @@ func (c *client) InspectImage(ctx context.Context, ctn *pipeline.Container) ([]b // send API call to inspect the image // // https://pkg.go.dev/github.com/docker/docker/client#Client.ImageInspectWithRaw - i, _, err := c.Docker.ImageInspectWithRaw(ctx, _image) + i, err := c.Docker.ImageInspect(ctx, _image) if err != nil { return output, err } diff --git a/runtime/docker/opts_test.go b/runtime/docker/opts_test.go index 5f97a6c8..abd3f295 100644 --- a/runtime/docker/opts_test.go +++ b/runtime/docker/opts_test.go @@ -34,7 +34,6 @@ func TestDocker_ClientOpt_WithPrivilegedImages(t *testing.T) { _service, err := New( WithPrivilegedImages(test.images), ) - if err != nil { t.Errorf("WithPrivilegedImages returned err: %v", err) } @@ -71,7 +70,6 @@ func TestDocker_ClientOpt_WithHostVolumes(t *testing.T) { _service, err := New( WithHostVolumes(test.volumes), ) - if err != nil { t.Errorf("WithHostVolumes returned err: %v", err) } @@ -157,7 +155,6 @@ func TestDocker_ClientOpt_WithDropCapabilities(t *testing.T) { _service, err := New( WithDropCapabilities(test.caps), ) - if err != nil { t.Errorf("WithDropCapabilities returned err: %v", err) } diff --git a/runtime/kubernetes/build.go b/runtime/kubernetes/build.go index c1fb23b9..930d1aac 100644 --- a/runtime/kubernetes/build.go +++ b/runtime/kubernetes/build.go @@ -15,11 +15,12 @@ import ( "sigs.k8s.io/yaml" "github.com/go-vela/server/compiler/types/pipeline" + "github.com/go-vela/server/constants" "github.com/go-vela/worker/runtime/kubernetes/apis/vela/v1alpha1" ) // InspectBuild displays details about the pod for the init step. -func (c *client) InspectBuild(ctx context.Context, b *pipeline.Build) ([]byte, error) { +func (c *client) InspectBuild(_ context.Context, b *pipeline.Build) ([]byte, error) { c.Logger.Tracef("inspecting build pod for pipeline %s", b.ID) output := []byte(fmt.Sprintf("> Inspecting pod for pipeline %s\n", b.ID)) @@ -173,8 +174,7 @@ func (c *client) AssembleBuild(ctx context.Context, b *pipeline.Build) error { } for _, _stage := range b.Stages { - // TODO: remove hardcoded reference - if _stage.Name == "init" { + if _stage.Name == constants.InitName { continue } @@ -187,8 +187,7 @@ func (c *client) AssembleBuild(ctx context.Context, b *pipeline.Build) error { } for _, _step := range b.Steps { - // TODO: remove hardcoded reference - if _step.Name == "init" { + if _step.Name == constants.InitName { continue } @@ -225,7 +224,7 @@ func (c *client) AssembleBuild(ctx context.Context, b *pipeline.Build) error { // remnants get deleted. c.createdPod = true - c.Logger.Infof("creating pod %s", c.Pod.ObjectMeta.Name) + c.Logger.Infof("creating pod %s", c.Pod.Name) // send API call to create the pod // // https://pkg.go.dev/k8s.io/client-go/kubernetes/typed/core/v1#PodInterface @@ -276,11 +275,11 @@ func (c *client) RemoveBuild(ctx context.Context, b *pipeline.Build) error { PropagationPolicy: &policy, } - c.Logger.Infof("removing pod %s", c.Pod.ObjectMeta.Name) + c.Logger.Infof("removing pod %s", c.Pod.Name) // send API call to delete the pod err := c.Kubernetes.CoreV1(). Pods(c.config.Namespace). - Delete(ctx, c.Pod.ObjectMeta.Name, opts) + Delete(ctx, c.Pod.Name, opts) if err != nil { return err } diff --git a/runtime/kubernetes/build_test.go b/runtime/kubernetes/build_test.go index 70cd3cb0..69c18b5b 100644 --- a/runtime/kubernetes/build_test.go +++ b/runtime/kubernetes/build_test.go @@ -311,7 +311,7 @@ func TestKubernetes_SetupBuild(t *testing.T) { } // make sure that worker-defined labels are set and cannot be overridden by PipelinePodsTemplate - if pipelineLabel, ok := _engine.Pod.ObjectMeta.Labels["pipeline"]; !ok { + if pipelineLabel, ok := _engine.Pod.Labels["pipeline"]; !ok { t.Errorf("Pod is missing the pipeline label: %v", _engine.Pod.ObjectMeta) } else if pipelineLabel != test.pipeline.ID { t.Errorf("Pod's pipeline label is %v, want %v", pipelineLabel, test.pipeline.ID) diff --git a/runtime/kubernetes/container.go b/runtime/kubernetes/container.go index 1512a8da..5321253e 100644 --- a/runtime/kubernetes/container.go +++ b/runtime/kubernetes/container.go @@ -21,13 +21,13 @@ import ( ) // InspectContainer inspects the pipeline container. -func (c *client) InspectContainer(ctx context.Context, ctn *pipeline.Container) error { +func (c *client) InspectContainer(_ context.Context, ctn *pipeline.Container) error { c.Logger.Tracef("inspecting container %s", ctn.ID) // get the pod from the local cache, which the Informer keeps up-to-date pod, err := c.PodTracker.PodLister. Pods(c.config.Namespace). - Get(c.Pod.ObjectMeta.Name) + Get(c.Pod.Name) if err != nil { return err } @@ -63,7 +63,7 @@ func (c *client) InspectContainer(ctx context.Context, ctn *pipeline.Container) // RemoveContainer deletes (kill, remove) the pipeline container. // This is a no-op for kubernetes. RemoveBuild handles deleting the pod. -func (c *client) RemoveContainer(ctx context.Context, ctn *pipeline.Container) error { +func (c *client) RemoveContainer(_ context.Context, ctn *pipeline.Container) error { c.Logger.Tracef("no-op: removing container %s", ctn.ID) return nil @@ -71,7 +71,7 @@ func (c *client) RemoveContainer(ctx context.Context, ctn *pipeline.Container) e // PollOutputsContainer captures the `cat` response for a given path in the Docker volume. // This is a no-op for kubernetes. Pod environments cannot be dynamic. -func (c *client) PollOutputsContainer(ctx context.Context, ctn *pipeline.Container, path string) ([]byte, error) { +func (c *client) PollOutputsContainer(_ context.Context, ctn *pipeline.Container, _ string) ([]byte, error) { c.Logger.Tracef("no-op: removing container %s", ctn.ID) return nil, nil @@ -94,7 +94,7 @@ func (c *client) RunContainer(ctx context.Context, ctn *pipeline.Container, _ *p // https://pkg.go.dev/k8s.io/client-go/kubernetes/typed/core/v1#PodInterface _, err = c.Kubernetes.CoreV1().Pods(c.config.Namespace).Patch( ctx, - c.Pod.ObjectMeta.Name, + c.Pod.Name, types.StrategicMergePatchType, []byte(fmt.Sprintf(imagePatch, ctn.ID, _image)), metav1.PatchOptions{}, @@ -313,7 +313,7 @@ func (c *client) TailContainer(ctx context.Context, ctn *pipeline.Container) (io } // WaitContainer blocks until the pipeline container completes. -func (c *client) WaitContainer(ctx context.Context, ctn *pipeline.Container) error { +func (c *client) WaitContainer(_ context.Context, ctn *pipeline.Container) error { c.Logger.Tracef("waiting for container %s", ctn.ID) // get the containerTracker for this container diff --git a/runtime/kubernetes/image.go b/runtime/kubernetes/image.go index 0542cbfb..d1eac31e 100644 --- a/runtime/kubernetes/image.go +++ b/runtime/kubernetes/image.go @@ -29,14 +29,14 @@ const ( ) // CreateImage creates the pipeline container image. -func (c *client) CreateImage(ctx context.Context, ctn *pipeline.Container) error { +func (c *client) CreateImage(_ context.Context, ctn *pipeline.Container) error { c.Logger.Tracef("no-op: creating image for container %s", ctn.ID) return nil } // InspectImage inspects the pipeline container image. -func (c *client) InspectImage(ctx context.Context, ctn *pipeline.Container) ([]byte, error) { +func (c *client) InspectImage(_ context.Context, ctn *pipeline.Container) ([]byte, error) { c.Logger.Tracef("inspecting image for container %s", ctn.ID) // TODO: consider updating this command diff --git a/runtime/kubernetes/kubernetes_test.go b/runtime/kubernetes/kubernetes_test.go index b2c53705..7d3116f4 100644 --- a/runtime/kubernetes/kubernetes_test.go +++ b/runtime/kubernetes/kubernetes_test.go @@ -9,6 +9,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "github.com/go-vela/server/compiler/types/pipeline" + "github.com/go-vela/server/constants" ) func TestKubernetes_New(t *testing.T) { @@ -172,14 +173,14 @@ var ( }, Stages: pipeline.StageSlice{ { - Name: "init", + Name: constants.InitName, Steps: pipeline.ContainerSlice{ { ID: "step-github-octocat-1-init-init", Directory: "/vela/src/github.com/octocat/helloworld", Environment: map[string]string{"FOO": "bar"}, Image: "#init", - Name: "init", + Name: constants.InitName, Number: 1, Pull: "always", }, @@ -187,7 +188,7 @@ var ( }, { Name: "clone", - Needs: []string{"init"}, + Needs: []string{constants.InitName}, Steps: pipeline.ContainerSlice{ { ID: "step-github-octocat-1-clone-clone", @@ -240,7 +241,7 @@ var ( Directory: "/vela/src/github.com/octocat/helloworld", Environment: map[string]string{"FOO": "bar"}, Image: "#init", - Name: "init", + Name: constants.InitName, Number: 1, Pull: "always", }, diff --git a/runtime/kubernetes/mock.go b/runtime/kubernetes/mock.go index 14fe8b4f..61361d89 100644 --- a/runtime/kubernetes/mock.go +++ b/runtime/kubernetes/mock.go @@ -140,8 +140,8 @@ func (c *client) WaitForPodTrackerReady() { func (c *client) WaitForPodCreate(namespace, name string) { created := make(chan struct{}) - c.PodTracker.podInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ - AddFunc: func(obj interface{}) { + _, err := c.PodTracker.podInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ + AddFunc: func(obj any) { select { case <-created: // not interested in any other create events. @@ -164,6 +164,9 @@ func (c *client) WaitForPodCreate(namespace, name string) { } }, }) + if err != nil { + return + } <-created } diff --git a/runtime/kubernetes/network.go b/runtime/kubernetes/network.go index d06c273a..40f5051d 100644 --- a/runtime/kubernetes/network.go +++ b/runtime/kubernetes/network.go @@ -13,7 +13,7 @@ import ( ) // CreateNetwork creates the pipeline network. -func (c *client) CreateNetwork(ctx context.Context, b *pipeline.Build) error { +func (c *client) CreateNetwork(_ context.Context, b *pipeline.Build) error { c.Logger.Tracef("creating network for pipeline %s", b.ID) // create the network for the pod @@ -83,7 +83,7 @@ func (c *client) CreateNetwork(ctx context.Context, b *pipeline.Build) error { } // InspectNetwork inspects the pipeline network. -func (c *client) InspectNetwork(ctx context.Context, b *pipeline.Build) ([]byte, error) { +func (c *client) InspectNetwork(_ context.Context, b *pipeline.Build) ([]byte, error) { c.Logger.Tracef("inspecting network for pipeline %s", b.ID) // TODO: consider updating this command @@ -107,7 +107,7 @@ func (c *client) InspectNetwork(ctx context.Context, b *pipeline.Build) ([]byte, // Currently, this is comparable to a no-op because in Kubernetes the // network lives and dies with the pod it's attached to. However, Vela // uses it to cleanup the network definition for the pod. -func (c *client) RemoveNetwork(ctx context.Context, b *pipeline.Build) error { +func (c *client) RemoveNetwork(_ context.Context, b *pipeline.Build) error { c.Logger.Tracef("removing network for pipeline %s", b.ID) // remove the network definition from the pod spec diff --git a/runtime/kubernetes/opts_test.go b/runtime/kubernetes/opts_test.go index 0508729d..392818e1 100644 --- a/runtime/kubernetes/opts_test.go +++ b/runtime/kubernetes/opts_test.go @@ -146,7 +146,6 @@ func TestKubernetes_ClientOpt_WithHostVolumes(t *testing.T) { WithConfigFile("testdata/config"), WithHostVolumes(test.volumes), ) - if err != nil { t.Errorf("WithHostVolumes returned err: %v", err) } @@ -184,7 +183,6 @@ func TestKubernetes_ClientOpt_WithPrivilegedImages(t *testing.T) { WithConfigFile("testdata/config"), WithPrivilegedImages(test.images), ) - if err != nil { t.Errorf("WithPrivilegedImages returned err: %v", err) } diff --git a/runtime/kubernetes/pod_tracker.go b/runtime/kubernetes/pod_tracker.go index a94dc2e6..2676be26 100644 --- a/runtime/kubernetes/pod_tracker.go +++ b/runtime/kubernetes/pod_tracker.go @@ -183,8 +183,8 @@ func newPodTracker(log *logrus.Entry, clientset kubernetes.Interface, pod *v1.Po return nil, fmt.Errorf("newPodTracker expected a pod, got nil") } - trackedPod := pod.ObjectMeta.Namespace + "/" + pod.ObjectMeta.Name - if pod.ObjectMeta.Name == "" || pod.ObjectMeta.Namespace == "" { + trackedPod := pod.Namespace + "/" + pod.Name + if pod.Name == "" || pod.Namespace == "" { return nil, fmt.Errorf("newPodTracker expects pod to have Name and Namespace, got %s", trackedPod) } @@ -194,7 +194,7 @@ func newPodTracker(log *logrus.Entry, clientset kubernetes.Interface, pod *v1.Po selector, err := labels.NewRequirement( "pipeline", selection.Equals, - []string{fields.EscapeValue(pod.ObjectMeta.Name)}, + []string{fields.EscapeValue(pod.Name)}, ) if err != nil { return nil, err @@ -204,7 +204,7 @@ func newPodTracker(log *logrus.Entry, clientset kubernetes.Interface, pod *v1.Po informerFactory := kubeinformers.NewSharedInformerFactoryWithOptions( clientset, defaultResync, - kubeinformers.WithNamespace(pod.ObjectMeta.Namespace), + kubeinformers.WithNamespace(pod.Namespace), kubeinformers.WithTweakListOptions(func(listOptions *metav1.ListOptions) { listOptions.LabelSelector = selector.String() }), @@ -223,11 +223,14 @@ func newPodTracker(log *logrus.Entry, clientset kubernetes.Interface, pod *v1.Po } // register event handler funcs in podInformer - podInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ + _, err = podInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ AddFunc: tracker.HandlePodAdd, UpdateFunc: tracker.HandlePodUpdate, DeleteFunc: tracker.HandlePodDelete, }) + if err != nil { + return nil, err + } return &tracker, nil } @@ -235,12 +238,12 @@ func newPodTracker(log *logrus.Entry, clientset kubernetes.Interface, pod *v1.Po // mockPodTracker returns a new podTracker with the given pod pre-loaded in the cache. func mockPodTracker(log *logrus.Entry, clientset kubernetes.Interface, pod *v1.Pod) (*podTracker, error) { // Make sure test pods are valid before passing to PodTracker (ie support &v1.Pod{}). - if pod.ObjectMeta.Name == "" { - pod.ObjectMeta.Name = "test-pod" + if pod.Name == "" { + pod.Name = "test-pod" } - if pod.ObjectMeta.Namespace == "" { - pod.ObjectMeta.Namespace = "test" + if pod.Namespace == "" { + pod.Namespace = "test" } tracker, err := newPodTracker(log, clientset, pod, 0*time.Second) diff --git a/runtime/kubernetes/pod_tracker_test.go b/runtime/kubernetes/pod_tracker_test.go index 99f159fd..8ec7ec31 100644 --- a/runtime/kubernetes/pod_tracker_test.go +++ b/runtime/kubernetes/pod_tracker_test.go @@ -52,8 +52,8 @@ func TestNewPodTracker(t *testing.T) { pod: &v1.Pod{ ObjectMeta: metav1.ObjectMeta{ Name: "github-octocat-1-for-some-odd-reason-this-name-is-way-too-long-and-will-cause-an-error", - Namespace: _pod.ObjectMeta.Namespace, - Labels: _pod.ObjectMeta.Labels, + Namespace: _pod.Namespace, + Labels: _pod.Labels, }, TypeMeta: _pod.TypeMeta, Spec: _pod.Spec, @@ -181,7 +181,7 @@ func Test_podTracker_HandlePodAdd(t *testing.T) { }, } for _, test := range tests { - t.Run(test.name, func(t *testing.T) { + t.Run(test.name, func(_ *testing.T) { p := &podTracker{ Logger: logger, TrackedPod: test.trackedPod, @@ -255,7 +255,7 @@ func Test_podTracker_HandlePodUpdate(t *testing.T) { }, } for _, test := range tests { - t.Run(test.name, func(t *testing.T) { + t.Run(test.name, func(_ *testing.T) { p := &podTracker{ Logger: logger, TrackedPod: test.trackedPod, @@ -324,7 +324,7 @@ func Test_podTracker_HandlePodDelete(t *testing.T) { }, } for _, test := range tests { - t.Run(test.name, func(t *testing.T) { + t.Run(test.name, func(_ *testing.T) { p := &podTracker{ Logger: logger, TrackedPod: test.trackedPod, @@ -370,6 +370,7 @@ func Test_podTracker_Stop(t *testing.T) { if test.started { tracker.Start(context.Background()) } + tracker.Stop() }) } diff --git a/runtime/kubernetes/volume.go b/runtime/kubernetes/volume.go index 394db079..edbc6b9f 100644 --- a/runtime/kubernetes/volume.go +++ b/runtime/kubernetes/volume.go @@ -16,7 +16,7 @@ import ( ) // CreateVolume creates the pipeline volume. -func (c *client) CreateVolume(ctx context.Context, b *pipeline.Build) error { +func (c *client) CreateVolume(_ context.Context, b *pipeline.Build) error { c.Logger.Tracef("creating volume for pipeline %s", b.ID) // create the workspace volume for the pod @@ -89,7 +89,7 @@ func (c *client) CreateVolume(ctx context.Context, b *pipeline.Build) error { } // InspectVolume inspects the pipeline volume. -func (c *client) InspectVolume(ctx context.Context, b *pipeline.Build) ([]byte, error) { +func (c *client) InspectVolume(_ context.Context, b *pipeline.Build) ([]byte, error) { c.Logger.Tracef("inspecting volume for pipeline %s", b.ID) // TODO: consider updating this command @@ -113,7 +113,7 @@ func (c *client) InspectVolume(ctx context.Context, b *pipeline.Build) ([]byte, // Currently, this is comparable to a no-op because in Kubernetes the // volume lives and dies with the pod it's attached to. However, Vela // uses it to cleanup the volume definition for the pod. -func (c *client) RemoveVolume(ctx context.Context, b *pipeline.Build) error { +func (c *client) RemoveVolume(_ context.Context, b *pipeline.Build) error { c.Logger.Tracef("removing volume for pipeline %s", b.ID) // remove the volume definition from the pod spec @@ -128,7 +128,7 @@ func (c *client) RemoveVolume(ctx context.Context, b *pipeline.Build) error { // setupVolumeMounts generates the VolumeMounts for a given container. // //nolint:unparam // keep signature similar to Engine interface methods despite unused ctx and err -func (c *client) setupVolumeMounts(ctx context.Context, ctn *pipeline.Container) ( +func (c *client) setupVolumeMounts(_ context.Context, ctn *pipeline.Container) ( volumeMounts []v1.VolumeMount, err error, ) {