aboutsummaryrefslogtreecommitdiffstats
path: root/test/mocks/datafilecollector-testharness/common/testsuite_common.sh
blob: e35d670de16b066748fd1210c30e151fcad70dc5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/bash

# Script containing all functions needed for auto testing of test suites

echo "Test suite started as: ${BASH_SOURCE[$i+1]} "$1 $2


IMAGE_TAG=""

if [ $# -eq 1 ]; then
	if [ $1 == "local" ] && [ $1 == "remote" ] && [ $1 == "remote-remove" ] ; then
		IMAGE_TAG="latest"
		echo "No image tag give, assuming 'latest'"
	fi
elif [ $# -eq 2 ] && [ $1 == "local" ]; then
	IMAGE_TAG=$2
elif [ $# -eq 2 ] && [ $1 == "remote" ]; then
	IMAGE_TAG=$2
elif [ $# -eq 2 ] && [ $1 == "remote-remove" ]; then
	IMAGE_TAG=$2
else
	echo "Expected arg: local [<image-tag>] | remote [<image-tag>] | remote-remove [<image-tag>] | manual-container | manual-app"
	exit 1
fi

# Set a description string for the test suite
if [ -z "$TS_ONELINE_DESCR" ]; then
	TS_ONELINE_DESCR="<no-description>"
	echo "No test suite description found, TC_ONELINE_DESCR should be set on in the test script , using "$TS_ONELINE_DESCR
fi

TSTEST_START=$SECONDS

suite_setup() {
    ATS=$(basename "${BASH_SOURCE[$i+1]}" .sh)

    echo "#################################################################################################"
    echo "###################################      Test suite: "$ATS
    echo "###################################      Started:    "$(date)
    echo "#################################################################################################"
    echo "## Description: " $TS_ONELINE_DESCR
    echo "#################################################################################################"
    echo ""
    echo 0 > .tmp_tcsuite_ctr
    echo 0 > .tmp_tcsuite_pass_ctr
    echo 0 > .tmp_tcsuite_fail_ctr
    rm .tmp_tcsuite_pass &> /dev/null
    touch .tmp_tcsuite_pass
    rm .tmp_tcsuite_fail &> /dev/null
    touch .tmp_tcsuite_fail
}

__print_err() {
    echo ${FUNCNAME[1]} " "$1" " ${BASH_SOURCE[$i+2]} " line" ${BASH_LINENO[$i+1]}
}

run_tc() {
	if [ $# -eq 2 ]; then
		./$1 $2 $IMAGE_TAG
	elif [ $# -eq 3 ]; then
		./$1 $2 $3
	else
		echo -e "Test case \033[31m\033[1m./"$1 $2 $3 "could not be executed.\033[0m"
	fi
}

suite_complete() {
    TSTEST_END=$SECONDS
    echo ""
    echo "#################################################################################################"
    echo "###################################      Test suite: "$ATS
    echo "###################################      Ended:      "$(date)
    echo "#################################################################################################"
    echo "## Description: " $TS_ONELINE_DESCR
    echo "## Execution time: " $((TSTEST_END-TSTEST_START)) " seconds"
    echo "#################################################################################################"
    echo "###################################      RESULTS"
    echo ""

    TCSUITE_CTR=$(< .tmp_tcsuite_ctr)
    TCSUITE_PASS_CTR=$(< .tmp_tcsuite_pass_ctr)
    TCSUITE_FAIL_CTR=$(< .tmp_tcsuite_fail_ctr)

    total=$((TCSUITE_PASS_CTR+TCSUITE_FAIL_CTR))
    if [ $TCSUITE_CTR -eq 0 ]; then
		echo -e "\033[1mNo test cases seem to have executed. Check the script....\033[0m"
	elif [ $total != $TCSUITE_CTR ]; then
        echo -e "\033[1mTotal number of test cases does not match the sum of passed and failed test cases. Check the script....\033[0m"
    fi
    echo "Number of test cases : " $TCSUITE_CTR
    echo -e "Number of \033[31m\033[1mFAIL\033[0m:        " $TCSUITE_FAIL_CTR
    echo -e "Number of \033[32m\033[1mPASS\033[0m:        " $TCSUITE_PASS_CTR
    echo ""
    echo "PASS test cases"
    cat .tmp_tcsuite_pass
    echo ""
    echo "FAIL test cases"
    cat .tmp_tcsuite_fail
    echo ""

    echo "###################################      Test suite completed      ##############################"
    echo "#################################################################################################"
}