summaryrefslogtreecommitdiffstats
path: root/tests/Dockerfiletest
diff options
context:
space:
mode:
authorMohamed Ashiq Liyazudeen <mliyazud@redhat.com>2017-05-08 21:08:09 +0530
committerMohamed Ashiq Liyazudeen <mliyazud@redhat.com>2017-05-08 22:39:07 +0530
commitec2d37cd987c6aafc7d0d71ab6c2643487d8ef92 (patch)
tree9d6137f38a97b149c4ef75878745ddd26095e2b2 /tests/Dockerfiletest
parente63a97ed1b464975c9df07ea07dec3b136fa034a (diff)
downloadgluster-ec2d37cd987c6aafc7d0d71ab6c2643487d8ef92.tar.gz
gluster-ec2d37cd987c6aafc7d0d71ab6c2643487d8ef92.tar.bz2
gluster-ec2d37cd987c6aafc7d0d71ab6c2643487d8ef92.tar.xz
gluster-ec2d37cd987c6aafc7d0d71ab6c2643487d8ef92.zip
Unit Test to check the shell script and Dockerfile lint. Travis.ci intergrated.
Refer: https://github.com/projectatomic/dockerfile_lint Signed-off-by: Mohamed Ashiq Liyazudeen <mliyazud@redhat.com>
Diffstat (limited to 'tests/Dockerfiletest')
-rw-r--r--tests/Dockerfiletest/Dockerfile_faulty10
-rw-r--r--tests/Dockerfiletest/Makefile2
-rwxr-xr-xtests/Dockerfiletest/run.sh12
-rwxr-xr-xtests/Dockerfiletest/test_gluster_dockerfile.sh45
4 files changed, 69 insertions, 0 deletions
diff --git a/tests/Dockerfiletest/Dockerfile_faulty b/tests/Dockerfiletest/Dockerfile_faulty
new file mode 100644
index 0000000..b538995
--- /dev/null
+++ b/tests/Dockerfiletest/Dockerfile_faulty
@@ -0,0 +1,10 @@
+
+MAINTAINER Humble Chirammal hchiramm@redhat.com Mohamed Ashiq Liyazudeen mliyazud@redhat.com
+
+LABEL Name="faulty"
+
+RUNCMD 'echo "fail"'
+
+EXPOSE 3333
+
+CMD ["/usr/sbin/init"]
diff --git a/tests/Dockerfiletest/Makefile b/tests/Dockerfiletest/Makefile
new file mode 100644
index 0000000..13cf414
--- /dev/null
+++ b/tests/Dockerfiletest/Makefile
@@ -0,0 +1,2 @@
+test:
+ ./run.sh
diff --git a/tests/Dockerfiletest/run.sh b/tests/Dockerfiletest/run.sh
new file mode 100755
index 0000000..b82b810
--- /dev/null
+++ b/tests/Dockerfiletest/run.sh
@@ -0,0 +1,12 @@
+#!/bin/bash
+
+SCRIPT_DIR=$(cd $(dirname $0); pwd)
+
+echo "running tests in ${SCRIPT_DIR}"
+
+for test in ${SCRIPT_DIR}/test_*.sh ; do
+ $test
+ if [ $? -ne 0 ]; then
+ exit 1
+ fi
+done
diff --git a/tests/Dockerfiletest/test_gluster_dockerfile.sh b/tests/Dockerfiletest/test_gluster_dockerfile.sh
new file mode 100755
index 0000000..fc52d44
--- /dev/null
+++ b/tests/Dockerfiletest/test_gluster_dockerfile.sh
@@ -0,0 +1,45 @@
+#!/bin/bash
+
+SCRIPT_DIR=$(cd $(dirname ${0}); pwd)
+TESTS_DIR="${SCRIPT_DIR}/.."
+INC_DIR="${TESTS_DIR}/common"
+BASE_DIR="${SCRIPT_DIR}/../.."
+FAULTY_DOCKERFILE="${SCRIPT_DIR}/Dockerfile_faulty"
+
+source "${INC_DIR}/subunit.sh"
+
+check_dockerfilelint_invalid() {
+ local file="${1}"
+ check_dockerfilelint ${file}
+ if [[ "x$?" == "x0" ]]; then
+ echo "ERROR: parsing invalid Dockerfile succeeded"
+ return 1
+ fi
+
+ return 0
+}
+
+check_dockerfilelint() {
+ local file="${1}"
+ if ! which dockerfile_lint ; then
+ echo "dockerfile_lint not found: skipping..."
+ return 0
+ fi
+
+ dockerfile_lint -p -f ${file}
+}
+
+failed=0
+
+ testit "check invalid Dockerfile" \
+ check_dockerfilelint_invalid ${FAULTY_DOCKERFILE} \
+ || ((failed++))
+
+ for Dockerfile in $(find ${BASE_DIR} -name "Dockerfile") ; do
+ testit "check Dockerfile_lint $(basename ${Dockerfile})" \
+ check_dockerfilelint ${Dockerfile} \
+ || ((failed++))
+ done
+
+
+testok $0 ${failed}