Repository: datanymizer/datanymizer (language: rust)

Issue:
Create the end-to-end test based on the "demo" folder



Discussion / hints:

Fix patch:
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index efe38ca3..1cdb3d9e 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -139,6 +139,23 @@ jobs:
           args: --package pg_datanymizer
         if: steps.cache-target.outputs.cache-hit != 'true'
 
+  test_demo:
+    name: Test demo
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v1
+      - name: Bootstrap demo, make a dump file, ensure that it is not empty
+        run: |
+          cd demo
+          make bootstrap
+          make dump
+          ([[ -s /tmp/fake_dump.sql ]] && echo "The dump file exists and is not empty") || (echo "No dump file or it is empty" && exit 1)
+      - name: Restore the dump and check the data
+        run: |
+          cd demo
+          make restore_dump
+          make check_data
+
   linux_build:
     name: Build / Linux
     runs-on: ubuntu-latest
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 287824c8..1ef85bef 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ## [Unreleased]
 ### 🚀 Added
+- Testing the demo [#114](https://github.com/datanymizer/datanymizer/pull/114)
+  ([@evgeniy-r](https://github.com/evgeniy-r))
 - Add support for `postgresql` scheme [#115](https://github.com/datanymizer/datanymizer/pull/115)
   ([@mgrachev](https://github.com/mgrachev))
 
diff --git a/demo/Makefile b/demo/Makefile
index a30eebc1..941683bc 100644
--- a/demo/Makefile
+++ b/demo/Makefile
@@ -1,5 +1,8 @@
 example_database_url="https://www.postgresqltutorial.com/wp-content/uploads/2019/05/dvdrental.zip"
 tmpfile="/tmp/dump.zip"
+dump_file="/tmp/fake_dump.sql"
+count_query="SELECT COUNT(*) FROM actor;"
+data_query="SELECT first_name, last_name FROM actor LIMIT 1;"
 pause=5
 .SILENT:
 
@@ -14,7 +17,7 @@ up:
 
 download: clean_file
 	echo -e "\n==> Download DVDRENTAL database"
-	curl $(example_database_url) -o "$(tmpfile)" && unzip $(tmpfile) -d /tmp
+	curl $(example_database_url) -o "$(tmpfile)" --retry 5 && unzip $(tmpfile) -d /tmp
 
 clean_file:
 	echo -e "\n==> Clean all temporary files"
@@ -22,11 +25,19 @@ clean_file:
 
 clean_db:
 	echo -e "\n==> Clean database if exists"
-	docker-compose exec pg_database psql -Upostgres -c "drop database if exists dvdrental;"
+	docker-compose exec -T pg_database psql -Upostgres -c "drop database if exists dvdrental;"
+
+clean_fake_db:
+	echo -e "\n==> Clean database for fake data if exists"
+	docker-compose exec -T pg_database psql -Upostgres -c "drop database if exists dvdrental_fake;"
 
 create_db: up clean_db
-	echo -e "\n==> Create empty database"
-	docker-compose exec pg_database psql -Upostgres -c "create database dvdrental;"
+	echo -e "\n==> Create an empty database"
+	docker-compose exec -T pg_database psql -Upostgres -c "create database dvdrental;"
+
+create_fake_db: clean_fake_db
+	echo -e "\n==> Create an empty database for fake data"
+	docker-compose exec -T pg_database psql -Upostgres -c "create database dvdrental_fake;"
 
 restore_db:
 	echo -e "\n==> Restore database from dump file"
@@ -35,5 +46,24 @@ restore_db:
 bootstrap: download create_db restore_db clean_file
 
 dump:
-	echo -e "\n==> Create dump"
-	docker-compose run --rm pg_datanymizer postgres://postgres:postgres@pg_database/dvdrental -c /dvdrental.yml > /tmp/fake_dump.sql
+	echo -e "\n==> Create the dump"
+	docker-compose run --rm pg_datanymizer postgres://postgres:postgres@pg_database/dvdrental -c /dvdrental.yml > $(dump_file)
+
+restore_dump: create_fake_db
+	echo -e "\n==> Restore the dump to the database for fake data"
+	cat $(dump_file) | docker-compose exec -T pg_database psql -Upostgres -d dvdrental_fake -v "ON_ERROR_STOP=1"
+
+check_data:
+	echo -e "\n==> Check data in the both databases"
+	( \
+	  [ \
+	    `docker-compose exec -T pg_database psql -At -Upostgres -d dvdrental -c $(count_query)` = \
+	    `docker-compose exec -T pg_database psql -At -Upostgres -d dvdrental_fake -c $(count_query)` \
+	  ] && echo "The row counts are equal" \
+	) || (echo "The row counts are different" && exit 1)
+	( \
+	  [ \
+	      `docker-compose exec -T pg_database psql -At -Upostgres -d dvdrental -c $(data_query)` != \
+	      `docker-compose exec -T pg_database psql -At -Upostgres -d dvdrental_fake -c $(data_query)` \
+	  ] && echo "The data is different" \
+	) || (echo "The data is the same" && exit 1)
diff --git a/demo/README.md b/demo/README.md
index 14dc1d15..1d53cda2 100644
--- a/demo/README.md
+++ b/demo/README.md
@@ -24,3 +24,9 @@ make dump
 It makes new `/tmp/fake_dump.sql` file with fake rows in tables from `dvdrental.yml` configuration.
 
 You can change configuration file and try again.
+
+4. For restoring this dump to the database `dvdrental_fake`, please run:
+
+```shell
+make restore_dump
+```


Test patch: