2020-04-12 17:13:20 +02:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-03-29 19:00:53 +02:00
|
|
|
"github.com/goreleaser/goreleaser/internal/yaml"
|
2020-10-06 14:48:04 +02:00
|
|
|
"github.com/stretchr/testify/require"
|
2020-04-12 17:13:20 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestBuildHook_justString(t *testing.T) {
|
2021-11-01 14:31:43 +02:00
|
|
|
var actual BuildHookConfig
|
2020-04-12 17:13:20 +02:00
|
|
|
|
|
|
|
err := yaml.UnmarshalStrict([]byte(`pre: ./script.sh`), &actual)
|
2020-10-06 14:48:04 +02:00
|
|
|
require.NoError(t, err)
|
2021-11-01 14:31:43 +02:00
|
|
|
require.Equal(t, Hook{
|
2020-04-12 17:13:20 +02:00
|
|
|
Cmd: "./script.sh",
|
|
|
|
Env: nil,
|
|
|
|
}, actual.Pre[0])
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBuildHook_stringCmds(t *testing.T) {
|
2021-11-01 14:31:43 +02:00
|
|
|
var actual BuildHookConfig
|
2020-04-12 17:13:20 +02:00
|
|
|
|
|
|
|
err := yaml.UnmarshalStrict([]byte(`pre:
|
|
|
|
- ./script.sh
|
|
|
|
- second-script.sh
|
|
|
|
`), &actual)
|
2020-10-06 14:48:04 +02:00
|
|
|
require.NoError(t, err)
|
2020-04-12 17:13:20 +02:00
|
|
|
|
2021-11-01 14:31:43 +02:00
|
|
|
require.Equal(t, Hooks{
|
2020-04-12 17:13:20 +02:00
|
|
|
{
|
|
|
|
Cmd: "./script.sh",
|
|
|
|
Env: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Cmd: "second-script.sh",
|
|
|
|
Env: nil,
|
|
|
|
},
|
|
|
|
}, actual.Pre)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBuildHook_complex(t *testing.T) {
|
2021-11-01 14:31:43 +02:00
|
|
|
var actual BuildHookConfig
|
2020-04-12 17:13:20 +02:00
|
|
|
|
|
|
|
err := yaml.UnmarshalStrict([]byte(`pre:
|
|
|
|
- cmd: ./script.sh
|
|
|
|
env:
|
|
|
|
- TEST=value
|
|
|
|
`), &actual)
|
2020-10-06 14:48:04 +02:00
|
|
|
require.NoError(t, err)
|
2021-11-01 14:31:43 +02:00
|
|
|
require.Equal(t, Hook{
|
2020-04-12 17:13:20 +02:00
|
|
|
Cmd: "./script.sh",
|
|
|
|
Env: []string{"TEST=value"},
|
|
|
|
}, actual.Pre[0])
|
|
|
|
}
|