From bad79849621f236cb778b6e4a285dd9fb3136d54 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Thu, 15 Jun 2023 23:51:07 -0300 Subject: [PATCH] test: improve executable not found checks (#4119) extracted from #3795 --- internal/pipe/build/build_test.go | 10 ++++++++-- internal/pipe/docker/docker.go | 2 +- internal/pipe/sign/sign_test.go | 4 ++-- internal/pipe/universalbinary/universalbinary_test.go | 8 ++++++-- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/internal/pipe/build/build_test.go b/internal/pipe/build/build_test.go index cdc47fb54..b5cabd39b 100644 --- a/internal/pipe/build/build_test.go +++ b/internal/pipe/build/build_test.go @@ -3,6 +3,7 @@ package build import ( "errors" "os" + "os/exec" "path/filepath" "testing" @@ -209,13 +210,18 @@ func TestRunPipeFailingHooks(t *testing.T) { ctx := testctx.NewWithCfg(cfg, testctx.WithCurrentTag("2.4.5")) ctx.Config.Builds[0].Hooks.Pre = []config.Hook{{Cmd: "exit 1"}} ctx.Config.Builds[0].Hooks.Post = []config.Hook{{Cmd: "echo post"}} - require.EqualError(t, Pipe{}.Run(ctx), "pre hook failed: failed to run 'exit 1': exec: \"exit\": executable file not found in $PATH") + + err := Pipe{}.Run(ctx) + require.ErrorIs(t, err, exec.ErrNotFound) + require.Contains(t, err.Error(), "pre hook failed") }) t.Run("post-hook", func(t *testing.T) { ctx := testctx.NewWithCfg(cfg, testctx.WithCurrentTag("2.4.5")) ctx.Config.Builds[0].Hooks.Pre = []config.Hook{{Cmd: "echo pre"}} ctx.Config.Builds[0].Hooks.Post = []config.Hook{{Cmd: "exit 1"}} - require.EqualError(t, Pipe{}.Run(ctx), `post hook failed: failed to run 'exit 1': exec: "exit": executable file not found in $PATH`) + err := Pipe{}.Run(ctx) + require.ErrorIs(t, err, exec.ErrNotFound) + require.Contains(t, err.Error(), "post hook failed") }) } diff --git a/internal/pipe/docker/docker.go b/internal/pipe/docker/docker.go index 3c35340ca..af1d3a457 100644 --- a/internal/pipe/docker/docker.go +++ b/internal/pipe/docker/docker.go @@ -201,7 +201,7 @@ func process(ctx *context.Context, docker config.Docker, artifacts []*artifact.A if err := imagers[docker.Use].Build(ctx, tmp, images, buildFlags); err != nil { if isFileNotFoundError(err.Error()) { var files []string - _ = filepath.Walk(tmp, func(path string, info fs.FileInfo, err error) error { + _ = filepath.Walk(tmp, func(_ string, info fs.FileInfo, _ error) error { if info.IsDir() { return nil } diff --git a/internal/pipe/sign/sign_test.go b/internal/pipe/sign/sign_test.go index dcc14ff79..ef4c30270 100644 --- a/internal/pipe/sign/sign_test.go +++ b/internal/pipe/sign/sign_test.go @@ -107,8 +107,8 @@ func TestSignArtifacts(t *testing.T) { user string }{ { - desc: "sign cmd not found", - expectedErrMsg: `sign: not-a-valid-cmd failed: exec: "not-a-valid-cmd": executable file not found in $PATH: `, + desc: "sign cmd not found", + expectedErrIs: exec.ErrNotFound, ctx: testctx.NewWithCfg(config.Project{ Signs: []config.Sign{ { diff --git a/internal/pipe/universalbinary/universalbinary_test.go b/internal/pipe/universalbinary/universalbinary_test.go index 4426183e6..c006f4ba8 100644 --- a/internal/pipe/universalbinary/universalbinary_test.go +++ b/internal/pipe/universalbinary/universalbinary_test.go @@ -290,14 +290,18 @@ func TestRun(t *testing.T) { ctx := ctx5 ctx.Config.UniversalBinaries[0].Hooks.Pre = []config.Hook{{Cmd: "exit 1"}} ctx.Config.UniversalBinaries[0].Hooks.Post = []config.Hook{{Cmd: "echo post"}} - require.EqualError(t, Pipe{}.Run(ctx), "pre hook failed: failed to run 'exit 1': exec: \"exit\": executable file not found in $PATH") + err := Pipe{}.Run(ctx) + require.ErrorIs(t, err, exec.ErrNotFound) + require.Contains(t, err.Error(), "pre hook failed") }) t.Run("failing post-hook", func(t *testing.T) { ctx := ctx5 ctx.Config.UniversalBinaries[0].Hooks.Pre = []config.Hook{{Cmd: "echo pre"}} ctx.Config.UniversalBinaries[0].Hooks.Post = []config.Hook{{Cmd: "exit 1"}} - require.EqualError(t, Pipe{}.Run(ctx), "post hook failed: failed to run 'exit 1': exec: \"exit\": executable file not found in $PATH") + err := Pipe{}.Run(ctx) + require.ErrorIs(t, err, exec.ErrNotFound) + require.Contains(t, err.Error(), "post hook failed") }) t.Run("hook with env tmpl", func(t *testing.T) {