forked from louisfelix/alertmanager-silences-exporter
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig_test.go
61 lines (51 loc) · 1.13 KB
/
config_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"io/ioutil"
"os"
"testing"
)
func TestLoadConfig_No_Env_No_Config(t *testing.T) {
os.Setenv("ALERTMANAGER_URL", "")
_, err := loadConfig("no-config.yml")
if err == nil {
t.Error(err)
}
}
func TestLoadConfig_Config_OK(t *testing.T) {
confStr := `
---
alertmanager_url: "http://localhost:9093/"
`
err := ioutil.WriteFile("test-config.yml", []byte(confStr), 0755)
if err != nil {
t.Error(err)
}
want := "http://localhost:9093/"
conf, err := loadConfig("sample-config.yml")
if err != nil {
t.Error(err)
}
if conf.AlertmanagerURL != want {
t.Errorf("want '%s' got '%s'", want, conf.AlertmanagerURL)
}
err = os.Remove("test-config.yml")
if err != nil {
t.Error(err)
}
}
func TestNewAlertmanagerSilencesCollector_Env_OK(t *testing.T) {
err := os.Setenv("ALERTMANAGER_URL", "http://localhost:9093/")
if err != nil {
t.Error(err)
}
conf, err := loadConfig("")
if err != nil {
t.Error(err)
}
asc := NewAlertmanagerSilencesCollector(conf, &AlertmanagerClient{})
got := asc.Config.AlertmanagerURL
want := "http://localhost:9093/"
if got != want {
t.Errorf("got '%s' want '%s'", got, want)
}
}