X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Futils_format_graphite_test.c;h=42efa681654deb06774d1048d39892621d8d44d9;hb=7c9d772c992647fcba64a96800c146eb9f1647f8;hp=415a283e0103127246a02461c4cbc7680edc12b2;hpb=3fb6fe5776c14f41879249f4147c0b8924b39cc1;p=collectd.git diff --git a/src/utils_format_graphite_test.c b/src/utils_format_graphite_test.c index 415a283e..42efa681 100644 --- a/src/utils_format_graphite_test.c +++ b/src/utils_format_graphite_test.c @@ -49,12 +49,12 @@ static data_set_t ds_double = { DEF_TEST(metric_name) { struct { - char *plugin_instance; - char *type_instance; - char *prefix; - char *suffix; + const char *plugin_instance; + const char *type_instance; + const char *prefix; + const char *suffix; unsigned int flags; - char *want_name; + const char *want_name; } cases[] = { { .want_name = "example@com.test.single", @@ -124,6 +124,22 @@ DEF_TEST(metric_name) { .suffix = NULL, .want_name = "foo.example@com.test.single", }, + /* flag GRAPHITE_USE_TAGS */ + {.flags = GRAPHITE_USE_TAGS, + .want_name = "test.single;host=example.com;plugin=test;type=single"}, + {.plugin_instance = "f.o.o", + .type_instance = "b.a.r", + .flags = GRAPHITE_USE_TAGS, + .want_name = "test.single;host=example.com;plugin=test;plugin_instance=" + "f.o.o;type=single;type_instance=b.a.r"}, + {.flags = GRAPHITE_USE_TAGS ^ GRAPHITE_ALWAYS_APPEND_DS, + .want_name = "test.single.value;host=example.com;plugin=test;type=" + "single;ds_name=value"}, + {.plugin_instance = "foo", + .type_instance = "foo", + .flags = GRAPHITE_USE_TAGS ^ GRAPHITE_DROP_DUPE_FIELDS, + .want_name = "test.single;host=example.com;plugin=test;plugin_instance=" + "foo;type=single"}, }; for (size_t i = 0; i < STATIC_ARRAY_SIZE(cases); i++) { @@ -157,8 +173,35 @@ DEF_TEST(metric_name) { return 0; } +DEF_TEST(null_termination) { + value_list_t vl = { + .values = &(value_t){.gauge = 1337}, + .values_len = 1, + .time = TIME_T_TO_CDTIME_T_STATIC(1480063672), + .interval = TIME_T_TO_CDTIME_T_STATIC(10), + .host = "example.com", + .plugin = "test", + .type = "single", + }; + char const *want = "example_com.test.single 1337 1480063672\r\n"; + + char buffer[128]; + for (size_t i = 0; i < sizeof(buffer); i++) + buffer[i] = (char)i; + + EXPECT_EQ_INT(0, format_graphite(buffer, sizeof(buffer), &ds_single, &vl, + NULL, NULL, '_', 0)); + EXPECT_EQ_STR(want, buffer); + EXPECT_EQ_INT(0, buffer[strlen(want)]); + for (size_t i = strlen(want) + 1; i < sizeof(buffer); i++) + EXPECT_EQ_INT((int)i, (int)buffer[i]); + + return 0; +} + int main(void) { RUN_TEST(metric_name); + RUN_TEST(null_termination); END_TEST; }