mirror of
https://github.com/YunoHost/package_check.git
synced 2024-09-03 20:06:20 +02:00
Improve semantic ... trying to decouple the 'test orchestration logic' from the actual tests...
This commit is contained in:
parent
a30b559509
commit
1bfa207369
2 changed files with 42 additions and 59 deletions
|
@ -23,6 +23,7 @@ clean_exit () {
|
||||||
rm -f "$script_dir/url_output"
|
rm -f "$script_dir/url_output"
|
||||||
rm -f "$script_dir/curl_print"
|
rm -f "$script_dir/curl_print"
|
||||||
rm -f "$script_dir/manifest_extract"
|
rm -f "$script_dir/manifest_extract"
|
||||||
|
rm -rf "$script_dir/tmp_context_for_tests"
|
||||||
|
|
||||||
# Remove the application which been tested
|
# Remove the application which been tested
|
||||||
if [ -n "$package_path" ]; then
|
if [ -n "$package_path" ]; then
|
||||||
|
@ -883,20 +884,15 @@ then
|
||||||
# Remove all spaces at the beginning of the lines
|
# Remove all spaces at the beginning of the lines
|
||||||
sed --in-place 's/^[ \t]*//g' "$check_process"
|
sed --in-place 's/^[ \t]*//g' "$check_process"
|
||||||
|
|
||||||
# Check if a string can be find in the current line
|
|
||||||
check_line () {
|
|
||||||
return $(echo "$line" | grep -q "$1")
|
|
||||||
}
|
|
||||||
|
|
||||||
# Search a string in the partial check_process
|
# Search a string in the partial check_process
|
||||||
find_string () {
|
find_string () {
|
||||||
echo $(grep -m1 "$1" "$partial_check_process")
|
echo $(grep -m1 "$1" "$check_process_section")
|
||||||
}
|
}
|
||||||
|
|
||||||
# Extract a section found between $1 and $2 from the file $3
|
# Extract a section found between $1 and $2 from the file $3
|
||||||
extract_section () {
|
extract_section () {
|
||||||
# Erase the partial check_process
|
# Erase the partial check_process
|
||||||
> "$partial_check_process"
|
> "$check_process_section"
|
||||||
local source_file="$3"
|
local source_file="$3"
|
||||||
local extract=0
|
local extract=0
|
||||||
local line=""
|
local line=""
|
||||||
|
@ -906,16 +902,16 @@ then
|
||||||
if [ $extract -eq 1 ]
|
if [ $extract -eq 1 ]
|
||||||
then
|
then
|
||||||
# Check if the line is the second line to found
|
# Check if the line is the second line to found
|
||||||
if check_line "$2"; then
|
if echo $line | grep -q "$2"; then
|
||||||
# Break the loop to finish the extract process
|
# Break the loop to finish the extract process
|
||||||
break;
|
break;
|
||||||
fi
|
fi
|
||||||
# Copy the line in the partial check_process
|
# Copy the line in the partial check_process
|
||||||
echo "$line" >> "$partial_check_process"
|
echo "$line" >> "$check_process_section"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Search for the first line
|
# Search for the first line
|
||||||
if check_line "$1"; then
|
if echo $line | grep -q "$1"; then
|
||||||
# Activate the extract process
|
# Activate the extract process
|
||||||
extract=1
|
extract=1
|
||||||
fi
|
fi
|
||||||
|
@ -928,7 +924,7 @@ then
|
||||||
|
|
||||||
|
|
||||||
# Extract the level section
|
# Extract the level section
|
||||||
partial_check_process=$partial1
|
check_process_section=$partial1
|
||||||
extract_section "^;;; Levels" ";; " "$check_process"
|
extract_section "^;;; Levels" ";; " "$check_process"
|
||||||
|
|
||||||
# Get the value associated to each level
|
# Get the value associated to each level
|
||||||
|
@ -945,7 +941,7 @@ then
|
||||||
|
|
||||||
|
|
||||||
# Extract the Options section
|
# Extract the Options section
|
||||||
partial_check_process=$partial1
|
check_process_section=$partial1
|
||||||
extract_section "^;;; Options" ";; " "$check_process"
|
extract_section "^;;; Options" ";; " "$check_process"
|
||||||
|
|
||||||
# Try to find a optionnal email address to notify the maintainer
|
# Try to find a optionnal email address to notify the maintainer
|
||||||
|
@ -963,39 +959,30 @@ then
|
||||||
# Initialize the values for this serie of tests
|
# Initialize the values for this serie of tests
|
||||||
initialize_values
|
initialize_values
|
||||||
|
|
||||||
|
rm -rf $script_dir/tmp_context_for_tests/
|
||||||
|
mkdir -p $script_dir/tmp_context_for_tests/
|
||||||
|
|
||||||
# Break after the first tests serie
|
# Break after the first tests serie
|
||||||
if [ $total_number_of_test -ne 0 ] && [ $bash_mode -ne 1 ]; then
|
if [ $total_number_of_test -ne 0 ] && [ $bash_mode -ne 1 ]; then
|
||||||
read -p "Press a key to start the next tests serie..." < /dev/tty
|
read -p "Press a key to start the next tests serie..." < /dev/tty
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Use the second file to extract the whole section of a tests serie
|
# Use the second file to extract the whole section of a tests serie
|
||||||
partial_check_process=$partial2
|
check_process_section=$partial2
|
||||||
|
|
||||||
# Extract the section of the current tests serie
|
# Extract the section of the current tests serie
|
||||||
extract_section "^$tests_serie" "^;;" "$check_process"
|
extract_section "^$tests_serie" "^;;" "$check_process"
|
||||||
partial_check_process=$partial1
|
check_process_section=$partial1
|
||||||
|
|
||||||
# Check if there a pre-install instruction for this serie
|
# Check if there a pre-install instruction for this serie
|
||||||
extract_section "^; pre-install" "^;" "$partial2"
|
extract_section "^; pre-install" "^;" "$partial2"
|
||||||
pre_install="$(cat "$partial_check_process")"
|
cat "$check_process_section" > ./tmp_context_for_tests/preinstall.sh.template
|
||||||
|
|
||||||
# Parse all infos about arguments of manifest
|
# Parse all infos about arguments of manifest
|
||||||
# Extract the manifest arguments section from the second partial file
|
# Extract the manifest arguments section from the second partial file
|
||||||
extract_section "^; Manifest" "^; " "$partial2"
|
extract_section "^; Manifest" "^; " "$partial2"
|
||||||
|
|
||||||
# Initialize the arguments list
|
manifest_arguments=$(cat $check_process_section | awk '{print $1}' | tr -d '"' | tr '\n' '&')
|
||||||
manifest_arguments=""
|
|
||||||
|
|
||||||
# Read each arguments and store them
|
|
||||||
while read line
|
|
||||||
do
|
|
||||||
# Extract each argument by removing spaces or tabulations before a parenthesis
|
|
||||||
add_arg="$(echo $line | sed 's/[ *|\t*](.*//')"
|
|
||||||
# Remove all double quotes
|
|
||||||
add_arg="${add_arg//\"/}"
|
|
||||||
# Then add this argument and follow it by &
|
|
||||||
manifest_arguments="${manifest_arguments}${add_arg}&"
|
|
||||||
done < "$partial_check_process"
|
|
||||||
|
|
||||||
# Try to find all specific arguments needed for the tests
|
# Try to find all specific arguments needed for the tests
|
||||||
keep_name_arg_only () {
|
keep_name_arg_only () {
|
||||||
|
@ -1056,7 +1043,7 @@ then
|
||||||
add_arg="${line//\"/}"
|
add_arg="${line//\"/}"
|
||||||
# Then add this argument and follow it by :
|
# Then add this argument and follow it by :
|
||||||
actions_arguments="${actions_arguments}${add_arg}:"
|
actions_arguments="${actions_arguments}${add_arg}:"
|
||||||
done < "$partial_check_process"
|
done < "$check_process_section"
|
||||||
|
|
||||||
# Parse all infos about arguments of config-panel.toml
|
# Parse all infos about arguments of config-panel.toml
|
||||||
# Extract the config_panel arguments section from the second partial file
|
# Extract the config_panel arguments section from the second partial file
|
||||||
|
@ -1072,7 +1059,7 @@ then
|
||||||
add_arg="${line//\"/}"
|
add_arg="${line//\"/}"
|
||||||
# Then add this argument and follow it by :
|
# Then add this argument and follow it by :
|
||||||
config_panel_arguments="${config_panel_arguments}${add_arg}:"
|
config_panel_arguments="${config_panel_arguments}${add_arg}:"
|
||||||
done < "$partial_check_process"
|
done < "$check_process_section"
|
||||||
|
|
||||||
# Parse all tests to perform
|
# Parse all tests to perform
|
||||||
# Extract the checks options section from the second partial file
|
# Extract the checks options section from the second partial file
|
||||||
|
@ -1080,9 +1067,7 @@ then
|
||||||
|
|
||||||
read_check_option () {
|
read_check_option () {
|
||||||
# Find the line for the given check option
|
# Find the line for the given check option
|
||||||
local line=$(find_string "^$1=")
|
local value=$(find_string "^$1=" | awk -F= '{print $2}')
|
||||||
# Get only the value
|
|
||||||
local value=$(echo "$line" | cut -d '=' -f2)
|
|
||||||
# And return this value
|
# And return this value
|
||||||
if [ "${value:0:1}" = "1" ]
|
if [ "${value:0:1}" = "1" ]
|
||||||
then
|
then
|
||||||
|
@ -1139,9 +1124,9 @@ then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Clean the upgrade list
|
# Clean the upgrade list
|
||||||
> "$script_dir/upgrade_list"
|
touch "$script_dir/tmp_context_for_tests/upgrade_list"
|
||||||
# Get multiples lines for upgrade option.
|
# Get multiples lines for upgrade option.
|
||||||
while $(grep --quiet "^upgrade=" "$partial_check_process")
|
while $(grep --quiet "^upgrade=" "$check_process_section")
|
||||||
do
|
do
|
||||||
# Get the value for the first upgrade test.
|
# Get the value for the first upgrade test.
|
||||||
temp_upgrade=$(read_check_option upgrade)
|
temp_upgrade=$(read_check_option upgrade)
|
||||||
|
@ -1158,14 +1143,14 @@ then
|
||||||
line="${line##*from_commit=}"
|
line="${line##*from_commit=}"
|
||||||
# Add the upgrade to the list only if the test is set to 1
|
# Add the upgrade to the list only if the test is set to 1
|
||||||
if [ $temp_upgrade -eq 1 ]; then
|
if [ $temp_upgrade -eq 1 ]; then
|
||||||
echo "$line" >> "$script_dir/upgrade_list"
|
echo "$line" >> "$script_dir/tmp_context_for_tests/upgrade_list"
|
||||||
fi
|
fi
|
||||||
elif [ $temp_upgrade -eq 1 ]; then
|
elif [ $temp_upgrade -eq 1 ]; then
|
||||||
# Or simply 'current' for a standard upgrade.
|
# Or simply 'current' for a standard upgrade.
|
||||||
echo "current" >> "$script_dir/upgrade_list"
|
echo "current" >> "$script_dir/tmp_context_for_tests/upgrade_list"
|
||||||
fi
|
fi
|
||||||
# Remove this line from the check_process
|
# Remove this line from the check_process
|
||||||
sed --in-place "\|${line}$|d" "$partial_check_process"
|
sed --in-place "\|${line}$|d" "$check_process_section"
|
||||||
done
|
done
|
||||||
|
|
||||||
# Launch all tests successively
|
# Launch all tests successively
|
||||||
|
@ -1188,7 +1173,7 @@ else
|
||||||
|
|
||||||
manifest_extract="$script_dir/manifest_extract"
|
manifest_extract="$script_dir/manifest_extract"
|
||||||
|
|
||||||
# Extract the informations from the manifest with the Bram's sly snake script.
|
# Extract the informations from the manifest with the Brams sly snake script.
|
||||||
python "$script_dir/sub_scripts/manifest_parsing.py" "$package_path/manifest.json" > "$manifest_extract"
|
python "$script_dir/sub_scripts/manifest_parsing.py" "$package_path/manifest.json" > "$manifest_extract"
|
||||||
|
|
||||||
# Default tests
|
# Default tests
|
||||||
|
|
|
@ -2,13 +2,6 @@
|
||||||
|
|
||||||
echo -e "Loads functions from testing_process.sh"
|
echo -e "Loads functions from testing_process.sh"
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# Globals variables
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
# A complete list of backup hooks is available at /usr/share/yunohost/hooks/backup/
|
|
||||||
backup_hooks="conf_ssowat data_home conf_ynh_firewall conf_cron"
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
break_before_continue () {
|
break_before_continue () {
|
||||||
|
@ -58,23 +51,25 @@ SETUP_APP () {
|
||||||
current_snapshot=snap0
|
current_snapshot=snap0
|
||||||
|
|
||||||
# Exec the pre-install instruction, if there one
|
# Exec the pre-install instruction, if there one
|
||||||
if [ -n "$pre_install" ]
|
preinstall_script_template="$script_dir/tmp_context_for_tests/preinstall.sh.template"
|
||||||
|
if [ -e "$preinstall_script_template" ]
|
||||||
then
|
then
|
||||||
small_title "Pre installation request"
|
small_title "Pre installation request"
|
||||||
# Start the lxc container
|
# Start the lxc container
|
||||||
LXC_START "true"
|
LXC_START "true"
|
||||||
# Copy all the instructions into a script
|
# Copy all the instructions into a script
|
||||||
echo "$pre_install" > "$script_dir/preinstall.sh"
|
preinstall_script="$script_dir/tmp_context_for_tests/preinstall.sh"
|
||||||
chmod +x "$script_dir/preinstall.sh"
|
cp "$preinstall_script_template" "$preinstall_script"
|
||||||
# Replace variables
|
chmod +x "$preinstall_script"
|
||||||
sed -i "s/\$USER/$test_user/" "$script_dir/preinstall.sh"
|
# Hydrate the template with variables
|
||||||
sed -i "s/\$DOMAIN/$main_domain/" "$script_dir/preinstall.sh"
|
sed -i "s/\$USER/$test_user/" "$preinstall_script"
|
||||||
sed -i "s/\$SUBDOMAIN/$sub_domain/" "$script_dir/preinstall.sh"
|
sed -i "s/\$DOMAIN/$main_domain/" "$preinstall_script"
|
||||||
sed -i "s/\$PASSWORD/$yuno_pwd/" "$script_dir/preinstall.sh"
|
sed -i "s/\$SUBDOMAIN/$sub_domain/" "$preinstall_script"
|
||||||
|
sed -i "s/\$PASSWORD/$yuno_pwd/" "$preinstall_script"
|
||||||
# Copy the pre-install script into the container.
|
# Copy the pre-install script into the container.
|
||||||
scp -rq "$script_dir/preinstall.sh" "$lxc_name":
|
scp -rq "$preinstall_script" "$lxc_name":
|
||||||
# Then execute the script to execute the pre-install commands.
|
# Then execute the script to execute the pre-install commands.
|
||||||
LXC_START "./preinstall.sh >&2" | tee -a "$complete_log"
|
LXC_START "./preinstall.sh >&2"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Install the application in a LXC container
|
# Install the application in a LXC container
|
||||||
|
@ -658,7 +653,7 @@ CHECK_UPGRADE () {
|
||||||
# Get the specific section for this upgrade from the check_process
|
# Get the specific section for this upgrade from the check_process
|
||||||
extract_section "^; commit=$commit" "^;" "$check_process"
|
extract_section "^; commit=$commit" "^;" "$check_process"
|
||||||
# Get the name for this upgrade.
|
# Get the name for this upgrade.
|
||||||
upgrade_name=$(grep "^name=" "$partial_check_process" | cut -d'=' -f2)
|
upgrade_name=$(grep "^name=" "$check_process_section" | cut -d'=' -f2)
|
||||||
# Or use the commit if there's no name.
|
# Or use the commit if there's no name.
|
||||||
if [ -z "$upgrade_name" ]; then
|
if [ -z "$upgrade_name" ]; then
|
||||||
start_test "Upgrade from the commit $commit"
|
start_test "Upgrade from the commit $commit"
|
||||||
|
@ -698,7 +693,7 @@ CHECK_UPGRADE () {
|
||||||
# Backup the modified arguments
|
# Backup the modified arguments
|
||||||
update_manifest_args="$manifest_args_mod"
|
update_manifest_args="$manifest_args_mod"
|
||||||
# Get the arguments of the manifest for this upgrade.
|
# Get the arguments of the manifest for this upgrade.
|
||||||
manifest_args_mod="$(grep "^manifest_arg=" "$partial_check_process" | cut -d'=' -f2-)"
|
manifest_args_mod="$(grep "^manifest_arg=" "$check_process_section" | cut -d'=' -f2-)"
|
||||||
if [ -z "$manifest_args_mod" ]; then
|
if [ -z "$manifest_args_mod" ]; then
|
||||||
# If there's no specific arguments, use the previous one.
|
# If there's no specific arguments, use the previous one.
|
||||||
manifest_args_mod="$update_manifest_args"
|
manifest_args_mod="$update_manifest_args"
|
||||||
|
@ -764,7 +759,7 @@ CHECK_UPGRADE () {
|
||||||
current_snapshot=snap0
|
current_snapshot=snap0
|
||||||
# Stop and restore the LXC container
|
# Stop and restore the LXC container
|
||||||
LXC_STOP >> $complete_log
|
LXC_STOP >> $complete_log
|
||||||
done 4< "$script_dir/upgrade_list"
|
done 4< "$script_dir/tmp_context_for_tests/upgrade_list"
|
||||||
}
|
}
|
||||||
|
|
||||||
CHECK_PUBLIC_PRIVATE () {
|
CHECK_PUBLIC_PRIVATE () {
|
||||||
|
@ -1144,6 +1139,9 @@ CHECK_BACKUP_RESTORE () {
|
||||||
else
|
else
|
||||||
small_title "Backup of the application..."
|
small_title "Backup of the application..."
|
||||||
|
|
||||||
|
# A complete list of backup hooks is available at /usr/share/yunohost/hooks/backup/
|
||||||
|
backup_hooks="conf_ssowat data_home conf_ynh_firewall conf_cron"
|
||||||
|
|
||||||
# Made a backup of the application
|
# Made a backup of the application
|
||||||
run_yunohost "backup create -n Backup_test --apps $ynh_app_id --system $backup_hooks"
|
run_yunohost "backup create -n Backup_test --apps $ynh_app_id --system $backup_hooks"
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue