Minor improvement on tests to make it quicker

This commit is contained in:
ViViDboarder 2017-11-15 11:02:12 -08:00
parent bf795d2089
commit ad2d5bdec9
3 changed files with 40 additions and 25 deletions

View File

@ -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

22
itest.sh Executable file
View File

@ -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

30
test.sh
View File

@ -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"