mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-10 15:44:05 -08:00
Move test helper function into scope of test func
This commit is contained in:
parent
79216011cb
commit
b9fb9742ed
|
@ -24,6 +24,18 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTargetSetRecreatesTargetGroupsEveryRun(t *testing.T) {
|
func TestTargetSetRecreatesTargetGroupsEveryRun(t *testing.T) {
|
||||||
|
|
||||||
|
verifyPresence := func(tgroups map[string][]*Target, name string, present bool) {
|
||||||
|
if _, ok := tgroups[name]; ok != present {
|
||||||
|
msg := ""
|
||||||
|
if !present {
|
||||||
|
msg = "not "
|
||||||
|
}
|
||||||
|
t.Fatalf("'%s' should %sbe present in TargetSet.tgroups: %s", name, msg, tgroups)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
scrapeConfig := &config.ScrapeConfig{}
|
scrapeConfig := &config.ScrapeConfig{}
|
||||||
|
|
||||||
sOne := `
|
sOne := `
|
||||||
|
@ -43,7 +55,7 @@ dns_sd_configs:
|
||||||
|
|
||||||
ts.runProviders(context.Background(), providersFromConfig(scrapeConfig))
|
ts.runProviders(context.Background(), providersFromConfig(scrapeConfig))
|
||||||
|
|
||||||
verifyPresence(t, ts.tgroups, "dns/0/srv.name.one.example.org", true)
|
verifyPresence(ts.tgroups, "dns/0/srv.name.one.example.org", true)
|
||||||
|
|
||||||
sTwo := `
|
sTwo := `
|
||||||
job_name: "foo"
|
job_name: "foo"
|
||||||
|
@ -57,18 +69,6 @@ dns_sd_configs:
|
||||||
|
|
||||||
ts.runProviders(context.Background(), providersFromConfig(scrapeConfig))
|
ts.runProviders(context.Background(), providersFromConfig(scrapeConfig))
|
||||||
|
|
||||||
verifyPresence(t, ts.tgroups, "dns/0/srv.name.one.example.org", false)
|
verifyPresence(ts.tgroups, "dns/0/srv.name.one.example.org", false)
|
||||||
verifyPresence(t, ts.tgroups, "dns/0/srv.name.two.example.org", true)
|
verifyPresence(ts.tgroups, "dns/0/srv.name.two.example.org", true)
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func verifyPresence(t *testing.T, tgroups map[string][]*Target, name string, present bool) {
|
|
||||||
if _, ok := tgroups[name]; ok != present {
|
|
||||||
msg := ""
|
|
||||||
if !present {
|
|
||||||
msg = "not "
|
|
||||||
}
|
|
||||||
t.Fatalf("'%s' should %sbe present in TargetSet.tgroups: %s", name, msg, tgroups)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue