diff options
author | Heikki Kallasjoki <fis@zem.fi> | 2018-12-12 19:04:10 +0000 |
---|---|---|
committer | Heikki Kallasjoki <fis+github@zem.fi> | 2018-12-12 19:10:51 +0000 |
commit | ed420c134eb2c2533cf67aabe37f68fe86fd98fd (patch) | |
tree | b98b6859139d463db5ee5f7b754640e4ce02e8f1 /test | |
parent | e6bac22eb94b25f3918d15d10029cfe8ea70eb23 (diff) | |
download | nano-exporter-ed420c134eb2c2533cf67aabe37f68fe86fd98fd.tar.gz nano-exporter-ed420c134eb2c2533cf67aabe37f68fe86fd98fd.tar.xz nano-exporter-ed420c134eb2c2533cf67aabe37f68fe86fd98fd.zip |
Add basic test for the uname collector.
Diffstat (limited to 'test')
-rw-r--r-- | test/Makefile | 2 | ||||
-rw-r--r-- | test/uname_test.c | 58 |
2 files changed, 59 insertions, 1 deletions
diff --git a/test/Makefile b/test/Makefile index 2e18d39..872cfe7 100644 --- a/test/Makefile +++ b/test/Makefile @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -COLLECTOR_TESTS := cpu diskstats filesystem hwmon meminfo network stat textfile +COLLECTOR_TESTS := cpu diskstats filesystem hwmon meminfo network stat textfile uname COLLECTOR_TEST_PROGS := $(foreach c,$(COLLECTOR_TESTS),$(c)_test) COLLECTOR_TEST_OBJS := $(foreach p,$(COLLECTOR_TEST_PROGS),$(p).o) diff --git a/test/uname_test.c b/test/uname_test.c new file mode 100644 index 0000000..3a8390c --- /dev/null +++ b/test/uname_test.c @@ -0,0 +1,58 @@ +/* + * Copyright 2018 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <string.h> +#include <sys/utsname.h> + +#include "harness.h" +#include "mock_scrape.h" +#include "../collector.h" + +extern const struct collector uname_collector; +void uname_test_override_data(void *ctx, struct utsname *name); + +TEST(uname_metrics) { + scrape_req *req = mock_scrape_start(env); + struct utsname mock_uname; + strcpy(mock_uname.machine, "x86_64"); + strcpy(mock_uname.nodename, "eris"); + strcpy(mock_uname.release, "4.18.0-1-amd64"); + strcpy(mock_uname.sysname, "Linux"); + strcpy(mock_uname.version, "#1 SMP Debian 4.18.6-1 (2018-09-06)"); + + void *ctx = uname_collector.init(0, 0); + uname_test_override_data(ctx, &mock_uname); + uname_collector.collect(req, ctx); + + mock_scrape_expect( + req, + "node_uname_info", + LABEL_LIST( + {"machine", "x86_64"}, + {"nodename", "eris"}, + {"release", "4.18.0-1-amd64"}, + {"sysname", "Linux"}, + {"version", "#1 SMP Debian 4.18.6-1 (2018-09-06)"}), + 1); + mock_scrape_expect_no_more(req); + mock_scrape_free(req); +} + +TEST_SUITE { + TEST_SUITE_START; + RUN_TEST(uname_metrics); + TEST_SUITE_END; +} |