Persist variables to file (~/.whenjobs/variables).
[whenjobs.git] / tests / variables / test-persistent-variables.sh
1 # whenjobs
2 # Copyright (C) 2012 Red Hat Inc.
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18 # Test that variables are reloaded across runs.
19
20 unset CDPATH
21 set -e
22
23 testdir=$(pwd)
24 libdir=$(cd ../../lib; pwd)
25 toolsdir=$(cd ../../tools; pwd)
26 daemondir=$(cd ../../daemon; pwd)
27
28 HOME="$testdir"
29 export HOME
30
31 rm -rf "$testdir/.whenjobs"
32
33 PATH="$toolsdir:$daemondir:$PATH"
34 export PATH
35
36 # Kill the daemon and clean up when the script exits.
37 function cleanup {
38     kill `cat "$testdir/.whenjobs/daemon_pid"`
39     rm -rf "$testdir/.whenjobs"
40 }
41 trap cleanup INT TERM QUIT EXIT
42
43 # Run the daemon.
44 whenjobsd -d
45
46 whenjobs --lib "$libdir" --type float --set test_float=4.2
47 whenjobs --lib "$libdir" --type int --set test_int=42
48 whenjobs --lib "$libdir" --type string --set test_string=fortytwo
49
50 whenjobs --lib "$libdir" --daemon-stop >/dev/null 2>&1 ||:
51
52 # Run the daemon again and read back the variables.
53 whenjobsd -d
54
55 output="$(whenjobs --lib "$libdir" --variables | LANG=C sort)"
56
57 whenjobs --lib "$libdir" --daemon-stop >/dev/null 2>&1 ||:
58
59 trap - INT TERM QUIT EXIT
60 rm -rf "$testdir/.whenjobs"
61
62 if [ "$output" != "JOBSERIAL=0
63 test_float=4.2
64 test_int=42
65 test_string=fortytwo" ]; then
66     echo "$0: unexpected variables in output:"
67     echo "$output"
68     exit 1
69 fi
70
71 rm -rf "$testdir/.whenjobs"