From 14479d66c893f72a6e8313cdca1b3269b2418bc3 Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Thu, 12 May 2022 12:01:36 +0200 Subject: 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 --- tests/setup_sshd_test | 35 ++++++++--------------------------- 1 file changed, 8 insertions(+), 27 deletions(-) (limited to 'tests/setup_sshd_test') 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 -- cgit v1.2.3