Code

t/integration/store.sh: Add integration tests for the STORE command.
[sysdb.git] / t / integration / store.sh
1 #! /bin/bash
2 #
3 # SysDB -- t/integration/store.sh
4 # Copyright (C) 2015 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 the STORE command.
30 #
32 set -ex
34 source "$( dirname "$0" )/test_lib.sh"
36 cat <<EOF > "$SYSDBD_CONF"
37 Listen "$SOCKET_FILE"
38 PluginDir "$PLUGIN_DIR"
40 LoadPlugin "store::memory"
41 EOF
43 run_sysdbd -D -C "$SYSDBD_CONF"
44 wait_for_sysdbd
46 # wait for things to settle and no data to show up
47 sleep 3
49 output="$( run_sysdb -H "$SOCKET_FILE" -c 'LIST hosts' )"
50 test "$output" = '[]' || exit 1
52 # populate the database
53 run_sysdb -H "$SOCKET_FILE" -c "STORE host 'h1'"
54 run_sysdb -H "$SOCKET_FILE" -c "STORE service 'h1'.'s1'"
55 run_sysdb -H "$SOCKET_FILE" -c "STORE metric 'h1'.'m1'"
56 run_sysdb -H "$SOCKET_FILE" -c "STORE host attribute 'h1'.'attrH' 'valueH'"
57 run_sysdb -H "$SOCKET_FILE" -c "STORE service attribute 'h1'.'s1'.'attrS' 'valueS'"
58 run_sysdb -H "$SOCKET_FILE" -c "STORE metric attribute 'h1'.'m1'.'attrM' 'valueM'"
60 # check the database
61 output="$( run_sysdb -H "$SOCKET_FILE" -c 'LIST hosts' )"
62 echo "$output" \
63         | grep -F '"h1"'
64 output="$( run_sysdb -H "$SOCKET_FILE" -c "FETCH host 'h1'" )"
65 echo "$output" \
66         | grep -F '"h1"' \
67         | grep -F '"attrH"' \
68         | grep -F '"valueH"'
70 output="$( run_sysdb -H "$SOCKET_FILE" -c 'LIST services' )"
71 echo "$output" \
72         | grep -F '"h1"' \
73         | grep -F '"s1"'
74 output="$( run_sysdb -H "$SOCKET_FILE" -c "FETCH service 'h1'.'s1'" )"
75 echo "$output" \
76         | grep -F '"h1"' \
77         | grep -F '"s1"' \
78         | grep -F '"attrS"' \
79         | grep -F '"valueS"'
81 output="$( run_sysdb -H "$SOCKET_FILE" -c 'LIST metrics' )"
82 echo "$output" \
83         | grep -F '"h1"' \
84         | grep -F '"m1"'
85 output="$( run_sysdb -H "$SOCKET_FILE" -c "FETCH metric 'h1'.'m1'" )"
86 echo "$output" \
87         | grep -F '"h1"' \
88         | grep -F '"m1"' \
89         | grep -F '"attrM"' \
90         | grep -F '"valueM"'
92 stop_sysdbd
94 # vim: set tw=78 sw=4 ts=4 noexpandtab :