From bafd30eb085c797616737b5f41940bf62b87a261 Mon Sep 17 00:00:00 2001 From: Antonio Terceiro Date: Thu, 19 Feb 2015 17:21:29 -0200 Subject: [PATCH] mailman_test: extract helper programs --- test/bin/create-list | 10 ++++++++++ test/bin/remove-list | 7 +++++++ test/bin/send-email | 8 ++++++++ test/bin/wait-for-file | 17 +++++++++++++++++ test/bin/wait-for-messages | 13 +++++++++++++ test/mailman_test.sh | 15 ++++----------- test/test_helper.sh | 17 +---------------- 7 files changed, 60 insertions(+), 27 deletions(-) create mode 100755 test/bin/create-list create mode 100755 test/bin/remove-list create mode 100755 test/bin/send-email create mode 100755 test/bin/wait-for-file create mode 100755 test/bin/wait-for-messages diff --git a/test/bin/create-list b/test/bin/create-list new file mode 100755 index 0000000..42c7d3e --- /dev/null +++ b/test/bin/create-list @@ -0,0 +1,10 @@ +#!/bin/sh + +set -eu + +listname="$1" +owner="$2" + +sudo -u mailman /usr/lib/mailman/bin/newlist --quiet "$listname" "$owner" PASSWORD + +echo "$owner" | sudo -u mailman /usr/lib/mailman/bin/add_members -r - --welcome-msg=n "$listname" > /dev/null diff --git a/test/bin/remove-list b/test/bin/remove-list new file mode 100755 index 0000000..a668a8c --- /dev/null +++ b/test/bin/remove-list @@ -0,0 +1,7 @@ +#!/bin/sh + +set -eu + +listname="$1" + +sudo -u mailman /usr/lib/mailman/bin/rmlist -a "$listname" > /dev/null diff --git a/test/bin/send-email b/test/bin/send-email new file mode 100755 index 0000000..1786ac0 --- /dev/null +++ b/test/bin/send-email @@ -0,0 +1,8 @@ +#!/bin/sh + +set -eu + +from="$1" +to="$2" + +date | mail -r "$from" -s test "$to" diff --git a/test/bin/wait-for-file b/test/bin/wait-for-file new file mode 100755 index 0000000..b4ab450 --- /dev/null +++ b/test/bin/wait-for-file @@ -0,0 +1,17 @@ +#!/bin/sh + +set -eu + +file="$1" + +total=0 +while [ "$total" -lt 10 ]; do + if sudo test -f "$file"; then + exit 0 + fi + sleep 1 + total=$(($total + 1)) +done +echo "E: $file not found! Other files in the same directory:" >&2 +sudo ls -1d $(dirname $file)/* >&2 +exit 1 diff --git a/test/bin/wait-for-messages b/test/bin/wait-for-messages new file mode 100755 index 0000000..f30ca96 --- /dev/null +++ b/test/bin/wait-for-messages @@ -0,0 +1,13 @@ +#!/bin/sh + +set -eu + +listname="$1" + +mbox=/var/lib/mailman/archives/private/$listname.mbox/$listname.mbox +if wait-for-file $mbox; then + sudo grep -i -c ^Message-ID: $mbox +else + echo 0 +fi + diff --git a/test/mailman_test.sh b/test/mailman_test.sh index 4712779..15f3597 100644 --- a/test/mailman_test.sh +++ b/test/mailman_test.sh @@ -6,23 +6,16 @@ test_mailman_running() { test_mailman_delivery() { # create list - run_on integration sudo -u mailman /usr/lib/mailman/bin/newlist --quiet foobar foobar@example.com foobar - # subscribe us - echo 'foobar@example.com' | run_on integration sudo -u mailman /usr/lib/mailman/bin/add_members -r - --welcome-msg=n foobar > /dev/null + run_on integration create-list mylist user@example.com # send message - date | run_on integration mail -r foobar@example.com -s test foobar@listas.softwarepublico.dev + run_on integration send-email user@example.com mylist@listas.softwarepublico.dev # wait for message to arrive at the list mailbox - mbox=/var/lib/mailman/archives/private/foobar.mbox/foobar.mbox - if wait_for integration $mbox; then - messages=$(run_on integration sudo grep -i -c ^Message-ID: $mbox) - else - messages=0 - fi + messages=$(run_on integration wait-for-messages mylist) # remove list - run_on integration sudo -u mailman /usr/lib/mailman/bin/rmlist -a foobar > /dev/null + run_on integration remove-list mylist assertEquals 'Message arrives at mailbox' "1" "$messages" } diff --git a/test/test_helper.sh b/test/test_helper.sh index efae52b..f7ec965 100644 --- a/test/test_helper.sh +++ b/test/test_helper.sh @@ -3,22 +3,7 @@ export PATH="$(dirname $0)/bin:$PATH" run_on() { local vm="$1" shift - ssh -F .ssh_config "$vm" -- "$@" -} - -# waits until a file exists -wait_for() { - local machine="$1" - local file="$2" - local total=0 - while [ "$total" -lt 10 ]; do - if run_on "$machine" sudo test -f "$file"; then - return 0 - fi - sleep 1 - total=$(($total + 1)) - done - return 1 + ssh -F .ssh_config "$vm" -- 'export PATH=/vagrant/test/bin:$PATH;' "$@" } . $(dirname $0)/ip_helper.sh -- libgit2 0.21.2