2021-02-01 00:10:16 +01:00
|
|
|
package vm
|
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
2024-07-12 08:59:31 +02:00
|
|
|
func TestAddExtraLabelsToImportPath_Failure(t *testing.T) {
|
|
|
|
f := func(path string, extraLabels []string) {
|
|
|
|
t.Helper()
|
|
|
|
|
|
|
|
_, err := AddExtraLabelsToImportPath(path, extraLabels)
|
|
|
|
if err == nil {
|
|
|
|
t.Fatalf("expecting non-nil error")
|
|
|
|
}
|
2021-02-01 00:10:16 +01:00
|
|
|
}
|
2024-07-12 08:59:31 +02:00
|
|
|
|
|
|
|
// bad incorrect format for extra label
|
|
|
|
f("/api/v1/import", []string{"label=value", "bad_label_wo_value"})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAddExtraLabelsToImportPath_Success(t *testing.T) {
|
|
|
|
f := func(path string, extraLabels []string, resultExpected string) {
|
|
|
|
t.Helper()
|
|
|
|
|
|
|
|
result, err := AddExtraLabelsToImportPath(path, extraLabels)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("AddExtraLabelsToImportPath() error: %s", err)
|
|
|
|
}
|
|
|
|
if result != resultExpected {
|
|
|
|
t.Fatalf("unexpected result; got %q; want %q", result, resultExpected)
|
|
|
|
}
|
2021-02-01 00:10:16 +01:00
|
|
|
}
|
2024-07-12 08:59:31 +02:00
|
|
|
|
|
|
|
// ok w/o extra labels
|
|
|
|
f("/api/v1/import", nil, "/api/v1/import")
|
|
|
|
|
|
|
|
// ok one extra label
|
|
|
|
f("/api/v1/import", []string{"instance=host-1"}, "/api/v1/import?extra_label=instance=host-1")
|
|
|
|
|
|
|
|
// ok two extra labels
|
|
|
|
f("/api/v1/import", []string{"instance=host-2", "job=vmagent"}, "/api/v1/import?extra_label=instance=host-2&extra_label=job=vmagent")
|
|
|
|
|
|
|
|
// ok two extra with exist param
|
|
|
|
f("/api/v1/import?timeout=50", []string{"instance=host-2", "job=vmagent"}, "/api/v1/import?timeout=50&extra_label=instance=host-2&extra_label=job=vmagent")
|
2021-02-01 00:10:16 +01:00
|
|
|
}
|