-
Notifications
You must be signed in to change notification settings - Fork 4
/
tests.sh
executable file
·57 lines (47 loc) · 1.78 KB
/
tests.sh
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
#!/bin/bash
set -e
set -o pipefail
_TFCODING_DOCKER_TAG="${TFCODING_DOCKER_TAG:-"unfor19/tfcoding:0.15.0-beta2-latest"}"
error_msg(){
local msg=$1
echo -e "\e[31m[ERROR]\e[0m $msg"
export DEBUG=1
exit 1
}
should(){
local expected=$1
local test_name=$2
local expr=$3
echo "-------------------------------------------------------"
echo "[LOG] $test_name - Should $expected"
echo "[LOG] Executing: $expr"
output_msg=$(trap '$expr' EXIT)
output_code=$?
echo -e "[LOG] Output:\n\n$output_msg\n"
if [[ $expected == "pass" && $output_code -eq 0 && ! $output_msg =~ .*(ERROR|Error|error).* ]]; then
echo -e "\e[92m[SUCCESS]\e[0m Test passed as expected"
elif [[ $expected == "fail" && $output_code -eq 1 ]] || [[ $expected == "fail" && $output_msg =~ .*(ERROR|Error|error).* ]]; then
echo -e "\e[92m[SUCCESS]\e[0m Test failed as expected"
else
error_msg "Test output is not expected, terminating"
fi
}
tfcoding(){
local container_id
rm .cidtests 2>/dev/null || true
set +e
docker run --cidfile .cidtests -t --network "tfcoding_aws_shared" -v tfcoding_code_dir_tmp:/tmp/ -v "${PWD}"/:/src/:ro \
"${_TFCODING_DOCKER_TAG}" "$@" > /dev/null
set -e
container_id="$(cat .cidtests)"
docker logs "$container_id"
docker rm "$container_id" 1>/dev/null
rm .cidtests 2>/dev/null || true
}
# Tests
make up-localstack
docker volume create tfcoding_code_dir_tmp 2>/dev/null || true
source scripts/wait_for_endpoints.sh "http://localhost:4566/health"
should pass "Examples - Basic" "tfcoding -r examples/basic --mock_aws"
should pass "Examples - Complete" "tfcoding -r examples/complete --mock_aws"
should fail "Directory SRC_RELATIVE_DIR_PATH does not exist" "tfcoding -r examples/unknown --mock_aws"