Skip to content

Commit 2172b85

Browse files
Merge remote-tracking branch 'magnus/feature/use-standalone-binaries-in-tests'
2 parents 172d9da + b0ccea7 commit 2172b85

File tree

4 files changed

+48
-11
lines changed

4 files changed

+48
-11
lines changed

test/scripts/build.sh

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ set -eu
77

88
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
99
TEST_FRAMEWORK_ROOT="$SCRIPT_DIR/.."
10+
REPO_ROOT="$SCRIPT_DIR/../.."
1011

1112
# Build
1213
build_linux() {
@@ -19,6 +20,10 @@ build_linux() {
1920
"$SCRIPT_DIR/build-runner.sh" linux
2021
cp "$TEST_FRAMEWORK_ROOT/target/x86_64-unknown-linux-gnu/release/test-runner" "$TEST_FRAMEWORK_ROOT/dist/"
2122
cp "$TEST_FRAMEWORK_ROOT/target/x86_64-unknown-linux-gnu/release/connection-checker" "$TEST_FRAMEWORK_ROOT/dist/"
23+
24+
# Build mullvad-version
25+
cargo build --manifest-path="$REPO_ROOT/Cargo.toml" --release --bin mullvad-version
26+
cp "$REPO_ROOT/target/release/mullvad-version" "$TEST_FRAMEWORK_ROOT/dist/"
2227
}
2328

2429
build_linux

test/scripts/container-run.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ if [ ! -d "$PACKAGE_DIR" ]; then
1010
echo "$PACKAGE_DIR does not exist. It is needed to build the test bundle, so please go ahead and create the directory and re-run this script."
1111
fi
1212

13-
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
13+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" > /dev/null && pwd )"
1414
REPO_DIR="$SCRIPT_DIR/../.."
1515
cd "$SCRIPT_DIR"
1616

test/scripts/test-utils.sh

+41-10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
set -eu
44

5+
function executable_not_found_in_dist_error {
6+
1>&2 echo "Executable \"$1\" not found in specified dist dir. Exiting."
7+
exit 1
8+
}
9+
510
# Returns the directory of the test-utils.sh script
611
function get_test_utls_dir {
712
local script_path="${BASH_SOURCE[0]}"
@@ -24,7 +29,14 @@ LATEST_STABLE_RELEASE=$(jq -r '[.[] | select(.prerelease==false)] | .[0].tag_nam
2429
function get_current_version {
2530
local app_dir
2631
app_dir="$(get_test_utls_dir)/../.."
27-
cargo run -q --manifest-path="$app_dir/Cargo.toml" --bin mullvad-version
32+
if [ -n "${TEST_DIST_DIR+x}" ]; then
33+
if [ ! -x "${TEST_DIST_DIR%/}/mullvad-version" ]; then
34+
executable_not_found_in_dist_error mullvad-version
35+
fi
36+
"${TEST_DIST_DIR%/}/mullvad-version"
37+
else
38+
cargo run -q --manifest-path="$app_dir/Cargo.toml" --bin mullvad-version
39+
fi
2840
}
2941

3042
CURRENT_VERSION=$(get_current_version)
@@ -224,12 +236,20 @@ function run_tests_for_os {
224236
exit 1
225237
fi
226238

227-
echo "**********************************"
228-
echo "* Building test runner"
229-
echo "**********************************"
230-
231-
nice_time build_test_runner "$vm"
239+
if [ -n "${TEST_DIST_DIR+x}" ]; then
240+
if [ ! -x "${TEST_DIST_DIR%/}/test-runner" ]; then
241+
executable_not_found_in_dist_error test-runner
242+
fi
232243

244+
echo "**********************************"
245+
echo "* Using test-runner in $TEST_DIST_DIR"
246+
echo "**********************************"
247+
else
248+
echo "**********************************"
249+
echo "* Building test runner"
250+
echo "**********************************"
251+
nice_time build_test_runner "$vm"
252+
fi
233253

234254
echo "**********************************"
235255
echo "* Running tests"
@@ -256,15 +276,26 @@ function run_tests_for_os {
256276
test_dir=$(get_test_utls_dir)/..
257277
read -ra test_filters_arg <<<"${TEST_FILTERS:-}" # Split the string by words into an array
258278
pushd "$test_dir"
259-
if ! RUST_LOG_STYLE=always cargo run --bin test-manager \
260-
run-tests \
279+
if [ -n "${TEST_DIST_DIR+x}" ]; then
280+
if [ ! -x "${TEST_DIST_DIR%/}/test-manager" ]; then
281+
executable_not_found_in_dist_error test-manager
282+
fi
283+
test_manager="${TEST_DIST_DIR%/}/test-manager"
284+
runner_dir_flag=("--runner-dir" "$TEST_DIST_DIR")
285+
else
286+
test_manager="cargo run --bin test-manager"
287+
runner_dir_flag=()
288+
fi
289+
290+
if ! RUST_LOG_STYLE=always $test_manager run-tests \
261291
--account "${ACCOUNT_TOKEN:?Error: ACCOUNT_TOKEN not set}" \
262292
--app-package "${APP_PACKAGE:?Error: APP_PACKAGE not set}" \
263293
"${upgrade_package_arg[@]}" \
264294
"${test_report_arg[@]}" \
265295
--package-dir "${package_dir}" \
266296
--vm "$vm" \
267297
"${test_filters_arg[@]}" \
298+
"${runner_dir_flag[@]}" \
268299
2>&1 | sed -r "s/${ACCOUNT_TOKEN}/\{ACCOUNT_TOKEN\}/g"; then
269300
echo "Test run failed"
270301
exit 1
@@ -279,7 +310,7 @@ function build_current_version {
279310
app_dir="$(get_test_utls_dir)/../.."
280311
local app_filename
281312
# TODO: TEST_OS must be set to local OS manually, should be set automatically
282-
app_filename=$(get_app_filename "$CURRENT_VERSION" "${TEST_OS:?Error: TEST_OS not set}")
313+
app_filename=$(get_app_filename "$CURRENT_VERSION" "${TEST_OS:?Error: TEST_OS not set}")
283314
local package_dir
284315
package_dir=$(get_package_dir)
285316
local app_package="$package_dir"/"$app_filename"
@@ -310,4 +341,4 @@ function build_current_version {
310341
else
311342
echo "GUI e2e executable for current version already exists at $gui_test_bin, skipping build"
312343
fi
313-
}
344+
}

test/test-by-version.sh

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ usage() {
1111
echo "Optional environment variables:"
1212
echo " - APP_VERSION: The version of the app to test (defaults to the latest stable release)"
1313
echo " - APP_PACKAGE_TO_UPGRADE_FROM: The package version to upgrade from (defaults to none)"
14+
echo " - TEST_DIST_DIR: Relative path to a directory with prebuilt binaries as produced by scripts/build.sh."
1415
echo " - TEST_FILTERS: specifies which tests to run (defaults to all)"
1516
echo " - TEST_REPORT : path to save the test results in a structured format"
1617
}

0 commit comments

Comments
 (0)