GroupByAll and a duplicate GroupBy were showing up
in the marshaled config, which we don't want.

Signed-off-by: stuart nelson <stuartnelson3@gmail.com>
This commit is contained in:
stuart nelson 2018-12-13 11:51:49 +01:00 committed by GitHub
parent 34f78c9146
commit 082b1efed0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 3 deletions

View File

@ -526,9 +526,9 @@ func (c *GlobalConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
type Route struct {
Receiver string `yaml:"receiver,omitempty" json:"receiver,omitempty"`
GroupByStr []string `yaml:"group_by,omitempty" json:"group_by,omitempty"`
GroupBy []model.LabelName
GroupByAll bool
GroupByStr []string `yaml:"group_by,omitempty" json:"group_by,omitempty"`
GroupBy []model.LabelName `yaml:"-" json:"-"`
GroupByAll bool `yaml:"-" json:"-"`
Match map[string]string `yaml:"match,omitempty" json:"match,omitempty"`
MatchRE map[string]Regexp `yaml:"match_re,omitempty" json:"match_re,omitempty"`

View File

@ -469,6 +469,47 @@ func TestJSONUnmarshal(t *testing.T) {
}
}
func TestMarshalIdempotency(t *testing.T) {
c, _, err := LoadFile("testdata/conf.good.yml")
if err != nil {
t.Errorf("Error parsing %s: %s", "testdata/conf.good.yml", err)
}
marshaled, err := yaml.Marshal(c)
if err != nil {
t.Fatal("YAML Marshaling failed:", err)
}
c = new(Config)
if err := yaml.Unmarshal(marshaled, c); err != nil {
t.Fatal("YAML Unmarshaling failed:", err)
}
}
func TestGroupByAllNotMarshaled(t *testing.T) {
in := `
route:
receiver: team-X-mails
group_by: [...]
receivers:
- name: 'team-X-mails'
`
c, err := Load(in)
if err != nil {
t.Fatal("load failed:", err)
}
dat, err := yaml.Marshal(c)
if err != nil {
t.Fatal("YAML Marshaling failed:", err)
}
if strings.Contains(string(dat), "groupbyall") {
t.Fatal("groupbyall found in config file")
}
}
func TestEmptyFieldsAndRegex(t *testing.T) {
boolFoo := true
var regexpFoo Regexp