26 | 26 |
}
|
27 | 27 |
if err := teststat.TestCounter(counter, value); err != nil {
|
28 | 28 |
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 | |
}
|
52 | 29 |
}
|
53 | 30 |
}
|
54 | 31 |
|
|
104 | 81 |
}
|
105 | 82 |
}
|
106 | 83 |
|
|
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 |
|
107 | 115 |
type bufWriter struct {
|
108 | 116 |
buf bytes.Buffer
|
109 | 117 |
}
|