Code

store_lookup_test: Ensure that filters are applied before matchers.
[sysdb.git] / t / unit / core / store_lookup_test.c
index 3c99bb15553d64f0407489b21a3db56334977935..698226e23db360ac792a9a4776821c71da20e0f6 100644 (file)
@@ -499,10 +499,13 @@ START_TEST(test_store_match_op)
 END_TEST
 
 static int
-scan_cb(sdb_store_obj_t *obj, void *user_data)
+scan_cb(sdb_store_obj_t *obj, sdb_store_matcher_t *filter, void *user_data)
 {
        int *i = user_data;
 
+       if (! sdb_store_matcher_matches(filter, obj, NULL))
+               return 0;
+
        fail_unless(obj != NULL,
                        "sdb_store_scan callback received NULL obj; expected: "
                        "<store base obj>");
@@ -534,24 +537,39 @@ START_TEST(test_scan)
                { "ANY metric = 'm1'",
                        "NOT attribute['x'] = ''",         2 }, /* filter always matches */
                { "ANY metric =~ 'm'", NULL,           2 },
-               { "ANY metric !~ 'm'", NULL,           1 },
+               { "ALL metric =~ 'm'", NULL,           3 },
+               { "ANY metric =~ 'm'", "name !~ '1'",  1 },
+               { "ANY metric =~ 'm'", "name !~ 'm'",  0 },
+               { "ALL metric =~ '1'", NULL,           2 },
+               { "ALL metric =~ '2'", NULL,           1 },
+               { "ANY metric !~ 'm'", NULL,           0 },
+               { "ALL metric !~ 'm'", NULL,           1 },
                { "ANY metric =~ 'x'", NULL,           0 },
                { "ANY service = 's1'", NULL,          2 },
                { "ANY service = 's1'", "host = 'x'",  0 }, /* filter never matches */
                { "ANY service = 's1'",
                        "NOT attribute['x'] = ''",         2 }, /* filter always matches */
                { "ANY service =~ 's'", NULL,          2 },
-               { "ANY service !~ 's'", NULL,          1 },
+               { "ANY service =~ 's'", "name !~ 's'", 0 },
+               { "ANY service =~ 's'", "name !~ '1'", 2 },
+               { "ANY service !~ 's'", NULL,          0 },
                { "ANY attribute = 'k1'", NULL,        2 },
                { "ANY attribute = 'k1'", "host = 'x'",0 }, /* filter never matches */
                { "ANY attribute = 'k1'",
                        "NOT attribute['x'] = ''",         2 }, /* filter always matches */
                { "ANY attribute =~ 'k'", NULL,        2 },
+               { "ANY attribute =~ 'k'",
+                       "name !~ '1'",                     1 },
+               { "ANY attribute =~ 'k'",
+                       "name !~ 'k'",                     0 },
                { "ANY attribute =~ '1'", NULL,        2 },
                { "ANY attribute =~ '2'", NULL,        1 },
                { "ANY attribute = 'x'", NULL,         0 },
                { "ANY attribute =~ 'x'", NULL,        0 },
+               { "ALL attribute = 'k1'", NULL,        2 },
                { "attribute['k1'] = 'v1'", NULL,      1 },
+               { "attribute['k1'] = 'v1'",
+                       "name != 'k1'",                    0 },
                { "attribute['k1'] =~ 'v1'", NULL,     1 },
                { "attribute['k1'] =~ '^v1$'", NULL,   1 },
                { "attribute['k1'] =~ 'v'", NULL,      2 },
@@ -575,14 +593,14 @@ START_TEST(test_scan)
                { "attribute['k1'] != 'v1'", NULL,     1 },
                { "attribute['k1'] != 'v2'", NULL,     1 },
                { "ANY attribute != 'x' "
-                 "AND attribute['y'] !~ 'x'", NULL,   3 },
+                 "AND attribute['y'] !~ 'x'", NULL,   2 },
        };
 
        int check, n;
        size_t i;
 
        n = 0;
-       check = sdb_store_scan(/* matcher */ NULL, /* filter */ NULL,
+       check = sdb_store_scan(SDB_HOST, /* matcher */ NULL, /* filter */ NULL,
                        scan_cb, &n);
        fail_unless(check == 0,
                        "sdb_store_scan() = %d; expected: 0", check);
@@ -605,11 +623,11 @@ START_TEST(test_scan)
                }
 
                n = 0;
-               sdb_store_scan(m, filter, scan_cb, &n);
+               sdb_store_scan(SDB_HOST, m, filter, scan_cb, &n);
                fail_unless(n == golden_data[i].expected,
-                               "sdb_store_scan(matcher{%s}, filter{%s}) found %d hosts; "
-                               "expected: %d", golden_data[i].query, golden_data[i].filter,
-                               n, golden_data[i].expected);
+                               "sdb_store_scan(HOST, matcher{%s}, filter{%s}) "
+                               "found %d hosts; expected: %d", golden_data[i].query,
+                               golden_data[i].filter, n, golden_data[i].expected);
                sdb_object_deref(SDB_OBJ(filter));
                sdb_object_deref(SDB_OBJ(m));
        }