mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Fix missing defaults in empty configurations
This commit is contained in:
parent
b4aa96c58a
commit
2a53b107c1
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue