1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-03-17 20:47:50 +02:00

test: improve executable not found checks (#4119)

extracted from #3795
This commit is contained in:
Carlos Alexandro Becker 2023-06-15 23:51:07 -03:00 committed by GitHub
parent bb33419beb
commit bad7984962
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 7 deletions

View File

@ -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")
})
}

View File

@ -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
}

View File

@ -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{
{

View File

@ -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) {