diff --git a/.dockerignore b/.dockerignore index 2253de8..8528d8e 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,8 +1,6 @@ +.travis.yml Dockerfile.* Makefile Readme.md docker-compose.yaml -docker-compose-test-s3.yml -test.sh -itest.sh -test-s3.sh +tests/ diff --git a/Makefile b/Makefile index 1c0929a..ee895db 100644 --- a/Makefile +++ b/Makefile @@ -19,22 +19,22 @@ build-all: build-x86 build-arm .PHONY: test-x86 test-x86: build-x86 - ./test.sh $(DOCKER_TAG):ubuntu + cd tests && ./test.sh $(DOCKER_TAG):ubuntu .PHONY: test-arm test-arm: build-arm - ./test.sh $(DOCKER_TAG):raspbian + cd tests && .test.sh $(DOCKER_TAG):raspbian .PHONY: test-all test-all: test-x86 test-arm .PHONY: test-s3-x86 test-s3-x86: - ./test-s3.sh ubuntu + cd tests && ./test-s3.sh ubuntu .PHONY: test-s3-arm test-s3-arm: - ./test-s3.sh raspbian + cd tests && ./test-s3.sh raspbian .PHONY: test-s3-all test-s3-all: test-s3-x86 test-s3-arm diff --git a/itest.sh b/itest.sh deleted file mode 100755 index dbe2248..0000000 --- a/itest.sh +++ /dev/null @@ -1,47 +0,0 @@ -#! /bin/bash -set -e - -echo "Performing backup tests" - -echo "Verify cron and crontab exist" -type cron -type crontab - -echo "Create test data..." -mkdir -p /data && echo Test > /data/test.txt - -echo "Making backup..." -/backup.sh - -echo "Verify backup..." -/verify.sh - -echo "Delete test data..." -rm -fr /data/* - -echo "Verify deleted..." -test -f /data/test.txt && exit 1 || echo "Gone" - -echo "Restore backup..." -/restore.sh - -echo "Verify backup..." -/verify.sh - -echo "Delete test data again..." -rm -fr /data/* - -echo "Verify deleted..." -test -f /data/test.txt && exit 1 || echo "Gone" - -echo "Simulate a restart with RESTORE_ON_EMPTY_START..." -RESTORE_ON_EMPTY_START=true /entrypoint.sh - -echo "Verify restore happened..." -test -f /data/test.txt - -echo "Verify restore with incorrect passphrase fails..." -export PASSPHRASE=Incorrect.Mule.Solar.Paperclip - -echo "Fail to restore backup..." -/restore.sh && exit 1 || echo "OK" diff --git a/test.sh b/test.sh deleted file mode 100755 index bf7db2b..0000000 --- a/test.sh +++ /dev/null @@ -1,10 +0,0 @@ -#! /bin/bash - -image=$1 - -# Run the test script within the container -docker run --rm \ - -e SKIP_ON_START=true \ - -v "$(pwd)/itest.sh:/itest.sh" \ - $image \ - bash -c "/itest.sh" diff --git a/docker-compose-test-s3.yml b/tests/docker-compose-test-s3.yml similarity index 86% rename from docker-compose-test-s3.yml rename to tests/docker-compose-test-s3.yml index ea68df5..24ba128 100644 --- a/docker-compose-test-s3.yml +++ b/tests/docker-compose-test-s3.yml @@ -2,12 +2,13 @@ version: '2' services: duplicity: build: - context: . + context: .. dockerfile: Dockerfile.${DOCKER_BASE} entrypoint: "bash" - command: ["/itest.sh"] + command: ["/test.sh"] hostname: itest environment: + IN_CONTAINER: 'true' SKIP_ON_START: 'true' OPT_ARGUMENTS: '--s3-unencrypted-connection' BACKUP_DEST: s3://minio:9000/duplicity @@ -15,7 +16,7 @@ services: AWS_ACCESS_KEY_ID: SUPER_SECRET_ACCESS_KEY AWS_SECRET_ACCESS_KEY: SUPER_SECRET_SECRET_KEY volumes: - - "./itest.sh:/itest.sh" + - "./test.sh:/test.sh" links: - minio minio: diff --git a/test-s3.sh b/tests/test-s3.sh similarity index 100% rename from test-s3.sh rename to tests/test-s3.sh diff --git a/tests/test.sh b/tests/test.sh new file mode 100755 index 0000000..00af13f --- /dev/null +++ b/tests/test.sh @@ -0,0 +1,58 @@ +#! /bin/bash + +image=$1 + +if [ "$IN_CONTAINER" != "true" ] ; then + # Run the test script within the container + docker run --rm \ + -e IN_CONTAINER=true \ + -e SKIP_ON_START=true \ + -v "$(pwd)/test.sh:/test.sh" \ + $image \ + bash -c "/test.sh" +else + echo "Performing backup tests" + + echo "Verify cron and crontab exist" + type cron + type crontab + + echo "Create test data..." + mkdir -p /data && echo Test > /data/test.txt + + echo "Making backup..." + /backup.sh + + echo "Verify backup..." + /verify.sh + + echo "Delete test data..." + rm -fr /data/* + + echo "Verify deleted..." + test -f /data/test.txt && exit 1 || echo "Gone" + + echo "Restore backup..." + /restore.sh + + echo "Verify backup..." + /verify.sh + + echo "Delete test data again..." + rm -fr /data/* + + echo "Verify deleted..." + test -f /data/test.txt && exit 1 || echo "Gone" + + echo "Simulate a restart with RESTORE_ON_EMPTY_START..." + RESTORE_ON_EMPTY_START=true /entrypoint.sh + + echo "Verify restore happened..." + test -f /data/test.txt + + echo "Verify restore with incorrect passphrase fails..." + export PASSPHRASE=Incorrect.Mule.Solar.Paperclip + + echo "Fail to restore backup..." + /restore.sh && exit 1 || echo "OK" +fi