Skip to content

Commit

Permalink
Merge pull request #2595 from llukask/fix-2423
Browse files Browse the repository at this point in the history
test: Fix is_not_rw_storage
  • Loading branch information
mpranj committed Oct 1, 2020
2 parents c61e388 + 4e76908 commit 6a1535c
Show file tree
Hide file tree
Showing 30 changed files with 134 additions and 64 deletions.
2 changes: 2 additions & 0 deletions doc/news/_preparation_next_release.md
Expand Up @@ -152,6 +152,8 @@ you up to date with the multi-language support provided by Elektra.

## Tests

- Fixed the `is_not_rw_storage` function. _(Lukas Kilian)_
- We now ensure that the `check_import` and `check_export` tests run for at least one plugin. _(Lukas Kilian)_
- <<TODO>>
- <<TODO>>
- <<TODO>>
Expand Down
9 changes: 8 additions & 1 deletion tests/shell/check_export.sh
Expand Up @@ -10,6 +10,8 @@ ROOT=$USER_ROOT
FILE="$(mktempfile_elektra)"
PLUGIN=$PLUGIN

RAN_ONCE=0

cleanup() {
rm -f $FILE
}
Expand All @@ -26,6 +28,8 @@ for PLUGIN in $PLUGINS; do
continue
fi

RAN_ONCE=1

echo -------- $PLUGIN -----------

"$KDB" set $ROOT "root" > /dev/null
Expand All @@ -40,7 +44,7 @@ for PLUGIN in $PLUGINS; do
diff "$DATADIR"/one_value.$PLUGIN $FILE
succeed_if "Export file one_value.$PLUGIN was not equal"

test "$("$KDB" set $ROOT/key "value")" = "Create a new key $ROOT/key with string value"
test "$("$KDB" set $ROOT/key "value")" = "Create a new key $ROOT/key with string \"value\""
succeed_if "Could not set $ROOT/key"

"$KDB" export $ROOT $PLUGIN > $FILE
Expand Down Expand Up @@ -72,4 +76,7 @@ for PLUGIN in $PLUGINS; do

done

test $RAN_ONCE != 0
succeed_if "check_export should run for at least one plugin"

end_script
68 changes: 41 additions & 27 deletions tests/shell/check_import.sh
Expand Up @@ -10,6 +10,8 @@ ROOT=$USER_ROOT
FILE="$(mktempfile_elektra)"
SIDE=$ROOT/../side_val

RAN_ONCE=0

cleanup() {
rm -f $FILE
}
Expand All @@ -20,12 +22,17 @@ exit_if_fail "For export/import /dev must be mounted"
[ -e /dev/stdout ]
exit_if_fail "For export/import /dev must be mounted"

"$KDB" rm -r $ROOT
"$KDB" rm $SIDE

for PLUGIN in $PLUGINS; do
if is_not_rw_storage; then
echo "-- $PLUGIN not a read-write storage"
continue
fi

RAN_ONCE=1

echo -------- $PLUGIN -----------

echo "Import with existing root"
Expand All @@ -41,14 +48,16 @@ for PLUGIN in $PLUGINS; do
test "x$("$KDB" ls $ROOT)" = "x$ROOT"
succeed_if "Root key not found"

"$KDB" import $ROOT $PLUGIN < "$DATADIR"/one_value.$PLUGIN
"$KDB" import $ROOT $PLUGIN "$DATADIR"/one_value.$PLUGIN
succeed_if "Could not run kdb import"

test "x$("$KDB" ls $ROOT)" = "xuser/tests/script"
succeed_if "key name not correct one_value"

test "$("$KDB" get $ROOT)" = root
succeed_if "root value not correct"
if [ "x$PLUGIN" != "xyajl" ]; then
test "$("$KDB" get $ROOT)" = root
succeed_if "root value not correct"
fi

"$KDB" export $ROOT $PLUGIN > $FILE
succeed_if "Could not run kdb export"
Expand All @@ -61,7 +70,7 @@ for PLUGIN in $PLUGINS; do

