Skip to content

Commit 53978cd

Browse files
committed
Added container tests with docker and podman (disabled on github actions)
1 parent 46bb0aa commit 53978cd

File tree

4 files changed

+99
-7
lines changed

4 files changed

+99
-7
lines changed

.github/workflows/test.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
uses: actions/setup-go@v4
3535
with:
3636
go-version: ${{ matrix.go-version }}
37-
- name: Test with Go
37+
- name: Unit tests
3838
run: |
3939
export CL_HOME=`pwd`
4040
rm -rf internal/server/appspecs && cd internal/server
@@ -52,7 +52,9 @@ jobs:
5252
git clone --single-branch --depth 1 https://github.com/claceio/appspecs.git
5353
rm -rf appspecs/.git
5454
cd $CL_HOME
55+
5556
go install github.com/commander-cli/commander/v2/cmd/commander@latest
57+
export CL_CONTAINER_COMMANDS=disable # docker/podman does not run on github actions
5658
tests/run_cli_tests.sh
5759
5860
- name: Upload Go test results

tests/flask.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from flask import Flask
2+
3+
app = Flask(__name__)
4+
5+
@app.route("/")
6+
def hello_world():
7+
return "hello"

tests/run_cli_tests.sh

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
11
#set -x
22
set -e
3+
4+
# Enabling verbose is useful for debugging but the commander command seems to
5+
# return exit code of 0 when verbose is enabled, even if tests fails. So verbose
6+
# is disabled by default.
7+
#export CL_TEST_VERBOSE="--verbose"
8+
39
cd $CL_HOME
10+
11+
# Setup app specs
12+
rm -rf appspecs_bk
13+
if [[ -d internal/server/appspecs/dummy ]]; then
14+
mv internal/server/appspecs appspecs_bk
15+
cp -r config/appspecs internal/server/
16+
fi
417
go build ./cmd/clace
18+
519
cd tests
620
rm -rf clace.db
721

822
export CL_HOME=.
923
unset CL_CONFIG_FILE
1024
unset SSH_AUTH_SOCK
1125

12-
# Enabling verbose is useful for debugging but the commander command seems to
13-
# return exit code of 0 when verbose is enabled, even if tests fails. So verbose
14-
# is disabled by default.
15-
# export CL_TEST_VERBOSE="--verbose"
16-
1726
trap "error_handler" ERR
1827

1928
error_handler () {
@@ -25,7 +34,13 @@ error_handler () {
2534

2635
cleanup() {
2736
rm -rf clace.db
28-
rm -rf logs/ clace.toml server.stdout
37+
rm -rf logs/ clace.toml config_container.toml server.stdout flaskapp
38+
39+
if [[ -d ../appspecs_bk ]]; then
40+
rm -rf ../internal/server/appspecs
41+
mv ../appspecs_bk ../internal/server/appspecs
42+
fi
43+
2944
set +e
3045
ps -ax | grep "clace server start" | grep -v grep | cut -c1-6 | xargs kill -9
3146

@@ -136,5 +151,37 @@ if [[ -n "$CL_GITHUB_SECRET" ]]; then
136151
commander test $CL_TEST_VERBOSE test_oauth.yaml
137152
fi
138153

154+
if [[ $CL_CONTAINER_COMMANDS = "disable" ]]; then
155+
CL_CONTAINER_COMMANDS=""
156+
elif [[ -z "$CL_CONTAINER_COMMANDS" ]]; then
157+
CL_CONTAINER_COMMANDS="docker podman"
158+
fi
159+
160+
port_base=9000
161+
162+
for cmd in ${CL_CONTAINER_COMMANDS}; do
163+
http_port=`expr $port_base + 1`
164+
https_port=`expr $port_base + 2`
165+
port_base=`expr $port_base + 2`
166+
167+
# Use password hash for "abcd"
168+
cat <<EOF > config_container.toml
169+
[http]
170+
port = $http_port
171+
[https]
172+
port = $https_port
173+
[security]
174+
app_default_auth_type="none"
175+
EOF
176+
rm -rf clace.db* run/clace.sock
177+
CL_CONFIG_FILE=config_container.toml ../clace server start &
178+
sleep 2
179+
180+
export CL_CONTAINER_CMD=$cmd
181+
export HTTP_PORT=$http_port
182+
echo "********Testing container apps for $cmd*********"
183+
commander test $CL_TEST_VERBOSE test_containers.yaml
184+
done
185+
139186
cleanup
140187
echo "All tests passed"

tests/test_containers.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
config:
2+
env:
3+
CL_CONFIG_FILE: clace.toml
4+
CL_CONTAINER_CMD: ${CL_CONTAINER_CMD}
5+
HTTP_PORT: ${HTTP_PORT}
6+
tests:
7+
container0010: # setup flask app
8+
command: rm -rf ./flaskapp && mkdir flaskapp && cp flask.py flaskapp/app.py
9+
container0020: # setup flask dev app
10+
command: ../clace app create --dev --spec python-flask --approve ./flaskapp /cont_flaskdev
11+
container0030: # setup flask prod app
12+
command: ../clace app create --spec python-flask --approve ./flaskapp /cont_flaskprod
13+
container0040: # check curl dev works
14+
command: curl -sS localhost:${HTTP_PORT}/cont_flaskdev
15+
stdout: "hello"
16+
container0050: # update app code
17+
command: perl -i -pe 's/"hello"/"updated"/g' flaskapp/app.py
18+
container0060: # check dev picked up change
19+
command: curl -sS localhost:${HTTP_PORT}/cont_flaskdev
20+
stdout: "updated"
21+
container0070: # stage is not yet updated
22+
command: curl -sS localhost:${HTTP_PORT}/cont_flaskprod_cl_stage
23+
stdout: "hello"
24+
container0080: # do reload
25+
command: ../clace app reload /cont_flaskprod
26+
container0090: # stage is updated
27+
command: curl -sS localhost:${HTTP_PORT}/cont_flaskprod_cl_stage
28+
stdout: "updated"
29+
container0100: # prod is not yet updated
30+
command: curl -sS localhost:${HTTP_PORT}/cont_flaskprod
31+
stdout: "hello"
32+
container0110: # do promote
33+
command: ../clace app promote /cont_flaskprod
34+
container0120: # prod is updated
35+
command: curl -sS localhost:${HTTP_PORT}/cont_flaskprod
36+
stdout: "updated"

0 commit comments

Comments
 (0)