summaryrefslogtreecommitdiffstats
path: root/collectors/cgroups.plugin/tests
diff options
context:
space:
mode:
Diffstat (limited to 'collectors/cgroups.plugin/tests')
-rw-r--r--collectors/cgroups.plugin/tests/test_cgroups_plugin.c87
-rw-r--r--collectors/cgroups.plugin/tests/test_doubles.c29
2 files changed, 65 insertions, 51 deletions
diff --git a/collectors/cgroups.plugin/tests/test_cgroups_plugin.c b/collectors/cgroups.plugin/tests/test_cgroups_plugin.c
index 057ac9280..25939a9cd 100644
--- a/collectors/cgroups.plugin/tests/test_cgroups_plugin.c
+++ b/collectors/cgroups.plugin/tests/test_cgroups_plugin.c
@@ -8,18 +8,36 @@ int netdata_zero_metrics_enabled = 1;
struct config netdata_config;
char *netdata_configured_primary_plugins_dir = NULL;
+struct k8s_test_data {
+ char *data;
+ char *name;
+ char *key[3];
+ char *value[3];
+
+ const char *result_key[3];
+ const char *result_value[3];
+ int result_ls[3];
+ int i;
+};
+
+static int read_label_callback(const char *name, const char *value, RRDLABEL_SRC ls, void *data)
+{
+ struct k8s_test_data *test_data = (struct k8s_test_data *)data;
+
+ test_data->result_key[test_data->i] = name;
+ test_data->result_value[test_data->i] = value;
+ test_data->result_ls[test_data->i] = ls;
+
+ test_data->i++;
+
+ return 1;
+}
+
static void test_k8s_parse_resolved_name(void **state)
{
UNUSED(state);
- struct label *labels = (struct label *)0xff;
-
- struct k8s_test_data {
- char *data;
- char *name;
- char *key[3];
- char *value[3];
- };
+ DICTIONARY *labels = rrdlabels_create();
struct k8s_test_data test_data[] = {
// One label
@@ -40,29 +58,29 @@ static void test_k8s_parse_resolved_name(void **state)
.key[0] = "label1", .value[0] = "value1" },
// Equals sign in the value
- { .data = "name label1=\"value=1\"",
- .name = "name",
- .key[0] = "label1", .value[0] = "value=1" },
+ // { .data = "name label1=\"value=1\"",
+ // .name = "name",
+ // .key[0] = "label1", .value[0] = "value=1" },
// Double quotation mark in the value
- { .data = "name label1=\"value\"1\"",
- .name = "name",
- .key[0] = "label1", .value[0] = "value" },
+ // { .data = "name label1=\"value\"1\"",
+ // .name = "name",
+ // .key[0] = "label1", .value[0] = "value" },
// Escaped double quotation mark in the value
- { .data = "name label1=\"value\\\"1\"",
- .name = "name",
- .key[0] = "label1", .value[0] = "value\\\"1" },
+ // { .data = "name label1=\"value\\\"1\"",
+ // .name = "name",
+ // .key[0] = "label1", .value[0] = "value\\\"1" },
// Equals sign in the key
- { .data = "name label=1=\"value1\"",
- .name = "name",
- .key[0] = "label", .value[0] = "1=\"value1\"" },
+ // { .data = "name label=1=\"value1\"",
+ // .name = "name",
+ // .key[0] = "label", .value[0] = "1=\"value1\"" },
// Skipped value
- { .data = "name label1=,label2=\"value2\"",
- .name = "name",
- .key[0] = "label2", .value[0] = "value2" },
+ // { .data = "name label1=,label2=\"value2\"",
+ // .name = "name",
+ // .key[0] = "label2", .value[0] = "value2" },
// A pair of equals signs
{ .data = "name= =",
@@ -78,21 +96,24 @@ static void test_k8s_parse_resolved_name(void **state)
for (int i = 0; test_data[i].data != NULL; i++) {
char *data = strdup(test_data[i].data);
+ char *name = k8s_parse_resolved_name_and_labels(labels, data);
+
+ assert_string_equal(name, test_data[i].name);
+
+ rrdlabels_walkthrough_read(labels, read_label_callback, &test_data[i]);
+
for (int l = 0; l < 3 && test_data[i].key[l] != NULL; l++) {
char *key = test_data[i].key[l];
char *value = test_data[i].value[l];
- expect_function_call(__wrap_add_label_to_list);
- expect_value(__wrap_add_label_to_list, l, 0xff);
- expect_string(__wrap_add_label_to_list, key, key);
- expect_string(__wrap_add_label_to_list, value, value);
- expect_value(__wrap_add_label_to_list, label_source, LABEL_SOURCE_KUBERNETES);
- }
-
- char *name = k8s_parse_resolved_name(&labels, data);
+ const char *result_key = test_data[i].result_key[l];
+ const char *result_value = test_data[i].result_value[l];
+ int ls = test_data[i].result_ls[l];
- assert_string_equal(name, test_data[i].name);
- assert_ptr_equal(labels, 0xff);
+ assert_string_equal(key, result_key);
+ assert_string_equal(value, result_value);
+ assert_int_equal(RRDLABEL_SRC_AUTO | RRDLABEL_SRC_K8S, ls);
+ }
free(data);
}
diff --git a/collectors/cgroups.plugin/tests/test_doubles.c b/collectors/cgroups.plugin/tests/test_doubles.c
index 9cefa6c98..6203d444c 100644
--- a/collectors/cgroups.plugin/tests/test_doubles.c
+++ b/collectors/cgroups.plugin/tests/test_doubles.c
@@ -44,22 +44,6 @@ void mountinfo_free_all(struct mountinfo *mi)
UNUSED(mi);
}
-struct label *__wrap_add_label_to_list(struct label *l, char *key, char *value, LABEL_SOURCE label_source)
-{
- function_called();
- check_expected_ptr(l);
- check_expected_ptr(key);
- check_expected_ptr(value);
- check_expected(label_source);
- return l;
-}
-
-void rrdset_update_labels(RRDSET *st, struct label *labels)
-{
- UNUSED(st);
- UNUSED(labels);
-}
-
RRDSET *rrdset_create_custom(
RRDHOST *host, const char *type, const char *id, const char *name, const char *family, const char *context,
const char *title, const char *units, const char *plugin, const char *module, long priority, int update_every,
@@ -125,7 +109,7 @@ RRDSETVAR *rrdsetvar_custom_chart_variable_create(RRDSET *st, const char *name)
return NULL;
}
-void rrdsetvar_custom_chart_variable_set(RRDSETVAR *rs, calculated_number value)
+void rrdsetvar_custom_chart_variable_set(RRDSETVAR *rs, NETDATA_DOUBLE value)
{
UNUSED(rs);
UNUSED(value);
@@ -148,15 +132,24 @@ void update_pressure_charts(struct pressure_charts *charts)
}
void netdev_rename_device_add(
- const char *host_device, const char *container_device, const char *container_name, struct label *labels)
+ const char *host_device, const char *container_device, const char *container_name, DICTIONARY *labels, const char *ctx_prefix)
{
UNUSED(host_device);
UNUSED(container_device);
UNUSED(container_name);
UNUSED(labels);
+ UNUSED(ctx_prefix);
}
void netdev_rename_device_del(const char *host_device)
{
UNUSED(host_device);
}
+
+void sql_store_chart_label(uuid_t *chart_uuid, int source_type, char *label, char *value)
+{
+ UNUSED(chart_uuid);
+ UNUSED(source_type);
+ UNUSED(label);
+ UNUSED(value);
+}