mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-10 03:47:03 +02:00
cf4aba68d3
* feat: global env * docs: hooks templateable, global env * docs: hooks templateable, global env * feat: templas on before hooks * docs: revert unwanted change * fix: use os.environ too * chore: travis * fix: goreleaser.yml
77 lines
1.4 KiB
Go
77 lines
1.4 KiB
Go
package before
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/goreleaser/goreleaser/pkg/config"
|
|
"github.com/goreleaser/goreleaser/pkg/context"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestDescription(t *testing.T) {
|
|
require.NotEmpty(t, Pipe{}.String())
|
|
}
|
|
|
|
func TestRunPipe(t *testing.T) {
|
|
for _, tc := range [][]string{
|
|
nil,
|
|
{},
|
|
{"go version"},
|
|
{"go version", "go list"},
|
|
} {
|
|
ctx := context.New(
|
|
config.Project{
|
|
Before: config.Before{
|
|
Hooks: tc,
|
|
},
|
|
},
|
|
)
|
|
require.NoError(t, Pipe{}.Run(ctx))
|
|
}
|
|
}
|
|
|
|
func TestRunPipeFail(t *testing.T) {
|
|
for _, tc := range [][]string{
|
|
{"go tool foobar"},
|
|
} {
|
|
ctx := context.New(
|
|
config.Project{
|
|
Before: config.Before{
|
|
Hooks: tc,
|
|
},
|
|
},
|
|
)
|
|
require.Error(t, Pipe{}.Run(ctx))
|
|
}
|
|
}
|
|
|
|
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`)
|
|
}
|