-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-apk-resolution.sh
More file actions
executable file
·148 lines (125 loc) · 6.07 KB
/
test-apk-resolution.sh
File metadata and controls
executable file
·148 lines (125 loc) · 6.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/usr/bin/env bash
# Android Plugin - APK Auto-Detection Resolution Tests
#
# Tests for the android_find_apk() precedence chain in deploy.sh.
# These tests use temporary directories with fixture APKs.
set -euo pipefail
script_dir="$(cd "$(dirname "$0")" && pwd)"
. "$script_dir/../test-framework.sh"
setup_logging
# ============================================================================
# Setup
# ============================================================================
deploy_path="$script_dir/../../android/virtenv/scripts/domain/deploy.sh"
lib_path="$script_dir/../../android/virtenv/scripts/lib/lib.sh"
core_path="$script_dir/../../android/virtenv/scripts/platform/core.sh"
if [ ! -f "$deploy_path" ]; then
echo "ERROR: deploy.sh not found at: $deploy_path"
exit 1
fi
# Source dependencies
. "$lib_path"
. "$core_path"
. "$deploy_path"
# Create temp project structures
TMPDIR_BASE="$(make_temp_dir "android-apk-resolution")"
trap 'rm -rf "$TMPDIR_BASE"' EXIT
echo "========================================"
echo "Android APK Resolution Tests"
echo "========================================"
echo "Testing: $deploy_path"
# ============================================================================
# Tests: android_find_apk with ANDROID_APP_APK env var (precedence 1)
# ============================================================================
start_test "android_find_apk - resolves via ANDROID_APP_APK env var"
test_root="$TMPDIR_BASE/test1"
mkdir -p "$test_root/app/build/outputs/apk/debug"
touch "$test_root/app/build/outputs/apk/debug/app-debug.apk"
ANDROID_APP_APK="app/build/outputs/apk/debug/app-debug.apk" \
result=$(android_find_apk "$test_root" 2>/dev/null)
assert_equal "$test_root/app/build/outputs/apk/debug/app-debug.apk" "$result" \
"Should find APK via ANDROID_APP_APK relative path"
start_test "android_find_apk - resolves via ANDROID_APP_APK glob"
test_root="$TMPDIR_BASE/test1b"
mkdir -p "$test_root/app/build/outputs/apk/debug"
touch "$test_root/app/build/outputs/apk/debug/app-debug.apk"
ANDROID_APP_APK="app/build/outputs/apk/debug/*.apk" \
result=$(android_find_apk "$test_root" 2>/dev/null)
assert_equal "$test_root/app/build/outputs/apk/debug/app-debug.apk" "$result" \
"Should find APK via ANDROID_APP_APK glob pattern"
start_test "android_find_apk - ANDROID_APP_APK takes priority over recursive search"
test_root="$TMPDIR_BASE/test1c"
mkdir -p "$test_root/specific" "$test_root/other"
touch "$test_root/specific/target.apk"
touch "$test_root/other/decoy.apk"
ANDROID_APP_APK="specific/target.apk" \
result=$(android_find_apk "$test_root" 2>/dev/null)
assert_equal "$test_root/specific/target.apk" "$result" \
"ANDROID_APP_APK should take priority"
# ============================================================================
# Tests: android_find_apk with recursive search (precedence 2)
# ============================================================================
start_test "android_find_apk - finds APK via recursive search"
test_root="$TMPDIR_BASE/test2"
mkdir -p "$test_root/app/build/outputs/apk/debug"
touch "$test_root/app/build/outputs/apk/debug/app-debug.apk"
ANDROID_APP_APK="" \
result=$(android_find_apk "$test_root" 2>/dev/null)
assert_equal "$test_root/app/build/outputs/apk/debug/app-debug.apk" "$result" \
"Should find APK via recursive search"
start_test "android_find_apk - excludes .gradle directory"
test_root="$TMPDIR_BASE/test2b"
mkdir -p "$test_root/.gradle/caches" "$test_root/app/build/outputs"
touch "$test_root/.gradle/caches/cached.apk"
touch "$test_root/app/build/outputs/real.apk"
ANDROID_APP_APK="" \
result=$(android_find_apk "$test_root" 2>/dev/null)
assert_equal "$test_root/app/build/outputs/real.apk" "$result" \
"Should skip .gradle directory"
start_test "android_find_apk - excludes build/intermediates directory"
test_root="$TMPDIR_BASE/test2c"
mkdir -p "$test_root/build/intermediates/apk" "$test_root/build/outputs"
touch "$test_root/build/intermediates/apk/intermediate.apk"
touch "$test_root/build/outputs/final.apk"
ANDROID_APP_APK="" \
result=$(android_find_apk "$test_root" 2>/dev/null)
assert_equal "$test_root/build/outputs/final.apk" "$result" \
"Should skip build/intermediates"
start_test "android_find_apk - excludes node_modules directory"
test_root="$TMPDIR_BASE/test2d"
mkdir -p "$test_root/node_modules/some-pkg" "$test_root/android/app"
touch "$test_root/node_modules/some-pkg/bundled.apk"
touch "$test_root/android/app/app.apk"
ANDROID_APP_APK="" \
result=$(android_find_apk "$test_root" 2>/dev/null)
assert_equal "$test_root/android/app/app.apk" "$result" \
"Should skip node_modules"
start_test "android_find_apk - excludes .devbox directory"
test_root="$TMPDIR_BASE/test2e"
mkdir -p "$test_root/.devbox/virtenv" "$test_root/app"
touch "$test_root/.devbox/virtenv/cached.apk"
touch "$test_root/app/real.apk"
ANDROID_APP_APK="" \
result=$(android_find_apk "$test_root" 2>/dev/null)
assert_equal "$test_root/app/real.apk" "$result" \
"Should skip .devbox"
# ============================================================================
# Tests: android_find_apk fails with clear error (precedence 4)
# ============================================================================
start_test "android_find_apk - fails when no APK found"
test_root="$TMPDIR_BASE/test4"
mkdir -p "$test_root"
# Run from a clean dir so $PWD fallback search doesn't find fixture APKs
(cd "$test_root" && ANDROID_APP_APK="" \
assert_failure "android_find_apk '$test_root'" "Should fail when no APK exists")
start_test "android_find_apk - error message includes guidance"
test_root="$TMPDIR_BASE/test4b"
mkdir -p "$test_root"
# Run from a clean dir so $PWD fallback search doesn't find fixture APKs
error_output=$(cd "$test_root" && ANDROID_APP_APK="" android_find_apk "$test_root" 2>&1 || true)
assert_contains "$error_output" "No APK found" "Error should mention no APK found"
assert_contains "$error_output" "ANDROID_APP_APK" "Error should mention env var"
# ============================================================================
# Summary
# ============================================================================
test_summary "android-apk-resolution"