Skip to content

Commit

Permalink
Improve tests
Browse files Browse the repository at this point in the history
- show output of failed tests
- ensure Docker images are not pulled in tests
  • Loading branch information
tyranron committed Nov 23, 2022
1 parent ea14366 commit 5b598e2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,9 @@ test: test.docker
# Docker commands #
###################

docker-registries = $(strip $(if $(call eq,$(registries),),\
$(REGISTRIES),$(subst $(comma), ,$(registries))))
docker-tags = $(strip $(if $(call eq,$(tags),),\
$(TAGS),$(subst $(comma), ,$(tags))))
docker-registries = $(strip \
$(or $(subst $(comma), ,$(registries)),$(REGISTRIES)))
docker-tags = $(strip $(or $(subst $(comma), ,$(tags)),$(TAGS)))


# Build Docker image with the given tag.
Expand Down Expand Up @@ -173,6 +172,7 @@ endif
IMAGE=$(OWNER)/$(NAME):$(or $(tag),$(VERSION)) \
node_modules/.bin/bats \
--timing $(if $(call eq,$(CI),),--pretty,--formatter tap) \
--print-output-on-failure \
tests/main.bats


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"devDependencies": {
"bats": "^1.1"
"bats": "^1.8"
}
}
21 changes: 13 additions & 8 deletions tests/main.bats
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@


@test "pure-ftpd is installed" {
run docker run --rm --entrypoint sh $IMAGE -c 'which pure-ftpd'
run docker run --rm --pull never --entrypoint sh $IMAGE -c \
'which pure-ftpd'
[ "$status" -eq 0 ]
}

@test "pure-ftpd runs ok" {
run docker run --rm --entrypoint sh $IMAGE -c 'pure-ftpd --help'
run docker run --rm --pull never --entrypoint sh $IMAGE -c \
'pure-ftpd --help'
[ "$status" -eq 0 ]
}

Expand All @@ -17,7 +19,7 @@
[ ! "$output" = '' ]
expected="$output"

run docker run --rm --entrypoint sh $IMAGE -c \
run docker run --rm --pull never --entrypoint sh $IMAGE -c \
"pure-ftpd --help | head -1 | cut -d ' ' -f 2"
[ "$status" -eq 0 ]
[ ! "$output" = '' ]
Expand All @@ -28,25 +30,27 @@


@test "pure-pw is installed" {
run docker run --rm --entrypoint sh $IMAGE -c 'which pure-pw'
run docker run --rm --pull never --entrypoint sh $IMAGE -c \
'which pure-pw'
[ "$status" -eq 0 ]
}

@test "pure-pw runs ok" {
run docker run --rm --entrypoint sh $IMAGE -c 'pure-pw --help'
run docker run --rm --pull never --entrypoint sh $IMAGE -c \
'pure-pw --help'
[ "$status" -eq 0 ]
}


@test "PURE_PASSWDFILE is converted to PURE_DBFILE on container start" {
run docker run --rm \
run docker run --rm --pull never \
-v $(pwd)/tests/resources/pureftpd.passwd:/etc/pureftpd.passwd:ro \
$IMAGE test -f /etc/pureftpd.pdb
[ "$status" -eq 0 ]
}

@test "PURE_PASSWDFILE is converted to PURE_DBFILE from custom location" {
run docker run --rm \
run docker run --rm --pull never \
-e PURE_PASSWDFILE=/tmp/pureftpd.passwd \
-e PURE_DBFILE=/pureftpd.pdb \
-v $(pwd)/tests/resources/pureftpd.passwd:/tmp/pureftpd.passwd:ro \
Expand All @@ -56,6 +60,7 @@


@test "syslogd runs ok" {
run docker run --rm --entrypoint sh $IMAGE -c '/sbin/syslogd --help'
run docker run --rm --pull never --entrypoint sh $IMAGE -c \
'/sbin/syslogd --help'
[ "$status" -eq 0 ]
}

0 comments on commit 5b598e2

Please sign in to comment.