mirror of
https://github.com/chaifeng/ufw-docker.git
synced 2025-05-12 06:08:32 +02:00
Add tests for ufw-docker--service-allow, failed scenarios
This commit is contained in:
parent
113c4b0797
commit
3ec94e453e
1 changed files with 44 additions and 1 deletions
|
@ -15,12 +15,15 @@ source "$working_dir"/bach/bach.sh
|
||||||
@ignore remove_blank_lines
|
@ignore remove_blank_lines
|
||||||
@ignore echo
|
@ignore echo
|
||||||
@ignore err
|
@ignore err
|
||||||
@ignore die
|
|
||||||
|
|
||||||
DEFAULT_PROTO=tcp
|
DEFAULT_PROTO=tcp
|
||||||
GREP_REGEXP_INSTANCE_NAME="[-_.[:alnum:]]\\+"
|
GREP_REGEXP_INSTANCE_NAME="[-_.[:alnum:]]\\+"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function die() {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
function load-ufw-docker-function() {
|
function load-ufw-docker-function() {
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
|
@ -119,3 +122,43 @@ test-ufw-docker--get-service-name() {
|
||||||
test-ufw-docker--get-service-name-assert() {
|
test-ufw-docker--get-service-name-assert() {
|
||||||
docker service inspect database --format "{{.Spec.Name}}"
|
docker service inspect database --format "{{.Spec.Name}}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
test-ufw-docker--service-allow-invalid-port-syntax() {
|
||||||
|
@mockfalse grep -E '^[0-9]+(/(tcp|udp))?$'
|
||||||
|
|
||||||
|
load-ufw-docker-function ufw-docker--service-allow
|
||||||
|
ufw-docker--service-allow webapp invalid-port
|
||||||
|
}
|
||||||
|
test-ufw-docker--service-allow-invalid-port-syntax-assert() {
|
||||||
|
@do-nothing
|
||||||
|
@fail
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
test-ufw-docker--service-allow-an-non-existed-service() {
|
||||||
|
@mocktrue grep -E '^[0-9]+(/(tcp|udp))?$'
|
||||||
|
@mock ufw-docker--get-service-id web404 === @stdout ""
|
||||||
|
|
||||||
|
load-ufw-docker-function ufw-docker--service-allow
|
||||||
|
ufw-docker--service-allow web404 80/tcp
|
||||||
|
}
|
||||||
|
test-ufw-docker--service-allow-an-non-existed-service-assert() {
|
||||||
|
@do-nothing
|
||||||
|
@fail
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
test-ufw-docker--service-allow-a-service-without-ports-published() {
|
||||||
|
@mocktrue grep -E '^[0-9]+(/(tcp|udp))?$'
|
||||||
|
@mock ufw-docker--get-service-id private-web === @stdout ""
|
||||||
|
@mock docker service inspect private-web \
|
||||||
|
--format '{{range .Endpoint.Spec.Ports}}{{.PublishedPort}} {{.TargetPort}}/{{.Protocol}}{{"\n"}}{{end}}' === @stdout ""
|
||||||
|
|
||||||
|
load-ufw-docker-function ufw-docker--service-allow
|
||||||
|
ufw-docker--service-allow private-web 80/tcp
|
||||||
|
}
|
||||||
|
test-ufw-docker--service-allow-a-service-without-ports-published-assert() {
|
||||||
|
@do-nothing
|
||||||
|
@fail
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue