Package list golang-github-go-kit-kit / c064ab5
execute the new influx tests as examples kpacha 5 years ago
1 changed file(s) with 37 addition(s) and 21 deletion(s). Raw diff Collapse all Expand all
2929 }
3030 }
3131
32 func TestCounter_multipleTags(t *testing.T) {
32 func ExampleCounter() {
3333 in := New(map[string]string{"a": "b"}, influxdb.BatchPointsConfig{}, log.NewNopLogger())
3434 counter := in.NewCounter("influx_counter")
3535 counter.Add(10)
4141 in.WriteTo(client)
4242
4343 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}`,
4747 }
4848
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())
5151 }
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
5257 }
5358
5459 func TestGauge(t *testing.T) {
6772 }
6873 }
6974
70 func TestGauge_multipleTags(t *testing.T) {
75 func ExampleGauge() {
7176 in := New(map[string]string{"a": "b"}, influxdb.BatchPointsConfig{}, log.NewNopLogger())
7277 gauge := in.NewGauge("influx_gauge")
7378 gauge.Set(10)
8085 in.WriteTo(client)
8186
8287 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}`,
8691 }
8792
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())
9095 }
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
91101 }
92102
93103 func TestHistogram(t *testing.T) {
112122 }
113123 }
114124
115 func TestHistogram_multipleTags(t *testing.T) {
125 func ExampleHistogram() {
116126 in := New(map[string]string{"foo": "alpha"}, influxdb.BatchPointsConfig{}, log.NewNopLogger())
117127 histogram := in.NewHistogram("influx_histogram")
118128 histogram.Observe(float64(10))
124134 in.WriteTo(client)
125135
126136 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}`,
130140 }
131141
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())
134144 }
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
135150 }
136151
137152 func TestHistogramLabels(t *testing.T) {
159174 return nil
160175 }
161176
162 func validateMessage(expected []string, msg string) error {
177 func extractAndPrintMessage(expected []string, msg string) error {
163178 for _, pattern := range expected {
164179 re := regexp.MustCompile(pattern)
165180 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)
168183 }
184 fmt.Println(match[1])
169185 }
170186 return nil
171187 }