提交 2a53b107 编写于 作者: F Fabian Reinartz

Fix missing defaults in empty configurations

上级 b4aa96c5
......@@ -26,6 +26,11 @@ var (
// Load parses the YAML input s into a Config.
func Load(s string) (*Config, error) {
cfg := &Config{}
// If the entire config body is empty the UnmarshalYAML method is
// never called. We thus have to set the DefaultConfig at the entry
// point as well.
*cfg = DefaultConfig
err := yaml.Unmarshal([]byte(s), cfg)
if err != nil {
return nil, err
......
......@@ -249,3 +249,15 @@ func TestBadTargetGroup(t *testing.T) {
t.Errorf("Expected unmarshal error but got none.")
}
}
func TestEmptyConfig(t *testing.T) {
c, err := Load("")
if err != nil {
t.Fatalf("Unexpected error parsing empty config file: %s", err)
}
exp := DefaultConfig
if !reflect.DeepEqual(*c, exp) {
t.Fatalf("want %v, got %v", exp, c)
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册