|
2 | 2 | set -euo pipefail |
3 | 3 |
|
4 | 4 | # Wrapper script to build the E2E test Docker image and configure local settings. |
5 | | -# Usage: ./run-functional-tests-e2e.sh [KustoConnectionString] |
6 | | -# KustoConnectionString is built from CLUSTER and DATABASE env vars if set, |
7 | | -# otherwise falls back to the first positional parameter. |
| 5 | +# Usage: ./run-functional-tests-e2e.sh <Cluster> <Database> [Language] |
| 6 | +# |
| 7 | +# Cluster and Database can also be set via CLUSTER and DATABASE env vars. |
| 8 | +# Language selects which sample to test (must be a LANG_MAP key, e.g. |
| 9 | +# samples-csharp, samples-java, etc.). Can also be set via SAMPLE_LANG env var. |
| 10 | +# Defaults to samples-node. |
8 | 11 |
|
9 | 12 | SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
10 | 13 | REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" |
11 | 14 | cd "$REPO_ROOT" |
12 | 15 |
|
13 | | -# Build KustoConnectionString from CLUSTER/DATABASE env vars, or fall back to $1 |
14 | | -if [ -n "${CLUSTER:-}" ] && [ -n "${DATABASE:-}" ]; then |
15 | | - KUSTO_CONNECTION_STRING="Data Source=${CLUSTER};Database=${DATABASE};Fed=True" |
16 | | - echo "==> Using KustoConnectionString from CLUSTER and DATABASE env vars" |
17 | | -elif [ $# -ge 1 ]; then |
18 | | - KUSTO_CONNECTION_STRING="$1" |
19 | | - echo "==> Using KustoConnectionString from parameter" |
| 16 | +# Build KustoConnectionString from positional args or CLUSTER/DATABASE env vars. |
| 17 | +# Positional args take precedence over env vars. |
| 18 | +LANG_ARG="" |
| 19 | +if [ $# -ge 2 ]; then |
| 20 | + CLUSTER="$1" |
| 21 | + DATABASE="$2" |
| 22 | + LANG_ARG="${3:-}" |
| 23 | + echo "==> Using Cluster and Database from positional parameters" |
| 24 | +elif [ -n "${CLUSTER:-}" ] && [ -n "${DATABASE:-}" ]; then |
| 25 | + LANG_ARG="${1:-}" |
| 26 | + echo "==> Using Cluster and Database from env vars" |
20 | 27 | else |
21 | | - echo "Error: Either set CLUSTER and DATABASE env vars, or pass KustoConnectionString as \$1" |
22 | | - echo "Usage: $0 [KustoConnectionString]" |
23 | | - echo " CLUSTER - Kusto cluster URL (e.g. https://mycluster.kusto.windows.net)" |
24 | | - echo " DATABASE - Kusto database name" |
| 28 | + echo "Error: Provide Cluster and Database as positional args, or set CLUSTER and DATABASE env vars" |
| 29 | + echo "Usage: $0 <Cluster> <Database> [Language]" |
| 30 | + echo " Cluster - Kusto cluster URL (e.g. https://mycluster.kusto.windows.net)" |
| 31 | + echo " Database - Kusto database name" |
| 32 | + echo " Language - LANG_MAP key (e.g. samples-csharp, samples-java). Default: samples-node" |
25 | 33 | exit 1 |
26 | 34 | fi |
27 | 35 |
|
| 36 | +KUSTO_CONNECTION_STRING="Data Source=${CLUSTER};Database=${DATABASE};Fed=True" |
| 37 | + |
28 | 38 | # Source access token from az CLI if not already set |
29 | 39 | if [ -z "${ACCESS_TOKEN:-}" ]; then |
30 | 40 | echo "==> Fetching access token from az CLI..." |
|
33 | 43 |
|
34 | 44 | # Map sample directories to their FUNCTIONS_WORKER_RUNTIME values |
35 | 45 | declare -A LANG_MAP=( |
36 | | - ["samples-csharp"]="dotnet" |
| 46 | + ["samples-csharp"]="csharp" |
37 | 47 | ["samples-java"]="java" |
38 | 48 | ["samples-node"]="node" |
39 | 49 | ["samples-outofproc"]="dotnet-isolated" |
40 | 50 | ["samples-powershell"]="powershell" |
41 | 51 | ["samples-python"]="python" |
42 | 52 | ) |
43 | 53 |
|
| 54 | +FUNC_PORT=7071 |
| 55 | + |
| 56 | +# Resolve language: positional arg > SAMPLE_LANG env var > default (samples-node) |
| 57 | +if [ -n "$LANG_ARG" ]; then |
| 58 | + SAMPLE_LANG="$LANG_ARG" |
| 59 | +else |
| 60 | + SAMPLE_LANG="${SAMPLE_LANG:-samples-node}" |
| 61 | +fi |
| 62 | + |
| 63 | +# Validate SAMPLE_LANG against LANG_MAP |
| 64 | +if [ -z "${LANG_MAP[$SAMPLE_LANG]+_}" ]; then |
| 65 | + echo "Error: '${SAMPLE_LANG}' is not a valid language key." |
| 66 | + echo "Valid keys: ${!LANG_MAP[*]}" |
| 67 | + exit 1 |
| 68 | +fi |
| 69 | +echo "==> Running tests for language: ${SAMPLE_LANG} (runtime: ${LANG_MAP[$SAMPLE_LANG]})" |
| 70 | + |
| 71 | +runtime="${LANG_MAP[$SAMPLE_LANG]}" |
| 72 | + |
44 | 73 | echo "=== Step 1: Building Docker image ===" |
45 | 74 | "$SCRIPT_DIR/build-docker-image.sh" |
46 | 75 |
|
47 | | -echo "=== Step 2: Generating local.settings.json for each language sample ===" |
| 76 | +echo "=== Step 2: Generating local.settings.json for ${SAMPLE_LANG} ===" |
48 | 77 |
|
49 | 78 | CONN_STRING_WITH_TOKEN="${KUSTO_CONNECTION_STRING};AAD Federated Security=True;UserToken=${ACCESS_TOKEN}" |
50 | 79 |
|
51 | | -for sample_dir in "${!LANG_MAP[@]}"; do |
52 | | - runtime="${LANG_MAP[$sample_dir]}" |
53 | | - target_dir="samples/${sample_dir}" |
54 | | - target="${target_dir}/local.settings.json" |
55 | | - |
56 | | - if [ ! -d "$target_dir" ]; then |
57 | | - echo "Warning: ${target_dir} does not exist, skipping" |
58 | | - continue |
59 | | - fi |
60 | | - |
61 | | - echo "Creating ${target} with FUNCTIONS_WORKER_RUNTIME=${runtime}" |
62 | | - |
63 | | - # Use jq if available for safe JSON manipulation, otherwise fall back to sed |
64 | | - if command -v jq &>/dev/null; then |
65 | | - jq \ |
66 | | - --arg runtime "$runtime" \ |
67 | | - --arg connStr "$CONN_STRING_WITH_TOKEN" \ |
68 | | - '.Values.FUNCTIONS_WORKER_RUNTIME = $runtime | .Values.KustoConnectionString = $connStr' \ |
69 | | - local.settings.json.example > "${target}" |
70 | | - else |
71 | | - sed \ |
72 | | - -e "s/<lang>/${runtime}/" \ |
73 | | - -e "s|<KustoConnectionString>|${CONN_STRING_WITH_TOKEN//|/\\|}|" \ |
74 | | - local.settings.json.example > "${target}" |
75 | | - fi |
76 | | -done |
77 | | - |
78 | | -echo "=== Step 3: Running functional tests ===" |
| 80 | +target_dir="samples/${SAMPLE_LANG}" |
| 81 | +target="${target_dir}/local.settings.json" |
| 82 | + |
| 83 | +if [ ! -d "$target_dir" ]; then |
| 84 | + echo "Error: ${target_dir} does not exist" |
| 85 | + exit 1 |
| 86 | +fi |
| 87 | + |
| 88 | +rm -f "${target}" |
| 89 | +echo "Creating ${target} with FUNCTIONS_WORKER_RUNTIME=${runtime}" |
| 90 | + |
| 91 | +if command -v jq &>/dev/null; then |
| 92 | + jq \ |
| 93 | + --arg runtime "$runtime" \ |
| 94 | + --arg connStr "$CONN_STRING_WITH_TOKEN" \ |
| 95 | + '.Values.FUNCTIONS_WORKER_RUNTIME = $runtime | .Values.KustoConnectionString = $connStr' \ |
| 96 | + local.settings.json.example > "${target}" |
| 97 | +else |
| 98 | + sed \ |
| 99 | + -e "s/<lang>/${runtime}/" \ |
| 100 | + -e "s|<KustoConnectionString>|${CONN_STRING_WITH_TOKEN//|/\\|}|" \ |
| 101 | + local.settings.json.example > "${target}" |
| 102 | +fi |
| 103 | + |
| 104 | +if [ "$SAMPLE_LANG" = "samples-outofproc" ]; then |
| 105 | + echo "=== Step 3: Building ${SAMPLE_LANG} ===" |
| 106 | + dotnet publish "${target_dir}" -c Debug -o "${target_dir}/bin/Debug/net8.0/publish" |
| 107 | + cp "${target}" "${target_dir}/bin/Debug/net8.0/publish/local.settings.json" |
| 108 | +fi |
| 109 | + |
| 110 | +echo "=== Step 4: Running functional tests ===" |
79 | 111 | cd "$REPO_ROOT/functions-int-tests" |
80 | | -mvn clean gatling:test |
| 112 | +test_language="${SAMPLE_LANG#samples-}" |
| 113 | +mvn clean gatling:test -Dlanguage="${test_language}" -Dport="${FUNC_PORT}" |
0 commit comments