From ad2d5bdec943415cfcfda84425e3ff8ec1a8b05c Mon Sep 17 00:00:00 2001 From: ViViDboarder Date: Wed, 15 Nov 2017 11:02:12 -0800 Subject: [PATCH] Minor improvement on tests to make it quicker --- Makefile | 13 +++++++++++-- itest.sh | 22 ++++++++++++++++++++++ test.sh | 30 +++++++----------------------- 3 files changed, 40 insertions(+), 25 deletions(-) create mode 100755 itest.sh diff --git a/Makefile b/Makefile index 5456c37..a9da3e5 100644 --- a/Makefile +++ b/Makefile @@ -1,31 +1,40 @@ -.PHONY: build-x86 build-arm build-all test - DOCKER_TAG ?= docker-duplicity-cron +.PHONY: default default: build-x86 +.PHONY: test test: test-x86 +.PHONY: build-x86 build-x86: docker build -f ./Dockerfile.ubuntu -t $(DOCKER_TAG):ubuntu . +.PHONY: build-arm build-arm: docker build -f ./Dockerfile.raspbian -t $(DOCKER_TAG):raspbian . +.PHONY: build-all build-all: build-x86 build-arm +.PHONY: test-x86 test-x86: build-x86 ./test.sh $(DOCKER_TAG) ubuntu +.PHONY: test-arm test-arm: build-arm ./test.sh $(DOCKER_TAG) raspbian +.PHONY: test-all test-all: test-x86 test-arm +.PHONY: shell-x86 shell-x86: build-x86 docker run --rm -it $(DOCKER_TAG):ubuntu bash +.PHONY: shell-arm shell-arm: build-arm docker run --rm -it $(DOCKER_TAG):raspbian bash +.PHONY: shell shell: shell-x86 diff --git a/itest.sh b/itest.sh new file mode 100755 index 0000000..3bd4dda --- /dev/null +++ b/itest.sh @@ -0,0 +1,22 @@ +#! /bin/bash +set -e + +echo "Performing backup tests" + +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 "Restore backup..." +/restore.sh + +echo "Verify backup..." +/verify.sh diff --git a/test.sh b/test.sh index 15b0fef..785f43f 100755 --- a/test.sh +++ b/test.sh @@ -6,26 +6,10 @@ tag=$2 full_image="${image_name}:${tag}" container_name="${image_name}-${tag}" -# Create backup container -docker run -d -e SKIP_ON_START=true --name ${container_name} $full_image bash -c "/bin/sleep 20" -# Create some test data -docker exec $container_name sh -c "mkdir -p /data && echo Test > /data/test.txt" -# Backup data -echo "Making backup..." -docker exec $container_name /backup.sh -# Verify the backup -echo "Verify backup..." -docker exec $container_name /verify.sh -# Remove test file -echo "Clear data..." -docker exec $container_name sh -c "rm /data/*" -# Restore the backup -echo "Restore backup..." -docker exec $container_name /restore.sh -# Verify the backup -echo "Verify backup..." -docker exec $container_name /verify.sh -# Stop the container -docker kill $container_name -# Remove the container -docker rm $container_name +# Run the test script within the container +docker run --rm \ + -e SKIP_ON_START=true \ + -v "$(pwd)/itest.sh:/itest.sh" \ + --name ${container_name} \ + $full_image \ + bash -c "/itest.sh"