X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=t%2Funit%2Fparser%2Fparser_test.c;h=f363dc2b6d3e9f51ca87780026b8ec051bd918e7;hb=c2f7813397319e930c81c4f64b213bec64549167;hp=f9049211440c513c342ce6c3769c7f160f8767bf;hpb=bc864220dfdef478fc644dbf0bfe4af40f90e8b0;p=sysdb.git diff --git a/t/unit/parser/parser_test.c b/t/unit/parser/parser_test.c index f904921..f363dc2 100644 --- a/t/unit/parser/parser_test.c +++ b/t/unit/parser/parser_test.c @@ -31,6 +31,7 @@ #include "parser/parser.h" #include "core/object.h" +#include "core/store.h" #include "testutils.h" #include @@ -357,6 +358,20 @@ struct { { "LOOKUP hosts MATCHING " "name < ''", -1, 1, SDB_AST_TYPE_LOOKUP, SDB_HOST }, + /* typed expressions */ + { "LOOKUP services MATCHING " + "host.attribute['a'] = 'a'", + -1, 1, SDB_AST_TYPE_LOOKUP, SDB_SERVICE }, + /* TODO: this should work but the analyzer currently sees ATTRIBUTE + * (instead of SERVICE-ATTRIBUTE) as the child type + { "LOOKUP services MATCHING " + "ANY attribute.service.name = 's'", + -1, 1, SDB_AST_TYPE_LOOKUP, SDB_SERVICE }, + */ + { "LOOKUP hosts MATCHING " + "ANY service.service.name = 's'", + -1, 1, SDB_AST_TYPE_LOOKUP, SDB_HOST }, + /* NULL */ { "LOOKUP hosts MATCHING " "attribute['foo'] " @@ -422,6 +437,8 @@ struct { "value = 'a'", -1, -1, 0, 0 }, { "LIST metrics FILTER " "value = 'a'", -1, -1, 0, 0 }, + { "LIST metrics FILTER " + "name.1 = 'a'", -1, -1, 0, 0 }, /* type mismatches */ { "LOOKUP hosts MATCHING " @@ -431,11 +448,6 @@ struct { "1 IN backend ", -1, -1, 0, 0 }, { "LOOKUP hosts MATCHING " "1 NOT IN backend ", -1, -1, 0, 0 }, - { "LOOKUP hosts MATCHING " - "ANY backend !~ backend", - -1, -1, 0, 0 }, - { "LOOKUP hosts MATCHING " - "ANY backend = 1", -1, -1, 0, 0 }, { "LOOKUP hosts MATCHING " "age > 0", -1, -1, 0, 0 }, { "LOOKUP hosts MATCHING " @@ -518,8 +530,23 @@ struct { "name + 1 IS NULL", -1, -1, 0, 0 }, { "LOOKUP hosts FILTER " "name + 1 IS NULL", -1, -1, 0, 0 }, + + /* invalid iterators */ + { "LOOKUP hosts MATCHING " + "ANY backend !~ backend", + -1, -1, 0, 0 }, + { "LOOKUP hosts MATCHING " + "ANY backend = 1", -1, -1, 0, 0 }, { "LOOKUP hosts MATCHING " "ANY 'patt' =~ 'p'", -1, -1, 0, 0 }, + { "LOOKUP hosts MATCHING " + "ALL 1 || '2' < '3'", -1, -1, 0, 0 }, + { "LOOKUP hosts MATCHING " + "ALL name =~ 'a'", -1, -1, 0, 0 }, + /* this could work in theory but is not supported atm */ + { "LOOKUP hosts MATCHING " + "ANY backend || 'a' = 'b'", + -1, -1, 0, 0 }, /* invalid LIST commands */ { "LIST", -1, -1, 0, 0 }, @@ -608,6 +635,7 @@ START_TEST(test_parse) sdb_strbuf_t *errbuf = sdb_strbuf_create(64); sdb_llist_t *check; sdb_ast_node_t *node; + sdb_store_matcher_t *m; _Bool ok; check = sdb_parser_parse(parse_data[_i].query, @@ -669,7 +697,14 @@ START_TEST(test_parse) SDB_STORE_TYPE_TO_NAME(parse_data[_i].expected_extra)); } + /* TODO: this should move into front-end specific tests */ + m = sdb_store_query_prepare(node); + fail_unless(m != NULL, + "sdb_store_query_prepare(AST<%s>) = NULL; expected: ", + parse_data[_i].query); + sdb_object_deref(SDB_OBJ(node)); + sdb_object_deref(SDB_OBJ(m)); sdb_llist_destroy(check); sdb_strbuf_destroy(errbuf); }