From 62912517341951aa0eff5b0f3551dc5edf3e9624 Mon Sep 17 00:00:00 2001 From: Chai Feng Date: Sat, 19 Oct 2019 13:01:55 +0200 Subject: [PATCH] Add a new test suite for ufw-docker--service commands --- .travis.yml | 1 + Vagrantfile | 1 + test/ufw-docker-service.test.sh | 103 ++++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100755 test/ufw-docker-service.test.sh diff --git a/.travis.yml b/.travis.yml index 9cf0d0a..cecec77 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,7 @@ os: linux dist: trusty script: - bash test/ufw-docker.test.sh +- bash test/ufw-docker-service.test.sh notifications: slack: secure: pbbwN/dxrXXvQnJM5YhLt3A7t7ptvm5G3yQOimqBJVlLY7dJdPcUy6agntyLQ5cf+CHKVgMreu5m7qdTlSUeypNSi5+gbfNQD70l5TPG/ClqN/GnaNlrv4Y9ugL7kUWBqtMZSCwHHCy3Omv+oYjBixonJBfDMr0mn6ShkHRpgmjjUtByHhGy5gyNlKjoxB+04AnLkuIiz9mRUIkgGeeIcIkS8pE4E69Mh/K78h0oCZbQF1H4Eu22nOCdQhWH5StT0G+/pDqHGP4J8mDo3NVNMyySFRY0lSwUj2OUnX+VVK9RWUicaozCgob4Oi3Pf+5bNcxTdo2ntI/e0fEcpIqiSHOy/iLBrQMGmZY7aoVNG7IWQwM2Zt6wXORcYl6l2XMOVuFx+h9PQd+nol9Eh9JxGsQjrfdQ8rNK8DkdNat0axpex3w3PWpbFRtQJ3A21ixqINsKCZC0y5vO0LF0ttsJEf9QEJrYRlA8VOw79NnCE3PimACnb0UU2cy91HmLcR2OvXqNiS0TZWS0kEajpW9BuqszNPnMrpLi9t7kHTSFjGx1Nb6XXUBG2lmoiXVNqutq+0zCEa8otObjZ0igQ6Kb2joJfbwSSWXNzDtp+jRmxQacqmXwvByz2BI37xnCs4KP0VYM37r0BmVxpBQlyFreoB7PRyezYbQSkaq2bahMLjA= diff --git a/Vagrantfile b/Vagrantfile index 49c5608..5c6b195 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -57,6 +57,7 @@ Vagrant.configure('2') do |config| master.vm.provision "unit-testing", type: 'shell', inline: <<-SHELL /vagrant/test/ufw-docker.test.sh + /vagrant/test/ufw-docker-service.test.sh SHELL master.vm.provision "docker-registry", type: 'docker' do |d| diff --git a/test/ufw-docker-service.test.sh b/test/ufw-docker-service.test.sh new file mode 100755 index 0000000..cdfe5bc --- /dev/null +++ b/test/ufw-docker-service.test.sh @@ -0,0 +1,103 @@ +#!/usr/bin/env bash +set -euo pipefail + +working_dir="$(cd "$(dirname "$BASH_SOURCE")"; pwd -P)" +source "$working_dir"/bach/bach.sh + +@setup { + set -euo pipefail +} + +@setup-test { + @mocktrue ufw status + @mocktrue grep -Fq "Status: active" + + @ignore remove_blank_lines + @ignore echo + @ignore err + @ignore die + + DEFAULT_PROTO=tcp + GREP_REGEXP_INSTANCE_NAME="[-_.[:alnum:]]\\+" +} + +function load-ufw-docker-function() { + set -euo pipefail + + @load_function "$working_dir/../ufw-docker" "$1" +} + + +test-ufw-docker--service-not-parameters() { + load-ufw-docker-function ufw-docker--service + + ufw-docker--service +} +test-ufw-docker--service-not-parameters-assert() { + ufw-docker--help +} + + +test-ufw-docker--service-allow() { + load-ufw-docker-function ufw-docker--service + + ufw-docker--service allow +} +test-ufw-docker--service-allow-assert() { + @do-nothing + @fail +} + + +test-ufw-docker--service-allow-webapp() { + load-ufw-docker-function ufw-docker--service + + ufw-docker--service allow webapp +} +test-ufw-docker--service-allow-webapp-assert() { + #ufw-docker--service-allow webapp "" "" + @do-nothing + @fail +} + + +test-ufw-docker--service-allow-webapp-80tcp() { + load-ufw-docker-function ufw-docker--service + + ufw-docker--service allow webapp 80/tcp +} +test-ufw-docker--service-allow-webapp-80tcp-assert() { + ufw-docker--service-allow webapp 80/tcp +} + + +test-ufw-docker--service-delete-deny() { + load-ufw-docker-function ufw-docker--service + + ufw-docker--service delete deny +} +test-ufw-docker--service-delete-deny-assert() { + @do-nothing + @fail +} + + +test-ufw-docker--service-delete-allow-no-service() { + load-ufw-docker-function ufw-docker--service + + ufw-docker--service delete allow +} +test-ufw-docker--service-delete-allow-no-service-assert() { + @do-nothing + @fail +} + + +test-ufw-docker--service-delete-allow-webapp() { + load-ufw-docker-function ufw-docker--service + + ufw-docker--service delete allow webapp +} +test-ufw-docker--service-delete-allow-webapp-assert() { + ufw-docker--service-delete webapp +}