Skip to content

Commit a3bc932

Browse files
cosmo0920edsiper
authored andcommitted
decoding: decode_statsd: tests: Add a test case
Signed-off-by: Hiroshi Hatake <[email protected]>
1 parent 426e3e7 commit a3bc932

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

tests/data/statsd_payload.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
statsdTestMetric011:5000|g|#mykey:myvalue,mykey2:othervalue
2+
statsdTestMetric012:400|s|@0.125|#mykey:myvalue
3+
statsdTestMetric013:+500|g|#mykey:myvalue
4+
statsdTestMetric014:-400|g|#mykey:myvalue
5+
statsdTestMetric015:+2|g|#mykey:myvalue
6+
statsdTestMetric016:-1|g|@0.1|#mykey:myvalue
7+
statsdTestMetric021:365|g|#mykey:myvalue
8+
statsdTestMetric022:+300|c|#mykey:myvalue
9+
statsdTestMetric023:-200|s|#mykey:myvalue
10+
statsdTestMetric024:200|g|#mykey:myvalue
11+
expohisto:1|ms|#mykey:myvalue
12+
expohisto:0|ms|#mykey:myvalue
13+
expohisto:-1|ms|#mykey:myvalue

tests/decoding.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <cmetrics/cmt_encode_opentelemetry.h>
2929
#include <cmetrics/cmt_decode_prometheus_remote_write.h>
3030
#include <cmetrics/cmt_encode_prometheus_remote_write.h>
31+
#include <cmetrics/cmt_decode_statsd.h>
3132

3233
#include "cmt_tests.h"
3334

@@ -197,9 +198,40 @@ void test_prometheus_remote_write()
197198
cfl_sds_destroy(payload);
198199
}
199200

201+
void test_statsd()
202+
{
203+
int ret;
204+
struct cmt *decoded_context;
205+
cfl_sds_t payload = read_file(CMT_TESTS_DATA_PATH "/statsd_payload.txt");
206+
size_t len = 0;
207+
cfl_sds_t text = NULL;
208+
int flags = 0;
209+
210+
/* For strtok_r, fill the last byte as \0. */
211+
len = cfl_sds_len(payload);
212+
cfl_sds_set_len(payload, len + 1);
213+
payload[len] = '\0';
214+
215+
cmt_initialize();
216+
217+
flags |= CMT_DECODE_STATSD_GAUGE_OBSERVER;
218+
219+
ret = cmt_decode_statsd_create(&decoded_context, payload, cfl_sds_len(payload), flags);
220+
TEST_CHECK(ret == CMT_DECODE_PROMETHEUS_REMOTE_WRITE_SUCCESS);
221+
text = cmt_encode_prometheus_create(decoded_context, CMT_FALSE);
222+
223+
printf("%s\n", text);
224+
cmt_encode_prometheus_destroy(text);
225+
226+
cmt_decode_statsd_destroy(decoded_context);
227+
228+
cfl_sds_destroy(payload);
229+
}
230+
200231

201232
TEST_LIST = {
202233
{"opentelemetry", test_opentelemetry},
203234
{"prometheus_remote_write", test_prometheus_remote_write},
235+
{"statsd", test_statsd},
204236
{ 0 }
205237
};

0 commit comments

Comments
 (0)