summaryrefslogtreecommitdiff
path: root/tests/setup_sshd_test
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2022-05-12 12:01:36 +0200
committerNatanael Copa <ncopa@alpinelinux.org>2022-05-12 12:01:36 +0200
commit14479d66c893f72a6e8313cdca1b3269b2418bc3 (patch)
tree9a1fa4319a8ccc73005355ba8bb25afc8e39b148 /tests/setup_sshd_test
parent654cbd2971de0d3e18b7610d3e7b3bd025348d5b (diff)
downloadalpine-conf-14479d66c893f72a6e8313cdca1b3269b2418bc3.zip
tests: refactor to de-duplicate code
Have a shared test_env.sh to de-duplicate code. Add a common test_usage, where we test that: - option -h prints to stdout and exit with success - invalid option prints usage to stderr and exit with error Use a common init_tests and a common atf_init_test_cases Move documenation links to README.md
Diffstat (limited to 'tests/setup_sshd_test')
-rwxr-xr-xtests/setup_sshd_test35
1 files changed, 8 insertions, 27 deletions
diff --git a/tests/setup_sshd_test b/tests/setup_sshd_test
index c8e9dc7..b47f05e 100755
--- a/tests/setup_sshd_test
+++ b/tests/setup_sshd_test
@@ -1,33 +1,17 @@
#!/usr/bin/env atf-sh
+. $(atf_get_srcdir)/test_env.sh
+init_tests \
+ setup_sshd_usage \
+ setup_sshd_empty \
+ setup_sshd_dropbear \
+ setup_sshd_openssh \
+ setup_sshd_interactive
-init_env() {
- PATH=$(atf_get_srcdir)/..:$PATH
- export ROOT=$PWD LIBDIR=$(atf_get_srcdir)/.. MOCK=echo
-}
-
-# docs:
-# - https://github.com/jmmv/kyua/wiki/Quickstart-atf-sh-test
-# - https://manned.org/atf-sh-api
-
-atf_init_test_cases() {
- atf_add_test_case setup_sshd_usage
- atf_add_test_case setup_sshd_empty
- atf_add_test_case setup_sshd_dropbear
- atf_add_test_case setup_sshd_openssh
- atf_add_test_case setup_sshd_interactive
-}
-
-atf_test_case setup_sshd_usage
setup_sshd_usage_body() {
- init_env
- atf_check -s exit:0 \
- -o match:'^usage:' \
- -e empty \
- setup-sshd -h
+ test_usage setup-sshd
}
-atf_test_case setup_sshd_empty
setup_sshd_empty_body() {
init_env
atf_check -s exit:0 \
@@ -36,7 +20,6 @@ setup_sshd_empty_body() {
setup-sshd none
}
-atf_test_case setup_sshd_dropbear
setup_sshd_dropbear_body() {
init_env
atf_check -s exit:0 \
@@ -47,7 +30,6 @@ setup_sshd_dropbear_body() {
setup-sshd dropbear
}
-atf_test_case setup_sshd_openssh
setup_sshd_openssh_body() {
init_env
atf_check -s exit:0 \
@@ -59,7 +41,6 @@ setup_sshd_openssh_body() {
grep '^wget .*https://example.com/user.keys$' root/.ssh/authorized_keys || atf_fail "failed to wget ssh key"
}
-atf_test_case setup_sshd_interactive
setup_sshd_interactive_body() {
init_env
mkdir -p etc/ssh