1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-24 04:16:27 +02:00
goreleaser/internal/pipe/before/before_test.go

77 lines
1.4 KiB
Go
Raw Normal View History

2018-03-28 15:31:09 +02:00
package before
import (
"io/ioutil"
"os"
2018-03-28 15:31:09 +02:00
"testing"
"github.com/goreleaser/goreleaser/pkg/config"
"github.com/goreleaser/goreleaser/pkg/context"
"github.com/stretchr/testify/require"
2018-03-28 15:31:09 +02:00
)
func TestDescription(t *testing.T) {
require.NotEmpty(t, Pipe{}.String())
2018-03-28 15:31:09 +02:00
}
func TestRunPipe(t *testing.T) {
for _, tc := range [][]string{
nil,
2018-04-03 21:37:16 -03:00
{},
{"go version"},
{"go version", "go list"},
2018-03-28 15:31:09 +02:00
} {
ctx := context.New(
config.Project{
Before: config.Before{
Hooks: tc,
},
},
)
require.NoError(t, Pipe{}.Run(ctx))
2018-03-28 15:31:09 +02:00
}
}
func TestRunPipeFail(t *testing.T) {
for _, tc := range [][]string{
2018-04-03 21:37:16 -03:00
{"go tool foobar"},
2018-03-28 15:31:09 +02:00
} {
ctx := context.New(
config.Project{
Before: config.Before{
Hooks: tc,
},
},
)
require.Error(t, Pipe{}.Run(ctx))
2018-03-28 15:31:09 +02:00
}
}
func TestRunWithEnv(t *testing.T) {
f, err := ioutil.TempFile("", "")
require.NoError(t, err)
require.NoError(t, os.Remove(f.Name()))
defer os.Remove(f.Name())
require.NoError(t, Pipe{}.Run(context.New(
config.Project{
Env: []string{
"TEST_FILE=" + f.Name(),
},
Before: config.Before{
Hooks: []string{"touch {{ .Env.TEST_FILE }}"},
},
},
)))
require.FileExists(t, f.Name())
}
func TestInvalidTemplate(t *testing.T) {
require.EqualError(t, Pipe{}.Run(context.New(
config.Project{
Before: config.Before{
Hooks: []string{"touch {{ .fasdsd }"},
},
},
)), `template: tmpl:1: unexpected "}" in operand`)
}