mirror of
https://github.com/goreleaser/goreleaser.git
synced 2024-12-27 01:33:39 +02:00
test: improving tests on windows
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
parent
cd1c5fb992
commit
3c55f2bb77
@ -56,7 +56,7 @@ func TestInitGitIgnoreExists(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestInitFileError(t *testing.T) {
|
||||
testlib.SkipIfWindows(t)
|
||||
testlib.SkipIfWindows(t, "windows permissions don't work the same way")
|
||||
folder := setupInitTest(t)
|
||||
cmd := newInitCmd().cmd
|
||||
path := filepath.Join(folder, "nope.yaml")
|
||||
|
@ -73,7 +73,6 @@ func TestRunPipeFail(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRunWithEnv(t *testing.T) {
|
||||
testlib.SkipIfWindows(t)
|
||||
f := filepath.Join(t.TempDir(), "testfile")
|
||||
require.NoError(t, Pipe{}.Run(testctx.NewWithCfg(
|
||||
config.Project{
|
||||
@ -81,7 +80,7 @@ func TestRunWithEnv(t *testing.T) {
|
||||
"TEST_FILE=" + f,
|
||||
},
|
||||
Before: config.Before{
|
||||
Hooks: []string{"touch {{ .Env.TEST_FILE }}"},
|
||||
Hooks: []string{testlib.Touch("{{ .Env.TEST_FILE }}")},
|
||||
},
|
||||
},
|
||||
)))
|
||||
@ -92,7 +91,7 @@ func TestInvalidTemplate(t *testing.T) {
|
||||
testlib.RequireTemplateError(t, Pipe{}.Run(testctx.NewWithCfg(
|
||||
config.Project{
|
||||
Before: config.Before{
|
||||
Hooks: []string{"touch {{ .fasdsd }"},
|
||||
Hooks: []string{"doesnt-matter {{ .fasdsd }"},
|
||||
},
|
||||
},
|
||||
)))
|
||||
|
@ -76,7 +76,7 @@ func TestMain(m *testing.M) {
|
||||
|
||||
func TestMinioUpload(t *testing.T) {
|
||||
testlib.CheckPath(t, "docker")
|
||||
testlib.SkipIfWindows(t)
|
||||
testlib.SkipIfWindows(t, "minio image not available for windows")
|
||||
name := "basic"
|
||||
directory := t.TempDir()
|
||||
srcpath := filepath.Join(directory, "source.tar.gz")
|
||||
@ -183,7 +183,7 @@ func TestMinioUpload(t *testing.T) {
|
||||
|
||||
func TestMinioUploadCustomBucketID(t *testing.T) {
|
||||
testlib.CheckPath(t, "docker")
|
||||
testlib.SkipIfWindows(t)
|
||||
testlib.SkipIfWindows(t, "minio image not available for windows")
|
||||
name := "fromenv"
|
||||
directory := t.TempDir()
|
||||
tgzpath := filepath.Join(directory, "bin.tar.gz")
|
||||
@ -221,7 +221,7 @@ func TestMinioUploadCustomBucketID(t *testing.T) {
|
||||
|
||||
func TestMinioUploadExtraFilesOnly(t *testing.T) {
|
||||
testlib.CheckPath(t, "docker")
|
||||
testlib.SkipIfWindows(t)
|
||||
testlib.SkipIfWindows(t, "minio image not available for windows")
|
||||
name := "only-extra-files"
|
||||
directory := t.TempDir()
|
||||
tgzpath := filepath.Join(directory, "bin.tar.gz")
|
||||
@ -268,7 +268,7 @@ func TestMinioUploadExtraFilesOnly(t *testing.T) {
|
||||
|
||||
func TestMinioUploadRootDirectory(t *testing.T) {
|
||||
testlib.CheckPath(t, "docker")
|
||||
testlib.SkipIfWindows(t)
|
||||
testlib.SkipIfWindows(t, "minio image not available for windows")
|
||||
name := "rootdir"
|
||||
directory := t.TempDir()
|
||||
tgzpath := filepath.Join(directory, "bin.tar.gz")
|
||||
@ -305,7 +305,7 @@ func TestMinioUploadRootDirectory(t *testing.T) {
|
||||
|
||||
func TestMinioUploadInvalidCustomBucketID(t *testing.T) {
|
||||
testlib.CheckPath(t, "docker")
|
||||
testlib.SkipIfWindows(t)
|
||||
testlib.SkipIfWindows(t, "minio image not available for windows")
|
||||
directory := t.TempDir()
|
||||
tgzpath := filepath.Join(directory, "bin.tar.gz")
|
||||
debpath := filepath.Join(directory, "bin.deb")
|
||||
@ -339,7 +339,7 @@ func TestMinioUploadInvalidCustomBucketID(t *testing.T) {
|
||||
|
||||
func TestMinioUploadSkip(t *testing.T) {
|
||||
testlib.CheckPath(t, "docker")
|
||||
testlib.SkipIfWindows(t)
|
||||
testlib.SkipIfWindows(t, "minio image not available for windows")
|
||||
name := "basic"
|
||||
directory := t.TempDir()
|
||||
debpath := filepath.Join(directory, "bin.deb")
|
||||
|
@ -22,18 +22,8 @@ import (
|
||||
var (
|
||||
errFailedBuild = errors.New("fake builder failed")
|
||||
errFailedDefault = errors.New("fake builder defaults failed")
|
||||
|
||||
touch = "touch "
|
||||
echo = "echo "
|
||||
)
|
||||
|
||||
func init() {
|
||||
if testlib.IsWindows() {
|
||||
touch = "cmd.exe /c copy nul "
|
||||
echo = "cmd.exe /c echo "
|
||||
}
|
||||
}
|
||||
|
||||
type fakeBuilder struct {
|
||||
fail bool
|
||||
failDefault bool
|
||||
@ -146,12 +136,12 @@ func TestRunFullPipe(t *testing.T) {
|
||||
},
|
||||
Hooks: config.BuildHookConfig{
|
||||
Pre: []config.Hook{
|
||||
{Cmd: touch + pre},
|
||||
{Cmd: touch + " pre_{{ .Env.THE_OS}}"},
|
||||
{Cmd: testlib.Touch(pre)},
|
||||
{Cmd: testlib.Touch("pre_{{ .Env.THE_OS}}")},
|
||||
},
|
||||
Post: []config.Hook{
|
||||
{Cmd: touch + post},
|
||||
{Cmd: touch + " post_{{ .Env.THE_OS}}"},
|
||||
{Cmd: testlib.Touch(post)},
|
||||
{Cmd: testlib.Touch("post_{{ .Env.THE_OS}}")},
|
||||
},
|
||||
},
|
||||
Targets: []string{"linux_amd64"},
|
||||
@ -188,10 +178,10 @@ func TestRunFullPipeFail(t *testing.T) {
|
||||
},
|
||||
Hooks: config.BuildHookConfig{
|
||||
Pre: []config.Hook{
|
||||
{Cmd: touch + pre},
|
||||
{Cmd: testlib.Touch(pre)},
|
||||
},
|
||||
Post: []config.Hook{
|
||||
{Cmd: touch + post},
|
||||
{Cmd: testlib.Touch(post)},
|
||||
},
|
||||
},
|
||||
Targets: []string{"linux_amd64"},
|
||||
@ -220,7 +210,7 @@ func TestRunPipeFailingHooks(t *testing.T) {
|
||||
t.Run("pre-hook", func(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"}}
|
||||
ctx.Config.Builds[0].Hooks.Post = []config.Hook{{Cmd: testlib.Echo("post")}}
|
||||
|
||||
err := Pipe{}.Run(ctx)
|
||||
require.ErrorIs(t, err, exec.ErrNotFound)
|
||||
@ -228,7 +218,7 @@ func TestRunPipeFailingHooks(t *testing.T) {
|
||||
})
|
||||
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.Pre = []config.Hook{{Cmd: testlib.Echo("pre")}}
|
||||
ctx.Config.Builds[0].Hooks.Post = []config.Hook{{Cmd: "exit 1"}}
|
||||
err := Pipe{}.Run(ctx)
|
||||
require.ErrorIs(t, err, exec.ErrNotFound)
|
||||
@ -241,7 +231,7 @@ func TestRunPipeFailingHooks(t *testing.T) {
|
||||
testctx.WithCurrentTag("2.4.5"),
|
||||
testctx.Skip(skips.PostBuildHooks),
|
||||
)
|
||||
ctx.Config.Builds[0].Hooks.Pre = []config.Hook{{Cmd: echo + " pre"}}
|
||||
ctx.Config.Builds[0].Hooks.Pre = []config.Hook{{Cmd: testlib.Echo("pre")}}
|
||||
ctx.Config.Builds[0].Hooks.Post = []config.Hook{{Cmd: "exit 1"}}
|
||||
require.NoError(t, Pipe{}.Run(ctx))
|
||||
})
|
||||
@ -252,7 +242,7 @@ func TestRunPipeFailingHooks(t *testing.T) {
|
||||
testctx.WithCurrentTag("2.4.5"),
|
||||
testctx.Skip(skips.PreBuildHooks),
|
||||
)
|
||||
ctx.Config.Builds[0].Hooks.Post = []config.Hook{{Cmd: echo + " pre"}}
|
||||
ctx.Config.Builds[0].Hooks.Pre = []config.Hook{{Cmd: testlib.Echo("pre")}}
|
||||
ctx.Config.Builds[0].Hooks.Pre = []config.Hook{{Cmd: "exit 1"}}
|
||||
require.NoError(t, Pipe{}.Run(ctx))
|
||||
})
|
||||
@ -515,10 +505,10 @@ func TestBuild_hooksKnowGoosGoarch(t *testing.T) {
|
||||
},
|
||||
Hooks: config.BuildHookConfig{
|
||||
Pre: []config.Hook{
|
||||
{Cmd: touch + " pre-hook-{{.Arch}}-{{.Os}}", Dir: tmpDir},
|
||||
{Cmd: testlib.Touch("pre-hook-{{.Arch}}-{{.Os}}"), Dir: tmpDir},
|
||||
},
|
||||
Post: config.Hooks{
|
||||
{Cmd: touch + " post-hook-{{.Arch}}-{{.Os}}", Dir: tmpDir},
|
||||
{Cmd: testlib.Touch(" post-hook-{{.Arch}}-{{.Os}}"), Dir: tmpDir},
|
||||
},
|
||||
},
|
||||
}
|
||||
@ -548,10 +538,10 @@ func TestPipeOnBuild_hooksRunPerTarget(t *testing.T) {
|
||||
},
|
||||
Hooks: config.BuildHookConfig{
|
||||
Pre: []config.Hook{
|
||||
{Cmd: touch + " pre-hook-{{.Target}}", Dir: tmpDir},
|
||||
{Cmd: testlib.Touch("pre-hook-{{.Target}}"), Dir: tmpDir},
|
||||
},
|
||||
Post: config.Hooks{
|
||||
{Cmd: touch + " post-hook-{{.Target}}", Dir: tmpDir},
|
||||
{Cmd: testlib.Touch("post-hook-{{.Target}}"), Dir: tmpDir},
|
||||
},
|
||||
},
|
||||
}
|
||||
@ -747,7 +737,7 @@ func TestBuildOptionsForTarget(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRunHookFailWithLogs(t *testing.T) {
|
||||
testlib.SkipIfWindows(t)
|
||||
testlib.SkipIfWindows(t, "subshells don't work in windows")
|
||||
folder := testlib.Mktmp(t)
|
||||
config := config.Project{
|
||||
Dist: folder,
|
||||
|
@ -35,7 +35,7 @@ func start(tb testing.TB) {
|
||||
// TODO: this test is too big... split in smaller tests? Mainly the manifest ones...
|
||||
func TestRunPipe(t *testing.T) {
|
||||
testlib.CheckPath(t, "docker")
|
||||
testlib.SkipIfWindows(t)
|
||||
testlib.SkipIfWindows(t, "images only available for windows")
|
||||
type errChecker func(*testing.T, error)
|
||||
shouldErr := func(msg string) errChecker {
|
||||
return func(t *testing.T, err error) {
|
||||
|
2
internal/pipe/env/env_test.go
vendored
2
internal/pipe/env/env_test.go
vendored
@ -292,7 +292,7 @@ func TestLoadEnv(t *testing.T) {
|
||||
require.Equal(t, "123", v)
|
||||
})
|
||||
t.Run("env file is not readable", func(t *testing.T) {
|
||||
testlib.SkipIfWindows(t)
|
||||
testlib.SkipIfWindows(t, "permissions work differently in windows")
|
||||
f, err := os.CreateTemp(t.TempDir(), "token")
|
||||
require.NoError(t, err)
|
||||
fmt.Fprintf(f, "123")
|
||||
|
@ -175,7 +175,7 @@ func TestGoModProxy(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("no perms", func(t *testing.T) {
|
||||
testlib.SkipIfWindows(t)
|
||||
testlib.SkipIfWindows(t, "windows permissions work differently")
|
||||
for file, mode := range map[string]os.FileMode{
|
||||
"go.mod": 0o500,
|
||||
"go.sum": 0o500,
|
||||
|
@ -156,7 +156,7 @@ func TestPublishPipeNoMatchingBuild(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPublishPipeSuccess(t *testing.T) {
|
||||
testlib.SkipIfWindows(t)
|
||||
testlib.SkipIfWindows(t, "ko doesn't work in windows")
|
||||
testlib.CheckPath(t, "docker")
|
||||
testlib.StartRegistry(t, "ko_registry", registryPort)
|
||||
|
||||
@ -412,7 +412,7 @@ func TestPublishPipeSuccess(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSnapshot(t *testing.T) {
|
||||
testlib.SkipIfWindows(t)
|
||||
testlib.SkipIfWindows(t, "ko doesn't work in windows")
|
||||
testlib.CheckDocker(t)
|
||||
ctx := testctx.NewWithCfg(config.Project{
|
||||
ProjectName: "test",
|
||||
|
@ -37,7 +37,7 @@ func TestSkip(t *testing.T) {
|
||||
})
|
||||
t.Run("nix-all-good", func(t *testing.T) {
|
||||
testlib.CheckPath(t, "nix-prefetch-url")
|
||||
testlib.SkipIfWindows(t)
|
||||
testlib.SkipIfWindows(t, "nix doesn't work on windows")
|
||||
require.False(t, NewPublish().Skip(testctx.NewWithCfg(config.Project{
|
||||
Nix: []config.Nix{{}},
|
||||
})))
|
||||
@ -66,7 +66,7 @@ func TestPrefetcher(t *testing.T) {
|
||||
})
|
||||
t.Run("valid", func(t *testing.T) {
|
||||
testlib.CheckPath(t, "nix-prefetch-url")
|
||||
testlib.SkipIfWindows(t)
|
||||
testlib.SkipIfWindows(t, "nix doesn't work on windows")
|
||||
sha, err := publishShaPrefetcher{nixPrefetchURLBin}.Prefetch("https://github.com/goreleaser/goreleaser/releases/download/v1.18.2/goreleaser_Darwin_arm64.tar.gz")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "0girjxp07srylyq36xk1ska8p68m2fhp05xgyv4wkcl61d6rzv3y", sha)
|
||||
@ -83,7 +83,7 @@ func TestPrefetcher(t *testing.T) {
|
||||
})
|
||||
t.Run("valid", func(t *testing.T) {
|
||||
testlib.CheckPath(t, "nix-prefetch-url")
|
||||
testlib.SkipIfWindows(t)
|
||||
testlib.SkipIfWindows(t, "nix doesn't work on windows")
|
||||
require.True(t, publishShaPrefetcher{nixPrefetchURLBin}.Available())
|
||||
})
|
||||
})
|
||||
|
@ -81,8 +81,7 @@ func TestBinaryDependencies(t *testing.T) {
|
||||
|
||||
func TestBinarySign(t *testing.T) {
|
||||
testlib.CheckPath(t, "gpg")
|
||||
// dunno why this tries to use /usr/bin/gpg-agent on a windows machine
|
||||
testlib.SkipIfWindows(t)
|
||||
testlib.SkipIfWindows(t, "tries to use /usr/bin/gpg-agent")
|
||||
doTest := func(tb testing.TB, sign config.Sign) []*artifact.Artifact {
|
||||
tb.Helper()
|
||||
tmpdir := tb.TempDir()
|
||||
|
@ -97,8 +97,7 @@ func TestSignInvalidArtifacts(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSignArtifacts(t *testing.T) {
|
||||
// dunno why this tries to use /usr/bin/gpg-agent on a windows machine
|
||||
testlib.SkipIfWindows(t)
|
||||
testlib.SkipIfWindows(t, "tries to use /usr/bin/gpg-agent")
|
||||
stdin := passwordUser
|
||||
tmplStdin := passwordUserTmpl
|
||||
tests := []struct {
|
||||
|
@ -48,8 +48,7 @@ func TestRunPipeMissingInfo(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRunPipe(t *testing.T) {
|
||||
// snap doesn't work on windows apparently
|
||||
testlib.SkipIfWindows(t)
|
||||
testlib.SkipIfWindows(t, "snap doesn't work in windows")
|
||||
testlib.CheckPath(t, "snapcraft")
|
||||
folder := t.TempDir()
|
||||
dist := filepath.Join(folder, "dist")
|
||||
@ -101,8 +100,7 @@ func TestRunPipe(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestBadTemplate(t *testing.T) {
|
||||
// snap doesn't work on windows apparently
|
||||
testlib.SkipIfWindows(t)
|
||||
testlib.SkipIfWindows(t, "snap doesn't work in windows")
|
||||
testlib.CheckPath(t, "snapcraft")
|
||||
folder := t.TempDir()
|
||||
dist := filepath.Join(folder, "dist")
|
||||
@ -135,8 +133,7 @@ func TestBadTemplate(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRunPipeInvalidNameTemplate(t *testing.T) {
|
||||
// snap doesn't work on windows apparently
|
||||
testlib.SkipIfWindows(t)
|
||||
testlib.SkipIfWindows(t, "snap doesn't work in windows")
|
||||
testlib.CheckPath(t, "snapcraft")
|
||||
folder := t.TempDir()
|
||||
dist := filepath.Join(folder, "dist")
|
||||
@ -159,8 +156,7 @@ func TestRunPipeInvalidNameTemplate(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRunPipeWithName(t *testing.T) {
|
||||
// snap doesn't work on windows apparently
|
||||
testlib.SkipIfWindows(t)
|
||||
testlib.SkipIfWindows(t, "snap doesn't work in windows")
|
||||
testlib.CheckPath(t, "snapcraft")
|
||||
folder := t.TempDir()
|
||||
dist := filepath.Join(folder, "dist")
|
||||
@ -195,8 +191,7 @@ func TestRunPipeWithName(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRunPipeMetadata(t *testing.T) {
|
||||
// snap doesn't work on windows apparently
|
||||
testlib.SkipIfWindows(t)
|
||||
testlib.SkipIfWindows(t, "snap doesn't work in windows")
|
||||
testlib.CheckPath(t, "snapcraft")
|
||||
folder := t.TempDir()
|
||||
dist := filepath.Join(folder, "dist")
|
||||
@ -352,8 +347,7 @@ func TestNoSnapcraftInPath(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRunNoArguments(t *testing.T) {
|
||||
// snap doesn't work on windows apparently
|
||||
testlib.SkipIfWindows(t)
|
||||
testlib.SkipIfWindows(t, "snap doesn't work in windows")
|
||||
testlib.CheckPath(t, "snapcraft")
|
||||
folder := t.TempDir()
|
||||
dist := filepath.Join(folder, "dist")
|
||||
@ -388,8 +382,7 @@ func TestRunNoArguments(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCompleter(t *testing.T) {
|
||||
// snap doesn't work on windows apparently
|
||||
testlib.SkipIfWindows(t)
|
||||
testlib.SkipIfWindows(t, "snap doesn't work in windows")
|
||||
testlib.CheckPath(t, "snapcraft")
|
||||
folder := t.TempDir()
|
||||
dist := filepath.Join(folder, "dist")
|
||||
@ -427,8 +420,7 @@ func TestCompleter(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCommand(t *testing.T) {
|
||||
// snap doesn't work on windows apparently
|
||||
testlib.SkipIfWindows(t)
|
||||
testlib.SkipIfWindows(t, "snap doesn't work in windows")
|
||||
testlib.CheckPath(t, "snapcraft")
|
||||
folder := t.TempDir()
|
||||
dist := filepath.Join(folder, "dist")
|
||||
@ -464,8 +456,7 @@ func TestCommand(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestExtraFile(t *testing.T) {
|
||||
// snap doesn't work on windows apparently
|
||||
testlib.SkipIfWindows(t)
|
||||
testlib.SkipIfWindows(t, "snap doesn't work in windows")
|
||||
testlib.CheckPath(t, "snapcraft")
|
||||
folder := t.TempDir()
|
||||
dist := filepath.Join(folder, "dist")
|
||||
|
@ -19,18 +19,6 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var (
|
||||
echo = "echo "
|
||||
touch = "touch "
|
||||
)
|
||||
|
||||
func init() {
|
||||
if testlib.IsWindows() {
|
||||
touch = "cmd.exe /c copy nul "
|
||||
echo = "cmd.exe /c echo "
|
||||
}
|
||||
}
|
||||
|
||||
func TestDescription(t *testing.T) {
|
||||
require.NotEmpty(t, Pipe{}.String())
|
||||
}
|
||||
@ -187,11 +175,11 @@ func TestRun(t *testing.T) {
|
||||
NameTemplate: "foo",
|
||||
Hooks: config.BuildHookConfig{
|
||||
Pre: []config.Hook{
|
||||
{Cmd: touch + pre},
|
||||
{Cmd: testlib.Touch(pre)},
|
||||
},
|
||||
Post: []config.Hook{
|
||||
{Cmd: touch + post},
|
||||
{Cmd: shc(`echo "{{ .Name }} {{ .Os }} {{ .Arch }} {{ .Arm }} {{ .Target }} {{ .Ext }}" > {{ .Path }}.post`), Output: true},
|
||||
{Cmd: testlib.Touch(post)},
|
||||
{Cmd: testlib.ShC(`echo "{{ .Name }} {{ .Os }} {{ .Arch }} {{ .Arm }} {{ .Target }} {{ .Ext }}" > {{ .Path }}.post`), Output: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -220,12 +208,12 @@ func TestRun(t *testing.T) {
|
||||
ModTimestamp: fmt.Sprintf("%d", modTime.Unix()),
|
||||
Hooks: config.BuildHookConfig{
|
||||
Pre: []config.Hook{
|
||||
{Cmd: touch + pre},
|
||||
{Cmd: testlib.Touch(pre)},
|
||||
},
|
||||
Post: []config.Hook{
|
||||
{Cmd: touch + post},
|
||||
{Cmd: testlib.Touch(post)},
|
||||
{
|
||||
Cmd: shc(`echo "{{ .Name }} {{ .Os }} {{ .Arch }} {{ .Arm }} {{ .Target }} {{ .Ext }}" > {{ .Path }}.post`),
|
||||
Cmd: testlib.ShC(`echo "{{ .Name }} {{ .Os }} {{ .Arch }} {{ .Arm }} {{ .Target }} {{ .Ext }}" > {{ .Path }}.post`),
|
||||
Output: true,
|
||||
},
|
||||
},
|
||||
@ -330,7 +318,7 @@ func TestRun(t *testing.T) {
|
||||
t.Run("failing pre-hook", func(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"}}
|
||||
ctx.Config.UniversalBinaries[0].Hooks.Post = []config.Hook{{Cmd: "doesnt-matter"}}
|
||||
err := Pipe{}.Run(ctx)
|
||||
require.ErrorIs(t, err, exec.ErrNotFound)
|
||||
require.ErrorContains(t, err, "pre hook failed")
|
||||
@ -338,7 +326,7 @@ func TestRun(t *testing.T) {
|
||||
|
||||
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.Pre = []config.Hook{{Cmd: testlib.Echo("pre")}}
|
||||
ctx.Config.UniversalBinaries[0].Hooks.Post = []config.Hook{{Cmd: "exit 1"}}
|
||||
err := Pipe{}.Run(ctx)
|
||||
require.ErrorIs(t, err, exec.ErrNotFound)
|
||||
@ -364,7 +352,7 @@ func TestRun(t *testing.T) {
|
||||
ctx.Skips[string(skips.PostBuildHooks)] = false
|
||||
ctx.Skips[string(skips.PreBuildHooks)] = false
|
||||
ctx.Config.UniversalBinaries[0].Hooks.Pre = []config.Hook{{
|
||||
Cmd: echo + "{{.Env.FOO}}",
|
||||
Cmd: testlib.Echo("{{.Env.FOO}}"),
|
||||
Env: []string{"FOO=foo-{{.Tag}}"},
|
||||
}}
|
||||
ctx.Config.UniversalBinaries[0].Hooks.Post = []config.Hook{}
|
||||
@ -376,7 +364,7 @@ func TestRun(t *testing.T) {
|
||||
ctx.Skips[string(skips.PostBuildHooks)] = false
|
||||
ctx.Skips[string(skips.PreBuildHooks)] = false
|
||||
ctx.Config.UniversalBinaries[0].Hooks.Pre = []config.Hook{{
|
||||
Cmd: echo + "blah",
|
||||
Cmd: testlib.Echo("blah"),
|
||||
Env: []string{"FOO=foo-{{.Tag}"},
|
||||
}}
|
||||
ctx.Config.UniversalBinaries[0].Hooks.Post = []config.Hook{}
|
||||
@ -386,7 +374,7 @@ func TestRun(t *testing.T) {
|
||||
t.Run("hook with bad dir tmpl", func(t *testing.T) {
|
||||
ctx := ctx5
|
||||
ctx.Config.UniversalBinaries[0].Hooks.Pre = []config.Hook{{
|
||||
Cmd: echo + "blah",
|
||||
Cmd: testlib.Echo("blah"),
|
||||
Dir: "{{.Tag}",
|
||||
}}
|
||||
ctx.Config.UniversalBinaries[0].Hooks.Post = []config.Hook{}
|
||||
@ -396,7 +384,7 @@ func TestRun(t *testing.T) {
|
||||
t.Run("hook with bad cmd tmpl", func(t *testing.T) {
|
||||
ctx := ctx5
|
||||
ctx.Config.UniversalBinaries[0].Hooks.Pre = []config.Hook{{
|
||||
Cmd: echo + "blah-{{.Tag }",
|
||||
Cmd: testlib.Echo("blah-{{.Tag }"),
|
||||
}}
|
||||
ctx.Config.UniversalBinaries[0].Hooks.Post = []config.Hook{}
|
||||
testlib.RequireTemplateError(t, Pipe{}.Run(ctx))
|
||||
@ -429,10 +417,3 @@ func checkUniversalBinary(tb testing.TB, unibin *artifact.Artifact) {
|
||||
require.NoError(tb, err)
|
||||
require.Len(tb, f.Arches, 2)
|
||||
}
|
||||
|
||||
func shc(cmd string) string {
|
||||
if testlib.IsWindows() {
|
||||
return fmt.Sprintf("cmd.exe /c '%s'", cmd)
|
||||
}
|
||||
return fmt.Sprintf("sh -c '%s'", cmd)
|
||||
}
|
||||
|
@ -1,31 +1,39 @@
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package shell_test
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/goreleaser/goreleaser/v2/internal/shell"
|
||||
"github.com/goreleaser/goreleaser/v2/internal/testctx"
|
||||
"github.com/goreleaser/goreleaser/v2/internal/testlib"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestRunCommand(t *testing.T) {
|
||||
t.Run("simple", func(t *testing.T) {
|
||||
require.NoError(t, shell.Run(testctx.New(), "", []string{"echo", "oi"}, []string{}, false))
|
||||
require.NoError(t, shell.Run(
|
||||
testctx.New(),
|
||||
"",
|
||||
strings.Fields(testlib.Echo("oi")),
|
||||
[]string{},
|
||||
false,
|
||||
))
|
||||
})
|
||||
|
||||
t.Run("cmd failed", func(t *testing.T) {
|
||||
require.EqualError(
|
||||
t,
|
||||
shell.Run(testctx.New(), "", []string{"sh", "-c", "exit 1"}, []string{}, false),
|
||||
`shell: 'sh -c exit 1': exit status 1: [no output]`,
|
||||
)
|
||||
require.Error(t, shell.Run(
|
||||
testctx.New(),
|
||||
"",
|
||||
strings.Fields(testlib.Exit(1)),
|
||||
[]string{},
|
||||
false,
|
||||
))
|
||||
})
|
||||
|
||||
t.Run("cmd with output", func(t *testing.T) {
|
||||
testlib.SkipIfWindows(t, "what would be a similar behavior in windows?")
|
||||
require.EqualError(
|
||||
t,
|
||||
shell.Run(testctx.New(), "", []string{"sh", "-c", `echo something; exit 1`}, []string{}, true),
|
||||
@ -34,6 +42,7 @@ func TestRunCommand(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("with env and dir", func(t *testing.T) {
|
||||
testlib.SkipIfWindows(t, "what would be a similar behavior in windows?")
|
||||
dir := t.TempDir()
|
||||
require.NoError(t, shell.Run(testctx.New(), dir, []string{"sh", "-c", "touch $FOO"}, []string{"FOO=bar"}, false))
|
||||
require.FileExists(t, filepath.Join(dir, "bar"))
|
||||
|
@ -1,28 +0,0 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package shell_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/goreleaser/goreleaser/v2/internal/shell"
|
||||
"github.com/goreleaser/goreleaser/v2/internal/testctx"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestRunCommandWindows(t *testing.T) {
|
||||
t.Run("simple", func(t *testing.T) {
|
||||
require.NoError(t, shell.Run(testctx.New(), "", []string{"cmd.exe", "/c", "echo", "oi"}, []string{}, false))
|
||||
})
|
||||
|
||||
t.Run("cmd failed", func(t *testing.T) {
|
||||
require.EqualError(
|
||||
t,
|
||||
shell.Run(testctx.New(), "", []string{"cmd.exe", "/c", "exit /b 1"}, []string{}, false),
|
||||
`shell: 'cmd.exe /c exit /b 1': exit status 1: [no output]`,
|
||||
)
|
||||
})
|
||||
|
||||
// TODO: more tests for windows
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package testlib
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
@ -28,9 +29,42 @@ func InPath(cmd string) bool {
|
||||
func IsWindows() bool { return runtime.GOOS == "windows" }
|
||||
|
||||
// SkipIfWindows skips the test if runtime OS is windows.
|
||||
func SkipIfWindows(tb testing.TB) {
|
||||
func SkipIfWindows(tb testing.TB, args ...any) {
|
||||
tb.Helper()
|
||||
if IsWindows() {
|
||||
tb.Skip("test skipped on windows")
|
||||
tb.Skip(args...)
|
||||
}
|
||||
}
|
||||
|
||||
// Echo returns a `echo s` command, handling it on windows.
|
||||
func Echo(s string) string {
|
||||
if IsWindows() {
|
||||
return "cmd.exe /c echo " + s
|
||||
}
|
||||
return "echo " + s
|
||||
}
|
||||
|
||||
// Touch returns a `touch name` command, handling it on windows.
|
||||
func Touch(name string) string {
|
||||
if IsWindows() {
|
||||
return "cmd.exe /c copy nul " + name
|
||||
}
|
||||
return "touch " + name
|
||||
}
|
||||
|
||||
// ShC returns the command line for the given cmd wrapped into a `sh -c` in
|
||||
// linux/mac, and the cmd.exe command in windows.
|
||||
func ShC(cmd string) string {
|
||||
if IsWindows() {
|
||||
return fmt.Sprintf("cmd.exe /c '%s'", cmd)
|
||||
}
|
||||
return fmt.Sprintf("sh -c '%s'", cmd)
|
||||
}
|
||||
|
||||
// Exit returns a command that exits the given status, handling windows.
|
||||
func Exit(status int) string {
|
||||
if IsWindows() {
|
||||
return fmt.Sprintf("cmd.exe /c exit /b %d", status)
|
||||
}
|
||||
return fmt.Sprintf("exit %d", status)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user