X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=t%2Fintegration%2Fsimple_query.sh;h=ef12bf8f2dbf1a735ff284c7cfb8b084b19098c9;hb=33d51d5f84495bc8d7805c2370af45948e46c30b;hp=d413b997ea4e6d422c2747e422904bda17eed398;hpb=42af3b662e70584b49ada6949f278bbaa5fd435b;p=sysdb.git diff --git a/t/integration/simple_query.sh b/t/integration/simple_query.sh index d413b99..ef12bf8 100755 --- a/t/integration/simple_query.sh +++ b/t/integration/simple_query.sh @@ -39,20 +39,22 @@ PluginDir "$PLUGIN_DIR" Interval 2 LoadBackend mock_plugin - + 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 )" +# 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"' \ @@ -60,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"' \ @@ -70,11 +80,15 @@ 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" \ +output="$( run_sysdb -H "$SOCKET_FILE" \ -c "LOOKUP hosts WHERE attribute.architecture = 'x42'" )" echo "$output" \ | grep -F '"host1.example.com"' \ @@ -83,6 +97,36 @@ 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 -kill $sysdbd_pid -wait $sysdbd_pid +output="$( run_sysdb -H "$SOCKET_FILE" \ + -c "LOOKUP hosts WHERE attribute != 'architecture'" )" +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 WHERE 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="$( run_sysdb -H "$SOCKET_FILE" \ + -c "LOOKUP hosts WHERE host =~ 'example.com'" )" +echo "$output" \ + | grep -F '"host1.example.com"' \ + | grep -F '"host2.example.com"' +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 + +# When querying hosts that don't exist, expect a zero exit code. +output="$( run_sysdb -H "$SOCKET_FILE" \ + -c "LOOKUP hosts WHERE attribute.invalid = 'none'" )" +echo $output | grep -E '^\[\]$' + +stop_sysdbd