about summary refs log tree commit diff
path: root/uname.c
diff options
context:
space:
mode:
authorHeikki Kallasjoki <fis@zem.fi>2018-12-12 19:04:10 +0000
committerHeikki Kallasjoki <fis+github@zem.fi>2018-12-12 19:10:51 +0000
commited420c134eb2c2533cf67aabe37f68fe86fd98fd (patch)
treeb98b6859139d463db5ee5f7b754640e4ce02e8f1 /uname.c
parente6bac22eb94b25f3918d15d10029cfe8ea70eb23 (diff)
downloadnano-exporter-ed420c134eb2c2533cf67aabe37f68fe86fd98fd.tar.gz
nano-exporter-ed420c134eb2c2533cf67aabe37f68fe86fd98fd.tar.xz
nano-exporter-ed420c134eb2c2533cf67aabe37f68fe86fd98fd.zip
Add basic test for the uname collector.
Diffstat (limited to 'uname.c')
-rw-r--r--uname.c32
1 files changed, 21 insertions, 11 deletions
diff --git a/uname.c b/uname.c
index 2ea5f92..b5ac849 100644
--- a/uname.c
+++ b/uname.c
@@ -43,6 +43,20 @@ struct uname_context {
   struct label labels[max_label + 1];
 };
 
+static void uname_set_labels(struct uname_context *ctx, struct utsname *name) {
+  ctx->labels[label_machine].key = "machine";
+  ctx->labels[label_machine].value = must_strdup(name->machine);
+  ctx->labels[label_nodename].key = "nodename";
+  ctx->labels[label_nodename].value = must_strdup(name->nodename);
+  ctx->labels[label_release].key = "release";
+  ctx->labels[label_release].value = must_strdup(name->release);
+  ctx->labels[label_sysname].key = "sysname";
+  ctx->labels[label_sysname].value = must_strdup(name->sysname);
+  ctx->labels[label_version].key = "version";
+  ctx->labels[label_version].value = must_strdup(name->version);
+  ctx->labels[max_label].key = ctx->labels[max_label].value = 0;
+}
+
 static void *uname_init(int argc, char *argv[]) {
   (void) argc; (void) argv;
 
@@ -53,17 +67,7 @@ static void *uname_init(int argc, char *argv[]) {
   }
 
   struct uname_context *ctx = must_malloc(sizeof *ctx);
-  ctx->labels[label_machine].key = "machine";
-  ctx->labels[label_machine].value = must_strdup(name.machine);
-  ctx->labels[label_nodename].key = "nodename";
-  ctx->labels[label_nodename].value = must_strdup(name.nodename);
-  ctx->labels[label_release].key = "release";
-  ctx->labels[label_release].value = must_strdup(name.release);
-  ctx->labels[label_sysname].key = "sysname";
-  ctx->labels[label_sysname].value = must_strdup(name.sysname);
-  ctx->labels[label_version].key = "version";
-  ctx->labels[label_version].value = must_strdup(name.version);
-  ctx->labels[max_label].key = ctx->labels[max_label].value = 0;
+  uname_set_labels(ctx, &name);
   return ctx;
 }
 
@@ -71,3 +75,9 @@ static void uname_collect(scrape_req *req, void *ctx_ptr) {
   struct uname_context *ctx = ctx_ptr;
   scrape_write(req, "node_uname_info", ctx->labels, 1.0);
 }
+
+// exposed only for testing
+
+void uname_test_override_data(void *ctx, struct utsname *name) {
+  uname_set_labels((struct uname_context *) ctx, name);
+}