execute the new influx tests as examples
kpacha
6 years ago
29 | 29 | } |
30 | 30 | } |
31 | 31 | |
32 | func TestCounter_multipleTags(t *testing.T) { | |
32 | func ExampleCounter() { | |
33 | 33 | in := New(map[string]string{"a": "b"}, influxdb.BatchPointsConfig{}, log.NewNopLogger()) |
34 | 34 | counter := in.NewCounter("influx_counter") |
35 | 35 | counter.Add(10) |
41 | 41 | in.WriteTo(client) |
42 | 42 | |
43 | 43 | expectedLines := []string{ |
44 | `influx_counter,a=b count=60 [0-9]+`, | |
45 | `influx_counter,a=b,error=true count=1 [0-9]+`, | |
46 | `influx_counter,a=b,error=false count=2 [0-9]+`, | |
44 | `(influx_counter,a=b count=60) [0-9]{19}`, | |
45 | `(influx_counter,a=b,error=true count=1) [0-9]{19}`, | |
46 | `(influx_counter,a=b,error=false count=2) [0-9]{19}`, | |
47 | 47 | } |
48 | 48 | |
49 | if err := validateMessage(expectedLines, client.buf.String()); err != nil { | |
50 | t.Error(err.Error()) | |
49 | if err := extractAndPrintMessage(expectedLines, client.buf.String()); err != nil { | |
50 | fmt.Println(err.Error()) | |
51 | 51 | } |
52 | ||
53 | // Output: | |
54 | // influx_counter,a=b count=60 | |
55 | // influx_counter,a=b,error=true count=1 | |
56 | // influx_counter,a=b,error=false count=2 | |
52 | 57 | } |
53 | 58 | |
54 | 59 | func TestGauge(t *testing.T) { |
67 | 72 | } |
68 | 73 | } |
69 | 74 | |
70 | func TestGauge_multipleTags(t *testing.T) { | |
75 | func ExampleGauge() { | |
71 | 76 | in := New(map[string]string{"a": "b"}, influxdb.BatchPointsConfig{}, log.NewNopLogger()) |
72 | 77 | gauge := in.NewGauge("influx_gauge") |
73 | 78 | gauge.Set(10) |
80 | 85 | in.WriteTo(client) |
81 | 86 | |
82 | 87 | expectedLines := []string{ |
83 | `influx_gauge,a=b value=50 [0-9]+`, | |
84 | `influx_gauge,a=b,error=true value=1 [0-9]+`, | |
85 | `influx_gauge,a=b,error=false value=2 [0-9]+`, | |
88 | `(influx_gauge,a=b value=50) [0-9]{19}`, | |
89 | `(influx_gauge,a=b,error=true value=1) [0-9]{19}`, | |
90 | `(influx_gauge,a=b,error=false value=2) [0-9]{19}`, | |
86 | 91 | } |
87 | 92 | |
88 | if err := validateMessage(expectedLines, client.buf.String()); err != nil { | |
89 | t.Error(err.Error()) | |
93 | if err := extractAndPrintMessage(expectedLines, client.buf.String()); err != nil { | |
94 | fmt.Println(err.Error()) | |
90 | 95 | } |
96 | ||
97 | // Output: | |
98 | // influx_gauge,a=b value=50 | |
99 | // influx_gauge,a=b,error=true value=1 | |
100 | // influx_gauge,a=b,error=false value=2 | |
91 | 101 | } |
92 | 102 | |
93 | 103 | func TestHistogram(t *testing.T) { |
112 | 122 | } |
113 | 123 | } |
114 | 124 | |
115 | func TestHistogram_multipleTags(t *testing.T) { | |
125 | func ExampleHistogram() { | |
116 | 126 | in := New(map[string]string{"foo": "alpha"}, influxdb.BatchPointsConfig{}, log.NewNopLogger()) |
117 | 127 | histogram := in.NewHistogram("influx_histogram") |
118 | 128 | histogram.Observe(float64(10)) |
124 | 134 | in.WriteTo(client) |
125 | 135 | |
126 | 136 | expectedLines := []string{ |
127 | `influx_histogram,foo=alpha p50=10,p90=50,p95=50,p99=50 [0-9]+`, | |
128 | `influx_histogram,error=true,foo=alpha p50=1,p90=1,p95=1,p99=1 [0-9]+`, | |
129 | `influx_histogram,error=false,foo=alpha p50=2,p90=2,p95=2,p99=2 [0-9]+`, | |
137 | `(influx_histogram,foo=alpha p50=10,p90=50,p95=50,p99=50) [0-9]{19}`, | |
138 | `(influx_histogram,error=true,foo=alpha p50=1,p90=1,p95=1,p99=1) [0-9]{19}`, | |
139 | `(influx_histogram,error=false,foo=alpha p50=2,p90=2,p95=2,p99=2) [0-9]{19}`, | |
130 | 140 | } |
131 | 141 | |
132 | if err := validateMessage(expectedLines, client.buf.String()); err != nil { | |
133 | t.Error(err.Error()) | |
142 | if err := extractAndPrintMessage(expectedLines, client.buf.String()); err != nil { | |
143 | fmt.Println(err.Error()) | |
134 | 144 | } |
145 | ||
146 | // Output: | |
147 | // influx_histogram,foo=alpha p50=10,p90=50,p95=50,p99=50 | |
148 | // influx_histogram,error=true,foo=alpha p50=1,p90=1,p95=1,p99=1 | |
149 | // influx_histogram,error=false,foo=alpha p50=2,p90=2,p95=2,p99=2 | |
135 | 150 | } |
136 | 151 | |
137 | 152 | func TestHistogramLabels(t *testing.T) { |
159 | 174 | return nil |
160 | 175 | } |
161 | 176 | |
162 | func validateMessage(expected []string, msg string) error { | |
177 | func extractAndPrintMessage(expected []string, msg string) error { | |
163 | 178 | for _, pattern := range expected { |
164 | 179 | re := regexp.MustCompile(pattern) |
165 | 180 | match := re.FindStringSubmatch(msg) |
166 | if len(match) != 1 { | |
167 | return fmt.Errorf("Pattern not found! {%s} %s\n", pattern, msg) | |
181 | if len(match) != 2 { | |
182 | return fmt.Errorf("Pattern not found! {%s} [%s]: %v\n", pattern, msg, match) | |
168 | 183 | } |
184 | fmt.Println(match[1]) | |
169 | 185 | } |
170 | 186 | return nil |
171 | 187 | } |