traefik/pkg/config/file/file_test.go
Ludovic Fernandez 8d7eccad5d New static configuration loading system.
Co-authored-by: Mathieu Lonjaret <mathieu.lonjaret@gmail.com>
2019-06-17 11:48:05 +02:00

76 lines
1.1 KiB
Go

package file
import (
"io/ioutil"
"os"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestDecode_TOML(t *testing.T) {
f, err := ioutil.TempFile("", "traefik-config-*.toml")
require.NoError(t, err)
defer func() {
_ = os.Remove(f.Name())
}()
_, err = f.Write([]byte(`
foo = "bar"
fii = "bir"
[yi]
`))
require.NoError(t, err)
element := &Yo{
Fuu: "test",
}
err = Decode(f.Name(), element)
require.NoError(t, err)
expected := &Yo{
Foo: "bar",
Fii: "bir",
Fuu: "test",
Yi: &Yi{
Foo: "foo",
Fii: "fii",
},
}
assert.Equal(t, expected, element)
}
func TestDecode_YAML(t *testing.T) {
f, err := ioutil.TempFile("", "traefik-config-*.yaml")
require.NoError(t, err)
defer func() {
_ = os.Remove(f.Name())
}()
_, err = f.Write([]byte(`
foo: bar
fii: bir
yi: {}
`))
require.NoError(t, err)
element := &Yo{
Fuu: "test",
}
err = Decode(f.Name(), element)
require.NoError(t, err)
expected := &Yo{
Foo: "bar",
Fii: "bir",
Fuu: "test",
Yi: &Yi{
Foo: "foo",
Fii: "fii",
},
}
assert.Equal(t, expected, element)
}