1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-08 03:31:59 +02:00
goreleaser/internal/shell/shell_test.go
Carlos Alexandro Becker f544c5ce69
test: testctx pkg (#3807)
alternative to #3806 

the idea is that both `context.New` and `context.Context{}` are never
used in tests.

not sure yet how much I like it, so far code does look a bit more
readable though.

---------

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
2023-03-02 00:01:11 -03:00

39 lines
1.1 KiB
Go

package shell_test
import (
"path/filepath"
"testing"
"github.com/goreleaser/goreleaser/internal/shell"
"github.com/goreleaser/goreleaser/internal/testctx"
"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))
})
t.Run("cmd failed", func(t *testing.T) {
require.EqualError(
t,
shell.Run(testctx.New(), "", []string{"sh", "-c", "exit 1"}, []string{}, false),
`failed to run 'sh -c exit 1': exit status 1`,
)
})
t.Run("cmd with output", func(t *testing.T) {
require.EqualError(
t,
shell.Run(testctx.New(), "", []string{"sh", "-c", `echo something; exit 1`}, []string{}, true),
`failed to run 'sh -c echo something; exit 1': exit status 1`,
)
})
t.Run("with env and dir", func(t *testing.T) {
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"))
})
}