This commit is contained in:
Christopher Homberger
2026-02-22 21:04:33 +01:00
parent a77f10683d
commit a27473e6a8
5 changed files with 24 additions and 42 deletions

View File

@@ -17,7 +17,7 @@ func TestNewWorkflow(t *testing.T) {
// empty // empty
emptyWorkflow := NewPipelineExecutor() emptyWorkflow := NewPipelineExecutor()
require.NoError(emptyWorkflow(ctx)) require.NoError(t, emptyWorkflow(ctx))
// error case // error case
errorWorkflow := NewErrorExecutor(errors.New("test error")) errorWorkflow := NewErrorExecutor(errors.New("test error"))
@@ -34,7 +34,7 @@ func TestNewWorkflow(t *testing.T) {
runcount++ runcount++
return nil return nil
}) })
require.NoError(successWorkflow(ctx)) require.NoError(t, successWorkflow(ctx))
assert.Equal(2, runcount) assert.Equal(2, runcount)
} }
@@ -56,7 +56,7 @@ func TestNewConditionalExecutor(t *testing.T) {
return nil return nil
})(ctx) })(ctx)
require.NoError(err) require.NoError(t, err)
assert.Equal(0, trueCount) assert.Equal(0, trueCount)
assert.Equal(1, falseCount) assert.Equal(1, falseCount)
@@ -70,7 +70,7 @@ func TestNewConditionalExecutor(t *testing.T) {
return nil return nil
})(ctx) })(ctx)
require.NoError(err) require.NoError(t, err)
assert.Equal(1, trueCount) assert.Equal(1, trueCount)
assert.Equal(1, falseCount) assert.Equal(1, falseCount)
} }
@@ -100,7 +100,7 @@ func TestNewParallelExecutor(t *testing.T) {
assert.Equal(3, count, "should run all 3 executors") assert.Equal(3, count, "should run all 3 executors")
assert.Equal(2, maxCount, "should run at most 2 executors in parallel") assert.Equal(2, maxCount, "should run at most 2 executors in parallel")
require.NoError(err) require.NoError(t, err)
// Reset to test running the executor with 0 parallelism // Reset to test running the executor with 0 parallelism
count = 0 count = 0
@@ -111,7 +111,7 @@ func TestNewParallelExecutor(t *testing.T) {
assert.Equal(3, count, "should run all 3 executors") assert.Equal(3, count, "should run all 3 executors")
assert.Equal(1, maxCount, "should run at most 1 executors in parallel") assert.Equal(1, maxCount, "should run at most 1 executors in parallel")
require.NoError(errSingle) require.NoError(t, errSingle)
} }
func TestNewParallelExecutorFailed(t *testing.T) { func TestNewParallelExecutorFailed(t *testing.T) {

View File

@@ -40,7 +40,7 @@ func TestFindGitSlug(t *testing.T) {
for _, tt := range slugTests { for _, tt := range slugTests {
provider, slug, err := findGitSlug(tt.url, "github.com") provider, slug, err := findGitSlug(tt.url, "github.com")
require.NoError(err) require.NoError(t, err)
assert.Equal(tt.provider, provider) assert.Equal(tt.provider, provider)
assert.Equal(tt.slug, slug) assert.Equal(tt.slug, slug)
} }
@@ -80,23 +80,23 @@ func TestFindGitRemoteURL(t *testing.T) {
basedir := testDir(t) basedir := testDir(t)
gitConfig() gitConfig()
err := gitCmd("init", basedir) err := gitCmd("init", basedir)
require.NoError(err) require.NoError(t, err)
err = cleanGitHooks(basedir) err = cleanGitHooks(basedir)
require.NoError(err) require.NoError(t, err)
remoteURL := "https://git-codecommit.us-east-1.amazonaws.com/v1/repos/my-repo-name" remoteURL := "https://git-codecommit.us-east-1.amazonaws.com/v1/repos/my-repo-name"
err = gitCmd("-C", basedir, "remote", "add", "origin", remoteURL) err = gitCmd("-C", basedir, "remote", "add", "origin", remoteURL)
require.NoError(err) require.NoError(t, err)
u, err := findGitRemoteURL(context.Background(), basedir, "origin") u, err := findGitRemoteURL(context.Background(), basedir, "origin")
require.NoError(err) require.NoError(t, err)
assert.Equal(remoteURL, u) assert.Equal(remoteURL, u)
remoteURL = "git@github.com/AwesomeOwner/MyAwesomeRepo.git" remoteURL = "git@github.com/AwesomeOwner/MyAwesomeRepo.git"
err = gitCmd("-C", basedir, "remote", "add", "upstream", remoteURL) err = gitCmd("-C", basedir, "remote", "add", "upstream", remoteURL)
require.NoError(err) require.NoError(t, err)
u, err = findGitRemoteURL(context.Background(), basedir, "upstream") u, err = findGitRemoteURL(context.Background(), basedir, "upstream")
require.NoError(err) require.NoError(t, err)
assert.Equal(remoteURL, u) assert.Equal(remoteURL, u)
} }

View File

@@ -19,7 +19,7 @@ func TestLineWriter(t *testing.T) {
assert := assert.New(t) assert := assert.New(t)
write := func(s string) { write := func(s string) {
n, err := lineWriter.Write([]byte(s)) n, err := lineWriter.Write([]byte(s))
require.NoError(err) require.NoError(t, err)
assert.Equal(len(s), n, s) assert.Equal(len(s), n, s)
} }

View File

@@ -205,7 +205,7 @@ func (j *TestJobFileInfo) runTest(ctx context.Context, t *testing.T, cfg *Config
planner, err := model.NewWorkflowPlanner(fullWorkflowPath, model.PlannerConfig{}) planner, err := model.NewWorkflowPlanner(fullWorkflowPath, model.PlannerConfig{})
if j.errorMessage != "" && err != nil { if j.errorMessage != "" && err != nil {
assert.Error(t, err, j.errorMessage) assert.Error(t, err, j.errorMessage)
} else if require.NoError(t, err, fullWorkflowPath) { } else if assert.NoError(t, err, fullWorkflowPath) {
plan, err := planner.PlanEvent(j.eventName) plan, err := planner.PlanEvent(j.eventName)
assert.NotEqual(t, (err == nil), (plan == nil), "PlanEvent should return either a plan or an error") assert.NotEqual(t, (err == nil), (plan == nil), "PlanEvent should return either a plan or an error")
if err == nil && plan != nil { if err == nil && plan != nil {

View File

@@ -19,9 +19,7 @@ jobs:
steps: steps:
- run: exit 0 - run: exit 0
`), &node) `), &node)
if !require.NoError(t, err) { require.NoError(t, err)
return
}
err = (&Node{ err = (&Node{
Definition: "workflow-root-strict", Definition: "workflow-root-strict",
Schema: GetWorkflowSchema(), Schema: GetWorkflowSchema(),
@@ -40,9 +38,7 @@ jobs:
steps: steps:
- run: exit 0 - run: exit 0
`), &node) `), &node)
if !require.NoError(t, err) { require.NoError(t, err)
return
}
err = (&Node{ err = (&Node{
Definition: "workflow-root-strict", Definition: "workflow-root-strict",
Schema: GetWorkflowSchema(), Schema: GetWorkflowSchema(),
@@ -61,9 +57,7 @@ jobs:
- run: exit 0 - run: exit 0
if: success() || failure() || always() if: success() || failure() || always()
`), &node) `), &node)
if !require.NoError(t, err) { require.NoError(t, err)
return
}
err = (&Node{ err = (&Node{
Definition: "workflow-root-strict", Definition: "workflow-root-strict",
Schema: GetWorkflowSchema(), Schema: GetWorkflowSchema(),
@@ -82,9 +76,7 @@ jobs:
- run: exit 0 - run: exit 0
if: ${{ success() || failure() || always() }} if: ${{ success() || failure() || always() }}
`), &node) `), &node)
if !require.NoError(t, err) { require.NoError(t, err)
return
}
err = (&Node{ err = (&Node{
Definition: "workflow-root-strict", Definition: "workflow-root-strict",
Schema: GetWorkflowSchema(), Schema: GetWorkflowSchema(),
@@ -101,9 +93,7 @@ jobs:
runs-on: self-hosted runs-on: self-hosted
x: failure x: failure
`), &node) `), &node)
if !require.NoError(t, err) { require.NoError(t, err)
return
}
err = (&Node{ err = (&Node{
Definition: "workflow-root-strict", Definition: "workflow-root-strict",
Schema: GetWorkflowSchema(), Schema: GetWorkflowSchema(),
@@ -120,9 +110,7 @@ jobs:
runs-on: self-hosted runs-on: self-hosted
Runs-on: failure Runs-on: failure
`), &node) `), &node)
if !require.NoError(t, err) { require.NoError(t, err)
return
}
err = (&Node{ err = (&Node{
Definition: "workflow-root-strict", Definition: "workflow-root-strict",
Schema: GetWorkflowSchema(), Schema: GetWorkflowSchema(),
@@ -140,9 +128,7 @@ jobs:
steps: steps:
- run: exit 0 - run: exit 0
`), &node) `), &node)
if !require.NoError(t, err) { require.NoError(t, err)
return
}
err = (&Node{ err = (&Node{
Definition: "workflow-root-strict", Definition: "workflow-root-strict",
Schema: GetWorkflowSchema(), Schema: GetWorkflowSchema(),
@@ -209,9 +195,7 @@ jobs:
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
var node yaml.Node var node yaml.Node
err := yaml.Unmarshal([]byte(test.input), &node) err := yaml.Unmarshal([]byte(test.input), &node)
if !require.NoError(t, err) { require.NoError(t, err)
return
}
err = (&Node{ err = (&Node{
Definition: "workflow-root-strict", Definition: "workflow-root-strict",
Schema: GetWorkflowSchema(), Schema: GetWorkflowSchema(),
@@ -247,9 +231,7 @@ runs:
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
var node yaml.Node var node yaml.Node
err := yaml.Unmarshal([]byte(test.input), &node) err := yaml.Unmarshal([]byte(test.input), &node)
if !require.NoError(t, err) { require.NoError(t, err)
return
}
err = (&Node{ err = (&Node{
Definition: "action-root", Definition: "action-root",
Schema: GetActionSchema(), Schema: GetActionSchema(),