git » chasquid » commit 6f04802

test: Readability cleanup

author Alberto Bertogli
2016-10-17 06:41:12 UTC
committer Alberto Bertogli
2016-10-21 21:20:49 UTC
parent f38ae4716460cd70e84db7dca906eb6bf40d526f

test: Readability cleanup

This patch makes a few small changes to the tests for readability, such
as changing the arguments to the add_user function.

test/README +4 -2
test/t-01-simple_local/run.sh +6 -10
test/t-02-exim/run.sh +3 -3
test/t-04-aliases/run.sh +1 -1
test/t-05-null_address/run.sh +1 -1
test/t-06-idna/run.sh +4 -4
test/t-07-smtputf8/run.sh +2 -2
test/t-09-loop/run.sh +1 -1
test/t-10-hooks/run.sh +6 -9
test/util/lib.sh +13 -7

diff --git a/test/README b/test/README
index 19f94f3..f091f74 100644
--- a/test/README
+++ b/test/README
@@ -6,7 +6,7 @@ They're not expected to be portable, as that gets impractical very quickly.
 They also have some dependencies, listed below.
 
 
-=== Dependencies
+## Dependencies
 
 The tests depend on the following things being installed on the system (listed
 as Debian package, for consistency):
@@ -15,9 +15,11 @@ as Debian package, for consistency):
  - msmtp
  - util-linux (for /usr/bin/setsid)
 
-For t-exim (Exim interaction tests):
+For t-02-exim (Exim interaction tests):
  - gettext-base (for /usr/bin/envsubst)
  - The exim binary available somewhere, but it doesn't have to be installed.
    There's a script "get-exim4-debian.sh" to get it from the archives.
 
+For some tests, python >= 3.5 is required; they will be skipped if it's not
+available.
 
diff --git a/test/t-01-simple_local/run.sh b/test/t-01-simple_local/run.sh
index 05ea77a..116b972 100755
--- a/test/t-01-simple_local/run.sh
+++ b/test/t-01-simple_local/run.sh
@@ -6,8 +6,8 @@ set -e
 init
 
 generate_certs_for testserver
-add_user testserver user secretpassword
-add_user testserver someone secretpassword
+add_user user@testserver secretpassword
+add_user someone@testserver secretpassword
 
 mkdir -p .logs
 chasquid -v=2 --log_dir=.logs --config_dir=config &
@@ -22,23 +22,19 @@ mail_diff content .mail/someone@testserver
 # At least for now, we allow AUTH over the SMTP port to avoid unnecessary
 # complexity, so we expect it to work.
 if ! run_msmtp -a smtpport someone@testserver < content 2> /dev/null; then
-	echo "ERROR: failed auth on the SMTP port"
-	exit 1
+	fail "failed auth on the SMTP port"
 fi
 
 if run_msmtp nobody@testserver < content 2> /dev/null; then
-	echo "ERROR: successfuly sent an email to a non-existent user"
-	exit 1
+	fail "successfuly sent an email to a non-existent user"
 fi
 
 if run_msmtp -a baduser someone@testserver < content 2> /dev/null; then
-	echo "ERROR: successfully sent an email with a bad password"
-	exit 1
+	fail "successfully sent an email with a bad password"
 fi
 
 if run_msmtp -a badpasswd someone@testserver < content 2> /dev/null; then
-	echo "ERROR: successfully sent an email with a bad password"
-	exit 1
+	fail "successfully sent an email with a bad password"
 fi
 
 success
diff --git a/test/t-02-exim/run.sh b/test/t-02-exim/run.sh
index fa12e8c..e8766e7 100755
--- a/test/t-02-exim/run.sh
+++ b/test/t-02-exim/run.sh
@@ -28,7 +28,7 @@ set -e
 init
 
 if ! .exim4/exim4 --version > /dev/null; then
-	skip "(exim4 binary at .exim4/exim4 is not functional)"
+	skip "exim4 binary at .exim4/exim4 is not functional"
 	exit 0
 fi
 
@@ -38,8 +38,8 @@ mkdir -p .exim4
 EXIMDIR="$PWD/.exim4" envsubst < config/exim4.in > .exim4/config
 
 generate_certs_for srv-chasquid
-add_user srv-chasquid user secretpassword
-add_user srv-chasquid someone secretpassword
+add_user user@srv-chasquid secretpassword
+add_user someone@srv-chasquid secretpassword
 
 # Launch chasquid at port 1025 (in config).
 # Use outgoing port 2025 which is where exim will be at.
diff --git a/test/t-04-aliases/run.sh b/test/t-04-aliases/run.sh
index 15e512f..c497985 100755
--- a/test/t-04-aliases/run.sh
+++ b/test/t-04-aliases/run.sh
@@ -6,7 +6,7 @@ set -e
 init
 
 generate_certs_for testserver
-add_user testserver user secretpassword
+add_user user@testserver secretpassword
 
 mkdir -p .logs
 chasquid -v=2 --log_dir=.logs --config_dir=config &
diff --git a/test/t-05-null_address/run.sh b/test/t-05-null_address/run.sh
index 23c28ca..33681e9 100755
--- a/test/t-05-null_address/run.sh
+++ b/test/t-05-null_address/run.sh
@@ -6,7 +6,7 @@ set -e
 init
 
 generate_certs_for testserver
-add_user testserver user secretpassword
+add_user user@testserver secretpassword
 
 mkdir -p .logs
 chasquid -v=2 --log_dir=.logs --config_dir=config &
