From 767faa44b6d59ae255d8d431eb36e5293ba02748 Mon Sep 17 00:00:00 2001 From: Krasi Georgiev Date: Sat, 30 Dec 2017 17:47:18 +0000 Subject: [PATCH] fixed the tests Signed-off-by: Krasi Georgiev --- discovery/manager_test.go | 13 +++++++++++-- notifier/notifier_test.go | 21 ++++++++++++++------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/discovery/manager_test.go b/discovery/manager_test.go index f3ecf784e..cf2b7e81e 100644 --- a/discovery/manager_test.go +++ b/discovery/manager_test.go @@ -24,6 +24,7 @@ import ( "github.com/prometheus/common/model" "github.com/prometheus/prometheus/config" + sd_config "github.com/prometheus/prometheus/discovery/config" "github.com/prometheus/prometheus/discovery/targetgroup" "gopkg.in/yaml.v2" ) @@ -743,7 +744,11 @@ scrape_configs: discoveryManager := NewManager(nil) go discoveryManager.Run(ctx) - discoveryManager.ApplyConfig(cfg) + c := make(map[string]sd_config.ServiceDiscoveryConfig) + for _, v := range cfg.ScrapeConfigs { + c[v.JobName] = v.ServiceDiscoveryConfig + } + discoveryManager.ApplyConfig(c) _ = <-discoveryManager.SyncCh() verifyPresence(discoveryManager.targets, poolKey{setName: "prometheus", provider: "static/0"}, "{__address__=\"foo:9090\"}", true) @@ -758,7 +763,11 @@ scrape_configs: if err := yaml.Unmarshal([]byte(sTwo), cfg); err != nil { t.Fatalf("Unable to load YAML config sOne: %s", err) } - discoveryManager.ApplyConfig(cfg) + c = make(map[string]sd_config.ServiceDiscoveryConfig) + for _, v := range cfg.ScrapeConfigs { + c[v.JobName] = v.ServiceDiscoveryConfig + } + discoveryManager.ApplyConfig(c) _ = <-discoveryManager.SyncCh() verifyPresence(discoveryManager.targets, poolKey{setName: "prometheus", provider: "static/0"}, "{__address__=\"foo:9090\"}", true) diff --git a/notifier/notifier_test.go b/notifier/notifier_test.go index 7ffc8d55e..ab62896db 100644 --- a/notifier/notifier_test.go +++ b/notifier/notifier_test.go @@ -173,7 +173,10 @@ func TestHandlerSendAll(t *testing.T) { Password: "testing_password", }, }, "auth_alertmanager") - h.alertmanagers = append(h.alertmanagers, &alertmanagerSet{ + + h.alertmanagers = make(map[string]*alertmanagerSet) + + h.alertmanagers["1"] = &alertmanagerSet{ ams: []alertmanager{ alertmanagerMock{ urlf: func() string { return server1.URL }, @@ -183,9 +186,9 @@ func TestHandlerSendAll(t *testing.T) { Timeout: time.Second, }, client: authClient, - }) + } - h.alertmanagers = append(h.alertmanagers, &alertmanagerSet{ + h.alertmanagers["2"] = &alertmanagerSet{ ams: []alertmanager{ alertmanagerMock{ urlf: func() string { return server2.URL }, @@ -194,7 +197,7 @@ func TestHandlerSendAll(t *testing.T) { cfg: &config.AlertmanagerConfig{ Timeout: time.Second, }, - }) + } for i := range make([]struct{}, maxBatchSize) { h.queue = append(h.queue, &Alert{ @@ -355,7 +358,10 @@ func TestHandlerQueueing(t *testing.T) { }, nil, ) - h.alertmanagers = append(h.alertmanagers, &alertmanagerSet{ + + h.alertmanagers = make(map[string]*alertmanagerSet) + + h.alertmanagers["1"] = &alertmanagerSet{ ams: []alertmanager{ alertmanagerMock{ urlf: func() string { return server.URL }, @@ -364,7 +370,7 @@ func TestHandlerQueueing(t *testing.T) { cfg: &config.AlertmanagerConfig{ Timeout: time.Second, }, - }) + } var alerts []*Alert @@ -374,7 +380,8 @@ func TestHandlerQueueing(t *testing.T) { }) } - go h.Run() + c := make(chan map[string][]*targetgroup.Group) + go h.Run(c) defer h.Stop() h.Send(alerts[:4*maxBatchSize]...)