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