diff --git a/README.md b/README.md index f5949ba..6f6b785 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ If you are reading this file in BINSCRIPTS.md, your container project is likely To use these scripts yourself, issue this command: ``` -curl "https://github.internet2.edu/raw/docker/util/master/bin/install.sh?token=AAAAETsVKUnOEAMM8TvUUZccPYi13wsnks5Xq46jwA%3D%3D" | bash +curl -u user:token "https://github.internet2.edu/raw/docker/util/master/bin/install.sh" | bash ``` ### common.bash @@ -38,4 +38,5 @@ This will also install a Jenkinsfile to your repository, if it doesn't have one. ### Testing -#### test.sh \ No newline at end of file +#### test.sh +`bin/test.sh` diff --git a/bin/build.sh b/bin/build.sh index 190c975..909b400 100755 --- a/bin/build.sh +++ b/bin/build.sh @@ -3,4 +3,4 @@ source common.bash . echo "Building new Docker image($maintainer/$imagename)" -docker build --rm -t $maintainer/$imagename --build-arg maintainer=$maintainer --build-arg imagename=$imagename --build-arg version=$version . \ No newline at end of file +docker build --rm -t $maintainer/$imagename --build-arg maintainer=$maintainer --build-arg imagename=$imagename --build-arg version=$version . diff --git a/bin/install.sh b/bin/install.sh index 2db62de..bb825b0 100755 --- a/bin/install.sh +++ b/bin/install.sh @@ -2,6 +2,8 @@ git clone git@github.internet2.edu:docker/util.git find util/bin -name "*.sh" -exec sh -c 'echo "$1" | sed "s/util\///" >> .gitignore' -- {} \; mkdir -p bin +mkdir -p tests +mv util/tests/* tests/. mv util/bin/* bin/. mv util/README.md BINSCRIPTS.md if [ ! -f common.bash ]; then @@ -10,4 +12,4 @@ fi if [ ! -f Jenkinsfile ]; then mv util/Jenkinsfile.sample Jenkinsfile fi -rm -rf util \ No newline at end of file +rm -rf util diff --git a/bin/test.sh b/bin/test.sh index 6d4b8be..2fbd340 100755 --- a/bin/test.sh +++ b/bin/test.sh @@ -1,3 +1,6 @@ #!/bin/bash -bats tests \ No newline at end of file +for i in $( ls tests/) +do +bats --tap tests/$i +done diff --git a/tests/image-test.bats b/tests/image-test.bats new file mode 100644 index 0000000..a7088cd --- /dev/null +++ b/tests/image-test.bats @@ -0,0 +1,66 @@ +#!/usr/bin/env bats +load ../common + +@test "Build Docker Image $imagename/$maintainer" { + run bash -c "ps -eaf |grep -v grep|grep -c docker" + if [ $output -eq 0 ]; then + skip "Docker service is not running" + fi + + run bash -c "ls -l Dockerfile" + if [ $status -ne 0 ]; then + skip "Dockerfile is not present" + fi + + run bash -c "grep -c -e imagename -e maintainer -e version common.bash " + if [ $output -ne 3 ]; then + skip "imagename,maintainer and version are not defined" + fi + + run bash -c "grep -c -e version -e imagename -e maintainer Dockerfile" + if [ $output -lt 3 ]; then + skip "imagename,maintainer and version are not defined in Dockerfile" + fi + + run bash -c "bin/build.sh" + [ $status -eq 0 ] +} +@test "Starting Docker Image $maintainer7$imagename" { + run bash -c "docker ps -a -f name=$imagename -q|wc -l" + if [ $output -eq 1 ]; then + skip "Can not start $imagename because exist a previous image with same name " + fi + run bash -c "bin/start.sh" + run bash -c "docker ps -f name=$imagename -q|wc -l" + [ $output -eq 1 ] +} +@test "Stopping Docker Image $maintainer/$imagename" { + run bash -c "docker ps -f name=$imagename -q|wc -l" + if [ $output -eq 0 ]; then + skip "Image $imagename is not running, nothing to stop" + fi + run bash -c "bin/stop.sh" + run bash -c "docker ps -a -f name=$imagename -q|wc -l" + [ $output -eq 1 ] +} +@test "Destroying Image $maintainer/$imagename" { + run bash -c "docker ps -q -a -f name=$imagename -q|wc -l" + if [ $output -eq 0 ]; then + skip "Cannot destroy a non created container" + fi + run bash -c "docker start $imagename" + run bash -c "docker ps -q -f name=$imagename -q|wc -l" + if [ $output -eq 0 ]; then + skip "Cannot destroy a non started container" + fi + run bash -c "bin/destroy.sh" + [ $status -eq 0 ] +} +@test "Rebuilding and destroying in one step" { + run bash -c "bin/build.sh" + if [ $status -ne 0 ]; then + skip "Cannot rebuild the image" + fi + run bash -c "bin/rebuild.sh" + [ $status -eq 0 ] +}