From 94afd32e63286aa5854b18d5d9b7f1d55e69870e Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Thu, 7 Sep 2017 10:39:15 -0700 Subject: [PATCH 1/2] refacto tests Signed-off-by: Victor Vieux --- .travis.yml | 10 +++++----- Makefile | 10 ++++++++++ {.travis => tests}/integration.sh | 4 ++-- {.travis/ssh => tests/testdata}/Dockerfile | 0 {.travis/ssh => tests/testdata}/id_rsa | 0 {.travis/ssh => tests/testdata}/id_rsa.pub | 0 {.travis => tests}/unit.sh | 0 7 files changed, 17 insertions(+), 7 deletions(-) rename {.travis => tests}/integration.sh (96%) rename {.travis/ssh => tests/testdata}/Dockerfile (100%) rename {.travis/ssh => tests/testdata}/id_rsa (100%) rename {.travis/ssh => tests/testdata}/id_rsa.pub (100%) rename {.travis => tests}/unit.sh (100%) 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/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/.travis/integration.sh b/tests/integration.sh similarity index 96% rename from .travis/integration.sh rename to tests/integration.sh index ef43642..383bfb7 100755 --- a/.travis/integration.sh +++ b/tests/integration.sh @@ -15,7 +15,7 @@ TAG=test sudo docker pull rastasheep/ubuntu-sshd sudo docker pull busybox -docker build -t sshd .travis/ssh +docker build -t sshd tests/testdata #script # make the plugin @@ -60,7 +60,7 @@ 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 set vieux/sshfs:$TAG sshkey.source=`pwd`/test/testdata/ 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" 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 From 6c308a5cfc4b30fbd151188731d55f82e6a7b914 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Thu, 7 Sep 2017 10:45:41 -0700 Subject: [PATCH 2/2] add restart test Signed-off-by: Victor Vieux --- tests/integration.sh | 83 +++++++++++++++++++++----------------------- 1 file changed, 40 insertions(+), 43 deletions(-) diff --git a/tests/integration.sh b/tests/integration.sh index 383bfb7..8114e50 100755 --- a/tests/integration.sh +++ b/tests/integration.sh @@ -5,65 +5,62 @@ 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 pull rastasheep/ubuntu-sshd +docker pull busybox docker build -t sshd tests/testdata #script # make the plugin -sudo PLUGIN_TAG=$TAG make +PLUGIN_TAG=$TAG make # enable the plugin -sudo docker plugin enable vieux/sshfs:$TAG +docker plugin enable vieux/sshfs:$TAG # list plugins -sudo docker plugin ls +docker plugin ls # start sshd -sudo docker run -d -p 2222:22 sshd +docker run --name sshd -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 +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 -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 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 -#sudo cat /var/lib/docker/plugins/sshfs-state.json -sudo docker volume rm sshvolume +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 +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: 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 +# 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: ssh key -sudo docker plugin disable vieux/sshfs:$TAG -sudo docker plugin set vieux/sshfs:$TAG sshkey.source=`pwd`/test/testdata/ -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 +# 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