HAPROXY_CFG_FILE="${BATS_FILE_TMPDIR}/haproxy/haproxy-test.cfg" function generate_haproxy_server_list() { local num_instances=${1} shift local ports=("$@") for ((i=0;i<${num_instances};i++)) do local port=${ports[$i]} echo " server zot${i} 127.0.0.1:${port}" done } # stops all haproxy instances started by the test function haproxy_stop_all() { pkill haproxy } # starts one haproxy instance with the given config file # expects the haproxy config to specify daemon mode function haproxy_start() { local haproxy_cfg_file=${1} # Check the config file haproxy -f ${haproxy_cfg_file} -c >&3 # Start haproxy haproxy -f ${haproxy_cfg_file} } # generates HAproxy config for use in the test function generate_haproxy_config() { local haproxy_cfg_file="${1}" shift local haproxy_root_dir="$(dirname ${haproxy_cfg_file})" # can be either http or https local protocol="${1}" shift local haproxy_port="${1}" shift local zot_ports=("$@") mkdir -p ${haproxy_root_dir} local haproxy_mode='http' if [ "$protocol" == 'https' ]; then haproxy_mode='tcp' fi cat > ${haproxy_cfg_file}<> ${haproxy_cfg_file} cat ${haproxy_cfg_file} >&3 }