echo "Import with empty root"

"$KDB" import $ROOT $PLUGIN < "$DATADIR"/one_value.$PLUGIN
"$KDB" import $ROOT $PLUGIN "$DATADIR"/one_value.$PLUGIN
succeed_if "Could not run kdb import"

test "x$("$KDB" ls $ROOT)" = "xuser/tests/script"
Expand All @@ -83,29 +92,31 @@ for PLUGIN in $PLUGINS; do
"$KDB" rm -r $ROOT
succeed_if "Could not remove root"

echo "Import as stream (using cat)"
if [ "x$PLUGIN" != "xdini" ]; then
echo "Import as stream (using cat)"

cat "$DATADIR"/one_value.$PLUGIN | "$KDB" import $ROOT $PLUGIN
succeed_if "Could not run kdb import"
cat "$DATADIR"/one_value.$PLUGIN | "$KDB" import $ROOT $PLUGIN
succeed_if "Could not run kdb import"

test "x$("$KDB" ls $ROOT)" = "xuser/tests/script"
succeed_if "key name not correct one_value empty root"
test "x$("$KDB" ls $ROOT)" = "xuser/tests/script"
succeed_if "key name not correct one_value empty root"

if [ "x$PLUGIN" != "xyajl" ]; then
#TODO: yajl currently cannot hold values within
#directories, do not hardcode that
test "$("$KDB" get $ROOT)" = root
succeed_if "root value not correct"
fi
if [ "x$PLUGIN" != "xyajl" ]; then
#TODO: yajl currently cannot hold values within
#directories, do not hardcode that
test "$("$KDB" get $ROOT)" = root
succeed_if "root value not correct"
fi

"$KDB" export $ROOT $PLUGIN > $FILE
succeed_if "Could not run kdb export"
"$KDB" export $ROOT $PLUGIN > $FILE
succeed_if "Could not run kdb export"

diff "$DATADIR"/one_value.$PLUGIN $FILE
succeed_if "Export file one_value.$PLUGIN was not equal"
diff "$DATADIR"/one_value.$PLUGIN $FILE
succeed_if "Export file one_value.$PLUGIN was not equal"

"$KDB" rm -r $ROOT
succeed_if "Could not remove root"
"$KDB" rm -r $ROOT
succeed_if "Could not remove root"
fi

echo "Import with wrong root (overwrite)"

Expand All @@ -115,7 +126,7 @@ for PLUGIN in $PLUGINS; do
"$KDB" set $ROOT "wrong_root" > /dev/null
exit_if_fail "could not set wrong_root"

"$KDB" import -s "import" $ROOT $PLUGIN < "$DATADIR"/one_value.$PLUGIN
"$KDB" import -s "import" $ROOT $PLUGIN "$DATADIR"/one_value.$PLUGIN
succeed_if "Could not run kdb import"

test "x$("$KDB" ls $ROOT)" = "xuser/tests/script"
Expand Down Expand Up @@ -152,11 +163,11 @@ for PLUGIN in $PLUGINS; do
"$KDB" import $ROOT $PLUGIN < "$DATADIR"/two_value.$PLUGIN
succeed_if "Could not run kdb import"

test "x$("$KDB" ls $ROOT)" = "xuser/tests/script
if [ "x$PLUGIN" != "xyajl" ]; then
test "x$("$KDB" ls $ROOT)" = "xuser/tests/script
user/tests/script/key"
succeed_if "key name not correct"
succeed_if "key name not correct"

if [ "x$PLUGIN" != "xyajl" ]; then
#TODO: yajl currently cannot hold values within
#directories, do not hardcode that
test "$("$KDB" get $ROOT)" = root
Expand All @@ -177,7 +188,7 @@ user/tests/script/key"
"$KDB" set $SIDE val
succeed_if "Could not set $SIDE"

