Skip to content

Commit

Permalink
Add script for migration testing
Browse files Browse the repository at this point in the history
  • Loading branch information
jcronenberg committed Oct 19, 2023
1 parent 37b9cf9 commit 2fa44fb
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions rust/agama-migrate-wicked/tests/test.sh
Original file line number Diff line number Diff line change
@@ -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 --color=always -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 failed${NC}"
fi
exit $RESULT

0 comments on commit 2fa44fb

Please sign in to comment.