summaryrefslogtreecommitdiff
path: root/testing
diff options
context:
space:
mode:
authorAlexey Neyman <stilor@att.net>2019-02-05 08:53:36 (GMT)
committerAlexey Neyman <stilor@att.net>2019-02-05 08:53:36 (GMT)
commit523534c9db64943ca8c25cffd6f3b186f60a856a (patch)
tree4b62a3eb147378d0bee8a01a3fe94873276d3315 /testing
parent3b86d2d0e6a2d28ee95ef9c3b78b8d6f836e4550 (diff)
Start a testsuite for upgrade script
Signed-off-by: Alexey Neyman <stilor@att.net>
Diffstat (limited to 'testing')
-rw-r--r--testing/upgrade/.gitignore2
-rwxr-xr-xtesting/upgrade/run.sh116
2 files changed, 118 insertions, 0 deletions
diff --git a/testing/upgrade/.gitignore b/testing/upgrade/.gitignore
new file mode 100644
index 0000000..4585bba
--- /dev/null
+++ b/testing/upgrade/.gitignore
@@ -0,0 +1,2 @@
+.config*
+logs
diff --git a/testing/upgrade/run.sh b/testing/upgrade/run.sh
new file mode 100755
index 0000000..41d3bb0
--- /dev/null
+++ b/testing/upgrade/run.sh
@@ -0,0 +1,116 @@
+#!/bin/bash
+
+CTNG=${CTNG-../../ct-ng}
+
+current_tc=unknown
+fails_tc=0
+fails_total=0
+
+fail()
+{
+ fails_tc=$[fails_tc + 1]
+ fails_total=$[fails_total + 1]
+}
+
+finish()
+{
+ if [ "${fails_tc}" != 0 ]; then
+ echo ">>>>> $current_tc: FAIL" >&2
+ else
+ echo ">>>>> $current_tc: PASS" >&2
+ fi
+ fails_tc=0
+}
+
+run_sample()
+{
+ local -A expect_set expect_unset
+ local o v ln
+
+ # Basename for logging
+ exec {LOG}>"logs/${current_tc}.log"
+
+ # Determine expected values
+ while read ln; do
+ case "${ln}" in
+ "## "*"="*)
+ ln=${ln#* }
+ o=${ln%%=*}
+ v=${ln#*=}
+ expect_set[${o}]=${v}
+ ;;
+ "## "*" is not set")
+ ln=${ln#* }
+ o=${ln%% *}
+ expect_unset[${o}]=1
+ ;;
+ esac
+ done < "samples/${current_tc}.config"
+
+ # Now run the upgrade
+ echo ">>>> Running the config through an upgrade" >&${LOG}
+ cp "samples/${current_tc}.config" .config
+ ${CTNG} upgradeconfig >&${LOG} 2>&${LOG}
+ echo >&${LOG}
+ echo ">>>> Checking the config after the upgrade" >&${LOG}
+ while read ln; do
+ case "${ln}" in
+ *"="*)
+ o=${ln%%=*}
+ v=${ln#*=}
+ if [ "${expect_unset[${o}]+set}" = "set" ]; then
+ echo "Expect ${o} to be unset" >&${LOG}
+ echo "Actual value of ${o}: ${v}" >&${LOG}
+ fail
+ elif [ "${expect_set[${o}]+set}" = "set" ]; then
+ if [ "${expect_set[${o}]}" != "${v}" ]; then
+ echo "Expect value of ${o}: ${expect_set[${o}]}" >&${LOG}
+ echo "Actual value of ${o}: ${v}" >&${LOG}
+ fail
+ else
+ echo "Matched value of ${o}: ${v}" >&${LOG}
+ fi
+ fi
+ unset expect_set[${o}]
+ unset expect_unset[${o}]
+ ;;
+ "# "*" is not set")
+ ln=${ln#* }
+ o=${ln%% *}
+ if [ "${expect_set[${o}]+set}" = "set" ]; then
+ echo "Expect value of ${o}: ${expect_set[${o}]}" >&${LOG}
+ echo "Actual ${o} is unset" >&${LOG}
+ fail
+ elif [ "${expect_unset[${o}]+set}" = "set" ]; then
+ echo "Matched unset ${o}" >&${LOG}
+ fi
+ unset expect_set[${o}]
+ unset expect_unset[${o}]
+ ;;
+ esac
+ done < .config
+ for o in "${!expect_set[@]}"; do
+ echo "Expect value of ${o}: ${expect_set[${o}]}" >&${LOG}
+ echo "Variable ${o} not present" >&${LOG}
+ fail
+ done
+ for o in "${!expect_unset[@]}"; do
+ echo "Expect ${o} being unset" >&${LOG}
+ echo "Variable ${o} not present" >&${LOG}
+ fail
+ done
+ exec {LOG}>&-
+ finish
+}
+
+mkdir -p logs
+for i in samples/*.config; do
+ current_tc=${i#samples/}
+ current_tc=${current_tc%.config}
+ run_sample
+done
+
+if [ "${fails_total}" != 0 ]; then
+ exit 1
+fi
+exit 0