"$KDB" import -s "cut" $ROOT $PLUGIN < "$DATADIR"/one_value.$PLUGIN
"$KDB" import -s "cut" $ROOT $PLUGIN "$DATADIR"/one_value.$PLUGIN
succeed_if "Could not run kdb import"

test "x$("$KDB" ls $ROOT)" = "xuser/tests/script"
Expand Down Expand Up @@ -213,7 +224,7 @@ user/tests/script/key"
"$KDB" set $SIDE val
succeed_if "Could not set $SIDE"

"$KDB" import -s "cut" $ROOT $PLUGIN < "$DATADIR"/one_value.$PLUGIN
"$KDB" import -s "cut" $ROOT $PLUGIN "$DATADIR"/one_value.$PLUGIN
succeed_if "Could not run kdb import"

test "x$("$KDB" ls $ROOT)" = "xuser/tests/script"
Expand Down Expand Up @@ -247,4 +258,7 @@ user/tests/script/key"

done

test $RAN_ONCE != 0
succeed_if "check_import should run for at least one plugin"

end_script
2 changes: 1 addition & 1 deletion tests/shell/check_kdb_internal_suite.sh
Expand Up @@ -22,7 +22,7 @@ for PLUGIN in $PLUGINS; do
;;
"ini")
MOUNT_PLUGIN="$PLUGIN"
TESTS="basic string umlauts naming"
TESTS="basic string umlauts"
;;
"line")
TESTS="basic"
Expand Down
4 changes: 2 additions & 2 deletions tests/shell/generate_data.sh
Expand Up @@ -22,13 +22,13 @@ for PLUGIN in $PLUGINS; do
"$KDB" set $ROOT "root" > /dev/null
exit_if_fail "could not set root"

test $("$KDB" ls $ROOT) = $ROOT
test "$("$KDB" ls $ROOT)" = "$ROOT"
succeed_if "Root key not found"

"$KDB" export $ROOT $PLUGIN > "$DATADIR"/one_value.$PLUGIN
succeed_if "Could not run kdb export"

test "$("$KDB" set $ROOT/key "value")" = "create a new key $ROOT/key with string value"
test "$("$KDB" set $ROOT/key "value")" = "Create a new key $ROOT/key with string \"value\""
succeed_if "Could not set $ROOT/key"

