Skip to content

Commit

Permalink
test: improve brittle tests
Browse files Browse the repository at this point in the history
  • Loading branch information
caarlos0 committed Nov 30, 2023
1 parent bd7933d commit 1ec5245
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
11 changes: 6 additions & 5 deletions internal/pipe/before/before_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,19 @@ func TestRunPipeInvalidCommand(t *testing.T) {
}

func TestRunPipeFail(t *testing.T) {
for err, tc := range map[string][]string{
"hook failed: shell: 'go tool foobar': exit status 2: go: no such tool \"foobar\"\n": {"go tool foobar"},
"hook failed: shell: 'sh ./testdata/foo.sh': exit status 1: lalala\n": {"sh ./testdata/foo.sh"},
for _, tc := range []string{
"go tool foobar",
"sh ./testdata/foo.sh",
} {
ctx := testctx.NewWithCfg(
config.Project{
Before: config.Before{
Hooks: tc,
Hooks: []string{tc},
},
},
)
require.EqualError(t, Pipe{}.Run(ctx), err)
err := Pipe{}.Run(ctx)
require.Contains(t, err.Error(), "hook failed")
}
}

Expand Down
4 changes: 3 additions & 1 deletion internal/pipe/build/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,8 @@ func TestRunHookFailWithLogs(t *testing.T) {
},
}
ctx := testctx.NewWithCfg(config, testctx.WithCurrentTag("2.4.5"))
require.EqualError(t, Pipe{}.Run(ctx), "pre hook failed: failed to run 'sh -c echo foo; exit 1': exit status 1")
err := Pipe{}.Run(ctx)
require.ErrorIs(t, err, exec.ErrNotFound)
require.Contains(t, err.Error(), "pre hook failed")
require.Empty(t, ctx.Artifacts.List())
}

0 comments on commit 1ec5245

Please sign in to comment.