1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2024-12-12 08:23:48 +02:00
woodpecker/pipeline/frontend/yaml/volume_test.go

109 lines
1.8 KiB
Go
Raw Normal View History

2019-04-06 15:44:04 +02:00
package yaml
import (
"reflect"
"testing"
"github.com/kr/pretty"
2019-11-14 21:16:03 +02:00
"gopkg.in/yaml.v3"
2019-04-06 15:44:04 +02:00
)
func TestUnmarshalVolume(t *testing.T) {
testdata := []struct {
from string
want Volume
}{
{
from: "{ name: foo, driver: bar }",
want: Volume{
Name: "foo",
Driver: "bar",
},
},
{
from: "{ name: foo, driver: bar, driver_opts: { baz: qux } }",
want: Volume{
Name: "foo",
Driver: "bar",
DriverOpts: map[string]string{
"baz": "qux",
},
},
},
}
for _, test := range testdata {
in := []byte(test.from)
got := Volume{}
err := yaml.Unmarshal(in, &got)
if err != nil {
t.Error(err)
} else if !reflect.DeepEqual(test.want, got) {
t.Errorf("problem parsing volume %q", test.from)
pretty.Ldiff(t, test.want, got)
}
}
}
func TestUnmarshalVolumes(t *testing.T) {
testdata := []struct {
from string
want []*Volume
}{
{
from: "foo: { driver: bar }",
want: []*Volume{
{
Name: "foo",
Driver: "bar",
},
},
},
{
from: "foo: { name: baz }",
want: []*Volume{
{
Name: "baz",
Driver: "local",
},
},
},
{
from: "foo: { name: baz, driver: bar }",
want: []*Volume{
{
Name: "baz",
Driver: "bar",
},
},
},
}
for _, test := range testdata {
in := []byte(test.from)
got := Volumes{}
err := yaml.Unmarshal(in, &got)
if err != nil {
t.Error(err)
} else if !reflect.DeepEqual(test.want, got.Volumes) {
t.Errorf("problem parsing volumes %q", test.from)
pretty.Ldiff(t, test.want, got.Volumes)
}
}
}
func TestUnmarshalVolumesErr(t *testing.T) {
testdata := []string{
"foo: { name: [ foo, bar] }",
"- foo",
}
for _, test := range testdata {
in := []byte(test)
err := yaml.Unmarshal(in, new(Volumes))
if err == nil {
t.Errorf("wanted error for volumes %q", test)
}
}
}