292 lines
8.2 KiB
Bash
Executable File
292 lines
8.2 KiB
Bash
Executable File
#! /bin/bash
|
|
#importer driglibash
|
|
. driglibash-base
|
|
echo "<execution of test_git_update.sh>"
|
|
|
|
REPO_NAME=performance_testing
|
|
REMOTE=ssh://git@git.jean-cloud.net:22529/eleonore/performance_testing.git
|
|
WITH_SUBMODULE="true"
|
|
FILENAMES=("sample0" "sample1")
|
|
FILENAMES_TAG=("sample0")
|
|
TAG_NAME=start
|
|
|
|
if [ "$WITH_SUBMODULE" = "true" ]; then
|
|
bash creation_repo.sh -s &> /dev/null
|
|
else
|
|
bash creation_repo.sh &> /dev/null
|
|
fi
|
|
|
|
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.
|
|
DESCRIPTION"
|
|
}
|
|
|
|
cloning_check(){
|
|
if [ -d "./$REPO_NAME" ]; then
|
|
echo "$REPO_NAME has been created"
|
|
cloning_result=0
|
|
local FILENAMES=("$@")
|
|
echo "--$1--"
|
|
echo "------------ $FILENAMES -----------------"
|
|
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 folder $REPO_NAME could not be created"
|
|
fi
|
|
}
|
|
|
|
history_check(){
|
|
run cd $REPO_NAME
|
|
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 ..
|
|
}
|
|
|
|
tag_check(){
|
|
run cd $REPO_NAME
|
|
run git branch > res
|
|
if [ $(grep "no branch" res | wc -l) = 1 ];then
|
|
tag_result=0
|
|
else
|
|
tag_result=1
|
|
fi
|
|
cd ..
|
|
}
|
|
|
|
test0 (){
|
|
#CASE 0: git cloned in an empty directory without tag
|
|
section TEST0
|
|
#if it exists, delete the directory
|
|
if [ -d $REPO_NAME ]; then
|
|
rm -rf $REPO_NAME
|
|
fi
|
|
run ./git_update.sh -d $REPO_NAME $REMOTE
|
|
#checks
|
|
cloning_check "${FILENAMES[@]}"
|
|
history_check
|
|
case0=$history_result+$cloning_result
|
|
echo "case0 $case0"
|
|
if [ "$case0" = "0" ]; then
|
|
echo "case 0, in a empty directory without history, without tag : OK"
|
|
else
|
|
echo "case 0, in a empty directory without history, without tag : FAIL"
|
|
fi
|
|
}
|
|
|
|
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
|
|
run ./git_update.sh -d $REPO_NAME -r $TAG_NAME $REMOTE
|
|
#checks
|
|
cloning_check $FILENAMES_TAG
|
|
history_check
|
|
tag_check
|
|
|
|
case1=$cloning_result+$history_result+$tag_result
|
|
if [ $case1 = 0 ]; then
|
|
echo "case 0, in a empty directory without history, with tag : OK"
|
|
else
|
|
echo "case 0, in a empty directory without history, with tag : FAIL"
|
|
fi
|
|
}
|
|
|
|
test2(){
|
|
#case 2 : git cloné dans un dossier git déjà rempli, on souhaite que tout soit écrasé
|
|
section TEST2.1
|
|
#sous-test 1 : dossier contenant le même repo dans un état antérieur, on ne garde pas les fichiers hors git
|
|
REPO_NAMEDst=leRepo2 #destination
|
|
FILENAMESToOverwrite=("texte" "texteHorsGit")
|
|
nonGitFILE=texteHorsGit
|
|
newFILE=main.c
|
|
|
|
if [ -d $REPO_NAME ]; then #reste d'un test précédent
|
|
run rm -rf $REPO_NAME
|
|
echo "le dossier de test préexistant $REPO_NAME a été supprimé"
|
|
fi
|
|
|
|
if [ -d $REPO_NAMEDst ]; then #reste de ce test-ci déjà exécuté
|
|
run rm -rf $REPO_NAMEDst
|
|
echo "le dossier de test préexistant $REPO_NAMEDst a été supprimé"
|
|
fi
|
|
|
|
run mkdir $REPO_NAMEDst
|
|
#on clone notre repo de test dans un état précédent (grâce au tag début quand on aura la fonctionnalité précédente fonctionnelle)
|
|
run git clone -q --recurse-submodules $REMOTE $REPO_NAMEDst
|
|
#on ajoute des fichiers hors Git
|
|
run touch $REPO_NAMEDst/$nonGitFILE
|
|
case2="true"
|
|
#on vérifie que l'initialisation est un succès
|
|
if [ -d "./$REPO_NAMEDst" ]; then
|
|
for FILE2 in ${FILENAMESToOverwrite[@]}
|
|
do
|
|
if [ ! -f "./$REPO_NAMEDst/$FILE2" ]; then
|
|
echo "Erreur dans l'initialisation du case de test 2"
|
|
die "Problème à régler dans l'initialisation du case 2 afin de pouvoir conduire le test"
|
|
fi
|
|
done
|
|
else
|
|
echo "Erreur dans l'initialisation du case de test 2"
|
|
die "Problème à régler dans l'initialisation du case 2 afin de pouvoir conduire le test"
|
|
|
|
fi
|
|
cd $REPO_NAMEDst
|
|
#commande de clonage dans un dossier préexistant
|
|
../git_update.sh -b $nomBranche $REMOTE
|
|
if [ -f $nonGitFILE ]; then
|
|
echo "Le fichier déjà présent qui n'était pas considéré par Git n'a pas été supprimé"
|
|
case2="false"
|
|
elif [ $(cat ${FILENAMESToOverwrite[0]} | grep $keyword | wc -l) -gt 0 ]; then
|
|
echo "Le fichier git déjà présent n'a pas été changé pour la nouvelle version"
|
|
case2="false"
|
|
elif [ ! -f $newFILE ]; then
|
|
echo "Un fichier git préalablement absent du folder n'a pas été importé"
|
|
case2="false"
|
|
fi
|
|
|
|
if [ "$case2" = "true" ]; then
|
|
echo "case de test 2 sous-test 1, dans un dossier préexistant du même repo Git dans un état antérieur, sans tag, sans garder de fichier non git : OK"
|
|
else
|
|
echo "case de test 2 sous-test 1, dans un dossier préexistant du même repo Git dans un état antérieur, sans tag, sans garder de fichier non git: ECHEC"
|
|
fi
|
|
cd ..
|
|
|
|
#sous-test 2 dossier contenant le même repo dans un état antérieur, on ne garde pas les fichiers hors git
|
|
section TEST2.2
|
|
if [ -d $REPO_NAME ]; then #reste d'un test précédent
|
|
rm -rf $REPO_NAME
|
|
echo "le dossier de test préexistant $REPO_NAME a été supprimé"
|
|
fi
|
|
|
|
if [ -d $REPO_NAMEDst ]; then #reste de ce test-ci déjà exécuté
|
|
rm -rf $REPO_NAMEDst
|
|
echo "le dossier de test préexistant $REPO_NAMEDst a été supprimé"
|
|
fi
|
|
|
|
mkdir $REPO_NAMEDst
|
|
#on clone notre repo de test dans un état précédent (grâce au tag début quand on aura la fonctionnalité précédente fonctionnelle)
|
|
git clone -q --recurse-submodules $REMOTE $REPO_NAMEDst
|
|
#on ajoute des fichiers hors Git
|
|
touch $REPO_NAMEDst/$nonGitFILE
|
|
case2="true"
|
|
#on vérifie que l'initialisation est un succès
|
|
if [ -d "./$REPO_NAMEDst" ]; then
|
|
for FILE2 in ${FILENAMESToOverwrite[@]}
|
|
do
|
|
if [ ! -f "./$REPO_NAMEDst/$FILE2" ]; then
|
|
echo "Erreur dans l'initialisation du case de test 2"
|
|
exit
|
|
fi
|
|
done
|
|
else
|
|
echo "Erreur dans l'initialisation du case de test 2"
|
|
exit
|
|
fi
|
|
cd $REPO_NAMEDst
|
|
#commande de clonage dans un dossier préexistant en gardant les fichiers qui étaient là avant
|
|
../git_update.sh -N -b $nomBranche $REMOTE
|
|
if [ ! -f $nonGitFILE ]; then
|
|
echo "Le fichier déjà présent qui n'était pas considéré par Git a été supprimé"
|
|
case2="false"
|
|
elif [ $(cat ${FILENAMESToOverwrite[0]} | grep $keyword | wc -l) -gt 0 ]; then
|
|
echo "Le fichier git déjà présent n'a pas été changé pour la nouvelle version"
|
|
case2="false"
|
|
elif [ ! -f $newFILE ]; then
|
|
echo "Un fichier git préalablement absent du folder n'a pas été importé"
|
|
case2="false"
|
|
fi
|
|
|
|
if [ "$case2" = "true" ]; then
|
|
echo "case de test 2 sous-test 2, dans un dossier préexistant du même repo Git dans un état antérieur, en gardant les fichiers non-git, sans tag : OK"
|
|
else
|
|
echo "case de test 2 sous-test 2, dans un dossier préexistant du même repo Git dans un état antérieur, en gardant les fichiers non-git, sans tag: ECHEC"
|
|
fi
|
|
cd ..
|
|
|
|
}
|
|
|
|
|
|
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 |