diff --git a/test/t-06-idna/run.sh b/test/t-06-idna/run.sh
index 2c04c2e..fa1a0df 100755
--- a/test/t-06-idna/run.sh
+++ b/test/t-06-idna/run.sh
@@ -14,12 +14,12 @@ skip_if_python_is_too_old
 # B - listens on :2015, hosts srv-ü
 
 CONFDIR=A generate_certs_for srv-ñ
-CONFDIR=A add_user srv-ñ ñangapirí antaño
-CONFDIR=A add_user nadaA nadaA nadaA
+CONFDIR=A add_user ñangapirí@srv-ñ antaño
+CONFDIR=A add_user nadaA@nadaA nadaA
 
 CONFDIR=B generate_certs_for srv-ü
-CONFDIR=B add_user srv-ü pingüino velóz
-CONFDIR=B add_user nadaB nadaB nadaB
+CONFDIR=B add_user pingüino@srv-ü velóz
+CONFDIR=B add_user nadaB@nadaB nadaB
 
 mkdir -p .logs-A .logs-B
 
diff --git a/test/t-07-smtputf8/run.sh b/test/t-07-smtputf8/run.sh
index d79ca30..c7b7281 100755
--- a/test/t-07-smtputf8/run.sh
+++ b/test/t-07-smtputf8/run.sh
@@ -15,10 +15,10 @@ generate_certs_for ñoños
 
 # Intentionally have a config directory for upper case; this should be
 # normalized to lowercase internally (and match the cert accordingly).
-add_user ñoñOS ñangapirí antaño
+add_user ñangapirí@ñoñOS antaño
 
 # Python doesn't support UTF8 for auth, use an ascii user and domain.
-add_user nada nada nada
+add_user nada@nada nada
 
 mkdir -p .logs
 chasquid -v=2 --log_dir=.logs --config_dir=config &
diff --git a/test/t-09-loop/run.sh b/test/t-09-loop/run.sh
index 04c218e..663c3de 100755
--- a/test/t-09-loop/run.sh
+++ b/test/t-09-loop/run.sh
@@ -15,7 +15,7 @@ rm -rf .data-A .data-B .mail
 #   userA -> aliasB -> aliasA -> aliasB -> ...
 
 CONFDIR=A generate_certs_for srv-A
-CONFDIR=A add_user srv-A userA userA
+CONFDIR=A add_user userA@srv-A userA
 
 CONFDIR=B generate_certs_for srv-B
 
diff --git a/test/t-10-hooks/run.sh b/test/t-10-hooks/run.sh
index 9624ee0..564a4b6 100755
--- a/test/t-10-hooks/run.sh
+++ b/test/t-10-hooks/run.sh
@@ -6,9 +6,9 @@ set -e
 init
 
 generate_certs_for testserver
-add_user testserver user secretpassword
-add_user testserver someone secretpassword
-add_user testserver blockme secretpassword
+add_user user@testserver secretpassword
+add_user someone@testserver secretpassword
+add_user blockme@testserver secretpassword
 
 mkdir -p .logs
 chasquid -v=2 --log_dir=.logs --config_dir=config &
@@ -23,14 +23,12 @@ wait_for_file .mail/someone@testserver
 mail_diff content .mail/someone@testserver
 
 if ! grep -q "X-Post-Data: success" .mail/someone@testserver; then
-	echo "missing X-Post-Data header"
-	exit 1
+	fail "missing X-Post-Data header"
 fi
 
 function check() {
 	if ! grep -q "$1" .data/post-data.out; then
-		echo missing: $1
-		exit 1
+		fail "missing: $1"
 	fi
 }
 
@@ -48,8 +46,7 @@ check "REMOTE_ADDR="
 
 # Check that a failure in the script results in failing delivery.
 if run_msmtp blockme@testserver < content 2>/dev/null; then
-	echo "ERROR: hook did not block email as expected"
-	exit 1
+	fail "ERROR: hook did not block email as expected"
 fi
 
 # Check that the bad hooks don't prevent delivery.
diff --git a/test/util/lib.sh b/test/util/lib.sh
index 53b47dc..44c40fd 100644
--- a/test/util/lib.sh
+++ b/test/util/lib.sh
@@ -40,11 +40,12 @@ function chasquid() {
 
 function add_user() {
 	CONFDIR="${CONFDIR:-config}"
-	mkdir -p "${CONFDIR}/domains/${1}/"
+	DOMAIN=$(echo $1 | cut -d @ -f 2)
+	mkdir -p "${CONFDIR}/domains/$DOMAIN/"
 	go run ${TBASE}/../../cmd/chasquid-util/chasquid-util.go \
 		-C "${CONFDIR}" \
-		user-add "$2@$1" \
-		--password "${3}" \
+		user-add "$1" \
+		--password "$2" \
 		>> .add_user_logs
 }
 
@@ -65,11 +66,17 @@ function mail_diff() {
 }
 
 function success() {
-	echo "SUCCESS"
+	echo success
 }
 
 function skip() {
-	echo "SKIPPED" $*
+	echo skipped: $*
+	exit 0
+}
+
+function fail() {
+	echo FAILED: $*
+	exit 1
 }
 
 # Wait until there's something listening on the given port.
@@ -103,8 +110,7 @@ function generate_certs_for() {
 function skip_if_python_is_too_old() {
 	# We need Python >= 3.5 to be able to use SMTPUTF8.
 	check='import sys; sys.exit(0 if sys.version_info >= (3, 5) else 1)'
-	if ! python3 -c "${check}"; then
+	if ! python3 -c "${check}" > /dev/null 2>&1; then
 		skip "python3 >= 3.5 not available"
-		exit 0
 	fi
 }