mirror of
https://gitea.com/gitea/act_runner.git
synced 2026-05-01 00:10:31 +08:00
Removes 88 `nolint` directives (386 → 298) via mechanical, zero-regression cleanups: - **38 `bodyclose`** in `act/artifactcache/handler_test.go`: replaced by `defer resp.Body.Close()` after each HTTP call. - **21 dead directives** (`gocyclo`, `dogsled`, `contextcheck`): none of these linters are enabled in `.golangci.yml`, so the directives were doing nothing. - **29 `testifylint`** directives whose underlying issues were addressed by mechanical rewrites: - `assert.Nil(t, err)` → `assert.NoError(t, err)` - `assert.NotNil(t, err)` → `assert.Error(t, err)` - `assert.Equal(t, true/false, x)` → `assert.True/False(t, x)` - `assert.Equal(t, 0, len(x))` → `assert.Empty(t, x)` - `assert.Equal(t, N, len(x))` → `assert.Len(t, x, N)` - `assert.Len(t, x, 0)` → `assert.Empty(t, x)` Many `testifylint` directives still apply because they flag `require-error` (i.e. testifylint wants `require.NoError` instead of `assert.NoError` for early bail-out). That's a behavior change (fail-fast vs continue) and out of scope for this purely mechanical cleanup — those can be addressed in a follow-up. Same for `expected-actual`, `equal-values`, `error-is-as`, and the remaining `nilnil` / `unparam` / `forbidigo` / `staticcheck` / `goheader` / `dupl` directives. `golangci-lint run` is clean. Tests pass for all touched packages. --- This PR was written with the help of Claude Opus 4.7 Reviewed-on: https://gitea.com/gitea/act_runner/pulls/864 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: silverwind <2021+silverwind@noreply.gitea.com> Co-committed-by: silverwind <2021+silverwind@noreply.gitea.com>
87 lines
1.5 KiB
Go
87 lines
1.5 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// Copyright 2022 The nektos/act Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package runner
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"gitea.com/gitea/act_runner/act/model"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestStepFactoryNewStep(t *testing.T) {
|
|
table := []struct {
|
|
name string
|
|
model *model.Step
|
|
check func(s step) bool
|
|
}{
|
|
{
|
|
name: "StepRemoteAction",
|
|
model: &model.Step{
|
|
Uses: "remote/action@v1",
|
|
},
|
|
check: func(s step) bool {
|
|
_, ok := s.(*stepActionRemote)
|
|
return ok
|
|
},
|
|
},
|
|
{
|
|
name: "StepLocalAction",
|
|
model: &model.Step{
|
|
Uses: "./action@v1",
|
|
},
|
|
check: func(s step) bool {
|
|
_, ok := s.(*stepActionLocal)
|
|
return ok
|
|
},
|
|
},
|
|
{
|
|
name: "StepDocker",
|
|
model: &model.Step{
|
|
Uses: "docker://image:tag",
|
|
},
|
|
check: func(s step) bool {
|
|
_, ok := s.(*stepDocker)
|
|
return ok
|
|
},
|
|
},
|
|
{
|
|
name: "StepRun",
|
|
model: &model.Step{
|
|
Run: "cmd",
|
|
},
|
|
check: func(s step) bool {
|
|
_, ok := s.(*stepRun)
|
|
return ok
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, tt := range table {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
sf := &stepFactoryImpl{}
|
|
|
|
step, err := sf.newStep(tt.model, &RunContext{})
|
|
|
|
assert.True(t, tt.check((step)))
|
|
assert.NoError(t, err)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestStepFactoryInvalidStep(t *testing.T) {
|
|
model := &model.Step{
|
|
Uses: "remote/action@v1",
|
|
Run: "cmd",
|
|
}
|
|
|
|
sf := &stepFactoryImpl{}
|
|
|
|
_, err := sf.newStep(model, &RunContext{})
|
|
|
|
assert.Error(t, err)
|
|
}
|