isle/go/daemon/daecommon/config_test.go

73 lines
1.4 KiB
Go
Raw Normal View History

package daecommon
import (
"isle/yamlutil"
"testing"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3"
)
func TestConfig_UnmarshalYAML(t *testing.T) { // TODO test validation
tests := []struct {
label string
str string
config Config
}{
{"empty", ``, Config{}},
{
"DEPRECATED single global network",
`
{"dns":{"resolvers":["a"]}}
`,
Config{
Networks: map[string]NetworkConfig{
DeprecatedNetworkID: NewNetworkConfig(func(c *NetworkConfig) {
c.DNS.Resolvers = []string{"a"}
}),
},
},
},
{
"single network",
`
networks:
foo: {"dns":{"resolvers":["a"]}}
`,
Config{
Networks: map[string]NetworkConfig{
"foo": NewNetworkConfig(func(c *NetworkConfig) {
c.DNS.Resolvers = []string{"a"}
}),
},
},
},
{
"multiple networks",
`
networks:
foo: {"dns":{"resolvers":["a"]}}
bar: {}
`,
Config{
Networks: map[string]NetworkConfig{
"foo": NewNetworkConfig(func(c *NetworkConfig) {
c.DNS.Resolvers = []string{"a"}
}),
"bar": NewNetworkConfig(nil),
},
},
},
}
for _, test := range tests {
t.Run(test.label, func(t *testing.T) {
test.str = yamlutil.ReplacePrefixTabs(test.str)
var config Config
err := yaml.Unmarshal([]byte(test.str), &config)
assert.NoError(t, err)
assert.Equal(t, test.config, config)
})
}
}