From 1c6dd31de7b38ede085e869c2390bea050fa7f5c Mon Sep 17 00:00:00 2001 From: Chai Feng Date: Sat, 19 Oct 2019 12:20:05 +0200 Subject: [PATCH] Add tests for ufw-docker--instance-name --- test/ufw-docker.test.sh | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/ufw-docker.test.sh b/test/ufw-docker.test.sh index e82e7c4..4633ecd 100755 --- a/test/ufw-docker.test.sh +++ b/test/ufw-docker.test.sh @@ -17,6 +17,7 @@ source "$working_dir"/bach/bach.sh @ignore err DEFAULT_PROTO=tcp + GREP_REGEXP_INSTANCE_NAME="[-_.[:alnum:]]\\+" } function ufw-docker() { @@ -350,3 +351,32 @@ test-ufw-docker--add-rule-modify-an-existing-rule-without-port-assert() { ufw route allow proto tcp from any to 172.18.0.4 comment "allow webapp" } + + +test-ufw-docker--instance-name-found-a-name() { + @mock docker inspect --format="{{.Name}}" foo + @mock sed -e 's,^/,,' + @mockfalse grep "^$GREP_REGEXP_INSTANCE_NAME\$" + + @mock echo -n foo + + load-ufw-docker-function ufw-docker--instance-name + ufw-docker--instance-name foo +} +test-ufw-docker--instance-name-found-a-name-assert() { + docker inspect --format="{{.Name}}" foo + echo -n foo +} + + +test-ufw-docker--instance-name-found-an-id() { + @mock docker inspect --format="{{.Name}}" fooid + @mock sed -e 's,^/,,' + @mockfalse grep "^$GREP_REGEXP_INSTANCE_NAME\$" + + load-ufw-docker-function ufw-docker--instance-name + ufw-docker--instance-name fooid +} +test-ufw-docker--instance-name-found-an-id-assert() { + docker inspect --format="{{.Name}}" fooid +}