Package list golang-github-go-kit-kit / 3d2e0cb
Fix after code review Kihamo 4 years ago
2 changed file(s) with 32 addition(s) and 25 deletion(s). Raw diff Collapse all Expand all
167167 if len(labelValues)%2 != 0 {
168168 panic("mergeTags received a labelValues with an odd number of strings")
169169 }
170
171 ret := make(map[string]string, len(tags) + len(labelValues) / 2)
170 ret := make(map[string]string, len(tags)+len(labelValues)/2)
172171 for k, v := range tags {
173172 ret[k] = v
174173 }
2626 }
2727 if err := teststat.TestCounter(counter, value); err != nil {
2828 t.Fatal(err)
29 }
30 }
31
32 func TestCounter_RewriteTags(t *testing.T) {
33 in := New(map[string]string{}, influxdb.BatchPointsConfig{}, log.NewNopLogger())
34
35 reFirst := regexp.MustCompile(`influx_counter_first,tag_for_counter_first=first count=([0-9\.]+) [0-9]+`)
36 counterFirst := in.NewCounter("influx_counter_first").With("tag_for_counter_first", "first")
37 counterFirst.Add(11)
38
39 reSecond := regexp.MustCompile(`influx_counter_second,tag_for_counter_second=second count=([0-9\.]+) [0-9]+`)
40 counterSecond := in.NewCounter("influx_counter_second").With("tag_for_counter_second", "second")
41 counterSecond.Add(22)
42
43 client := &bufWriter{}
44 in.WriteTo(client)
45
46 for _, row := range strings.Split(client.buf.String(), string('\n')) {
47 if strings.HasPrefix(row, "influx_counter_first") && !reFirst.MatchString(row) {
48 t.Fatal(`First counter not equal "`, reFirst.String() , `" want "`, row, `"`)
49 } else if strings.HasPrefix(row, "influx_counter_second") && !reSecond.MatchString(row) {
50 t.Fatal(`Second counter not equal "`, reSecond.String() , `" want "`, row, `"`)
51 }
5229 }
5330 }
5431
10481 }
10582 }
10683
84 func TestIssue404(t *testing.T) {
85 in := New(map[string]string{}, influxdb.BatchPointsConfig{}, log.NewNopLogger())
86
87 counterOne := in.NewCounter("influx_counter_one").With("a", "b")
88 counterOne.Add(123)
89
90 counterTwo := in.NewCounter("influx_counter_two").With("c", "d")
91 counterTwo.Add(456)
92
93 w := &bufWriter{}
94 in.WriteTo(w)
95
96 lines := strings.Split(strings.TrimSpace(w.buf.String()), "\n")
97 if want, have := 2, len(lines); want != have {
98 t.Fatalf("want %d, have %d", want, have)
99 }
100 for _, line := range lines {
101 if strings.HasPrefix(line, "influx_counter_one") {
102 if !strings.HasPrefix(line, "influx_counter_one,a=b count=123 ") {
103 t.Errorf("invalid influx_counter_one: %s", line)
104 }
105 } else if strings.HasPrefix(line, "influx_counter_two") {
106 if !strings.HasPrefix(line, "influx_counter_two,c=d count=456 ") {
107 t.Errorf("invalid influx_counter_two: %s", line)
108 }
109 } else {
110 t.Errorf("unexpected line: %s", line)
111 }
112 }
113 }
114
107115 type bufWriter struct {
108116 buf bytes.Buffer
109117 }