Code

store::memory: Add a plugin providing an in-memory store.
[sysdb.git] / t / integration / matching.sh
1 #! /bin/bash
2 #
3 # SysDB -- t/integration/basic_matching.sh
4 # Copyright (C) 2012 Sebastian 'tokkee' Harl <sh@tokkee.org>
5 # All rights reserved.
6 #
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
9 # are met:
10 # 1. Redistributions of source code must retain the above copyright
11 #    notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 #    notice, this list of conditions and the following disclaimer in the
14 #    documentation and/or other materials provided with the distribution.
15 #
16 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
20 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23 # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25 # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26 # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #
29 # Integration tests for matching clauses.
30 #
32 set -ex
34 source "$( dirname "$0" )/test_lib.sh"
36 cat <<EOF > "$SYSDBD_CONF"
37 Listen "$SOCKET_FILE"
38 PluginDir "$PLUGIN_DIR"
39 Interval 2
41 LoadPlugin "store::memory"
42 LoadBackend "mock_plugin"
43 <Backend "mock_plugin">
44 </Backend>
45 EOF
47 run_sysdbd -D -C "$SYSDBD_CONF"
49 wait_for_sysdbd
50 sleep 3
52 output="$( run_sysdb -H "$SOCKET_FILE" \
53         -c "LOOKUP hosts MATCHING ANY metric.name = 'foo/bar/qux'" )"
54 echo "$output" \
55         | grep -F '"some.host.name"' \
56         | grep -F '"other.host.name"'
57 echo "$output" | grep -F 'localhost' && exit 1
58 echo "$output" | grep -F 'host1.example.com' && exit 1
59 echo "$output" | grep -F 'host2.example.com' && exit 1
61 output="$( run_sysdb -H "$SOCKET_FILE" \
62         -c "LOOKUP hosts MATCHING ANY service.name = 'mock service'" )"
63 echo "$output" \
64         | grep -F '"some.host.name"' \
65         | grep -F '"host1.example.com"' \
66         | grep -F '"host2.example.com"'
67 echo "$output" | grep -F 'localhost' && exit 1
68 echo "$output" | grep -F 'other.host.name' && exit 1
70 output="$( run_sysdb -H "$SOCKET_FILE" \
71         -c "LOOKUP hosts MATCHING attribute['architecture'] = 'x42'" )"
72 echo "$output" \
73         | grep -F '"host1.example.com"' \
74         | grep -F '"host2.example.com"'
75 echo "$output" | grep -F 'localhost' && exit 1
76 echo "$output" | grep -F 'other.host.name' && exit 1
77 echo "$output" | grep -F 'some.host.name' && exit 1
79 output="$( run_sysdb -H "$SOCKET_FILE" \
80         -c "LOOKUP hosts MATCHING ANY attribute.name != 'architecture'" )"
81 echo "$output" \
82         | grep -F '"localhost"' \
83         | grep -F '"other.host.name"' \
84         | grep -F '"host1.example.com"' \
85         | grep -F '"host2.example.com"'
86 echo "$output" | grep -F 'some.host.name' && exit 1
88 output="$( run_sysdb -H "$SOCKET_FILE" \
89         -c "LOOKUP hosts MATCHING ALL attribute.name != 'architecture'" )"
90 echo "$output" \
91         | grep -F '"some.host.name"' \
92         | grep -F '"localhost"'
93 echo "$output" | grep -F 'other.host.name' && exit 1
94 echo "$output" | grep -F 'host1.example.com' && exit 1
95 echo "$output" | grep -F 'host2.example.com' && exit 1
97 output="$( run_sysdb -H "$SOCKET_FILE" \
98         -c "LOOKUP hosts MATCHING ANY service.name = 'sysdbd'" )"
99 echo "$output" | grep -F '"localhost"'
100 echo "$output" | grep -F 'some.host.name' && exit 1
101 echo "$output" | grep -F 'other.host.name' && exit 1
102 echo "$output" | grep -F 'host1.example.com' && exit 1
103 echo "$output" | grep -F 'host2.example.com' && exit 1
105 output="$( run_sysdb -H "$SOCKET_FILE" \
106         -c "LOOKUP hosts MATCHING name =~ 'example.com'" )"
107 echo "$output" \
108         | grep -F '"host1.example.com"' \
109         | grep -F '"host2.example.com"'
110 echo "$output" | grep -F 'some.host.name' && exit 1
111 echo "$output" | grep -F 'other.host.name' && exit 1
112 echo "$output" | grep -F 'localhost' && exit 1
114 # When querying hosts that don't exist, expect a zero exit code.
115 output="$( run_sysdb -H "$SOCKET_FILE" \
116         -c "LOOKUP hosts MATCHING attribute['invalid'] = 'none'" )"
117 echo $output | grep -E '^\[\]$'
119 stop_sysdbd
121 # vim: set tw=78 sw=4 ts=4 noexpandtab :