-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathtest.sh
73 lines (62 loc) · 2.11 KB
/
test.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env bats
CONTAINER_NAME=bitnami-php-fpm-test
NGINX_CONTAINER_NAME=bitnami-nginx-test
IMAGE_NAME=bitnami/php-fpm
NGINX_IMAGE_NAME=bitnami/nginx
SLEEP_TIME=3
VOL_PREFIX=/bitnami/php-fpm
HOST_VOL_PREFIX=/tmp/bitnami/php-fpm
cleanup_running_containers() {
if [ "$(docker ps -a | grep $CONTAINER_NAME)" ]; then
docker rm -fv $CONTAINER_NAME
fi
if [ "$(docker ps -a | grep $NGINX_CONTAINER_NAME)" ]; then
docker rm -fv $NGINX_CONTAINER_NAME
fi
}
create_container(){
docker run -d --name $CONTAINER_NAME "$@" $IMAGE_NAME
}
add_vhost() {
docker exec $NGINX_CONTAINER_NAME sh -c "echo 'server { listen 0.0.0.0:81; root /app; location ~ \.php$ { fastcgi_pass php:9000; include fastcgi.conf; } }' > /bitnami/nginx/conf/vhosts/test.conf"
}
create_nginx_container(){
docker run -d --name $NGINX_CONTAINER_NAME\
--link $CONTAINER_NAME:php $NGINX_IMAGE_NAME
add_vhost
docker restart $NGINX_CONTAINER_NAME
sleep $SLEEP_TIME
}
setup () {
cleanup_running_containers
}
teardown() {
cleanup_running_containers
}
@test "php and php-fpm installed" {
create_container
run docker exec $CONTAINER_NAME php -v
[ "$status" = 0 ]
run docker exec $CONTAINER_NAME php-fpm -v
[ "$status" = 0 ]
}
@test "winter is coming via nginx" {
create_container
docker exec $CONTAINER_NAME sh -c "echo '<?php echo \"Winter is coming\"; ?>' > index.php"
create_nginx_container
run docker exec $NGINX_CONTAINER_NAME curl 127.0.0.1:81/index.php
[[ "$output" =~ "Winter is coming" ]]
}
@test "required volumes exposed" {
create_container
run docker inspect $CONTAINER_NAME
[[ "$output" =~ "/app" ]]
[[ "$output" =~ "$VOL_PREFIX/logs" ]]
[[ "$output" =~ "$VOL_PREFIX/conf" ]]
}
@test "Data gets generated in conf if bind mounted in the host" {
create_container -v $HOST_VOL_PREFIX/conf:$VOL_PREFIX/conf -v $HOST_VOL_PREFIX/logs:$VOL_PREFIX/logs
run docker run --rm -v $HOST_VOL_PREFIX:$HOST_VOL_PREFIX $IMAGE_NAME ls -l $HOST_VOL_PREFIX/conf/php-fpm.conf $HOST_VOL_PREFIX/logs/php-fpm.log
[ $status = 0 ]
docker run --rm -v $HOST_VOL_PREFIX:$HOST_VOL_PREFIX $IMAGE_NAME sh -c "sudo rm -rf $HOST_VOL_PREFIX/*"
}