github.com/prebid/prebid-server/v2@v2.18.0/metrics/prometheus/preload_test.go (about) 1 package prometheusmetrics 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 8 "github.com/prometheus/client_golang/prometheus" 9 ) 10 11 func TestRegisterLabelPermutations(t *testing.T) { 12 testCases := []struct { 13 description string 14 labelsWithValues map[string][]string 15 expectedLabels []prometheus.Labels 16 }{ 17 { 18 description: "Empty set.", 19 labelsWithValues: map[string][]string{}, 20 expectedLabels: []prometheus.Labels{}, 21 }, 22 { 23 description: "Set of 1 label and 1 value.", 24 labelsWithValues: map[string][]string{ 25 "1": {"A"}, 26 }, 27 expectedLabels: []prometheus.Labels{ 28 {"1": "A"}, 29 }, 30 }, 31 { 32 description: "Set of 1 label and 2 values.", 33 labelsWithValues: map[string][]string{ 34 "1": {"A", "B"}, 35 }, 36 expectedLabels: []prometheus.Labels{ 37 {"1": "A"}, 38 {"1": "B"}, 39 }, 40 }, 41 { 42 description: "Set of 2 labels and 2 values.", 43 labelsWithValues: map[string][]string{ 44 "1": {"A", "B"}, 45 "2": {"C", "D"}, 46 }, 47 expectedLabels: []prometheus.Labels{ 48 {"1": "A", "2": "C"}, 49 {"1": "A", "2": "D"}, 50 {"1": "B", "2": "C"}, 51 {"1": "B", "2": "D"}, 52 }, 53 }, 54 } 55 56 for _, test := range testCases { 57 resultLabels := []prometheus.Labels{} 58 registerLabelPermutations(test.labelsWithValues, func(label prometheus.Labels) { 59 resultLabels = append(resultLabels, label) 60 }) 61 62 assert.ElementsMatch(t, test.expectedLabels, resultLabels) 63 } 64 }