#! /bin/bash #importer driglibash . driglibash-base echo "" REPO_NAME=performance_testing REMOTE=ssh://git@git.jean-cloud.net:22529/eleonore/performance_testing.git WITH_SUBMODULE="true" FILENAMES=("sample0" "sample1") #we do not check for all files FILENAMES_TAG=("sample0") FILENAMES_BRANCH=("sample0" "sample1") #we do not check for all files, especially not those specific to the branch. TAG_NAME=start BRANCH_NAME=secondary 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 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 " } cloning_check(){ if [ -d "./$REPO_NAME" ]; then echo "$REPO_NAME has been created" cloning_result=0 local 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 echo "The tag instruction has been respected" tag_result=0 else tag_result=1 echo "The tag instruction has not been respected" fi cd .. } branch_check(){ run cd $REPO_NAME run git branch > res 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 .. } test0 (){ #CASE 0: git cloned in an empty directory 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)) if [ "$case0" = "0" ]; then echo "case 0, in a empty directory without history: OK" else echo "case 0, in a empty directory without history: 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 1, in a empty directory without history, with tag: OK" else echo "case 1, in a empty directory without history, with tag: FAIL" fi } test2(){ #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 cloning_check $FILENAMES_BRANCH #we do not check for all files, especially not those specific to the branch. history_check branch_check case1=$(($cloning_result+$history_result+$branch_result)) if [ $case1 = 0 ]; then echo "case 1, in a empty directory without history, with branch: OK" else echo "case 1, in a empty directory without history, with branch: FAIL" fi } 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