Add integration test check

This commit is contained in:
Yong Wen Chua 2020-12-16 15:09:55 +08:00
parent 677f798443
commit e73781948d
No known key found for this signature in database
GPG Key ID: 2D68945D154B53AD
3 changed files with 39 additions and 0 deletions

View File

@ -9,4 +9,9 @@ config_entries {
}
]
}
bootstrap {
kind = "service-defaults"
name = "s4"
protocol = "http"
}
}

View File

@ -31,3 +31,7 @@ load helpers
@test "terminating-gateway is used for the upstream connection" {
assert_envoy_metric_at_least 127.0.0.1:20000 "s4.default.primary.*cx_total" 1
}
@test "terminating-gateway adds the Host header for connection to s3" {
assert_expected_fortio_host_header "localhost:8382" localhost 5000
}

View File

@ -835,3 +835,33 @@ function assert_expected_fortio_name_pattern {
return 1
fi
}
function get_upstream_fortio_host_header {
local HOST=$1
local PORT=$2
local PREFIX=$3
local DEBUG_HEADER_VALUE="${4:-""}"
local extra_args
if [[ -n "${DEBUG_HEADER_VALUE}" ]]; then
extra_args="-H x-test-debug:${DEBUG_HEADER_VALUE}"
fi
run retry_default curl -v -s -f -H"Host: ${HOST}" $extra_args \
"localhost:${PORT}${PREFIX}/debug"
[ "$status" == 0 ]
echo "$output" | grep -E "^Host: "
}
function assert_expected_fortio_host_header {
local EXPECT_HOST=$1
local HOST=${2:-"localhost"}
local PORT=${3:-5000}
local URL_PREFIX=${4:-""}
local DEBUG_HEADER_VALUE="${5:-""}"
GOT=$(get_upstream_fortio_host_header ${HOST} ${PORT} "${URL_PREFIX}" "${DEBUG_HEADER_VALUE}")
if [ "$GOT" != "Host: ${EXPECT_HOST}" ]; then
echo "expected Host header: $EXPECT_HOST, actual Host header: $GOT" 1>&2
return 1
fi
}