Skip to content

Commit fb37a40

Browse files
committed
test scripts
1 parent 4826c6a commit fb37a40

File tree

6 files changed

+341
-152
lines changed

6 files changed

+341
-152
lines changed

eng/scripts/tests/test-get-aspire-cli-pr.ps1

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ function Test-ArgumentValidation {
107107
function Test-WhatIfFunctionality {
108108
Write-ColoredOutput "=== WhatIf Functionality Tests ===" -Color 'Yellow'
109109

110-
$testInstallDir = Join-Path (New-TestEnvironment -TestSuiteName "pr-test") "install"
110+
$testBaseDir = New-TestEnvironment -TestSuiteName "pr-whatif"
111+
$testInstallDir = Join-Path $testBaseDir "install"
111112

112113
# Test: WhatIf with valid PR number
113114
$result = Invoke-TestCommand -Command $Script:ScriptPath -Arguments @("-PRNumber", $Script:TestPRNumber, "-InstallPath", $testInstallDir, "-WhatIf", "-Verbose")
@@ -137,7 +138,8 @@ function Test-WhatIfFunctionality {
137138
function Test-ParameterBehavior {
138139
Write-ColoredOutput "=== Parameter Behavior Tests ===" -Color 'Yellow'
139140

140-
$testInstallDir = Join-Path (New-TestEnvironment -TestSuiteName "pr-param-test") "install"
141+
$testBaseDir = New-TestEnvironment -TestSuiteName "pr-param"
142+
$testInstallDir = Join-Path $testBaseDir "install"
141143

142144
# Test: Verbose parameter increases output
143145
$resultQuiet = Invoke-TestCommand -Command $Script:ScriptPath -Arguments @("-PRNumber", $Script:TestPRNumber, "-InstallPath", $testInstallDir, "-WhatIf")
@@ -155,7 +157,7 @@ function Test-ParameterBehavior {
155157
}
156158

157159
# Test: Custom install path is properly handled
158-
$customInstallPath = Join-Path (New-TestEnvironment -TestSuiteName "pr-custom-test") "custom" "aspire"
160+
$customInstallPath = Join-Path $testBaseDir "custom" "aspire"
159161
$result = Invoke-TestCommand -Command $Script:ScriptPath -Arguments @("-PRNumber", $Script:TestPRNumber, "-InstallPath", $customInstallPath, "-WhatIf", "-Verbose")
160162

161163
if ($result.Success -and (Test-ScriptSuccess $result.Output) -and ($result.Output -match "custom.*aspire" -or $result.Output -match [regex]::Escape($customInstallPath))) {
@@ -168,7 +170,8 @@ function Test-ParameterBehavior {
168170
function Test-OSArchitectureOverride {
169171
Write-ColoredOutput "=== OS and Architecture Override Tests ===" -Color 'Yellow'
170172

171-
$testInstallDir = Join-Path (New-TestEnvironment -TestSuiteName "pr-os-test") "install"
173+
$testBaseDir = New-TestEnvironment -TestSuiteName "pr-os-arch"
174+
$testInstallDir = Join-Path $testBaseDir "install"
172175

173176
# Test: OS and architecture override works correctly
174177
$result = Invoke-TestCommand -Command $Script:ScriptPath -Arguments @("-PRNumber", $Script:TestPRNumber, "-InstallPath", $testInstallDir, "-OS", "linux", "-Architecture", "arm64", "-WhatIf", "-Verbose")
@@ -192,7 +195,8 @@ function Test-OSArchitectureOverride {
192195
function Test-PRSpecificOutput {
193196
Write-ColoredOutput "=== PR-Specific Output Tests ===" -Color 'Yellow'
194197

195-
$testInstallDir = Join-Path (New-TestEnvironment -TestSuiteName "pr-output-test") "install"
198+
$testBaseDir = New-TestEnvironment -TestSuiteName "pr-output"
199+
$testInstallDir = Join-Path $testBaseDir "install"
196200

197201
# Test: PR number is properly displayed in output
198202
$result = Invoke-TestCommand -Command $Script:ScriptPath -Arguments @("-PRNumber", $Script:TestPRNumber, "-InstallPath", $testInstallDir, "-WhatIf", "-Verbose")
@@ -225,7 +229,8 @@ function Test-PRSpecificOutput {
225229
function Test-GitHubCLIDependency {
226230
Write-ColoredOutput "=== GitHub CLI Dependency Tests ===" -Color 'Yellow'
227231

228-
$testInstallDir = Join-Path (New-TestEnvironment -TestSuiteName "pr-gh-test") "install"
232+
$testBaseDir = New-TestEnvironment -TestSuiteName "pr-gh-cli"
233+
$testInstallDir = Join-Path $testBaseDir "install"
229234

230235
# Check if gh is available
231236
$ghAvailable = Get-Command gh -ErrorAction SilentlyContinue
@@ -254,9 +259,11 @@ function Test-GitHubCLIDependency {
254259
function Test-EdgeCases {
255260
Write-ColoredOutput "=== Edge Case Tests ===" -Color 'Yellow'
256261

262+
$testBaseDir = New-TestEnvironment -TestSuiteName "pr-edge-cases"
263+
257264
# Test: Large PR number validation (should fail for non-existent PR)
258265
$largePR = 999999999
259-
$result = Invoke-TestCommand -Command $Script:ScriptPath -Arguments @("-PRNumber", $largePR, "-InstallPath", "test-large-pr", "-WhatIf") -ExpectedExitCode 1
266+
$result = Invoke-TestCommand -Command $Script:ScriptPath -Arguments @("-PRNumber", $largePR, "-InstallPath", (Join-Path $testBaseDir "test-large-pr"), "-WhatIf") -ExpectedExitCode 1
260267

261268
if ($result.Success) {
262269
Write-TestResult "Non-existent large PR numbers are properly rejected" "PASS"
@@ -275,7 +282,7 @@ function Test-EdgeCases {
275282

276283
# Test: Large workflow run ID format is accepted
277284
$largeRunId = 99999999999999
278-
$testInstallDir = Join-Path (New-TestEnvironment -TestSuiteName "pr-large-run-test") "install"
285+
$testInstallDir = Join-Path $testBaseDir "test-large-run"
279286
$result = Invoke-TestCommand -Command $Script:ScriptPath -Arguments @("-PRNumber", $Script:TestPRNumber, "-WorkflowRunId", $largeRunId, "-InstallPath", $testInstallDir, "-WhatIf")
280287

281288
if ($result.Success -and (Test-ScriptSuccess $result.Output)) {
@@ -288,7 +295,8 @@ function Test-EdgeCases {
288295
function Test-SwitchParameterCombinations {
289296
Write-ColoredOutput "=== Switch Parameter Combination Tests ===" -Color 'Yellow'
290297

291-
$testInstallDir = Join-Path (New-TestEnvironment -TestSuiteName "pr-switch-test") "install"
298+
$testBaseDir = New-TestEnvironment -TestSuiteName "pr-switches"
299+
$testInstallDir = Join-Path $testBaseDir "install"
292300

293301
# Test: Multiple switch parameters work together
294302
$result = Invoke-TestCommand -Command $Script:ScriptPath -Arguments @("-PRNumber", $Script:TestPRNumber, "-InstallPath", $testInstallDir, "-WhatIf", "-KeepArchive", "-Verbose")
@@ -788,7 +796,7 @@ function Main {
788796
Show-TestSummary
789797
}
790798
finally {
791-
# Cleanup test environments
799+
# Cleanup test environments - this removes the entire top-level test directory
792800
Remove-TestEnvironment
793801
}
794802
}

eng/scripts/tests/test-get-aspire-cli-pr.sh

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ readonly TEST_RUN_ID="16698575623"
1414
# Source common test utilities
1515
source "$SCRIPT_DIR/test-utils.sh"
1616

17-
# Test installation directory
18-
TEST_INSTALL_DIR=""
19-
2017
# Test: Script exists and is executable
2118
test_script_exists_wrapper() {
2219
test_script_exists "$SCRIPT_UNDER_TEST"
@@ -59,44 +56,50 @@ test_empty_option_value() {
5956

6057
# Test: Dry run with valid PR number
6158
test_dry_run_basic() {
62-
run_test "Dry run with valid PR number executes successfully" "$SCRIPT_UNDER_TEST $TEST_PR_NUMBER --install-path $TEST_INSTALL_DIR --dry-run --verbose" 0 "[DRY RUN]" ""
59+
local test_install_path="$TEST_BASE_DIR/test-install-basic"
60+
run_test "Dry run with valid PR number executes successfully" "$SCRIPT_UNDER_TEST $TEST_PR_NUMBER --install-path $test_install_path --dry-run --verbose" 0 "[DRY RUN]" ""
6361
}
6462

6563
# Test: Dry run with run ID
6664
test_dry_run_with_run_id() {
67-
run_test "Dry run with specific run ID executes successfully" "$SCRIPT_UNDER_TEST $TEST_PR_NUMBER --run-id $TEST_RUN_ID --install-path $TEST_INSTALL_DIR --dry-run --verbose" 0 "workflow run ID: $TEST_RUN_ID" ""
65+
local test_install_path="$TEST_BASE_DIR/test-install-run-id"
66+
run_test "Dry run with specific run ID executes successfully" "$SCRIPT_UNDER_TEST $TEST_PR_NUMBER --run-id $TEST_RUN_ID --install-path $test_install_path --dry-run --verbose" 0 "workflow run ID: $TEST_RUN_ID" ""
6867
}
6968

7069
# Test: Dry run with all options
7170
test_dry_run_all_options() {
72-
run_test "Dry run with all options executes successfully" "$SCRIPT_UNDER_TEST $TEST_PR_NUMBER --install-path $TEST_INSTALL_DIR --os linux --arch x64 --verbose --keep-archive --dry-run" 0 "[DRY RUN]" ""
71+
local test_install_path="$TEST_BASE_DIR/test-install-all-options"
72+
run_test "Dry run with all options executes successfully" "$SCRIPT_UNDER_TEST $TEST_PR_NUMBER --install-path $test_install_path --os linux --arch x64 --verbose --keep-archive --dry-run" 0 "[DRY RUN]" ""
7373
}
7474

7575
# Test: Verbose flag increases output
7676
test_verbose_flag() {
77-
local test_cmd_quiet="$SCRIPT_UNDER_TEST $TEST_PR_NUMBER --install-path $TEST_INSTALL_DIR --dry-run"
78-
local test_cmd_verbose="$SCRIPT_UNDER_TEST $TEST_PR_NUMBER --install-path $TEST_INSTALL_DIR --dry-run --verbose"
77+
local test_install_path="$TEST_BASE_DIR/test-install-verbose"
78+
local test_cmd_quiet="$SCRIPT_UNDER_TEST $TEST_PR_NUMBER --install-path $test_install_path --dry-run"
79+
local test_cmd_verbose="$SCRIPT_UNDER_TEST $TEST_PR_NUMBER --install-path $test_install_path --dry-run --verbose"
7980

8081
test_verbose_flag_effect "Verbose flag increases output" "$test_cmd_quiet" "$test_cmd_verbose" 0
8182
}
8283

8384
# Test: Short and long option equivalence
8485
test_option_equivalence_wrapper() {
85-
local test_cmd_short="$SCRIPT_UNDER_TEST $TEST_PR_NUMBER -i $TEST_INSTALL_DIR -r $TEST_RUN_ID -v -k --dry-run"
86-
local test_cmd_long="$SCRIPT_UNDER_TEST $TEST_PR_NUMBER --install-path $TEST_INSTALL_DIR --run-id $TEST_RUN_ID --verbose --keep-archive --dry-run"
86+
local test_install_path="$TEST_BASE_DIR/test-install-options"
87+
local test_cmd_short="$SCRIPT_UNDER_TEST $TEST_PR_NUMBER -i $test_install_path -r $TEST_RUN_ID -v -k --dry-run"
88+
local test_cmd_long="$SCRIPT_UNDER_TEST $TEST_PR_NUMBER --install-path $test_install_path --run-id $TEST_RUN_ID --verbose --keep-archive --dry-run"
8789

8890
test_option_equivalence "Short and long options are equivalent" "$test_cmd_short" "$test_cmd_long" 0 "workflow run ID: $TEST_RUN_ID"
8991
}
9092

9193
# Test: Check GitHub CLI dependency
9294
test_gh_dependency_check() {
9395
# This test assumes gh is available in the environment
96+
local test_install_path="$TEST_BASE_DIR/test-install-gh-check"
9497
if command -v gh >/dev/null 2>&1; then
9598
# gh is available, script should proceed to dry run
96-
run_test "GitHub CLI dependency check passes when gh is available" "$SCRIPT_UNDER_TEST $TEST_PR_NUMBER --install-path $TEST_INSTALL_DIR --dry-run" 0 "" ""
99+
run_test "GitHub CLI dependency check passes when gh is available" "$SCRIPT_UNDER_TEST $TEST_PR_NUMBER --install-path $test_install_path --dry-run" 0 "" ""
97100
else
98101
# gh is not available, script should fail with appropriate message
99-
run_test "GitHub CLI dependency check fails appropriately when gh not available" "$SCRIPT_UNDER_TEST $TEST_PR_NUMBER --install-path $TEST_INSTALL_DIR --dry-run" 1 "GitHub CLI (gh) is required" ""
102+
run_test "GitHub CLI dependency check fails appropriately when gh not available" "$SCRIPT_UNDER_TEST $TEST_PR_NUMBER --install-path $test_install_path --dry-run" 1 "GitHub CLI (gh) is required" ""
100103
fi
101104
}
102105

@@ -108,43 +111,51 @@ test_install_path_handling() {
108111

109112
# Test: OS and architecture override
110113
test_os_arch_override() {
111-
run_test "OS and architecture override works correctly" "$SCRIPT_UNDER_TEST $TEST_PR_NUMBER --install-path $TEST_INSTALL_DIR --os linux --arch arm64 --dry-run --verbose" 0 "cli-native-archives-linux-arm64" ""
114+
local test_install_path="$TEST_BASE_DIR/test-install-os-arch"
115+
run_test "OS and architecture override works correctly" "$SCRIPT_UNDER_TEST $TEST_PR_NUMBER --install-path $test_install_path --os linux --arch arm64 --dry-run --verbose" 0 "cli-native-archives-linux-arm64" ""
112116
}
113117

114118
# Test: Windows OS override
115119
test_windows_os_override() {
116-
run_test "Windows OS override works correctly" "$SCRIPT_UNDER_TEST $TEST_PR_NUMBER --install-path $TEST_INSTALL_DIR --os win --arch x64 --dry-run --verbose" 0 "cli-native-archives-win-x64" ""
120+
local test_install_path="$TEST_BASE_DIR/test-install-windows"
121+
run_test "Windows OS override works correctly" "$SCRIPT_UNDER_TEST $TEST_PR_NUMBER --install-path $test_install_path --os win --arch x64 --dry-run --verbose" 0 "cli-native-archives-win-x64" ""
117122
}
118123

119124
# Test: PR-specific functionality is mentioned in output
120125
test_pr_specific_output() {
121-
run_test "PR number is properly displayed in output" "$SCRIPT_UNDER_TEST $TEST_PR_NUMBER --install-path $TEST_INSTALL_DIR --dry-run --verbose" 0 "PR #$TEST_PR_NUMBER" ""
126+
local test_install_path="$TEST_BASE_DIR/test-install-pr-output"
127+
run_test "PR number is properly displayed in output" "$SCRIPT_UNDER_TEST $TEST_PR_NUMBER --install-path $test_install_path --dry-run --verbose" 0 "PR #$TEST_PR_NUMBER" ""
122128
}
123129

124130
# Test: Run ID specific functionality
125131
test_run_id_specific_output() {
126-
run_test "Workflow run URL is properly displayed" "$SCRIPT_UNDER_TEST $TEST_PR_NUMBER --run-id $TEST_RUN_ID --install-path $TEST_INSTALL_DIR --dry-run --verbose" 0 "workflow run https://github.com/dotnet/aspire/actions/runs/$TEST_RUN_ID" ""
132+
local test_install_path="$TEST_BASE_DIR/test-install-run-id-output"
133+
run_test "Workflow run URL is properly displayed" "$SCRIPT_UNDER_TEST $TEST_PR_NUMBER --run-id $TEST_RUN_ID --install-path $test_install_path --dry-run --verbose" 0 "workflow run https://github.com/dotnet/aspire/actions/runs/$TEST_RUN_ID" ""
127134
}
128135

129136
# Test: Artifact names are correctly constructed
130137
test_artifact_names() {
131-
run_test "Expected artifact names appear in output" "$SCRIPT_UNDER_TEST $TEST_PR_NUMBER --install-path $TEST_INSTALL_DIR --dry-run --verbose" 0 "built-nugets" ""
138+
local test_install_path="$TEST_BASE_DIR/test-install-artifacts"
139+
run_test "Expected artifact names appear in output" "$SCRIPT_UNDER_TEST $TEST_PR_NUMBER --install-path $test_install_path --dry-run --verbose" 0 "built-nugets" ""
132140
}
133141

134142
# Test: Keep archive flag is processed
135143
test_keep_archive_flag() {
136-
run_test "Keep archive flag is properly processed" "$SCRIPT_UNDER_TEST $TEST_PR_NUMBER --install-path $TEST_INSTALL_DIR --keep-archive --dry-run --verbose" 0 "[DRY RUN]" ""
144+
local test_install_path="$TEST_BASE_DIR/test-install-keep-archive"
145+
run_test "Keep archive flag is properly processed" "$SCRIPT_UNDER_TEST $TEST_PR_NUMBER --install-path $test_install_path --keep-archive --dry-run --verbose" 0 "[DRY RUN]" ""
137146
}
138147

139148
# Test: NuGet hive path construction
140149
test_nuget_hive_path() {
141-
run_test "NuGet hive path is correctly constructed" "$SCRIPT_UNDER_TEST $TEST_PR_NUMBER --install-path $TEST_INSTALL_DIR --dry-run --verbose" 0 "hive/pr-$TEST_PR_NUMBER" ""
150+
local test_install_path="$TEST_BASE_DIR/test-install-nuget-hive"
151+
run_test "NuGet hive path is correctly constructed" "$SCRIPT_UNDER_TEST $TEST_PR_NUMBER --install-path $test_install_path --dry-run --verbose" 0 "hive/pr-$TEST_PR_NUMBER" ""
142152
}
143153

144154
# Test: Large PR number validation (should fail for non-existent PR)
145155
test_large_pr_number() {
146156
local large_pr="999999999"
147-
run_test "Non-existent large PR numbers are properly rejected" "$SCRIPT_UNDER_TEST $large_pr --install-path $TEST_INSTALL_DIR --dry-run" 1 "Failed to get HEAD SHA" ""
157+
local test_install_path="$TEST_BASE_DIR/test-install-large-pr"
158+
run_test "Non-existent large PR numbers are properly rejected" "$SCRIPT_UNDER_TEST $large_pr --install-path $test_install_path --dry-run" 1 "Failed to get HEAD SHA" ""
148159
}
149160

150161
# Test: Zero PR number rejection
@@ -160,7 +171,8 @@ test_negative_run_id() {
160171
# Test: Very large run ID (should accept valid format but may fail on API call)
161172
test_large_run_id() {
162173
local large_run_id="99999999999999"
163-
run_test "Large run ID format is accepted" "$SCRIPT_UNDER_TEST $TEST_PR_NUMBER --run-id $large_run_id --install-path $TEST_INSTALL_DIR --dry-run" 0 "workflow run ID: $large_run_id" ""
174+
local test_install_path="$TEST_BASE_DIR/test-install-large-run-id"
175+
run_test "Large run ID format is accepted" "$SCRIPT_UNDER_TEST $TEST_PR_NUMBER --run-id $large_run_id --install-path $test_install_path --dry-run" 0 "workflow run ID: $large_run_id" ""
164176
}
165177

166178
# Main test execution function
@@ -174,7 +186,6 @@ run_all_tests() {
174186

175187
# Setup test environment
176188
create_test_environment "aspire-cli-pr"
177-
TEST_INSTALL_DIR="$TEST_BASE_DIR/install"
178189

179190
# Basic functionality tests
180191
test_script_exists_wrapper

0 commit comments

Comments
 (0)