assert => require

This commit is contained in:
Christopher Homberger
2026-02-22 21:00:42 +01:00
parent d187ac2fc1
commit a77f10683d
35 changed files with 228 additions and 200 deletions

View File

@@ -10,6 +10,7 @@ import (
"gitea.com/gitea/act_runner/pkg/model"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
)
type closerMock struct {
@@ -99,7 +100,7 @@ runs:
action, err := readActionImpl(context.Background(), tt.step, readFile, model.ActionConfig{})
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, tt.expected, action)
closerMock.AssertExpectations(t)
@@ -218,7 +219,7 @@ func TestActionRunner(t *testing.T) {
err := runActionImpl(tt.step)(ctx)
assert.NoError(t, err)
require.NoError(t, err)
cm.AssertExpectations(t)
})
}

View File

@@ -12,6 +12,7 @@ import (
"gitea.com/gitea/act_runner/pkg/exprparser"
"gitea.com/gitea/act_runner/pkg/model"
assert "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
yaml "gopkg.in/yaml.v3"
)
@@ -21,7 +22,7 @@ func createRunContext(t *testing.T) *RunContext {
"os": {"Linux", "Windows"},
"foo": {"bar", "baz"},
})
assert.NoError(t, err)
require.NoError(t, err)
return &RunContext{
Config: &Config{

View File

@@ -13,6 +13,7 @@ import (
"gitea.com/gitea/act_runner/pkg/model"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
)
func TestJobExecutor(t *testing.T) {
@@ -324,7 +325,7 @@ func TestNewJobExecutor(t *testing.T) {
executor := newJobExecutor(jim, sfm, rc)
err := executor(ctx)
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, tt.executedSteps, executorOrder)
jim.AssertExpectations(t)

View File

@@ -16,6 +16,7 @@ import (
log "github.com/sirupsen/logrus"
assert "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
yaml "gopkg.in/yaml.v3"
)
@@ -25,7 +26,7 @@ func TestRunContext_EvalBool(t *testing.T) {
"os": {"Linux", "Windows"},
"foo": {"bar", "baz"},
})
assert.NoError(t, err)
require.NoError(t, err)
rc := &RunContext{
Config: &Config{
@@ -310,7 +311,7 @@ func TestRunContext_GetBindsAndMounts(t *testing.T) {
err := job.RawContainer.Encode(map[string][]string{
"volumes": testcase.volumes,
})
assert.NoError(t, err)
require.NoError(t, err)
rc := &RunContext{
Name: "TestRCName",
@@ -345,7 +346,7 @@ func TestGetGitHubContext(t *testing.T) {
log.SetLevel(log.DebugLevel)
cwd, err := os.Getwd()
assert.NoError(t, err)
require.NoError(t, err)
rc := &RunContext{
Config: &Config{
@@ -401,7 +402,7 @@ func TestGetGitHubContextOverlay(t *testing.T) {
log.SetLevel(log.DebugLevel)
cwd, err := os.Getwd()
assert.NoError(t, err)
require.NoError(t, err)
rc := &RunContext{
Config: &Config{
@@ -511,7 +512,7 @@ func createIfTestRunContext(jobs map[string]*model.Job) *RunContext {
func createJob(t *testing.T, input string, result string) *model.Job {
var job *model.Job
err := yaml.Unmarshal([]byte(input), &job)
assert.NoError(t, err)
require.NoError(t, err)
job.Result = result
return job
@@ -748,7 +749,7 @@ func TestSetRuntimeVariables(t *testing.T) {
tkn, _, err := jwt.NewParser().ParseUnverified(runtimeToken, jwt.MapClaims{})
assert.NotNil(t, tkn)
assert.NoError(t, err)
require.NoError(t, err)
}
func TestSetRuntimeVariablesWithRunID(t *testing.T) {
@@ -773,7 +774,7 @@ func TestSetRuntimeVariablesWithRunID(t *testing.T) {
claims := jwt.MapClaims{}
tkn, _, err := jwt.NewParser().ParseUnverified(runtimeToken, &claims)
assert.NotNil(t, tkn)
assert.NoError(t, err)
require.NoError(t, err)
scp, ok := claims["scp"]
assert.True(t, ok, "scp claim exists")
assert.Equal(t, "Actions.Results:45:45", scp, "contains expected scp claim")

View File

@@ -19,6 +19,7 @@ import (
"github.com/joho/godotenv"
log "github.com/sirupsen/logrus"
assert "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v3"
"gitea.com/gitea/act_runner/pkg/common"
@@ -58,7 +59,7 @@ func init() {
func TestNoWorkflowsFoundByPlanner(t *testing.T) {
planner, err := model.NewWorkflowPlanner("hashfiles", model.PlannerConfig{})
assert.NoError(t, err)
require.NoError(t, err)
out := log.StandardLogger().Out
var buf bytes.Buffer
@@ -66,19 +67,19 @@ func TestNoWorkflowsFoundByPlanner(t *testing.T) {
log.SetLevel(log.DebugLevel)
plan, err := planner.PlanEvent("pull_request")
assert.NotNil(t, plan)
assert.NoError(t, err)
require.NoError(t, err)
assert.Contains(t, buf.String(), "no workflows found by planner")
buf.Reset()
plan, err = planner.PlanAll()
assert.NotNil(t, plan)
assert.NoError(t, err)
require.NoError(t, err)
assert.Contains(t, buf.String(), "no workflows found by planner")
log.SetOutput(out)
}
func TestGraphMissingEvent(t *testing.T) {
planner, err := model.NewWorkflowPlanner("testdata/issue-1595/no-event.yml", model.PlannerConfig{})
assert.NoError(t, err)
require.NoError(t, err)
out := log.StandardLogger().Out
var buf bytes.Buffer
@@ -86,7 +87,7 @@ func TestGraphMissingEvent(t *testing.T) {
log.SetLevel(log.DebugLevel)
plan, err := planner.PlanEvent("push")
assert.NoError(t, err)
require.NoError(t, err)
assert.NotNil(t, plan)
assert.Empty(t, plan.Stages)
@@ -96,7 +97,7 @@ func TestGraphMissingEvent(t *testing.T) {
func TestGraphMissingFirst(t *testing.T) {
planner, err := model.NewWorkflowPlanner("testdata/issue-1595/no-first.yml", model.PlannerConfig{})
assert.NoError(t, err)
require.NoError(t, err)
plan, err := planner.PlanEvent("push")
assert.EqualError(t, err, "unable to build dependency graph for no first (no-first.yml)")
@@ -106,7 +107,7 @@ func TestGraphMissingFirst(t *testing.T) {
func TestGraphWithMissing(t *testing.T) {
planner, err := model.NewWorkflowPlanner("testdata/issue-1595/missing.yml", model.PlannerConfig{})
assert.NoError(t, err)
require.NoError(t, err)
out := log.StandardLogger().Out
var buf bytes.Buffer
@@ -125,7 +126,7 @@ func TestGraphWithSomeMissing(t *testing.T) {
log.SetLevel(log.DebugLevel)
planner, err := model.NewWorkflowPlanner("testdata/issue-1595/", model.PlannerConfig{})
assert.NoError(t, err)
require.NoError(t, err)
out := log.StandardLogger().Out
var buf bytes.Buffer
@@ -143,10 +144,10 @@ func TestGraphWithSomeMissing(t *testing.T) {
func TestGraphEvent(t *testing.T) {
planner, err := model.NewWorkflowPlanner("testdata/basic", model.PlannerConfig{})
assert.NoError(t, err)
require.NoError(t, err)
plan, err := planner.PlanEvent("push")
assert.NoError(t, err)
require.NoError(t, err)
assert.NotNil(t, plan)
assert.NotNil(t, plan.Stages)
assert.Len(t, plan.Stages, 3, "stages")
@@ -158,7 +159,7 @@ func TestGraphEvent(t *testing.T) {
assert.Equal(t, "test", plan.Stages[2].Runs[0].JobID, "jobid")
plan, err = planner.PlanEvent("release")
assert.NoError(t, err)
require.NoError(t, err)
assert.NotNil(t, plan)
assert.Empty(t, plan.Stages)
}
@@ -178,7 +179,7 @@ func (j *TestJobFileInfo) runTest(ctx context.Context, t *testing.T, cfg *Config
log.SetLevel(logLevel)
workdir, err := filepath.Abs(j.workdir)
assert.NoError(t, err, workdir)
require.NoError(t, err, workdir)
fullWorkflowPath := filepath.Join(workdir, j.workflowPath)
runnerConfig := &Config{
@@ -199,18 +200,18 @@ func (j *TestJobFileInfo) runTest(ctx context.Context, t *testing.T, cfg *Config
}
runner, err := New(runnerConfig)
assert.NoError(t, err, j.workflowPath)
require.NoError(t, err, j.workflowPath)
planner, err := model.NewWorkflowPlanner(fullWorkflowPath, model.PlannerConfig{})
if j.errorMessage != "" && err != nil {
assert.Error(t, err, j.errorMessage)
} else if assert.NoError(t, err, fullWorkflowPath) {
} else if require.NoError(t, err, fullWorkflowPath) {
plan, err := planner.PlanEvent(j.eventName)
assert.NotEqual(t, (err == nil), (plan == nil), "PlanEvent should return either a plan or an error")
if err == nil && plan != nil {
err = runner.NewPlanExecutor(plan)(ctx)
if j.errorMessage == "" {
assert.NoError(t, err, fullWorkflowPath)
require.NoError(t, err, fullWorkflowPath)
} else {
assert.Error(t, err, j.errorMessage)
}
@@ -780,9 +781,9 @@ func TestRunEventSecrets(t *testing.T) {
}
env, err := godotenv.Read(filepath.Join(workdir, workflowPath, ".env"))
assert.NoError(t, err, "Failed to read .env")
require.NoError(t, err, "Failed to read .env")
secrets, _ := godotenv.Read(filepath.Join(workdir, workflowPath, ".secrets"))
assert.NoError(t, err, "Failed to read .secrets")
require.NoError(t, err, "Failed to read .secrets")
tjfi.runTest(context.Background(), t, &Config{Secrets: secrets, Env: env})
}

View File

@@ -11,6 +11,7 @@ import (
"gitea.com/gitea/act_runner/pkg/model"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v3"
)
@@ -92,10 +93,10 @@ func TestStepActionLocalTest(t *testing.T) {
})
err := sal.pre()(ctx)
assert.NoError(t, err)
require.NoError(t, err)
err = sal.main()(ctx)
assert.NoError(t, err)
require.NoError(t, err)
cm.AssertExpectations(t)
salm.AssertExpectations(t)

View File

@@ -9,6 +9,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v3"
"gitea.com/gitea/act_runner/pkg/common"
@@ -290,7 +291,7 @@ func TestStepActionRemotePre(t *testing.T) {
err := sar.pre()(ctx)
assert.NoError(t, err)
require.NoError(t, err)
sarm.AssertExpectations(t)
cacheMock.AssertExpectations(t)
@@ -343,7 +344,7 @@ func TestStepActionRemotePreThroughAction(t *testing.T) {
err := sar.pre()(ctx)
assert.NoError(t, err)
require.NoError(t, err)
sarm.AssertExpectations(t)
cacheMock.AssertExpectations(t)
@@ -397,7 +398,7 @@ func TestStepActionRemotePreThroughActionToken(t *testing.T) {
err := sar.pre()(ctx)
assert.NoError(t, err)
require.NoError(t, err)
sarm.AssertExpectations(t)
cacheMock.AssertExpectations(t)

View File

@@ -10,6 +10,7 @@ import (
"gitea.com/gitea/act_runner/pkg/model"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
)
func TestStepDockerMain(t *testing.T) {
@@ -97,7 +98,7 @@ func TestStepDockerMain(t *testing.T) {
cm.On("GetContainerArchive", ctx, "/var/run/act/workflow/pathcmd.txt").Return(io.NopCloser(&bytes.Buffer{}), nil)
err := sd.main()(ctx)
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, "node:14", input.Image)
@@ -109,8 +110,8 @@ func TestStepDockerPrePost(t *testing.T) {
sd := &stepDocker{}
err := sd.pre()(ctx)
assert.NoError(t, err)
require.NoError(t, err)
err = sd.post()(ctx)
assert.NoError(t, err)
require.NoError(t, err)
}

View File

@@ -5,6 +5,7 @@ import (
"gitea.com/gitea/act_runner/pkg/model"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestStepFactoryNewStep(t *testing.T) {
@@ -62,7 +63,7 @@ func TestStepFactoryNewStep(t *testing.T) {
step, err := sf.newStep(tt.model, &RunContext{})
assert.True(t, tt.check((step)))
assert.NoError(t, err)
require.NoError(t, err)
})
}
}

View File

@@ -6,8 +6,8 @@ import (
"io"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"gitea.com/gitea/act_runner/pkg/container"
"gitea.com/gitea/act_runner/pkg/model"
@@ -78,7 +78,7 @@ func TestStepRun(t *testing.T) {
cm.On("GetContainerArchive", ctx, "/var/run/act/workflow/pathcmd.txt").Return(io.NopCloser(&bytes.Buffer{}), nil)
err := sr.main()(ctx)
assert.NoError(t, err)
require.NoError(t, err)
cm.AssertExpectations(t)
}
@@ -88,8 +88,8 @@ func TestStepRunPrePost(t *testing.T) {
sr := &stepRun{}
err := sr.pre()(ctx)
assert.NoError(t, err)
require.NoError(t, err)
err = sr.post()(ctx)
assert.NoError(t, err)
require.NoError(t, err)
}

View File

@@ -9,6 +9,7 @@ import (
log "github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
yaml "gopkg.in/yaml.v3"
)
@@ -152,7 +153,7 @@ func TestSetupEnv(t *testing.T) {
sm.On("getEnv").Return(&env)
err := setupEnv(context.Background(), sm)
assert.NoError(t, err)
require.NoError(t, err)
// These are commit or system specific
delete((env), "GITHUB_REF")
@@ -198,7 +199,7 @@ func TestIsStepEnabled(t *testing.T) {
createTestStep := func(t *testing.T, input string) step {
var step *model.Step
err := yaml.Unmarshal([]byte(input), &step)
assert.NoError(t, err)
require.NoError(t, err)
return &stepRun{
RunContext: &RunContext{
@@ -280,7 +281,7 @@ func TestIsContinueOnError(t *testing.T) {
createTestStep := func(t *testing.T, input string) step {
var step *model.Step
err := yaml.Unmarshal([]byte(input), &step)
assert.NoError(t, err)
require.NoError(t, err)
return &stepRun{
RunContext: &RunContext{
@@ -365,7 +366,7 @@ func TestSymlinkJoin(t *testing.T) {
for _, entry := range table {
result, err := symlinkJoin(entry.from, entry.target, entry.root...)
if entry.err == "" {
assert.NoError(t, err)
require.NoError(t, err)
} else {
assert.Error(t, err, entry.err)
}