From 2efe0d8940ec67c630a02b14cd27bccb810be77f Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Sun, 3 Aug 2014 22:34:14 +0200 Subject: [PATCH] integration tests: Added simple tests for service and metric queries. To make that work, let the mock_plugin store some metrics as well. --- t/integration/mock_plugin.c | 22 ++++++++++++++++++++++ t/integration/simple_query.sh | 18 ++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/t/integration/mock_plugin.c b/t/integration/mock_plugin.c index 8dcb410..8c16194 100644 --- a/t/integration/mock_plugin.c +++ b/t/integration/mock_plugin.c @@ -51,6 +51,20 @@ static const char *hostnames[] = { "localhost", }; +static struct { + const char *hostname; + const char *metric; +} metrics[] = { + { "some.host.name", "foo/bar/qux" }, + { "some.host.name", "foo/bar/baz" }, + { "some.host.name", "foo2/bar/qux" }, + { "some.host.name", "foo2/bar/baz" }, + { "other.host.name", "foo/bar/qux" }, + { "other.host.name", "foo/bar/baz" }, + { "other.host.name", "foo2/bar/qux" }, + { "other.host.name", "foo2/bar/baz" }, +}; + static struct { const char *hostname; const char *service; @@ -136,6 +150,14 @@ mock_collect(sdb_object_t *user_data) exit(1); } } + for (i = 0; i < SDB_STATIC_ARRAY_LEN(metrics); ++i) { + if ((check = sdb_store_metric(metrics[i].hostname, + metrics[i].metric, sdb_gettime()))) { + sdb_log(SDB_LOG_ERR, "mock::plugin: Failed to store metric: " + "status %d", check); + exit(1); + } + } for (i = 0; i < SDB_STATIC_ARRAY_LEN(services); ++i) { if ((check = sdb_store_service(services[i].hostname, services[i].service, sdb_gettime()))) { diff --git a/t/integration/simple_query.sh b/t/integration/simple_query.sh index f191d65..4398b2b 100755 --- a/t/integration/simple_query.sh +++ b/t/integration/simple_query.sh @@ -88,6 +88,24 @@ output="$( run_sysdb -H "$SOCKET_FILE" -c "FETCH host 'does.not.exist'" )" \ && exit 1 echo "$output" | grep -F 'not found' +output="$( run_sysdb -H "$SOCKET_FILE" \ + -c "LOOKUP hosts MATCHING metric = 'foo/bar/qux'" )" +echo "$output" \ + | grep -F '"some.host.name"' \ + | grep -F '"other.host.name"' +echo "$output" | grep -F 'localhost' && exit 1 +echo "$output" | grep -F 'host1.example.com' && exit 1 +echo "$output" | grep -F 'host2.example.com' && exit 1 + +output="$( run_sysdb -H "$SOCKET_FILE" \ + -c "LOOKUP hosts MATCHING service = 'mock service'" )" +echo "$output" \ + | grep -F '"some.host.name"' \ + | grep -F '"host1.example.com"' \ + | grep -F '"host2.example.com"' +echo "$output" | grep -F 'localhost' && exit 1 +echo "$output" | grep -F 'other.host.name' && exit 1 + output="$( run_sysdb -H "$SOCKET_FILE" \ -c "LOOKUP hosts MATCHING attribute.architecture = 'x42'" )" echo "$output" \ -- 2.30.2