From 0ae7e85eb6a97370446041baf1a5943262a11d7f Mon Sep 17 00:00:00 2001 From: Jorik Cronenberg Date: Thu, 12 Oct 2023 17:29:38 +0200 Subject: [PATCH] Add script for migration testing --- rust/agama-migrate-wicked/tests/test.sh | 55 +++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100755 rust/agama-migrate-wicked/tests/test.sh diff --git a/rust/agama-migrate-wicked/tests/test.sh b/rust/agama-migrate-wicked/tests/test.sh new file mode 100755 index 0000000000..2af7b34dfe --- /dev/null +++ b/rust/agama-migrate-wicked/tests/test.sh @@ -0,0 +1,55 @@ +#!/bin/bash +RED='\033[0;31m' +GREEN='\033[0;32m' +NC='\033[0m' +RESULT=0 +MIGRATE_WICKED_BIN=../../target/debug/migrate-wicked +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +cd $SCRIPT_DIR +TEST_DIRS=$(ls -d */ | sed 's#/##') + +error_msg() { + echo -e "${RED}Error for test $1: $2${NC}" +} + +if [[ $(ls -A /etc/NetworkManager/system-connections/) ]]; then + echo -e "${RED}There are already NM connections. You may be running this script on a live system, which is highly discouraged!${NC}" + exit 1 +fi + +if [ ! -f $MIGRATE_WICKED_BIN ]; then + echo -e "${RED}No migrate-wicked binary found${NC}" + exit 1 +fi + +for test_dir in ${TEST_DIRS}; do + echo "Testing ${test_dir}" + $MIGRATE_WICKED_BIN show $test_dir/wicked_xml + if [ $? -ne 0 ]; then + error_msg ${test_dir} "show failed" + RESULT=1 + fi + $MIGRATE_WICKED_BIN migrate $test_dir/wicked_xml + if [ $? -ne 0 ]; then + error_msg ${test_dir} "migration failed" + RESULT=1 + continue + fi + for cmp_file in $(ls $test_dir/system-connections/); do + diff --unified=0 -I uuid $test_dir/system-connections/$cmp_file /etc/NetworkManager/system-connections/${cmp_file/\./\*.} + if [ $? -ne 0 ]; then + error_msg ${test_dir} "$cmp_file didn't match" + RESULT=1 + else + echo -e "${GREEN}Migration for connection ${cmp_file/\.*/} successful${NC}" + fi + done + rm -f /etc/NetworkManager/system-connections/* +done + +if [ $RESULT -eq 0 ]; then + echo -e "${GREEN}All tests successful${NC}" +else + echo -e "${RED}Some tests were unsuccessful${NC}" +fi +exit $RESULT