Code

frontend: Added 'FILTER' support to the 'LOOKUP' command.
[sysdb.git] / t / integration / simple_query.sh
index 232d3e192ef5b42203ee1b7e5cbf4331f92a7506..86ac03fd80962dae080dc08c7425ee4319f172c3 100755 (executable)
@@ -29,7 +29,7 @@
 # Integration tests using simple queries.
 #
 
-set -e
+set -ex
 
 source "$( dirname "$0" )/test_lib.sh"
 
@@ -39,21 +39,22 @@ PluginDir "$PLUGIN_DIR"
 Interval 2
 
 LoadBackend mock_plugin
-<Backend "test::integration::mock">
+<Backend "mock_plugin">
 </Backend>
 EOF
 
-$SYSDBD -D -C "$SYSDBD_CONF" &
-sysdbd_pid=$!
+run_sysdbd -D -C "$SYSDBD_CONF"
 
 wait_for_sysdbd
 sleep 3
 
-output="$( $SYSDB -H "$SOCKET_FILE" -c INVALID )" && exit 1
+# On parse errors, expect a non-zero exit code.
+output="$( run_sysdb -H "$SOCKET_FILE" -c INVALID )" && exit 1
 echo "$output" | grep "Failed to parse query 'INVALID'"
 echo "$output" | grep "parse error: syntax error"
 
-output="$( $SYSDB -H "$SOCKET_FILE" -c LIST )"
+# Simple, successful commands.
+output="$( run_sysdb -H "$SOCKET_FILE" -c LIST )"
 echo "$output" \
        | grep -F '"host1.example.com"' \
        | grep -F '"host2.example.com"' \
@@ -61,7 +62,15 @@ echo "$output" \
        | grep -F '"other.host.name"' \
        | grep -F '"some.host.name"'
 
-output="$( $SYSDB -H "$SOCKET_FILE" -c "FETCH 'host1.example.com'" )"
+output="$( echo 'LIST;' | run_sysdb -H "$SOCKET_FILE" )" || echo $?
+echo "$output" \
+       | grep -F '"host1.example.com"' \
+       | grep -F '"host2.example.com"' \
+       | grep -F '"localhost"' \
+       | grep -F '"other.host.name"' \
+       | grep -F '"some.host.name"'
+
+output="$( run_sysdb -H "$SOCKET_FILE" -c "FETCH 'host1.example.com'" )"
 echo "$output" \
        | grep -F '"host1.example.com"' \
        | grep -F '"mock service"' \
@@ -71,12 +80,16 @@ echo "$output" | grep -F 'localhost' && exit 1
 echo "$output" | grep -F 'other.host.name' && exit 1
 echo "$output" | grep -F 'some.host.name' && exit 1
 
-output="$( $SYSDB -H "$SOCKET_FILE" -c "FETCH 'does.not.exist'" )" \
+(echo 'LIST;'; sleep 1; echo "FETCH 'host1.example.com'") \
+       | run_sysdb -H "$SOCKET_FILE"
+
+# When requesting information for unknown hosts, expect a non-zero exit code.
+output="$( run_sysdb -H "$SOCKET_FILE" -c "FETCH 'does.not.exist'" )" \
        && exit 1
 echo "$output" | grep -F 'not found'
 
-output="$( $SYSDB -H "$SOCKET_FILE" \
-       -c "LOOKUP hosts WHERE attribute.architecture = 'x42'" )"
+output="$( run_sysdb -H "$SOCKET_FILE" \
+       -c "LOOKUP hosts MATCHING attribute.architecture = 'x42'" )"
 echo "$output" \
        | grep -F '"host1.example.com"' \
        | grep -F '"host2.example.com"'
@@ -84,8 +97,8 @@ echo "$output" | grep -F 'localhost' && exit 1
 echo "$output" | grep -F 'other.host.name' && exit 1
 echo "$output" | grep -F 'some.host.name' && exit 1
 
-output="$( $SYSDB -H "$SOCKET_FILE" \
-       -c "LOOKUP hosts WHERE attribute.name != 'architecture'" )"
+output="$( run_sysdb -H "$SOCKET_FILE" \
+       -c "LOOKUP hosts MATCHING attribute != 'architecture'" )"
 echo "$output" \
        | grep -F '"some.host.name"' \
        | grep -F '"localhost"'
@@ -93,16 +106,31 @@ echo "$output" | grep -F 'other.host.name' && exit 1
 echo "$output" | grep -F 'host1.example.com' && exit 1
 echo "$output" | grep -F 'host2.example.com' && exit 1
 
-output="$( $SYSDB -H "$SOCKET_FILE" \
-       -c "LOOKUP hosts WHERE service.name = 'sysdbd'" )"
+output="$( run_sysdb -H "$SOCKET_FILE" \
+       -c "LOOKUP hosts MATCHING attribute != 'architecture' 
+               FILTER :age >= 0s" )"
+echo "$output" \
+       | grep -F '"some.host.name"' \
+       | grep -F '"localhost"'
+echo "$output" | grep -F 'other.host.name' && 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 attribute != 'architecture' 
+               FILTER :last_update < 2Y" )"
+echo $output | grep -E '^\[\]$'
+
+output="$( run_sysdb -H "$SOCKET_FILE" \
+       -c "LOOKUP hosts MATCHING service = 'sysdbd'" )"
 echo "$output" | grep -F '"localhost"'
 echo "$output" | grep -F 'some.host.name' && exit 1
 echo "$output" | grep -F 'other.host.name' && exit 1
 echo "$output" | grep -F 'host1.example.com' && exit 1
 echo "$output" | grep -F 'host2.example.com' && exit 1
 
-output="$( $SYSDB -H "$SOCKET_FILE" \
-       -c "LOOKUP hosts WHERE host.name =~ 'example.com'" )"
+output="$( run_sysdb -H "$SOCKET_FILE" \
+       -c "LOOKUP hosts MATCHING host =~ 'example.com'" )"
 echo "$output" \
        | grep -F '"host1.example.com"' \
        | grep -F '"host2.example.com"'
@@ -110,6 +138,10 @@ echo "$output" | grep -F 'some.host.name' && exit 1
 echo "$output" | grep -F 'other.host.name' && exit 1
 echo "$output" | grep -F 'localhost' && exit 1
 
-kill $sysdbd_pid
-wait $sysdbd_pid
+# When querying hosts that don't exist, expect a zero exit code.
+output="$( run_sysdb -H "$SOCKET_FILE" \
+       -c "LOOKUP hosts MATCHING attribute.invalid = 'none'" )"
+echo $output | grep -E '^\[\]$'
+
+stop_sysdbd