mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-01 14:47:38 +00:00
a9525da8a4
This makes easier to read and debug these tests. This also reduces test lines count by 15% from 3K to 2.5K See https://itnext.io/f-tests-as-a-replacement-for-table-driven-tests-in-go-8814a8b19e9e While at it, consistently use t.Fatal* instead of t.Error*, since t.Error* usually leads to more complicated and fragile tests, while it doesn't bring any practical benefits over t.Fatal*.
40 lines
1.2 KiB
Go
40 lines
1.2 KiB
Go
package http
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
|
|
)
|
|
|
|
func TestAddHTTPTargetLabels(t *testing.T) {
|
|
f := func(src []httpGroupTarget, labelssExpected []*promutils.Labels) {
|
|
t.Helper()
|
|
|
|
labelss := addHTTPTargetLabels(src, "http://foo.bar/baz?aaa=bb")
|
|
discoveryutils.TestEqualLabelss(t, labelss, labelssExpected)
|
|
}
|
|
|
|
// add ok
|
|
src := []httpGroupTarget{
|
|
{
|
|
Targets: []string{"127.0.0.1:9100", "127.0.0.2:91001"},
|
|
Labels: promutils.NewLabelsFromMap(map[string]string{"__meta_kubernetes_pod": "pod-1", "__meta_consul_dc": "dc-2"}),
|
|
},
|
|
}
|
|
labelssExpected := []*promutils.Labels{
|
|
promutils.NewLabelsFromMap(map[string]string{
|
|
"__address__": "127.0.0.1:9100",
|
|
"__meta_kubernetes_pod": "pod-1",
|
|
"__meta_consul_dc": "dc-2",
|
|
"__meta_url": "http://foo.bar/baz?aaa=bb",
|
|
}),
|
|
promutils.NewLabelsFromMap(map[string]string{
|
|
"__address__": "127.0.0.2:91001",
|
|
"__meta_kubernetes_pod": "pod-1",
|
|
"__meta_consul_dc": "dc-2",
|
|
"__meta_url": "http://foo.bar/baz?aaa=bb",
|
|
}),
|
|
}
|
|
f(src, labelssExpected)
|
|
}
|