forked from openhab/openhabian
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.bash
executable file
·51 lines (45 loc) · 1.8 KB
/
test.bash
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
#!/usr/bin/env bash
set -e
##########################
#### Load help method ####
##########################
## This format timestamp
timestamp() { date +"%F_%T_%Z"; }
## This function format log messages
##
## echo_process(String message)
##
echo_process() { echo -e "$(timestamp) [openHABian] $*"; }
## This enables printout of both a executed command and its output
##
## cond_redirect(bash command)
##
cond_redirect() {
echo -e "\n$COL_DGRAY\$ $@ $COL_DEF"
"$@"
return $?
}
###########################
#### Test script start ####
###########################
# What test case should be run?
if [ "$1" == "docker-full" ]; then
echo_process "Starting Docker based test..."
cond_redirect docker stop install-test || true
cond_redirect docker rm install-test || true
cond_redirect docker build --tag openhabian/openhabian-bats .
cond_redirect docker run -it openhabian/openhabian-bats bash -c 'bats -r -f "unit-." .'
cond_redirect docker run --name "install-test" --privileged -d openhabian/openhabian-bats
cond_redirect docker exec -it install-test bash -c "./build.bash local-test && mv ~/.profile ~/.bash_profil && /etc/rc.local"
cond_redirect docker exec -it install-test bash -c 'bats -r -f "installation-." .'
cond_redirect docker exec -it install-test bash -c 'bats -r -f "destructive-." .'
echo_process "Test complete, please review result in terminal. Access tested container by executing: \"docker exec -it install-test bash\""
exit 0
elif [ "$1" == "shellcheck" ]; then
shellcheck -s bash openhabian-setup.sh
shellcheck -s bash functions/*.bash
shellcheck -s bash build-image/*.bash
else
echo_process "Please provide a valid test profile, \"docker-full\" or \"shellcheck\". Exiting"
exit 0
fi