Skip to content

Commit

Permalink
decoding: decode_statsd: tests: Add a test case
Browse files Browse the repository at this point in the history
Signed-off-by: Hiroshi Hatake <[email protected]>
  • Loading branch information
cosmo0920 authored and edsiper committed Aug 13, 2024
1 parent 426e3e7 commit a3bc932
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests/data/statsd_payload.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
statsdTestMetric011:5000|g|#mykey:myvalue,mykey2:othervalue
statsdTestMetric012:400|s|@0.125|#mykey:myvalue
statsdTestMetric013:+500|g|#mykey:myvalue
statsdTestMetric014:-400|g|#mykey:myvalue
statsdTestMetric015:+2|g|#mykey:myvalue
statsdTestMetric016:-1|g|@0.1|#mykey:myvalue
statsdTestMetric021:365|g|#mykey:myvalue
statsdTestMetric022:+300|c|#mykey:myvalue
statsdTestMetric023:-200|s|#mykey:myvalue
statsdTestMetric024:200|g|#mykey:myvalue
expohisto:1|ms|#mykey:myvalue
expohisto:0|ms|#mykey:myvalue
expohisto:-1|ms|#mykey:myvalue
32 changes: 32 additions & 0 deletions tests/decoding.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <cmetrics/cmt_encode_opentelemetry.h>
#include <cmetrics/cmt_decode_prometheus_remote_write.h>
#include <cmetrics/cmt_encode_prometheus_remote_write.h>
#include <cmetrics/cmt_decode_statsd.h>

#include "cmt_tests.h"

Expand Down Expand Up @@ -197,9 +198,40 @@ void test_prometheus_remote_write()
cfl_sds_destroy(payload);
}

void test_statsd()
{
int ret;
struct cmt *decoded_context;
cfl_sds_t payload = read_file(CMT_TESTS_DATA_PATH "/statsd_payload.txt");
size_t len = 0;
cfl_sds_t text = NULL;
int flags = 0;

/* For strtok_r, fill the last byte as \0. */
len = cfl_sds_len(payload);
cfl_sds_set_len(payload, len + 1);
payload[len] = '\0';

cmt_initialize();

flags |= CMT_DECODE_STATSD_GAUGE_OBSERVER;

ret = cmt_decode_statsd_create(&decoded_context, payload, cfl_sds_len(payload), flags);
TEST_CHECK(ret == CMT_DECODE_PROMETHEUS_REMOTE_WRITE_SUCCESS);
text = cmt_encode_prometheus_create(decoded_context, CMT_FALSE);

printf("%s\n", text);
cmt_encode_prometheus_destroy(text);

cmt_decode_statsd_destroy(decoded_context);

cfl_sds_destroy(payload);
}


TEST_LIST = {
{"opentelemetry", test_opentelemetry},
{"prometheus_remote_write", test_prometheus_remote_write},
{"statsd", test_statsd},
{ 0 }
};

0 comments on commit a3bc932

Please sign in to comment.