mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-06 03:13:48 +02:00
8d6ef40020
* chore(yaml): upgraded from yaml.v2 to yaml.v3 * provided internal package to take care of backward compatible settings: * UnmarshalStrict method * mute io.EOF unmarshaling errors * marshal indenting with 2 chars * adapted unit tests to new yaml v3 Signed-off-by: Frederic BIDON <fredbi@yahoo.com> * fixed failing tests Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
116 lines
1.9 KiB
Go
116 lines
1.9 KiB
Go
package config
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/goreleaser/goreleaser/internal/yaml"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
type Unmarshaled struct {
|
|
Strings StringArray `yaml:"strings,omitempty"`
|
|
Flags FlagArray `yaml:"flags,omitempty"`
|
|
}
|
|
|
|
type yamlUnmarshalTestCase struct {
|
|
yaml string
|
|
expected Unmarshaled
|
|
err string
|
|
}
|
|
|
|
var stringArrayTests = []yamlUnmarshalTestCase{
|
|
{
|
|
"",
|
|
Unmarshaled{},
|
|
"",
|
|
},
|
|
{
|
|
"strings: []",
|
|
Unmarshaled{
|
|
Strings: StringArray{},
|
|
},
|
|
"",
|
|
},
|
|
{
|
|
"strings: [one two, three]",
|
|
Unmarshaled{
|
|
Strings: StringArray{"one two", "three"},
|
|
},
|
|
"",
|
|
},
|
|
{
|
|
"strings: one two",
|
|
Unmarshaled{
|
|
Strings: StringArray{"one two"},
|
|
},
|
|
"",
|
|
},
|
|
{
|
|
"strings: {key: val}",
|
|
Unmarshaled{},
|
|
"yaml: unmarshal errors:\n line 1: cannot unmarshal !!map into string",
|
|
},
|
|
}
|
|
|
|
var flagArrayTests = []yamlUnmarshalTestCase{
|
|
{
|
|
"",
|
|
Unmarshaled{},
|
|
"",
|
|
},
|
|
{
|
|
"flags: []",
|
|
Unmarshaled{
|
|
Flags: FlagArray{},
|
|
},
|
|
"",
|
|
},
|
|
{
|
|
"flags: [one two, three]",
|
|
Unmarshaled{
|
|
Flags: FlagArray{"one two", "three"},
|
|
},
|
|
"",
|
|
},
|
|
{
|
|
"flags: one two",
|
|
Unmarshaled{
|
|
Flags: FlagArray{"one", "two"},
|
|
},
|
|
"",
|
|
},
|
|
{
|
|
"flags: {key: val}",
|
|
Unmarshaled{},
|
|
"yaml: unmarshal errors:\n line 1: cannot unmarshal !!map into string",
|
|
},
|
|
}
|
|
|
|
func TestStringArray(t *testing.T) {
|
|
for _, testCase := range stringArrayTests {
|
|
var actual Unmarshaled
|
|
|
|
err := yaml.UnmarshalStrict([]byte(testCase.yaml), &actual)
|
|
if testCase.err == "" {
|
|
require.NoError(t, err)
|
|
require.Equal(t, testCase.expected, actual)
|
|
} else {
|
|
require.EqualError(t, err, testCase.err)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestFlagArray(t *testing.T) {
|
|
for _, testCase := range flagArrayTests {
|
|
var actual Unmarshaled
|
|
|
|
err := yaml.UnmarshalStrict([]byte(testCase.yaml), &actual)
|
|
if testCase.err == "" {
|
|
require.NoError(t, err)
|
|
} else {
|
|
require.EqualError(t, err, testCase.err)
|
|
}
|
|
require.Equal(t, testCase.expected, actual)
|
|
}
|
|
}
|