2018-08-26 15:17:15 +02:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/kr/pretty"
|
|
|
|
"path/filepath"
|
2018-08-26 16:44:34 +02:00
|
|
|
"testing"
|
2018-08-31 21:50:59 +02:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/zrepl/yaml-config"
|
2018-08-26 15:17:15 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestSampleConfigsAreParsedWithoutErrors(t *testing.T) {
|
|
|
|
paths, err := filepath.Glob("./samples/*")
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("glob failed: %+v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, p := range paths {
|
|
|
|
|
2018-08-26 23:11:50 +02:00
|
|
|
t.Run(p, func(t *testing.T) {
|
|
|
|
c, err := ParseConfig(p)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("error parsing %s:\n%+v", p, err)
|
|
|
|
}
|
2018-08-26 15:17:15 +02:00
|
|
|
|
2018-08-26 23:11:50 +02:00
|
|
|
t.Logf("file: %s", p)
|
|
|
|
t.Log(pretty.Sprint(c))
|
|
|
|
})
|
2018-08-26 15:17:15 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2018-08-31 21:50:59 +02:00
|
|
|
|
|
|
|
func TestLoggingOutletEnumList_SetDefaults(t *testing.T) {
|
|
|
|
e := &LoggingOutletEnumList{}
|
|
|
|
var i yaml.Defaulter = e
|
|
|
|
require.NotPanics(t, func() {
|
|
|
|
i.SetDefault()
|
|
|
|
assert.Equal(t, "warn", (*e)[0].Ret.(StdoutLoggingOutlet).Level)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func testValidConfig(t *testing.T, input string) (*Config) {
|
|
|
|
t.Helper()
|
|
|
|
conf, err := testConfig(t, input)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, conf)
|
|
|
|
return conf
|
|
|
|
}
|
|
|
|
|
|
|
|
func testConfig(t *testing.T, input string) (*Config, error) {
|
|
|
|
t.Helper()
|
|
|
|
return ParseConfigBytes([]byte(input))
|
|
|
|
}
|