Commit bafd30eb085c797616737b5f41940bf62b87a261

Authored by Antonio Terceiro
1 parent d3660aa8
Exists in master and in 90 other branches 3.x, add_sisp_to_chef, add_super_archives_plugin, api_for_colab, automates_core_packing, backup, backup_not_prod, cdtc_configuration, changes_in_buttons_on_content_panel, colab_automated_login, colab_spb_plugin_recipe, colab_widgets_settings, design_validation, dev-lappis, dev_env_minimal, disable_email_dev, docs, fix_breadcrumbs_position, fix_categories_software_link, fix_edit_institution, fix_edit_software_with_another_license, fix_get_license_info, fix_gitlab_assets_permission, fix_list_style_inside_article, fix_list_style_on_folder_elements, fix_members_pagination, fix_merge_request_url, fix_models_translations, fix_no_license, fix_software_api, fix_software_block_migration, fix_software_communities_translations, fix_software_communities_unit_test, fix_style_create_institution_admin_panel, fix_superarchives_imports, fix_sym_links_noosfero, focus_search_field_theme, gov-user-refactoring, gov-user-refactoring-rails4, header_fix, institution_modal_on_rating, kalibro-conf-refactoring, kalibro-processor-package, lxc_settings, margin_fix, mezuro_cookbook, performance, prezento, r3, refactor_download_block, refactor_software_communities, refactor_software_for_sisp, register_page, release-process, release-process-v2, remove-unused-images, remove_backup_emails, remove_broken_theme, remove_secondary_email_from_user, remove_sisp_buttons, removing_super_archives_email, review_message, scope2method, signals_user_noosfero, sisp_catalog_header, sisp_colab_config, sisp_dev, sisp_dev_master, sisp_simple_version, software_as_organization, software_catalog_style_fix, software_communities_html_refactor, software_infos_api, spb_minimal_env, spb_to_rails4, spec_refactor, stable-4.1, stable-4.2, stable-4.x, stable-devel, support_docs, syslog, temp_soft_comm_refactoring, theme_header, theme_javascript_refactory, thread_dropdown, thread_page, update_search_by_categories, update_software_api, update_softwares_boxes

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 @@ @@ -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 @@ @@ -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 @@ @@ -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 @@ @@ -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 @@ @@ -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,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