Commit bafd30eb085c797616737b5f41940bf62b87a261
1 parent
d3660aa8
Exists in
master
and in
90 other branches
mailman_test: extract helper programs
They are going to be used when testing the mail relay
Showing
7 changed files
with
60 additions
and
27 deletions
Show diff stats
| @@ -0,0 +1,10 @@ | @@ -0,0 +1,10 @@ | ||
| 1 | +#!/bin/sh | ||
| 2 | + | ||
| 3 | +set -eu | ||
| 4 | + | ||
| 5 | +listname="$1" | ||
| 6 | +owner="$2" | ||
| 7 | + | ||
| 8 | +sudo -u mailman /usr/lib/mailman/bin/newlist --quiet "$listname" "$owner" PASSWORD | ||
| 9 | + | ||
| 10 | +echo "$owner" | sudo -u mailman /usr/lib/mailman/bin/add_members -r - --welcome-msg=n "$listname" > /dev/null |
| @@ -0,0 +1,17 @@ | @@ -0,0 +1,17 @@ | ||
| 1 | +#!/bin/sh | ||
| 2 | + | ||
| 3 | +set -eu | ||
| 4 | + | ||
| 5 | +file="$1" | ||
| 6 | + | ||
| 7 | +total=0 | ||
| 8 | +while [ "$total" -lt 10 ]; do | ||
| 9 | + if sudo test -f "$file"; then | ||
| 10 | + exit 0 | ||
| 11 | + fi | ||
| 12 | + sleep 1 | ||
| 13 | + total=$(($total + 1)) | ||
| 14 | +done | ||
| 15 | +echo "E: $file not found! Other files in the same directory:" >&2 | ||
| 16 | +sudo ls -1d $(dirname $file)/* >&2 | ||
| 17 | +exit 1 |
test/mailman_test.sh
| @@ -6,23 +6,16 @@ test_mailman_running() { | @@ -6,23 +6,16 @@ test_mailman_running() { | ||
| 6 | 6 | ||
| 7 | test_mailman_delivery() { | 7 | test_mailman_delivery() { |
| 8 | # create list | 8 | # create list |
| 9 | - run_on integration sudo -u mailman /usr/lib/mailman/bin/newlist --quiet foobar foobar@example.com foobar | ||
| 10 | - # subscribe us | ||
| 11 | - echo 'foobar@example.com' | run_on integration sudo -u mailman /usr/lib/mailman/bin/add_members -r - --welcome-msg=n foobar > /dev/null | 9 | + run_on integration create-list mylist user@example.com |
| 12 | 10 | ||
| 13 | # send message | 11 | # send message |
| 14 | - date | run_on integration mail -r foobar@example.com -s test foobar@listas.softwarepublico.dev | 12 | + run_on integration send-email user@example.com mylist@listas.softwarepublico.dev |
| 15 | 13 | ||
| 16 | # wait for message to arrive at the list mailbox | 14 | # wait for message to arrive at the list mailbox |
| 17 | - mbox=/var/lib/mailman/archives/private/foobar.mbox/foobar.mbox | ||
| 18 | - if wait_for integration $mbox; then | ||
| 19 | - messages=$(run_on integration sudo grep -i -c ^Message-ID: $mbox) | ||
| 20 | - else | ||
| 21 | - messages=0 | ||
| 22 | - fi | 15 | + messages=$(run_on integration wait-for-messages mylist) |
| 23 | 16 | ||
| 24 | # remove list | 17 | # remove list |
| 25 | - run_on integration sudo -u mailman /usr/lib/mailman/bin/rmlist -a foobar > /dev/null | 18 | + run_on integration remove-list mylist |
| 26 | 19 | ||
| 27 | assertEquals 'Message arrives at mailbox' "1" "$messages" | 20 | assertEquals 'Message arrives at mailbox' "1" "$messages" |
| 28 | } | 21 | } |
test/test_helper.sh
| @@ -3,22 +3,7 @@ export PATH="$(dirname $0)/bin:$PATH" | @@ -3,22 +3,7 @@ export PATH="$(dirname $0)/bin:$PATH" | ||
| 3 | run_on() { | 3 | run_on() { |
| 4 | local vm="$1" | 4 | local vm="$1" |
| 5 | shift | 5 | shift |
| 6 | - ssh -F .ssh_config "$vm" -- "$@" | ||
| 7 | -} | ||
| 8 | - | ||
| 9 | -# waits until a file exists | ||
| 10 | -wait_for() { | ||
| 11 | - local machine="$1" | ||
| 12 | - local file="$2" | ||
| 13 | - local total=0 | ||
| 14 | - while [ "$total" -lt 10 ]; do | ||
| 15 | - if run_on "$machine" sudo test -f "$file"; then | ||
| 16 | - return 0 | ||
| 17 | - fi | ||
| 18 | - sleep 1 | ||
| 19 | - total=$(($total + 1)) | ||
| 20 | - done | ||
| 21 | - return 1 | 6 | + ssh -F .ssh_config "$vm" -- 'export PATH=/vagrant/test/bin:$PATH;' "$@" |
| 22 | } | 7 | } |
| 23 | 8 | ||
| 24 | . $(dirname $0)/ip_helper.sh | 9 | . $(dirname $0)/ip_helper.sh |