Skip to content

Commit 8358de2

Browse files
committed
Add tests for NextCloud
1 parent f03cf95 commit 8358de2

7 files changed

Lines changed: 228 additions & 0 deletions

File tree

test/config.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,17 @@ imageTests+=(
128128
mysql-initdb
129129
mysql-log-bin
130130
'
131+
[nextcloud]='
132+
nextcloud-cli-mysql
133+
nextcloud-cli-postgres
134+
nextcloud-cli-sqlite
135+
'
136+
[nextcloud:apache]='
137+
nextcloud-apache-run
138+
'
139+
[nextcloud:fpm]='
140+
nextcloud-fpm-run
141+
'
131142
[node]='
132143
node-hello-world
133144
'
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
set -eo pipefail
3+
4+
dir="$(dirname "$(readlink -f "$BASH_SOURCE")")"
5+
6+
# since we have curl in the php image, we'll use that
7+
clientImage="$1"
8+
serverImage="$1"
9+
10+
# Create an instance of the container-under-test
11+
cid="$(docker run -d "$serverImage")"
12+
trap "docker rm -vf $cid > /dev/null" EXIT
13+
14+
_request() {
15+
local method="$1"
16+
shift
17+
18+
local url="${1#/}"
19+
shift
20+
21+
docker run --rm --link "$cid":apache "$clientImage" \
22+
curl -fsL -X"$method" "$@" "http://apache/$url"
23+
}
24+
25+
# Make sure that Apache is listening and ready
26+
. "$dir/../../retry.sh" --tries 30 '_request GET / --output /dev/null'
27+
28+
# Check that we can request / and that it contains the pattern "Finish setup" somewhere
29+
# <input type="submit" class="primary" value="Finish setup" data-finishing="Finishing …">
30+
_request GET '/' |tac|tac| grep -iq "Finish setup"
31+
# (without "|tac|tac|" we get "broken pipe" since "grep" closes the pipe before "curl" is done reading it)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
set -eo pipefail
3+
4+
dir="$(dirname "$(readlink -f "$BASH_SOURCE")")"
5+
6+
mysqlImage='mariadb:10'
7+
serverImage="$1"
8+
dbPass="test-$RANDOM-password-$RANDOM-$$"
9+
dbName="test-$RANDOM-db"
10+
dbUsr="test-$RANDOM-db"
11+
12+
# Create an instance of the container-under-test
13+
mysqlCid="$(docker run -d \
14+
-e MYSQL_RANDOM_ROOT_PASSWORD=yes \
15+
-e MYSQL_USER="$dbUsr" \
16+
-e MYSQL_PASSWORD="$dbPass" \
17+
-e MYSQL_DATABASE="$dbName" \
18+
"$mysqlImage")"
19+
trap "docker rm -vf $mysqlCid > /dev/null" EXIT
20+
cid="$(docker run -d --link "$mysqlCid":mysql \
21+
-e MYSQL_HOST="mysql" \
22+
-e MYSQL_USER="$dbUsr" \
23+
-e MYSQL_PASSWORD="$dbPass" \
24+
-e MYSQL_DATABASE="$dbName" \
25+
-e NEXTCLOUD_ADMIN_USER="test-$RANDOM-user" \
26+
-e NEXTCLOUD_ADMIN_PASSWORD="test-$RANDOM-password" \
27+
"$serverImage")"
28+
trap "docker rm -vf $cid $mysqlCid > /dev/null" EXIT
29+
30+
_occ() {
31+
docker exec -u www-data $cid php occ $1
32+
}
33+
34+
# Give some time to install
35+
. "$dir/../../retry.sh" --tries 30 '_occ app:list' > /dev/null
36+
37+
# Check if NextCloud is installed
38+
_occ status | grep -iq "installed: true"
39+
_occ check
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
set -eo pipefail
3+
4+
dir="$(dirname "$(readlink -f "$BASH_SOURCE")")"
5+
6+
postgresImage='postgres:11-alpine'
7+
serverImage="$1"
8+
dbPass="test-$RANDOM-password-$RANDOM-$$"
9+
dbName="test-$RANDOM-db"
10+
dbUsr="test-$RANDOM-db"
11+
12+
# Create an instance of the container-under-test
13+
# Static username due https://github.com/nextcloud/docker/issues/345
14+
postgresCid="$(docker run -d \
15+
-e POSTGRES_USER="oc_postgres" \
16+
-e POSTGRES_PASSWORD="$dbPass" \
17+
-e POSTGRES_DB="$dbName" \
18+
"$postgresImage")"
19+
trap "docker rm -vf $postgresCid > /dev/null" EXIT
20+
cid="$(docker run -d --link "$postgresCid":postgres \
21+
-e POSTGRES_HOST="postgres" \
22+
-e POSTGRES_USER="oc_postgres" \
23+
-e POSTGRES_PASSWORD="$dbPass" \
24+
-e POSTGRES_DB="$dbName" \
25+
-e NEXTCLOUD_ADMIN_USER="postgres" \
26+
-e NEXTCLOUD_ADMIN_PASSWORD="test-$RANDOM-password" \
27+
"$serverImage")"
28+
trap "docker rm -vf $cid $postgresCid > /dev/null" EXIT
29+
30+
_occ() {
31+
docker exec -u www-data $cid php occ $1
32+
}
33+
34+
# Give some time to install
35+
. "$dir/../../retry.sh" --tries 30 '_occ app:list' > /dev/null
36+
37+
# Check if NextCloud is installed
38+
_occ status | grep -iq "installed: true"
39+
_occ check
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
set -eo pipefail
3+
4+
dir="$(dirname "$(readlink -f "$BASH_SOURCE")")"
5+
6+
serverImage="$1"
7+
dbName="test-$RANDOM-db"
8+
9+
# Create an instance of the container-under-test
10+
cid="$(docker run -d \
11+
-e SQLITE_DATABASE="$dbName" \
12+
-e NEXTCLOUD_ADMIN_USER="test-$RANDOM-user" \
13+
-e NEXTCLOUD_ADMIN_PASSWORD="test-$RANDOM-password" \
14+
"$serverImage")"
15+
trap "docker rm -vf $cid > /dev/null" EXIT
16+
17+
_occ() {
18+
docker exec -u www-data $cid php occ $1
19+
}
20+
21+
# Give some time to install
22+
. "$dir/../../retry.sh" --tries 30 '_occ app:list' > /dev/null
23+
24+
# Check if NextCloud is installed
25+
_occ status | grep -iq "installed: true"
26+
_occ check
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Minimal server config
2+
3+
server {
4+
listen 80;
5+
root /var/www/html;
6+
7+
location = /.well-known/carddav {
8+
return 301 $scheme://$host/remote.php/dav;
9+
}
10+
location = /.well-known/caldav {
11+
return 301 $scheme://$host/remote.php/dav;
12+
}
13+
14+
location / {
15+
rewrite ^ /index.php$request_uri;
16+
}
17+
18+
location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)/ {
19+
deny all;
20+
}
21+
location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) {
22+
deny all;
23+
}
24+
25+
location ~ ^/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+)\.php(?:$|/) {
26+
fastcgi_split_path_info ^(.+\.php)(/.*)$;
27+
include fastcgi_params;
28+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
29+
fastcgi_pass fpm:9000;
30+
}
31+
32+
location ~ ^/(?:updater|ocs-provider)(?:$|/) {
33+
try_files $uri/ =404;
34+
index index.php;
35+
}
36+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash
2+
set -eo pipefail
3+
4+
dir="$(dirname "$(readlink -f "$BASH_SOURCE")")"
5+
6+
# since we have curl in the php image, we'll use that
7+
clientImage="$1"
8+
serverImage="$1"
9+
10+
# Create an instance of the container-under-test
11+
cid="$(docker run -d "$serverImage")"
12+
trap "docker rm -vf $cid > /dev/null" EXIT
13+
14+
# Build a client image with cgi-fcgi for testing
15+
nginxImage="$("$dir/../image-name.sh" librarytest/nextcloud-fpm-run-nginx "$1")"
16+
"$dir/../docker-build.sh" "$dir" "$nginxImage" <<EOD
17+
FROM nginx:alpine
18+
COPY dir/nginx-default.conf /etc/nginx/conf.d/default.conf
19+
EOD
20+
21+
serverImage="$1"
22+
23+
# Create an instance of the container-under-test
24+
cid="$(docker run -d "$serverImage")"
25+
trap "docker rm -vf $cid > /dev/null" EXIT
26+
nginxCid="$(docker run -d --link "$cid":fpm --volumes-from "$cid" "$nginxImage")"
27+
trap "docker rm -vf $nginxCid $cid > /dev/null" EXIT
28+
29+
_request() {
30+
local method="$1"
31+
shift
32+
33+
local url="${1#/}"
34+
shift
35+
36+
docker run --rm --link "$nginxCid":nginx "$clientImage" \
37+
curl -fsL -X"$method" "$@" "http://nginx/$url"
38+
}
39+
40+
# Make sure that PHP-FPM is listening and ready
41+
. "$dir/../../retry.sh" --tries 30 '_request GET / --output /dev/null'
42+
43+
# Check that we can request / and that it contains the pattern "Finish setup" somewhere
44+
# <input type="submit" class="primary" value="Finish setup" data-finishing="Finishing …">
45+
_request GET '/' |tac|tac| grep -iq "Finish setup"
46+
# (without "|tac|tac|" we get "broken pipe" since "grep" closes the pipe before "curl" is done reading it)

0 commit comments

Comments
 (0)