Code

integration tests: Added simple tests for service and metric queries.
authorSebastian Harl <sh@tokkee.org>
Sun, 3 Aug 2014 20:34:14 +0000 (22:34 +0200)
committerSebastian Harl <sh@tokkee.org>
Sun, 3 Aug 2014 20:34:14 +0000 (22:34 +0200)
To make that work, let the mock_plugin store some metrics as well.

t/integration/mock_plugin.c
t/integration/simple_query.sh

index 8dcb410af3492a0da588c6ba56f5cc7c3b5ddfaf..8c161943617f58db39f195df1b87b7589941bc3b 100644 (file)
@@ -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()))) {
index f191d650babfa663d1d78eb47104d1614406ec4a..4398b2b9da935be695ed80871cffc7db4690c976 100755 (executable)
@@ -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" \