diff options
author | Heikki Kallasjoki <fis@zem.fi> | 2018-12-12 18:04:20 +0000 |
---|---|---|
committer | Heikki Kallasjoki <fis+github@zem.fi> | 2018-12-12 19:10:51 +0000 |
commit | 9f2db173733774cd7a991ea7f2a37c9e2c491ae9 (patch) | |
tree | 516af3b62167976506e473158c97e5e67a45966d /test | |
parent | 79b14a8f79b63f79a282551c913f82ca4d1ed22d (diff) | |
download | nano-exporter-9f2db173733774cd7a991ea7f2a37c9e2c491ae9.tar.gz nano-exporter-9f2db173733774cd7a991ea7f2a37c9e2c491ae9.tar.xz nano-exporter-9f2db173733774cd7a991ea7f2a37c9e2c491ae9.zip |
Add basic test for the meminfo collector.
Diffstat (limited to 'test')
-rw-r--r-- | test/Makefile | 2 | ||||
-rw-r--r-- | test/meminfo_test.c | 53 |
2 files changed, 54 insertions, 1 deletions
diff --git a/test/Makefile b/test/Makefile index a6d5ae6..94e9121 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 +COLLECTOR_TESTS := cpu diskstats filesystem hwmon meminfo COLLECTOR_TEST_PROGS := $(foreach c,$(COLLECTOR_TESTS),$(c)_test) COLLECTOR_TEST_OBJS := $(foreach p,$(COLLECTOR_TEST_PROGS),$(p).o) diff --git a/test/meminfo_test.c b/test/meminfo_test.c new file mode 100644 index 0000000..91b4102 --- /dev/null +++ b/test/meminfo_test.c @@ -0,0 +1,53 @@ +/* + * 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 "harness.h" +#include "mock_scrape.h" +#include "../collector.h" + +extern const struct collector meminfo_collector; + +TEST(meminfo_metrics) { + test_write_file( + env, + "proc/meminfo", + "MemTotal: 16316872 kB\n" + "MemFree: 1986284 kB\n" + "MemAvailable: 11459644 kB\n" + "Active(anon): 3434548 kB\n" + "Inactive(anon): 417032 kB\n" + "HugePages_Total: 123\n" + "HugePages_Free: 12\n"); + scrape_req *req = mock_scrape_start(env); + + meminfo_collector.collect(req, 0); + + mock_scrape_expect(req, "node_memory_MemTotal_bytes", 0, 16708476928); + mock_scrape_expect(req, "node_memory_MemFree_bytes", 0, 2033954816); + mock_scrape_expect(req, "node_memory_MemAvailable_bytes", 0, 11734675456); + mock_scrape_expect(req, "node_memory_Active_anon_bytes", 0, 3516977152); + mock_scrape_expect(req, "node_memory_Inactive_anon_bytes", 0, 427040768); + mock_scrape_expect(req, "node_memory_HugePages_Total", 0, 123); + mock_scrape_expect(req, "node_memory_HugePages_Free", 0, 12); + mock_scrape_expect_no_more(req); + mock_scrape_free(req); +} + +TEST_SUITE { + TEST_SUITE_START; + RUN_TEST(meminfo_metrics); + TEST_SUITE_END; +} |