MCPcopy
hub / github.com/prometheus/client_golang / checkLinesAreEqual

Function checkLinesAreEqual

prometheus/graphite/bridge_test.go:298–337  ·  view source on GitHub ↗
(w, g string, useTags bool)

Source from the content-addressed store, hash-verified

296}
297
298func checkLinesAreEqual(w, g string, useTags bool) error {
299 if useTags {
300 taggedLineRegexp := regexp.MustCompile(`;| `)
301
302 wantLines, err := stringToLines(w)
303 if err != nil {
304 return err
305 }
306
307 gotLines, err := stringToLines(g)
308 if err != nil {
309 return err
310 }
311
312 for lineInd := range gotLines {
313 var log string
314 // Tagged metric, order of tags doesn't matter
315 // m1 := "prefix.name;tag1=val1;tag2=val2 3 1477043"
316 // m2 := "prefix.name;tag2=val2;tag1=val1 3 1477043"
317 // m1 should be equal to m2
318 wantSplit := taggedLineRegexp.Split(wantLines[lineInd], -1)
319 gotSplit := taggedLineRegexp.Split(gotLines[lineInd], -1)
320 sort.Strings(wantSplit)
321 sort.Strings(gotSplit)
322
323 log += fmt.Sprintf("want: %v\ngot: %v\n\n", wantSplit, gotSplit)
324
325 if !reflect.DeepEqual(wantSplit, gotSplit) {
326 return errors.New(log)
327 }
328 }
329 return nil
330 }
331
332 if w != g {
333 return fmt.Errorf("wanted:\n\n%s\ngot:\n\n%s", w, g)
334 }
335
336 return nil
337}
338
339func stringToLines(s string) (lines []string, err error) {
340 scanner := bufio.NewScanner(strings.NewReader(s))

Callers 3

testWriteSummaryFunction · 0.85
testWriteHistogramFunction · 0.85
testToReaderFunction · 0.85

Calls 2

stringToLinesFunction · 0.85
StringsMethod · 0.80

Tested by

no test coverage detected