diff --git a/.travis.yml b/.travis.yml index 55f6367..8d7594d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,13 +6,13 @@ include: - language: go go: 1.8.x - env: TESTFILE=unit.sh + env: RULE=test-unit - language: go go: 1.9.x - env: TESTFILE=unit.sh + env: RULE=test-unit - language: go go: master - env: TESTFILE=unit.sh + env: RULE=test-unit - language: generic sudo: required services: @@ -22,7 +22,7 @@ - sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" - sudo apt-get update - sudo apt-get -y install docker-ce - env: TESTFILE=integration.sh + env: RULE=test-integration script: - - ./.travis/$TESTFILE \ No newline at end of file + - make $RULE \ No newline at end of file diff --git a/.travis/integration.sh b/.travis/integration.sh deleted file mode 100755 index ef43642..0000000 --- a/.travis/integration.sh +++ /dev/null @@ -1,69 +0,0 @@ -#!/bin/bash - -set -e -set -x - -TAG=test - -# before_install -#curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - -#sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" -#sudo apt-get update -#sudo apt-get -y install docker-ce - -# install -sudo docker pull rastasheep/ubuntu-sshd -sudo docker pull busybox - -docker build -t sshd .travis/ssh -#script - -# make the plugin -sudo PLUGIN_TAG=$TAG make -# enable the plugin -sudo docker plugin enable vieux/sshfs:$TAG -# list plugins -sudo docker plugin ls -# start sshd -sudo docker run -d -p 2222:22 sshd - -# test1: simple -sudo docker volume create -d vieux/sshfs:$TAG -o sshcmd=root@localhost:/ -o port=2222 -o password=root sshvolume -sudo docker run --rm -v sshvolume:/write busybox sh -c "echo hello > /write/world" -sudo docker run --rm -v sshvolume:/read busybox grep -Fxq hello /read/world -#sudo cat /var/lib/docker/plugins/sshfs-state.json -sudo docker volume rm sshvolume - -# test2: allow_other -sudo docker volume create -d vieux/sshfs:$TAG -o sshcmd=root@localhost:/ -o allow_other -o port=2222 -o password=root sshvolume -sudo docker run --rm -v sshvolume:/write -u nobody busybox sh -c "echo hello > /write/world" -docker run --rm -v sshvolume:/read -u nobody busybox grep -Fxq hello /read/world -#sudo cat /var/lib/docker/plugins/sshfs-state.json -sudo docker volume rm sshvolume - -# test3: compression -sudo docker volume create -d vieux/sshfs:$TAG -o sshcmd=root@localhost:/ -o Ciphers=arcfour -o Compression=no -o port=2222 -o password=root sshvolume -sudo docker run --rm -v sshvolume:/write busybox sh -c "echo hello > /write/world" -sudo docker run --rm -v sshvolume:/read busybox grep -Fxq hello /read/world -#sudo cat /var/lib/docker/plugins/sshfs-state.json -sudo docker volume rm sshvolume - -# test4: source -sudo docker plugin disable vieux/sshfs:$TAG -sudo docker plugin set vieux/sshfs:$TAG state.source=/tmp -sudo docker plugin enable vieux/sshfs:$TAG -sudo docker volume create -d vieux/sshfs:$TAG -o sshcmd=root@localhost:/ -o Ciphers=arcfour -o Compression=no -o port=2222 -o password=root sshvolume -sudo docker run --rm -v sshvolume:/write busybox sh -c "echo hello > /write/world" -sudo docker run --rm -v sshvolume:/read busybox grep -Fxq hello /read/world -#sudo cat /tmp/sshfs-state.json -sudo docker volume rm sshvolume - -# test5: ssh key -sudo docker plugin disable vieux/sshfs:$TAG -sudo docker plugin set vieux/sshfs:$TAG sshkey.source=`pwd`/.travis/ssh/ -sudo docker plugin enable vieux/sshfs:$TAG -sudo docker volume create -d vieux/sshfs:$TAG -o sshcmd=root@localhost:/ -o port=2222 sshvolume -sudo docker run --rm -v sshvolume:/write busybox sh -c "echo hello > /write/world" -sudo docker run --rm -v sshvolume:/read busybox grep -Fxq hello /read/world -#sudo cat /var/lib/docker/plugins/sshfs-state.json -sudo docker volume rm sshvolume diff --git a/Makefile b/Makefile index 393ab21..4ca43ce 100644 --- a/Makefile +++ b/Makefile @@ -31,3 +31,13 @@ enable: push: clean rootfs create enable @echo "### push plugin ${PLUGIN_NAME}:${PLUGIN_TAG}" @docker plugin push ${PLUGIN_NAME}:${PLUGIN_TAG} + +test: test-unit test-integration + +test-unit: + @echo "### unit tests" + ./tests/unit.sh + +test-integration: + @echo "### integration tests" + ./tests/integration.sh diff --git a/tests/integration.sh b/tests/integration.sh new file mode 100755 index 0000000..8114e50 --- /dev/null +++ b/tests/integration.sh @@ -0,0 +1,66 @@ +#!/bin/bash + +set -e +set -x + +TAG=test + + +# install +docker pull rastasheep/ubuntu-sshd +docker pull busybox + +docker build -t sshd tests/testdata +#script + +# make the plugin +PLUGIN_TAG=$TAG make +# enable the plugin +docker plugin enable vieux/sshfs:$TAG +# list plugins +docker plugin ls +# start sshd +docker run --name sshd -d -p 2222:22 sshd + +# test1: simple +docker volume create -d vieux/sshfs:$TAG -o sshcmd=root@localhost:/ -o port=2222 -o password=root sshvolume +docker run --rm -v sshvolume:/write busybox sh -c "echo hello > /write/world" +docker run --rm -v sshvolume:/read busybox grep -Fxq hello /read/world +docker volume rm sshvolume + +# test2: allow_other +docker volume create -d vieux/sshfs:$TAG -o sshcmd=root@localhost:/ -o allow_other -o port=2222 -o password=root sshvolume +docker run --rm -v sshvolume:/write -u nobody busybox sh -c "echo hello > /write/world" +docker run --rm -v sshvolume:/read -u nobody busybox grep -Fxq hello /read/world +docker volume rm sshvolume + +# test3: compression +docker volume create -d vieux/sshfs:$TAG -o sshcmd=root@localhost:/ -o Ciphers=arcfour -o Compression=no -o port=2222 -o password=root sshvolume +docker run --rm -v sshvolume:/write busybox sh -c "echo hello > /write/world" +docker run --rm -v sshvolume:/read busybox grep -Fxq hello /read/world +docker volume rm sshvolume + +# test4: restart +docker volume create -d vieux/sshfs:$TAG -o sshcmd=root@localhost:/ -o port=2222 -o password=root sshvolume +docker run --rm -v sshvolume:/write busybox sh -c "echo hello > /write/world" +(sleep 2; docker restart sshd) & +docker run --rm -v sshvolume:/read busybox sh -c "sleep 4 ; grep -Fxq hello /read/world" +docker volume rm sshvolume + +# test5: source +docker plugin disable vieux/sshfs:$TAG +docker plugin set vieux/sshfs:$TAG state.source=/tmp +docker plugin enable vieux/sshfs:$TAG +docker volume create -d vieux/sshfs:$TAG -o sshcmd=root@localhost:/ -o Ciphers=arcfour -o Compression=no -o port=2222 -o password=root sshvolume +docker run --rm -v sshvolume:/write busybox sh -c "echo hello > /write/world" +docker run --rm -v sshvolume:/read busybox grep -Fxq hello /read/world +docker volume rm sshvolume + +# test6: ssh key +docker plugin disable vieux/sshfs:$TAG +docker plugin set vieux/sshfs:$TAG sshkey.source=`pwd`/tests/testdata/ +docker plugin enable vieux/sshfs:$TAG +docker volume create -d vieux/sshfs:$TAG -o sshcmd=root@localhost:/ -o port=2222 sshvolume +docker run --rm -v sshvolume:/write busybox sh -c "echo hello > /write/world" +docker run --rm -v sshvolume:/read busybox grep -Fxq hello /read/world +docker volume rm sshvolume diff --git a/.travis/ssh/Dockerfile b/tests/testdata/Dockerfile similarity index 100% rename from .travis/ssh/Dockerfile rename to tests/testdata/Dockerfile diff --git a/.travis/ssh/id_rsa b/tests/testdata/id_rsa similarity index 100% rename from .travis/ssh/id_rsa rename to tests/testdata/id_rsa diff --git a/.travis/ssh/id_rsa.pub b/tests/testdata/id_rsa.pub similarity index 100% rename from .travis/ssh/id_rsa.pub rename to tests/testdata/id_rsa.pub diff --git a/.travis/unit.sh b/tests/unit.sh similarity index 100% rename from .travis/unit.sh rename to tests/unit.sh