MCPcopy Index your code
hub / github.com/prometheus/pushgateway / TestSplitLabelsUTF8

Function TestSplitLabelsUTF8

handler/handler_test.go:868–920  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

866}
867
868func TestSplitLabelsUTF8(t *testing.T) {
869 scenarios := map[string]struct {
870 input string
871 expectError bool
872 expectedOutput map[string]string
873 }{
874 "regular label and UTF-8 escaped label name": {
875 input: "/label_name1/label_value1/U__label_2e_name2/label_value2",
876 expectedOutput: map[string]string{
877 "label_name1": "label_value1",
878 "label.name2": "label_value2",
879 },
880 },
881 "encoded slash in both label values and UTF-8 escaped label name": {
882 input: "/label_name1@base64/bGFiZWwvdmFsdWUx/U__label_2e_name2@base64/bGFiZWwvdmFsdWUy",
883 expectedOutput: map[string]string{
884 "label_name1": "label/value1",
885 "label.name2": "label/value2",
886 },
887 },
888 }
889
890 ValidationScheme = model.UTF8Validation
891 EscapingScheme = model.ValueEncodingEscaping
892
893 for name, scenario := range scenarios {
894 t.Run(name, func(t *testing.T) {
895 parsed, err := splitLabels(scenario.input)
896 if err != nil {
897 if scenario.expectError {
898 return // All good.
899 }
900 t.Fatalf("Got unexpected error: %s.", err)
901 }
902 for k, v := range scenario.expectedOutput {
903 got, ok := parsed[k]
904 if !ok {
905 t.Errorf("Expected to find %s=%q.", k, v)
906 }
907 if got != v {
908 t.Errorf("Expected %s=%q but got %s=%q.", k, v, k, got)
909 }
910 delete(parsed, k)
911 }
912 for k, v := range parsed {
913 t.Errorf("Found unexpected label %s=%q.", k, v)
914 }
915 })
916 }
917
918 ValidationScheme = model.LegacyValidation
919 EscapingScheme = model.NoEscaping
920}
921
922func TestWipeMetricStore(t *testing.T) {
923 // Create MockMetricStore with a few GroupingKeyToMetricGroup metrics

Callers

nothing calls this directly

Calls 1

splitLabelsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…