Fix missing defaults in empty configurations

This commit is contained in:
Fabian Reinartz 2015-07-17 16:12:33 +02:00
parent b4aa96c58a
commit 2a53b107c1
2 changed files with 17 additions and 0 deletions

View file

@ -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

View file

@ -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)
}
}