1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2024-12-12 08:23:48 +02:00
woodpecker/pipeline/frontend/yaml/network_test.go
6543 fc6a2a9975
Remove github.com/kr/pretty in favor of assert.EqualValues() (#564)
* remove github.com/kr/pretty in favor of assert.EqualValues()

* code format
2021-12-04 13:23:33 +01:00

98 lines
1.7 KiB
Go

package yaml
import (
"testing"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3"
)
func TestUnmarshalNetwork(t *testing.T) {
testdata := []struct {
from string
want Network
}{
{
from: "{ name: foo, driver: bar }",
want: Network{
Name: "foo",
Driver: "bar",
},
},
{
from: "{ name: foo, driver: bar, driver_opts: { baz: qux } }",
want: Network{
Name: "foo",
Driver: "bar",
DriverOpts: map[string]string{
"baz": "qux",
},
},
},
}
for _, test := range testdata {
in := []byte(test.from)
got := Network{}
err := yaml.Unmarshal(in, &got)
assert.NoError(t, err)
assert.EqualValues(t, test.want, got, "problem parsing network %q", test.from)
}
}
func TestUnmarshalNetworks(t *testing.T) {
testdata := []struct {
from string
want []*Network
}{
{
from: "foo: { driver: bar }",
want: []*Network{
{
Name: "foo",
Driver: "bar",
},
},
},
{
from: "foo: { name: baz }",
want: []*Network{
{
Name: "baz",
Driver: "bridge",
},
},
},
{
from: "foo: { name: baz, driver: bar }",
want: []*Network{
{
Name: "baz",
Driver: "bar",
},
},
},
}
for _, test := range testdata {
in := []byte(test.from)
got := Networks{}
err := yaml.Unmarshal(in, &got)
assert.NoError(t, err)
assert.EqualValues(t, test.want, got.Networks, "problem parsing network %q", test.from)
}
}
func TestUnmarshalNetworkErr(t *testing.T) {
testdata := []string{
"foo: { name: [ foo, bar] }",
"- foo",
}
for _, test := range testdata {
in := []byte(test)
err := yaml.Unmarshal(in, new(Networks))
assert.Error(t, err, "wanted error for networks %q", test)
}
}