2018-03-28 15:31:09 +02:00
|
|
|
package before
|
|
|
|
|
|
|
|
import (
|
2019-03-03 14:12:22 -03:00
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
2018-03-28 15:31:09 +02:00
|
|
|
"testing"
|
|
|
|
|
2018-08-14 23:50:20 -03:00
|
|
|
"github.com/goreleaser/goreleaser/pkg/config"
|
|
|
|
"github.com/goreleaser/goreleaser/pkg/context"
|
2019-03-03 14:12:22 -03:00
|
|
|
"github.com/stretchr/testify/require"
|
2018-03-28 15:31:09 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestDescription(t *testing.T) {
|
2019-03-03 14:12:22 -03:00
|
|
|
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,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
2019-03-03 14:12:22 -03:00
|
|
|
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,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
2019-03-03 14:12:22 -03:00
|
|
|
require.Error(t, Pipe{}.Run(ctx))
|
2018-03-28 15:31:09 +02:00
|
|
|
}
|
|
|
|
}
|
2019-03-03 14:12:22 -03: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`)
|
|
|
|
}
|