diff --git a/tests/data/remote_write_dump_originally_from_node_exporter.bin b/tests/data/remote_write_dump_originally_from_node_exporter.bin new file mode 100644 index 0000000..7f8afe3 Binary files /dev/null and b/tests/data/remote_write_dump_originally_from_node_exporter.bin differ diff --git a/tests/decoding.c b/tests/decoding.c index 69db52b..358ca53 100644 --- a/tests/decoding.c +++ b/tests/decoding.c @@ -123,59 +123,6 @@ static struct cmt *generate_encoder_test_data() return cmt; } -static struct cmt *generate_encoder_test_basic_data() -{ - double val; - struct cmt *cmt; - uint64_t ts; - struct cmt_gauge *g1; - struct cmt_counter *c1; - struct cmt_untyped *u1; - - /* Use the current timestamp because there is cut off. */ - ts = cfl_time_now(); - cmt = cmt_create(); - - c1 = cmt_counter_create(cmt, "kubernetes", "network", "load_counter", "Network load counter", - 2, (char *[]) {"hostname", "app"}); - - cmt_counter_get_val(c1, 0, NULL, &val); - cmt_counter_inc(c1, ts, 0, NULL); - cmt_counter_add(c1, ts, 2, 0, NULL); - cmt_counter_get_val(c1, 0, NULL, &val); - - cmt_counter_inc(c1, ts, 2, (char *[]) {"localhost", "cmetrics"}); - cmt_counter_get_val(c1, 2, (char *[]) {"localhost", "cmetrics"}, &val); - cmt_counter_add(c1, ts, 10.55, 2, (char *[]) {"localhost", "test"}); - cmt_counter_get_val(c1, 2, (char *[]) {"localhost", "test"}, &val); - cmt_counter_set(c1, ts, 12.15, 2, (char *[]) {"localhost", "test"}); - cmt_counter_set(c1, ts, 1, 2, (char *[]) {"localhost", "test"}); - - g1 = cmt_gauge_create(cmt, "kubernetes", "network", "load_gauge", "Network load gauge", 0, NULL); - - cmt_gauge_get_val(g1, 0, NULL, &val); - cmt_gauge_set(g1, ts, 2.0, 0, NULL); - cmt_gauge_get_val(g1, 0, NULL, &val); - cmt_gauge_inc(g1, ts, 0, NULL); - cmt_gauge_get_val(g1, 0, NULL, &val); - cmt_gauge_sub(g1, ts, 2, 0, NULL); - cmt_gauge_get_val(g1, 0, NULL, &val); - cmt_gauge_dec(g1, ts, 0, NULL); - cmt_gauge_get_val(g1, 0, NULL, &val); - cmt_gauge_inc(g1, ts, 0, NULL); - - u1 = cmt_untyped_create(cmt, "kubernetes", "network", "load", "Network load", - 2, (char *[]) {"hostname", "app"}); - - cmt_untyped_set(u1, ts, 2, 0, NULL); - cmt_untyped_get_val(u1, 2, (char *[]) {"localhost", "cmetrics"}, &val); - cmt_untyped_get_val(u1, 2, (char *[]) {"localhost", "test"}, &val); - cmt_untyped_set(u1, ts, 12.15, 2, (char *[]) {"localhost", "test"}); - cmt_untyped_set(u1, ts, 1, 2, (char *[]) {"localhost", "test"}); - - return cmt; -} - void test_opentelemetry() { cfl_sds_t reference_prometheus_context; @@ -237,31 +184,17 @@ void test_opentelemetry() void test_prometheus_remote_write() { int ret; - cfl_sds_t payload; struct cmt *decoded_context; - struct cmt *cmt; + cfl_sds_t payload = read_file(CMT_TESTS_DATA_PATH "/remote_write_dump_originally_from_node_exporter.bin"); cmt_initialize(); - cmt = generate_encoder_test_basic_data(); - TEST_CHECK(cmt != NULL); - - payload = cmt_encode_prometheus_remote_write_create(cmt); - TEST_CHECK(payload != NULL); - - if (payload == NULL) { - cmt_destroy(cmt); - - return; - } - ret = cmt_decode_prometheus_remote_write_create(&decoded_context, payload, cfl_sds_len(payload)); TEST_CHECK(ret == CMT_DECODE_PROMETHEUS_REMOTE_WRITE_SUCCESS); - cmt_encode_prometheus_remote_write_destroy(payload); cmt_decode_prometheus_remote_write_destroy(decoded_context); - cmt_destroy(cmt); + cfl_sds_destroy(payload); }