Commit 8eba91a0 by shammash

fix template config loading

Signed-off-by: shammash <shammash@autistici.org>
parent c0c22cd5
Pipeline #335 passed with stages
in 1 minute 17 seconds
Showing with 32 additions and 4 deletions
......@@ -53,10 +53,13 @@ func LoadConfig(configFile string) (*Config, error) {
}
}
if config.NoticeOnce {
config.NoticeTemplate = defaultNoticeOnceTemplate
} else {
config.NoticeTemplate = defaultNoticeTemplate
// Set default template if config does not have one.
if config.NoticeTemplate == "" {
if config.NoticeOnce {
config.NoticeTemplate = defaultNoticeOnceTemplate
} else {
config.NoticeTemplate = defaultNoticeTemplate
}
}
return config, nil
......
package main
import (
"fmt"
"gopkg.in/yaml.v2"
"io/ioutil"
"os"
......@@ -139,3 +140,27 @@ func TestNoticeDefaultTemplate(t *testing.T) {
t.Error("Expecting defaultNoticeTemplate when NoticeOnce is false")
}
}
func TestGivenTemplateNotOverwritten(t *testing.T) {
tmpfile, err := ioutil.TempFile("", "jinxertestexpectedtemmplate")
if err != nil {
t.Error("Could not create tmpfile for testing: %s", err)
}
defer os.Remove(tmpfile.Name())
expectedTemplate := "Alert {{ .Status }}: {{ .Annotations.SUMMARY }}"
configData := []byte(fmt.Sprintf("notice_template: \"%s\"", expectedTemplate))
if _, err := tmpfile.Write(configData); err != nil {
t.Error("Could not write test data in tmpfile: %s", err)
}
tmpfile.Close()
config, err := LoadConfig(tmpfile.Name())
if config == nil {
t.Error("Expected a config, got: %s", err)
}
if config.NoticeTemplate != expectedTemplate {
t.Error("Template does not match configuration")
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment