From 07be10b95fd3078e92f3950c8fb182b1ad5d26c7 Mon Sep 17 00:00:00 2001
From: Dariusz Janny <janny@man.poznan.pl>
Date: Thu, 21 Jan 2021 23:19:19 +0100
Subject: [PATCH] [edugain/faas#9] test suite for faas-db added.

---
 Makefile                |  6 ++++++
 README.md               |  3 +++
 test/faas-db-tests.bats | 38 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 47 insertions(+)
 create mode 100644 test/faas-db-tests.bats

diff --git a/Makefile b/Makefile
index e7a0ddc..d534494 100644
--- a/Makefile
+++ b/Makefile
@@ -32,5 +32,11 @@ stop: # stop container
 version: # print current component version
 	@echo ${FAAS_DB_VERSION}
 
+test: testFaasDB  # run all tests
+
+testFaasDB: # run checking docker image tests
+	@echo "# run test version"
+	bats test/faas-db-tests.bats
+
 help: # this help
 	@awk 'BEGIN {FS = ":.*?# "} /^[a-zA-Z_-]+:.*?# / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
diff --git a/README.md b/README.md
index 9c6fca5..4082da8 100644
--- a/README.md
+++ b/README.md
@@ -2,6 +2,7 @@
 
 ## structure
 `_conf/`_ - directory with configuration files
+`test/` - directory with tests files
 
 ## build image
 To build `faas-db` docker image
@@ -26,4 +27,6 @@ up                             build and run container
 logs                           print docker logs
 stop                           stop container
 version                        print current component version
+test                           run all tests
+testFaasDB                     run checking docker image tests
 `
diff --git a/test/faas-db-tests.bats b/test/faas-db-tests.bats
new file mode 100644
index 0000000..41313a4
--- /dev/null
+++ b/test/faas-db-tests.bats
@@ -0,0 +1,38 @@
+#! /usr/bin/env bats
+
+@test "faas-db - checking version in variables" {
+    [ $FAAS_DB_VERSION = "1.0-SNAPSHOT" ]
+}
+
+@test "faas-db - checking app name in variables" {
+    [ $FAAS_DB_NAME = "faas-db" ]
+}
+
+@test "faas-db - checking image string in variables" {
+    [ $FAAS_DB_IMAGE = "faas/faas-db:1.0-SNAPSHOT" ]
+}
+
+@test "faas-db - checking version in image file" {
+    run docker exec $FAAS_DB_NAME bash -c 'cat /faas-docker-version'
+    [ "$output" = "1.0-SNAPSHOT" ]
+}
+
+@test "faas-db - checking app name in image file" {
+    run docker exec $FAAS_DB_NAME bash -c 'cat /faas-docker-name'
+    [ "$output" = "faas-db" ]
+}
+
+@test "faas-db - checking image string in image file" {
+    run docker exec $FAAS_DB_NAME bash -c 'cat /faas-docker-image'
+    [ "$output" = "faas/faas-db:1.0-SNAPSHOT" ]
+}
+
+@test "faas-db - checking DB version in client command" {
+    run docker exec $FAAS_DB_NAME bash -c 'mysql --version'
+    [ "$output" = "mysql  Ver 15.1 Distrib 10.5.8-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2" ]
+}
+
+@test "faas-db - checking DB version in running DB instance" {
+    run docker exec $FAAS_DB_NAME bash -c "mysql --disable-column-names -uroot -p${MYSQL_ROOT_PASSWORD} mysql -e 'select version();'"
+    [ "$output" = "10.5.8-MariaDB-1:10.5.8+maria~focal" ]
+}
-- 
GitLab