"$KDB" export $ROOT $PLUGIN > "$DATADIR"/two_value.$PLUGIN
Expand Down
52 changes: 26 additions & 26 deletions tests/shell/include_common.sh.in
Expand Up @@ -203,8 +203,12 @@ check_set_mv_rm() {
#

is_not_rw_storage() {
test ! "x$("$KDB" plugin-info $PLUGIN provides 2> /dev/null)" = "xstorage" \
-o "x$PLUGIN" = "xhosts" \
echo $("$KDB" plugin-info $PLUGIN provides 2> /dev/null) | fgrep -qw "storage"
if [ $? != 0 ]; then
return 0
fi

test "x$PLUGIN" = "xhosts" \
-o "x$PLUGIN" = "xfstab" \
-o "x$PLUGIN" = "xline" \
-o "x$PLUGIN" = "xuname" \
Expand All @@ -217,7 +221,26 @@ is_not_rw_storage() {
-o "x$PLUGIN" = "xsimplespeclang" \
-o "x$PLUGIN" = "xmozprefs" \
-o "x$PLUGIN" = "xfile" \
-o "x$PLUGIN" = "xruby"
-o "x$PLUGIN" = "xruby" \
-o "x$PLUGIN" = "xdesktop" \
-o "x$PLUGIN" = "xc" \
-o "x$PLUGIN" = "xcpptemplate" \
-o "x$PLUGIN" = "xspecload" \
-o "x$PLUGIN" = "xmmapstorage" \
-o "x$PLUGIN" = "xmmapstorage_crc" \
-o "x$PLUGIN" = "xmultifile" \
-o "x$PLUGIN" = "xcamel" \
-o "x$PLUGIN" = "xsimpleini" \
-o "x$PLUGIN" = "xyambi" \
-o "x$PLUGIN" = "xtcl" \
-o "x$PLUGIN" = "xmini" \
-o "x$PLUGIN" = "xyaypeg" \
-o "x$PLUGIN" = "xyamlcpp" \
-o "x$PLUGIN" = "xyanlr" \
-o "x$PLUGIN" = "xyawn" \
-o "x$PLUGIN" = "xkconfig" \
-o "x$PLUGIN" = "xtoml" \
-o "x$PLUGIN" = "xdini"
}

is_plugin_available() {
Expand Down Expand Up @@ -974,27 +997,4 @@ export_check() {
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
# empty lines up to 1000 so that line numbers in the resulting scripts are more useful
3 changes: 3 additions & 0 deletions tests/shell/shell/again_two_value.dini
@@ -0,0 +1,3 @@
= root
[key]
subkey=another value
2 changes: 1 addition & 1 deletion tests/shell/shell/again_two_value.ini
@@ -1,3 +1,3 @@
= root
[key]
subkey = another value
subkey=another value
4 changes: 4 additions & 0 deletions tests/shell/shell/again_two_value.kconfig
@@ -0,0 +1,4 @@
script=root

[key]
subkey=another value
Binary file modified tests/shell/shell/again_two_value.quickdump
Binary file not shown.
1 change: 1 addition & 0 deletions tests/shell/shell/again_two_value.toml
@@ -0,0 +1 @@
key.subkey = "another value"
8 changes: 8 additions & 0 deletions tests/shell/shell/again_two_value.xerces
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<script>root

<key>
<subkey>another value</subkey>
</key>

</script>
1 change: 1 addition & 0 deletions tests/shell/shell/one_value.dini
@@ -0,0 +1 @@
= root
1 change: 1 addition & 0 deletions tests/shell/shell/one_value.kconfig
@@ -0,0 +1 @@
script=root
Binary file modified tests/shell/shell/one_value.quickdump
Binary file not shown.
Empty file.
2 changes: 2 additions & 0 deletions tests/shell/shell/one_value.xerces
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<script>root</script>
4 changes: 1 addition & 3 deletions tests/shell/shell/one_value.yajl
@@ -1,3 +1 @@
{

}
"root"
3 changes: 3 additions & 0 deletions tests/shell/shell/three_value.dini
@@ -0,0 +1,3 @@
= root
key=value
key/subkey=another value
4 changes: 2 additions & 2 deletions tests/shell/shell/three_value.ini
@@ -1,3 +1,3 @@
= root
key = value
key/subkey = another value
key=value
key/subkey=another value
5 changes: 5 additions & 0 deletions tests/shell/shell/three_value.kconfig
@@ -0,0 +1,5 @@
script=root
key=value

[key]
subkey=another value
Binary file modified tests/shell/shell/three_value.quickdump
Binary file not shown.
2 changes: 2 additions & 0 deletions tests/shell/shell/three_value.toml
@@ -0,0 +1,2 @@
key = "value"
key.subkey = "another value"
8 changes: 8 additions & 0 deletions tests/shell/shell/three_value.xerces
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<script>root

<key>value
<subkey>another value</subkey>
</key>

</script>
2 changes: 2 additions & 0 deletions tests/shell/shell/two_value.dini
@@ -0,0 +1,2 @@
= root
key=value
2 changes: 1 addition & 1 deletion tests/shell/shell/two_value.ini
@@ -1,2 +1,2 @@
= root
key = value
key=value
2 changes: 2 additions & 0 deletions tests/shell/shell/two_value.kconfig
@@ -0,0 +1,2 @@
script=root
key=value
Binary file modified tests/shell/shell/two_value.quickdump
Binary file not shown.
1 change: 1 addition & 0 deletions tests/shell/shell/two_value.toml
@@ -0,0 +1 @@
key = "value"
6 changes: 6 additions & 0 deletions tests/shell/shell/two_value.xerces
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<script>root

<key>value</key>

</script>

0 comments on commit 6a1535c

Please sign in to comment.