VictoriaMetrics/app/vmagent/remotewrite/remotewrite_test.go
hagen1778 b6bd9a97a3
app/vmagent: follow-up 166b97b8d0
* add tests for sharding function
* update flags description
* add changelog note

166b97b8d0
Signed-off-by: hagen1778 <roman@victoriametrics.com>
2024-03-29 14:08:08 +01:00

39 lines
1.2 KiB
Go

package remotewrite
import (
"reflect"
"testing"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/prompbmarshal"
)
func TestExtractShardingLabels(t *testing.T) {
shardByURLLabelsMap = make(map[string]struct{})
shardByURLLabelsMap["instance"] = struct{}{}
shardByURLLabelsMap["job"] = struct{}{}
defer func() {
shardByURLLabelsMap = nil
}()
f := func(in, exp []prompbmarshal.Label, inverse bool) {
t.Helper()
var got []prompbmarshal.Label
got = extractShardingLabels(got, in, inverse)
if !reflect.DeepEqual(got, exp) {
t.Fatalf("expected to get \n%#v; \ngot \n%#v instead", exp, got)
}
}
f(nil, nil, true)
f(nil, nil, false)
f([]prompbmarshal.Label{{Name: "foo"}}, nil, false)
f([]prompbmarshal.Label{{Name: "foo"}}, []prompbmarshal.Label{{Name: "foo"}}, true)
f([]prompbmarshal.Label{{Name: "foo"}, {Name: "job"}}, []prompbmarshal.Label{{Name: "job"}}, false)
f([]prompbmarshal.Label{{Name: "foo"}, {Name: "job"}}, []prompbmarshal.Label{{Name: "foo"}}, true)
f([]prompbmarshal.Label{{Name: "foo"}, {Name: "instance"}, {Name: "job"}}, []prompbmarshal.Label{{Name: "instance"}, {Name: "job"}}, false)
f([]prompbmarshal.Label{{Name: "foo"}, {Name: "instance"}, {Name: "job"}}, []prompbmarshal.Label{{Name: "foo"}}, true)
}