mirror of
https://github.com/offen/docker-volume-backup.git
synced 2024-12-23 09:20:22 +01:00
Add test setup for notification feature (#61)
* Add test case for notification feature * Fix template data * bash is needed to interpret test * Do not use bashisms in test * Only print FullPath * Fix assertion
This commit is contained in:
parent
34d04211eb
commit
e6af6efd8a
1
test/notifications/.gitignore
vendored
Normal file
1
test/notifications/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
local
|
36
test/notifications/docker-compose.yml
Normal file
36
test/notifications/docker-compose.yml
Normal file
@ -0,0 +1,36 @@
|
||||
version: '3'
|
||||
|
||||
services:
|
||||
backup: &default_backup_service
|
||||
image: offen/docker-volume-backup:${TEST_VERSION}
|
||||
restart: always
|
||||
environment:
|
||||
BACKUP_FILENAME: test.tar.gz
|
||||
BACKUP_CRON_EXPRESSION: 0 0 5 31 2 ?
|
||||
BACKUP_PRUNING_PREFIX: test
|
||||
NOTIFICATION_LEVEL: info
|
||||
NOTIFICATION_URLS: gotify://gotify/${GOTIFY_TOKEN}?disableTLS=true
|
||||
volumes:
|
||||
- ./local:/archive
|
||||
- app_data:/backup/app_data:ro
|
||||
- ./notifications.tmpl:/etc/dockervolumebackup/notifications.d/notifications.tmpl
|
||||
|
||||
offen:
|
||||
image: offen/offen:latest
|
||||
labels:
|
||||
- docker-volume-backup.stop-during-backup=true
|
||||
volumes:
|
||||
- app_data:/var/opt/offen
|
||||
|
||||
gotify:
|
||||
image: gotify/server
|
||||
ports:
|
||||
- 8080:80
|
||||
environment:
|
||||
- GOTIFY_DEFAULTUSER_PASS=custom
|
||||
volumes:
|
||||
- gotify_data:/app/data
|
||||
|
||||
volumes:
|
||||
app_data:
|
||||
gotify_data:
|
7
test/notifications/notifications.tmpl
Normal file
7
test/notifications/notifications.tmpl
Normal file
@ -0,0 +1,7 @@
|
||||
{{ define "title_success" -}}
|
||||
Successful test run, yay!
|
||||
{{- end }}
|
||||
|
||||
{{ define "body_success" -}}
|
||||
Backing up {{ .Stats.BackupFile.FullPath }} succeeded.
|
||||
{{- end }}
|
58
test/notifications/run.sh
Executable file
58
test/notifications/run.sh
Executable file
@ -0,0 +1,58 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
cd $(dirname $0)
|
||||
|
||||
mkdir -p local
|
||||
|
||||
docker-compose up -d
|
||||
sleep 5
|
||||
|
||||
GOTIFY_TOKEN=$(curl -sSLX POST -H 'Content-Type: application/json' -d '{"name":"test"}' http://admin:custom@localhost:8080/application | jq -r '.token')
|
||||
|
||||
docker-compose down
|
||||
|
||||
GOTIFY_TOKEN=$GOTIFY_TOKEN docker-compose up -d
|
||||
|
||||
echo "[TEST:INFO] Set up Gotify application using token $GOTIFY_TOKEN"
|
||||
|
||||
docker-compose exec backup backup
|
||||
|
||||
tar -xf ./local/test.tar.gz -C /tmp && test -f /tmp/backup/app_data/offen.db
|
||||
echo "[TEST:PASS] Found relevant files in untared local backup."
|
||||
|
||||
if [ "$(docker-compose ps -q | wc -l)" != "3" ]; then
|
||||
echo "[TEST:FAIL] Expected all containers to be running post backup, instead seen:"
|
||||
docker-compose ps
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "[TEST:PASS] All containers running post backup."
|
||||
|
||||
MESSAGE=$(curl -sSL http://admin:custom@localhost:8080/message | jq -r '.messages[0]')
|
||||
|
||||
|
||||
case "$MESSAGE" in
|
||||
*"Successful test run, yay!"*)
|
||||
echo "[TEST:PASS] Custom notification title was used"
|
||||
;;
|
||||
*)
|
||||
echo "[TEST:FAIL] Expected custom title to be used in notification, instead seen:"
|
||||
echo $MESSAGE
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
case "$MESSAGE" in
|
||||
*"Backing up /tmp/test.tar.gz succeeded."*)
|
||||
echo "[TEST:PASS] Custom notification body was used"
|
||||
;;
|
||||
*)
|
||||
echo "[TEST:FAIL] Expected custom body to be used in notification, instead seen:"
|
||||
echo $MESSAGE
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
docker-compose down --volumes
|
Loading…
Reference in New Issue
Block a user