Commit bafd30eb085c797616737b5f41940bf62b87a261

Authored by Antonio Terceiro
1 parent d3660aa8

mailman_test: extract helper programs

They are going to be used when testing the mail relay
test/bin/create-list 0 → 100755
... ... @@ -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
... ...
test/bin/remove-list 0 → 100755
... ... @@ -0,0 +1,7 @@
  1 +#!/bin/sh
  2 +
  3 +set -eu
  4 +
  5 +listname="$1"
  6 +
  7 +sudo -u mailman /usr/lib/mailman/bin/rmlist -a "$listname" > /dev/null
... ...
test/bin/send-email 0 → 100755
... ... @@ -0,0 +1,8 @@
  1 +#!/bin/sh
  2 +
  3 +set -eu
  4 +
  5 +from="$1"
  6 +to="$2"
  7 +
  8 +date | mail -r "$from" -s test "$to"
... ...
test/bin/wait-for-file 0 → 100755
... ... @@ -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/bin/wait-for-messages 0 → 100755
... ... @@ -0,0 +1,13 @@
  1 +#!/bin/sh
  2 +
  3 +set -eu
  4 +
  5 +listname="$1"
  6 +
  7 +mbox=/var/lib/mailman/archives/private/$listname.mbox/$listname.mbox
  8 +if wait-for-file $mbox; then
  9 + sudo grep -i -c ^Message-ID: $mbox
  10 +else
  11 + echo 0
  12 +fi
  13 +
... ...
test/mailman_test.sh
... ... @@ -6,23 +6,16 @@ test_mailman_running() {
6 6  
7 7 test_mailman_delivery() {
8 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 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 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 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 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 3 run_on() {
4 4 local vm="$1"
5 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 9 . $(dirname $0)/ip_helper.sh
... ...