From 28f081c8d086913306f0e5e6574cc002997f4ce8 Mon Sep 17 00:00:00 2001 From: Ian Fijolek Date: Wed, 2 Aug 2023 13:59:59 -0700 Subject: [PATCH] Add integration testing to verify backup and restoration Including databases --- .gitignore | 4 ++++ Makefile | 4 ++++ itest/bootstrap-tests.sh | 31 +++++++++++++++++++++++++++++ itest/docker-compose.yml | 42 ++++++++++++++++++++++++++++++++++++++++ itest/run.sh | 35 +++++++++++++++++++++++++++++++++ itest/test-backup.hcl | 29 +++++++++++++++++++++++++++ itest/validate-tests.sh | 15 ++++++++++++++ 7 files changed, 160 insertions(+) create mode 100755 itest/bootstrap-tests.sh create mode 100644 itest/docker-compose.yml create mode 100755 itest/run.sh create mode 100644 itest/test-backup.hcl create mode 100755 itest/validate-tests.sh diff --git a/.gitignore b/.gitignore index b1630ac..d119013 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,7 @@ dist/ # Built executable restic-scheduler data/ + +# Itest temp dirs +itest/data +itest/repo diff --git a/Makefile b/Makefile index 4815a9b..36e84c6 100644 --- a/Makefile +++ b/Makefile @@ -32,6 +32,10 @@ test: go test -v -coverprofile=coverage.out # -short go tool cover -func=coverage.out +.PHONY: itest +itest: docker-build + ./itest/run.sh + # Installs pre-commit hooks .PHONY: install-hooks install-hooks: diff --git a/itest/bootstrap-tests.sh b/itest/bootstrap-tests.sh new file mode 100755 index 0000000..e4dbf64 --- /dev/null +++ b/itest/bootstrap-tests.sh @@ -0,0 +1,31 @@ +#! /bin/sh +set -ex + +# Create flat file +echo "Hello" > /data/test.txt + +# Create Sqlite database +touch /data/test_database.db +sqlite3 /data/test_database.db <<-EOF +CREATE TABLE test_table ( + id integer PRIMARY KEY, + data text NOT NULL +); + +INSERT INTO test_table(data) +VALUES ("Test row"); +EOF + +# Create MySql database +until mysql --host "$MYSQL_HOST" --user "$MYSQL_USER" --password="$MYSQL_PWD" --execute "SHOW DATABASES;"; do + sleep 1 +done +mysql --host "$MYSQL_HOST" --user "$MYSQL_USER" --password="$MYSQL_PWD" main <