forked from ElektraInitiative/libelektra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_get_set.sh
executable file
·151 lines (112 loc) · 3.47 KB
/
check_get_set.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/bin/sh
@INCLUDE_COMMON@
echo
echo ELEKTRA BASIC COMMAND SCRIPTS TESTS
echo
check_version
VALUE=value
#override for specific testing
#PLUGINS="ini"
for PLUGIN in $PLUGINS; do
if is_not_rw_storage; then
echo "$PLUGIN not a read-write storage"
continue
fi
case "$PLUGIN" in
"tcl")
MOUNT_PLUGIN="tcl ccode null"
;;
"yajl")
MOUNT_PLUGIN="$PLUGIN"
;;
"simpleini")
MOUNT_PLUGIN="simpleini ccode null"
;;
"ini")
MOUNT_PLUGIN="ini array="
;;
*)
MOUNT_PLUGIN="$PLUGIN"
;;
esac
unset -f cleanup
FILE=test.$PLUGIN
echo
echo "-- Testing $PLUGIN"
check_remaining_files "$FILE"
"$KDB" mount "$FILE" "$MOUNTPOINT" "$MOUNT_PLUGIN" 1> /dev/null
exit_if_fail "could not mount $FILE at $MOUNTPOINT using $MOUNT_PLUGIN"
cleanup() {
"$KDB" umount "$MOUNTPOINT" > /dev/null
succeed_if "could not umount $MOUNTPOINT"
rm -f "$USER_FOLDER"/"$FILE"
rm -f "$SYSTEM_FOLDER"/"$FILE"
USER_REMAINING="$(find "$USER_FOLDER" -maxdepth 1 -name "$FILE"'*' -print -exec rm {} +)"
test -z "$USER_REMAINING"
succeed_if "found remaining files $USER_REMAINING in $USER_FOLDER"
SYSTEM_REMAINING="$(find "$SYSTEM_FOLDER" -maxdepth 1 -name "$FILE"'*' -print -exec rm {} +)"
test -z "$SYSTEM_REMAINING"
succeed_if "found remaining files $SYSTEM_REMAINING in $SYSTEM_FOLDER"
}
for ROOT in $ROOTS; do
#echo "do preparation for $PLUGIN in $ROOT"
"$KDB" set "$ROOT" "root" 1> /dev/null
succeed_if "could not set root"
[ "x$("$KDB" sget "$ROOT"/value defvalue 2> /dev/null)" = "xdefvalue" ]
succeed_if "Did not get default value"
"$KDB" set "$ROOT/value" "$VALUE" 1> /dev/null
succeed_if "could not set value"
[ "x$("$KDB" get "$ROOT"/value 2> /dev/null)" = "x$VALUE" ]
succeed_if "cant get $ROOT/value"
[ "x$("$KDB" sget "$ROOT"/value default 2> /dev/null)" = "x$VALUE" ]
succeed_if "cant shell get $ROOT/value"
echo "testing ls command"
[ "x$("$KDB" ls "$ROOT"/value 2> /dev/null)" = "x$ROOT/value" ]
succeed_if "cant ls $ROOT (may mean that $ROOT folder is not clean)"
echo "testing rm command"
"$KDB" rm "$ROOT"/value 1> /dev/null
succeed_if "could not remove user:/test/value"
"$KDB" get "$ROOT"/value 1> /dev/null
[ $? != "0" ]
succeed_if "got removed key $ROOT/value"
"$KDB" rm "$ROOT" 1> /dev/null
succeed_if "could not remove user:/test/value"
[ "x$("$KDB" sget "$ROOT"/value value 2> /dev/null)" = "xvalue" ]
succeed_if "Did not get default value after remove"
"$KDB" get "$ROOT"/value 1> /dev/null
[ $? != "0" ]
succeed_if "got removed key $ROOT"
check_set_rm "$ROOT"/value other_value
echo "testing array"
KEY=$ROOT/hello/a/key
"$KDB" set "$KEY" "$VALUE" 1> /dev/null
succeed_if "could not set key $KEY"
[ "x$("$KDB" get "$KEY")" = "x$VALUE" ]
succeed_if "$KEY is not $VALUE"
i=0
j=9
while [ "$i" -le "$j" ]; do
KEY="$ROOT/hello/a/array/#$i"
VALUE="$i"
"$KDB" set "$KEY" "$VALUE" 1> /dev/null
succeed_if "could not set key $ROOT/hello/a/array/#0"
if [ "$i" -eq 0 ] && [ "x$PLUGIN" = "xini" ]; then
[ "x$("$KDB" get "$ROOT"/hello/a/array)" = "x$VALUE" ]
succeed_if "$KEY is not $VALUE"
else
[ "x$("$KDB" get "$KEY")" = "x$VALUE" ]
succeed_if "$KEY is not $VALUE"
fi
i=$((i + 1))
done
"$KDB" rm -r "$ROOT"
succeed_if "could not remove all keys"
test ! -f "$USER_FOLDER"/"$FILE"
succeed_if "user file was not removed"
test ! -f "$SYSTEM_FOLDER"/"$FILE"
succeed_if "system file was not removed"
done
cleanup
done
unset -f cleanup
end_script basic commands