more lint errors

This commit is contained in:
Christopher Homberger
2026-02-23 00:30:44 +01:00
parent bffc600775
commit 09d18916bf
22 changed files with 46 additions and 61 deletions

View File

@@ -9,6 +9,7 @@ import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
//nolint:gosec
@@ -69,7 +70,7 @@ func TestActionCache(t *testing.T) {
buf := &bytes.Buffer{}
// G110: Potential DoS vulnerability via decompression bomb (gosec)
_, err = io.Copy(buf, mytar)
a.NoError(err)
require.NoError(t, err)
str := buf.String()
a.NotEmpty(str)
})

View File

@@ -3,6 +3,7 @@ package runner
import (
"bytes"
"context"
"errors"
"fmt"
"maps"
"path"
@@ -431,7 +432,7 @@ func rewriteSubExpression(ctx context.Context, in string, forceFormat bool) (str
if strStart > -1 {
matches := strPattern.FindStringIndex(in[pos:])
if matches == nil {
panic("unclosed string.")
return "", errors.New("unclosed string.")
}
strStart = -1

View File

@@ -189,7 +189,7 @@ func TestEvaluateStep(t *testing.T) {
require.NoError(t, err, table.in)
assertObject.Equal(table.out, out, table.in)
} else {
assertObject.Error(err, table.in)
require.Error(t, err, table.in)
assertObject.Equal(table.errMesg, err.Error(), table.in)
}
})

View File

@@ -3,7 +3,6 @@ package runner
import (
"context"
"errors"
"fmt"
"io"
"slices"
"testing"
@@ -240,7 +239,7 @@ func TestNewJobExecutor(t *testing.T) {
for _, tt := range table {
t.Run(tt.name, func(t *testing.T) {
fmt.Printf("::group::%s\n", tt.name)
t.Log("::group::%s\n", tt.name)
ctx := common.WithJobErrorContainer(context.Background())
jim := &jobInfoMock{}
@@ -331,7 +330,7 @@ func TestNewJobExecutor(t *testing.T) {
jim.AssertExpectations(t)
sfm.AssertExpectations(t)
fmt.Println("::endgroup::")
t.Log("::endgroup::")
})
}
}

View File

@@ -620,7 +620,7 @@ func (rc *RunContext) waitForServiceContainer(c container.ExecutionsEnvironment)
return func(ctx context.Context) error {
sctx, cancel := context.WithTimeout(ctx, time.Minute*5)
defer cancel()
health := container.HealthStarting
var health container.Health
delay := time.Second
for i := 0; ; i++ {
health = c.GetHealth(sctx)
@@ -1119,7 +1119,7 @@ func (rc *RunContext) setMainCtxVars(env map[string]string, name string, value s
}
}
func (rc *RunContext) withGithubEnv(ctx context.Context, github *model.GithubContext, env map[string]string) map[string]string {
func (rc *RunContext) withGithubEnv(ctx context.Context, github *model.GithubContext, env map[string]string) {
env["CI"] = "true"
rc.setMainCtxVars(env, "WORKFLOW", github.Workflow)
rc.setMainCtxVars(env, "RUN_ATTEMPT", github.RunAttempt)
@@ -1165,8 +1165,6 @@ func (rc *RunContext) withGithubEnv(ctx context.Context, github *model.GithubCon
}
}
}
return env
}
func setActionRuntimeVars(rc *RunContext, env map[string]string) {

View File

@@ -160,7 +160,7 @@ func TestRunContext_EvalBool(t *testing.T) {
assertObject := assert.New(t)
b, err := EvalBool(context.Background(), rc.ExprEval, table.in, exprparser.DefaultStatusCheckSuccess)
if table.wantErr {
assertObject.Error(err)
require.Error(t, err)
}
assertObject.Equal(table.out, b, "Expected %s to be %v, was %v", table.in, table.out, b)

View File

@@ -6,7 +6,6 @@ import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"os"
"os/exec"
@@ -117,7 +116,7 @@ func TestGraphWithMissing(t *testing.T) {
plan, err := planner.PlanEvent("push")
assert.NotNil(t, plan)
assert.Empty(t, plan.Stages)
assert.EqualError(t, err, "unable to build dependency graph for missing (missing.yml)")
require.EqualError(t, err, "unable to build dependency graph for missing (missing.yml)")
assert.Contains(t, buf.String(), "unable to build dependency graph for missing (missing.yml)")
log.SetOutput(out)
}
@@ -174,7 +173,7 @@ type TestJobFileInfo struct {
}
func (j *TestJobFileInfo) runTest(ctx context.Context, t *testing.T, cfg *Config) {
fmt.Printf("::group::%s\n", j.workflowPath)
t.Log("::group::%s\n", j.workflowPath)
log.SetLevel(logLevel)
@@ -218,7 +217,7 @@ func (j *TestJobFileInfo) runTest(ctx context.Context, t *testing.T, cfg *Config
}
}
fmt.Println("::endgroup::")
t.Log("::endgroup::")
}
type TestConfig struct {
@@ -739,7 +738,7 @@ func TestMaskValues(t *testing.T) {
assertNoSecret := func(text string, _ string) {
found := strings.Contains(text, "composite secret")
if found {
fmt.Printf("\nFound Secret in the given text:\n%s\n", text)
t.Logf("\nFound Secret in the given text:\n%s\n", text)
}
assert.NotContains(t, text, "composite secret")
}

View File

@@ -110,10 +110,7 @@ func runStepExecutor(step step, stage stepStage, executor common.Executor) commo
rc.StepResults[rc.CurrentStep] = stepResult
}
err := setupEnv(ctx, step)
if err != nil {
return err
}
setupEnv(ctx, step)
cctx := common.JobCancelContext(ctx)
rc.Cancelled = cctx != nil && cctx.Err() != nil
@@ -241,7 +238,7 @@ func evaluateStepTimeout(ctx context.Context, exprEval ExpressionEvaluator, step
return ctx, func() {}
}
func setupEnv(ctx context.Context, step step) error {
func setupEnv(ctx context.Context, step step) {
rc := step.getRunContext()
mergeEnv(ctx, step)
@@ -264,8 +261,6 @@ func setupEnv(ctx context.Context, step step) error {
}
common.Logger(ctx).Debugf("setupEnv => %v", *step.getEnv())
return nil
}
func mergeEnv(ctx context.Context, step step) {

View File

@@ -237,7 +237,7 @@ func TestStepActionRemote(t *testing.T) {
err = sar.main()(ctx)
}
assert.ErrorIs(t, err, tt.runError)
require.ErrorIs(t, err, tt.runError)
assert.Equal(t, sar.RunContext.StepResults["step"], tt.result)
sarm.AssertExpectations(t)

View File

@@ -205,7 +205,7 @@ func (sr *stepRun) setupShell(ctx context.Context) {
func (sr *stepRun) setupWorkingDirectory(ctx context.Context) {
rc := sr.RunContext
step := sr.Step
workingdirectory := ""
var workingdirectory string
if step.WorkingDirectory == "" {
workingdirectory = rc.Run.Job().Defaults.Run.WorkingDirectory

View File

@@ -152,8 +152,7 @@ func TestSetupEnv(t *testing.T) {
sm.On("getStepModel").Return(step)
sm.On("getEnv").Return(&env)
err := setupEnv(context.Background(), sm)
require.NoError(t, err)
setupEnv(context.Background(), sm)
// These are commit or system specific
delete((env), "GITHUB_REF")