2024-06-24 16:09:48 +00:00
|
|
|
#! /bin/bash
|
2024-06-25 13:52:05 +00:00
|
|
|
#importer driglibash
|
2024-07-11 12:04:25 +00:00
|
|
|
. driglibash-base
|
|
|
|
echo "<execution of test_git_update.sh>"
|
|
|
|
|
|
|
|
REPO_NAME=performance_testing
|
2024-07-11 16:31:19 +00:00
|
|
|
REMOTE=ssh://git@git.jean-cloud.net:22529/eleonore/performance_testing.git
|
2024-07-11 12:04:25 +00:00
|
|
|
WITH_SUBMODULE="true"
|
2024-07-12 08:10:04 +00:00
|
|
|
FILENAMES=("sample0" "sample1") #we do not check for all files
|
2024-07-11 16:31:19 +00:00
|
|
|
FILENAMES_TAG=("sample0")
|
2024-07-12 08:10:04 +00:00
|
|
|
FILENAMES_BRANCH=("sample0" "sample1") #we do not check for all files, especially not those specific to the branch.
|
2024-07-11 12:04:25 +00:00
|
|
|
TAG_NAME=start
|
2024-07-12 08:10:04 +00:00
|
|
|
BRANCH_NAME=secondary
|
2024-07-11 12:04:25 +00:00
|
|
|
|
|
|
|
if [ "$WITH_SUBMODULE" = "true" ]; then
|
|
|
|
bash creation_repo.sh -s &> /dev/null
|
|
|
|
else
|
|
|
|
bash creation_repo.sh &> /dev/null
|
2024-06-24 16:09:48 +00:00
|
|
|
fi
|
2024-07-11 12:04:25 +00:00
|
|
|
|
|
|
|
Help()
|
|
|
|
{
|
|
|
|
echo "
|
|
|
|
NAME
|
|
|
|
test_git_update.sh
|
|
|
|
SYNOPSIS
|
|
|
|
test_git_update.sh [-a] [-h] [-n number]
|
|
|
|
OPTIONS
|
|
|
|
-a excutes all the tests.
|
|
|
|
-n number executes test number
|
|
|
|
-h prints the help.
|
2024-07-12 08:10:04 +00:00
|
|
|
DESCRIPTION
|
|
|
|
Tests on the initial cloning
|
|
|
|
TEST0: git cloned in an empty directory
|
|
|
|
TEST1: git cloned in an empty directory with tag
|
|
|
|
TEST2: git cloned in an empty directory with branch
|
2024-07-12 16:30:57 +00:00
|
|
|
TEST3: git cloned in an existing directory
|
2024-07-12 08:10:04 +00:00
|
|
|
"
|
2024-07-11 12:04:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cloning_check(){
|
2024-07-12 15:17:29 +00:00
|
|
|
local input=("$@")
|
|
|
|
local repo_name=${input[0]}
|
|
|
|
local FILENAMES=${input[@]:1}
|
|
|
|
if [[ -d "./$repo_name" ]]; then
|
|
|
|
echo "into $repo_name"
|
|
|
|
cloning_result=0
|
|
|
|
for FILE in ${FILENAMES[@]}
|
|
|
|
do
|
|
|
|
if [ -f "./$repo_name/$FILE" ]; then
|
|
|
|
echo "the file $FILE has correctly been imported"
|
|
|
|
else
|
|
|
|
echo "the file $FILE could not be imported"
|
|
|
|
cloning_result=1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
else
|
|
|
|
cloning_result=1
|
|
|
|
echo "the directory $repo_name could not be created"
|
|
|
|
fi
|
2024-07-11 12:04:25 +00:00
|
|
|
}
|
2024-06-24 16:09:48 +00:00
|
|
|
|
2024-07-11 12:04:25 +00:00
|
|
|
history_check(){
|
2024-07-12 15:17:29 +00:00
|
|
|
local repo_name=$1
|
|
|
|
cd $repo_name
|
2024-07-11 12:04:25 +00:00
|
|
|
history_result=0
|
|
|
|
if [ $(git log | grep "commit" | wc -l) -gt 1 ]; then
|
|
|
|
echo "Several commits have been saved"
|
|
|
|
history_result=1
|
|
|
|
elif [ $(git log | grep "commit" | wc -l) = 1 ]; then
|
|
|
|
echo "Only the last commit has been saved"
|
|
|
|
else
|
|
|
|
history_result=1
|
|
|
|
echo "Cloning error, incoherent git log"
|
|
|
|
fi
|
|
|
|
cd ..
|
|
|
|
}
|
2024-06-24 16:09:48 +00:00
|
|
|
|
2024-07-11 16:31:19 +00:00
|
|
|
tag_check(){
|
2024-07-12 15:17:29 +00:00
|
|
|
local repo_name=$1
|
|
|
|
cd $repo_name
|
|
|
|
run $(git branch) > res
|
2024-07-11 16:31:19 +00:00
|
|
|
if [ $(grep "no branch" res | wc -l) = 1 ];then
|
2024-07-12 07:54:26 +00:00
|
|
|
echo "The tag instruction has been respected"
|
2024-07-11 16:31:19 +00:00
|
|
|
tag_result=0
|
|
|
|
else
|
|
|
|
tag_result=1
|
2024-07-12 07:54:26 +00:00
|
|
|
echo "The tag instruction has not been respected"
|
2024-07-11 16:31:19 +00:00
|
|
|
fi
|
|
|
|
cd ..
|
|
|
|
}
|
|
|
|
|
2024-07-12 08:10:04 +00:00
|
|
|
branch_check(){
|
2024-07-12 15:17:29 +00:00
|
|
|
local repo_name=$1
|
|
|
|
run cd $repo_name
|
|
|
|
run $(git branch) > res
|
2024-07-12 08:10:04 +00:00
|
|
|
if [ $(grep $BRANCH_NAME res | wc -l) = 1 ];then
|
|
|
|
echo "The branch instruction has been respected"
|
|
|
|
branch_result=0
|
|
|
|
else
|
|
|
|
branch_result=1
|
|
|
|
echo "The branch instruction has not been respected"
|
|
|
|
fi
|
|
|
|
cd ..
|
|
|
|
}
|
|
|
|
|
2024-07-11 12:04:25 +00:00
|
|
|
test0 (){
|
2024-07-12 08:10:04 +00:00
|
|
|
#CASE 0: git cloned in an empty directory
|
2024-07-11 12:04:25 +00:00
|
|
|
section TEST0
|
|
|
|
#if it exists, delete the directory
|
|
|
|
if [ -d $REPO_NAME ]; then
|
|
|
|
rm -rf $REPO_NAME
|
|
|
|
fi
|
2024-07-11 16:31:19 +00:00
|
|
|
run ./git_update.sh -d $REPO_NAME $REMOTE
|
2024-07-11 12:04:25 +00:00
|
|
|
#checks
|
2024-07-12 15:17:29 +00:00
|
|
|
cloning_check $REPO_NAME ${FILENAMES[@]}
|
|
|
|
history_check $REPO_NAME
|
2024-07-12 07:54:26 +00:00
|
|
|
case0=$(($history_result+$cloning_result))
|
2024-07-11 16:31:19 +00:00
|
|
|
if [ "$case0" = "0" ]; then
|
2024-07-12 16:30:57 +00:00
|
|
|
echo "case 0, in a empty directory: OK"
|
2024-07-11 12:04:25 +00:00
|
|
|
else
|
2024-07-12 16:30:57 +00:00
|
|
|
echo "case 0, in a empty directory: FAIL"
|
2024-07-11 12:04:25 +00:00
|
|
|
fi
|
|
|
|
}
|
2024-06-24 16:09:48 +00:00
|
|
|
|
2024-07-11 12:04:25 +00:00
|
|
|
test1(){
|
|
|
|
#CASE 1: git cloned in an empty directory with tag
|
|
|
|
section TEST1
|
|
|
|
#if it exists, delete the directory
|
|
|
|
if [ -d $REPO_NAME ]; then
|
|
|
|
run rm -rf $REPO_NAME
|
|
|
|
fi
|
2024-07-12 07:54:26 +00:00
|
|
|
run ./git_update.sh -d $REPO_NAME -r $TAG_NAME $REMOTE
|
2024-07-11 12:04:25 +00:00
|
|
|
#checks
|
2024-07-12 15:17:29 +00:00
|
|
|
cloning_check $REPO_NAME ${FILENAMES_TAG[@]}
|
|
|
|
history_check $REPO_NAME
|
|
|
|
tag_check $REPO_NAME
|
2024-06-25 13:52:05 +00:00
|
|
|
|
2024-07-12 07:54:26 +00:00
|
|
|
case1=$(($cloning_result+$history_result+$tag_result))
|
2024-07-11 16:31:19 +00:00
|
|
|
if [ $case1 = 0 ]; then
|
2024-07-12 16:30:57 +00:00
|
|
|
echo "case 1, in a empty directory, with tag: OK"
|
2024-07-11 12:04:25 +00:00
|
|
|
else
|
2024-07-12 16:30:57 +00:00
|
|
|
echo "case 1, in a empty directory, with tag: FAIL"
|
2024-07-11 12:04:25 +00:00
|
|
|
fi
|
|
|
|
}
|
2024-06-25 13:52:05 +00:00
|
|
|
|
2024-07-11 12:04:25 +00:00
|
|
|
test2(){
|
2024-07-12 08:10:04 +00:00
|
|
|
#CASE 2: git cloned in an empty directory with branch
|
|
|
|
section TEST2
|
|
|
|
#if it exists, delete the directory
|
|
|
|
if [ -d $REPO_NAME ]; then
|
|
|
|
run rm -rf $REPO_NAME
|
|
|
|
fi
|
|
|
|
run ./git_update.sh -d $REPO_NAME -r $BRANCH_NAME $REMOTE
|
|
|
|
#checks
|
2024-07-12 15:17:29 +00:00
|
|
|
cloning_check $REPO_NAME ${FILENAMES_BRANCH[@]} #we do not check for all files, especially not those specific to the branch.
|
|
|
|
history_check $REPO_NAME
|
|
|
|
branch_check $REPO_NAME
|
2024-06-24 16:09:48 +00:00
|
|
|
|
2024-07-12 15:17:29 +00:00
|
|
|
case2=$(($cloning_result+$history_result+$branch_result))
|
|
|
|
if [ $case2 = 0 ]; then
|
2024-07-12 16:30:57 +00:00
|
|
|
echo "case 2, in a empty directory, with branch: OK"
|
2024-07-12 08:10:04 +00:00
|
|
|
else
|
2024-07-12 16:30:57 +00:00
|
|
|
echo "case 2, in a empty directory, with branch: FAIL"
|
2024-07-12 08:10:04 +00:00
|
|
|
fi
|
2024-07-11 12:04:25 +00:00
|
|
|
}
|
|
|
|
|
2024-07-12 15:17:29 +00:00
|
|
|
test3(){
|
|
|
|
#CASE 3: git cloned in an existing directory
|
|
|
|
section TEST3
|
|
|
|
#if it exists, delete the directory
|
|
|
|
if [ -d $REPO_NAME ]; then
|
|
|
|
run rm -rf $REPO_NAME
|
|
|
|
fi
|
|
|
|
#mimic an existing directory, with two existing file, one with the same name as a to-be-cloned file
|
|
|
|
run mkdir tmp_dir
|
|
|
|
run cd tmp_dir
|
|
|
|
run touch tmp_file
|
|
|
|
run touch "${FILENAMES[0]}"
|
|
|
|
echo "this should be overwritten" > ${FILENAMES[0]}
|
|
|
|
run ../git_update.sh -N $REMOTE
|
|
|
|
run cd ..
|
|
|
|
#checks
|
|
|
|
cloning_check "tmp_dir" ${FILENAMES[@]}
|
|
|
|
history_check $"tmp_dir"
|
|
|
|
|
|
|
|
#existing check
|
|
|
|
cd tmp_dir
|
|
|
|
if [ -f tmp_file ]; then
|
|
|
|
echo "The preexisting non-conflicting file is still here."
|
|
|
|
existing_result=0
|
|
|
|
if [ $(grep "overwritten" ${FILENAMES[0]} | wc -l) = 0 ]; then
|
|
|
|
echo "The conflicting files have been overwitten."
|
|
|
|
else
|
|
|
|
echo "The conflicting existing files have not been overwritten."
|
|
|
|
existing_result=1
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "The preexisting non-conflicting file has been deleted."
|
|
|
|
existing_result=1
|
|
|
|
fi
|
|
|
|
cd ..
|
|
|
|
case3=$(($cloning_result+$history_result+$existing_result))
|
|
|
|
if [ $case3 = 0 ]; then
|
2024-07-12 16:30:57 +00:00
|
|
|
echo "case 3, in a non-empty directory : OK"
|
2024-07-12 15:17:29 +00:00
|
|
|
else
|
2024-07-12 16:30:57 +00:00
|
|
|
echo "case 3, in a non-empty directory : FAIL"
|
2024-07-12 15:17:29 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2024-07-12 16:30:57 +00:00
|
|
|
TEST4(){
|
|
|
|
#CASE 4: git updated ff
|
|
|
|
section TEST4
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-07-11 12:04:25 +00:00
|
|
|
|
|
|
|
while getopts ":hn:a" option; do
|
|
|
|
case $option in
|
|
|
|
h) # display Help
|
|
|
|
Help
|
|
|
|
exit;;
|
|
|
|
n)
|
|
|
|
TEST_NUM=$OPTARG;;
|
|
|
|
a)
|
|
|
|
ALL_TESTS=true;;
|
|
|
|
\?) # Invalid option
|
|
|
|
echo "Error: Invalid option here"
|
|
|
|
exit;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ "$ALL_TESTS" = "true" ]; then
|
|
|
|
test0
|
|
|
|
test1
|
|
|
|
test2
|
|
|
|
test3
|
|
|
|
test4
|
|
|
|
test5
|
|
|
|
test6
|
|
|
|
test7
|
|
|
|
test8
|
|
|
|
test9
|
|
|
|
|
|
|
|
elif [ -n "$TEST_NUM" ]; then
|
|
|
|
case $TEST_NUM in
|
|
|
|
0)
|
|
|
|
test0;;
|
|
|
|
1)
|
|
|
|
test1;;
|
|
|
|
2)
|
|
|
|
test2;;
|
|
|
|
3)
|
|
|
|
test3;;
|
|
|
|
4)
|
|
|
|
test4;;
|
|
|
|
5)
|
|
|
|
test5;;
|
|
|
|
6)
|
|
|
|
test6;;
|
|
|
|
7)
|
|
|
|
test7;;
|
|
|
|
8)
|
|
|
|
test8;;
|
|
|
|
9)
|
|
|
|
test9;;
|
|
|
|
*)
|
|
|
|
echo "Error: Invalid test number"
|
|
|
|
die;;
|
|
|
|
esac
|
|
|
|
else
|
|
|
|
Help
|
|
|
|
fi
|