<commit_before>#!/usr/bin/env bash
set -e

function usage() {
  echo "usage: $1 IMAGE"
  echo " e.g.: $1 praekeltfoundation/freeswitch"
}

image="$1"
shift || { usage "$0" >&2; exit 1; }

# Set a trap on errors to make it clear when tests have failed
trap '{ set +x; echo; echo FAILED; echo; } >&2' ERR

# macOS-compatible timeout function: http://stackoverflow.com/a/35512328
function timeout() { perl -e 'alarm shift; exec @ARGV' "$@"; }

function wait_for_log_line() {
  local log_pattern="$1"; shift
  timeout "${LOG_TIMEOUT:-20}" grep -m 1 -E "$log_pattern" <(docker logs -f freeswitch 2>&1)
}

function module_exists {
  local module="$1"; shift
  [ $(docker exec freeswitch fs_cli -x "module_exists $module") = 'true' ]
}

set -x

docker run -d --name freeswitch "$image"
# Set a trap to stop the container when we exit
trap "{ set +x; docker stop freeswitch; docker rm -f freeswitch; }" EXIT

wait_for_log_line 'FreeSWITCH Started'

# Check our modules are configured correctly
! module_exists mod_logfile
module_exists mod_h26x
module_exists mod_flite
module_exists mod_shout

set +x
echo
echo "PASSED"<commit_msg>Test a few more things<commit_after>#!/usr/bin/env bash
set -e

function usage() {
  echo "usage: $1 IMAGE"
  echo " e.g.: $1 praekeltfoundation/freeswitch"
}

image="$1"
shift || { usage "$0" >&2; exit 1; }

# Set a trap on errors to make it clear when tests have failed
trap '{ set +x; echo; echo FAILED; echo; } >&2' ERR

# macOS-compatible timeout function: http://stackoverflow.com/a/35512328
function timeout() { perl -e 'alarm shift; exec @ARGV' "$@"; }

function wait_for_log_line() {
  local log_pattern="$1"; shift
  timeout "${LOG_TIMEOUT:-20}" grep -m 1 -E "$log_pattern" <(docker logs -f freeswitch 2>&1)
}

function fs_cli_command() {
  docker exec freeswitch fs_cli -x "$*"
}

function module_exists {
  local module="$1"; shift
  [ $(fs_cli_command module_exists "$module") = 'true' ]
}

set -x

docker run -d --name freeswitch "$image"
# Set a trap to stop the container when we exit
trap "{ set +x; docker stop freeswitch; docker rm -f freeswitch; }" EXIT

wait_for_log_line 'FreeSWITCH Started'

# Check console colorize is disabled
fs_cli_command console colorize | fgrep '+OK console color disabled'

# Check our modules are configured correctly
! module_exists mod_logfile
module_exists mod_h26x
module_exists mod_flite
module_exists mod_shout

# No Sofia profiles (no default ones)
fs_cli_command sofia profile internal gwlist | fgrep '-ERR no reply'
fs_cli_command sofia profile external gwlist | fgrep '-ERR no reply'

set +x
echo
echo "PASSED"
{'fraction_non_alphanumeric': 0.12037037037037036, 'fraction_numerical': 0.018518518518518517, 'mean_word_length': 4.470464135021097, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '26811', 'n_tokens_mistral': 952, 'n_tokens_neox': 912, 'n_words': 315}