Skip to content

Commit 0bb9853

Browse files
committed
removing sub id as required param
1 parent fb7cfea commit 0bb9853

4 files changed

Lines changed: 161 additions & 78 deletions

File tree

tests/integration/all-resource-types/run-roundtrip-phase2-extract.ps1

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
[CmdletBinding()]
88
param(
9-
[Parameter(Mandatory)]
109
[string]$SourceSubscriptionId,
1110

1211
[Parameter(Mandatory)]
@@ -49,18 +48,25 @@ if (Test-Path $ExtractOutputDir) {
4948

5049
$extractArgs = @(
5150
'extract',
52-
'--subscription-id', $SourceSubscriptionId,
53-
'--resource-group', $SourceResourceGroup,
54-
'--service-name', $SourceApimName,
55-
'--output', $ExtractOutputDir,
56-
'--log-level', $apiopsLogLevel
57-
) + $apiopsAuthArgs
58-
59-
$extractExitCode = Invoke-MaskedApiopsCommand -Replacements @{
60-
$SourceSubscriptionId = Protect-SubscriptionId -Value $SourceSubscriptionId
61-
$SourceResourceGroup = Protect-ResourceGroupName -Value $SourceResourceGroup
62-
$SourceApimName = Protect-ApimName -Value $SourceApimName
63-
} -Arguments $extractArgs
51+
'--resource-group', $SourceResourceGroup,
52+
'--service-name', $SourceApimName,
53+
'--output', $ExtractOutputDir,
54+
'--log-level', $apiopsLogLevel
55+
)
56+
if (-not [string]::IsNullOrWhiteSpace($SourceSubscriptionId)) {
57+
$extractArgs += @('--subscription-id', $SourceSubscriptionId)
58+
}
59+
$extractArgs += $apiopsAuthArgs
60+
61+
$replacements = @{
62+
$SourceResourceGroup = Protect-ResourceGroupName -Value $SourceResourceGroup
63+
$SourceApimName = Protect-ApimName -Value $SourceApimName
64+
}
65+
if (-not [string]::IsNullOrWhiteSpace($SourceSubscriptionId)) {
66+
$replacements[$SourceSubscriptionId] = Protect-SubscriptionId -Value $SourceSubscriptionId
67+
}
68+
69+
$extractExitCode = Invoke-MaskedApiopsCommand -Replacements $replacements -Arguments $extractArgs
6470

6571
if ($extractExitCode -ne 0) {
6672
Write-Host "❌ Extract failed (exit code $extractExitCode)"

tests/integration/all-resource-types/run-roundtrip-phase4-publish.ps1

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
[CmdletBinding()]
88
param(
9-
[Parameter(Mandatory)]
109
[string]$TargetSubscriptionId,
1110

1211
[Parameter(Mandatory)]
@@ -97,19 +96,28 @@ loggers:
9796
$overrideYaml | Set-Content -Path $overrideFile -Encoding utf8
9897

9998
Write-Host "📤 Publish — Publish artifacts to target APIM"
100-
$publishExitCode = Invoke-MaskedApiopsCommand -Replacements @{
101-
$TargetSubscriptionId = Protect-SubscriptionId -Value $TargetSubscriptionId
102-
$TargetResourceGroup = Protect-ResourceGroupName -Value $TargetResourceGroup
103-
$TargetApimName = Protect-ApimName -Value $TargetApimName
104-
} -Arguments @(
99+
$publishArgs = @(
105100
'publish',
106-
'--subscription-id', $TargetSubscriptionId,
107-
'--resource-group', $TargetResourceGroup,
108-
'--service-name', $TargetApimName,
109-
'--source', $ExtractOutputDir,
110-
'--overrides', $overrideFile,
111-
'--log-level', $apiopsLogLevel
112-
) + $apiopsAuthArgs
101+
'--resource-group', $TargetResourceGroup,
102+
'--service-name', $TargetApimName,
103+
'--source', $ExtractOutputDir,
104+
'--overrides', $overrideFile,
105+
'--log-level', $apiopsLogLevel
106+
)
107+
if (-not [string]::IsNullOrWhiteSpace($TargetSubscriptionId)) {
108+
$publishArgs += @('--subscription-id', $TargetSubscriptionId)
109+
}
110+
$publishArgs += $apiopsAuthArgs
111+
112+
$replacements = @{
113+
$TargetResourceGroup = Protect-ResourceGroupName -Value $TargetResourceGroup
114+
$TargetApimName = Protect-ApimName -Value $TargetApimName
115+
}
116+
if (-not [string]::IsNullOrWhiteSpace($TargetSubscriptionId)) {
117+
$replacements[$TargetSubscriptionId] = Protect-SubscriptionId -Value $TargetSubscriptionId
118+
}
119+
120+
$publishExitCode = Invoke-MaskedApiopsCommand -Replacements $replacements -Arguments $publishArgs
113121

114122
if ($publishExitCode -ne 0) {
115123
Write-Host "❌ Publish failed (exit code $publishExitCode)"

tests/integration/all-resource-types/run-roundtrip-phase5-compare.ps1

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
[CmdletBinding()]
88
param(
9-
[Parameter(Mandatory)]
109
[string]$SourceSubscriptionId,
1110

1211
[Parameter(Mandatory)]
@@ -15,7 +14,6 @@ param(
1514
[Parameter(Mandatory)]
1615
[string]$SourceApimName,
1716

18-
[Parameter(Mandatory)]
1917
[string]$TargetSubscriptionId,
2018

2119
[Parameter(Mandatory)]
@@ -39,6 +37,23 @@ if (-not (Test-Path $compareScript)) {
3937
exit 2
4038
}
4139

40+
if ([string]::IsNullOrWhiteSpace($SourceSubscriptionId)) {
41+
$SourceSubscriptionId = $env:SOURCE_SUBSCRIPTION_ID
42+
}
43+
if ([string]::IsNullOrWhiteSpace($TargetSubscriptionId)) {
44+
$TargetSubscriptionId = $env:TARGET_SUBSCRIPTION_ID
45+
}
46+
47+
if ([string]::IsNullOrWhiteSpace($SourceSubscriptionId) -or [string]::IsNullOrWhiteSpace($TargetSubscriptionId)) {
48+
$account = az account show --output json 2>$null | ConvertFrom-Json
49+
if (-not $account -or -not $account.id) {
50+
Write-Error "Unable to resolve subscription IDs for compare phase. Set -SourceSubscriptionId/-TargetSubscriptionId, SOURCE_SUBSCRIPTION_ID/TARGET_SUBSCRIPTION_ID, or run 'az login'."
51+
exit 2
52+
}
53+
if ([string]::IsNullOrWhiteSpace($SourceSubscriptionId)) { $SourceSubscriptionId = $account.id }
54+
if ([string]::IsNullOrWhiteSpace($TargetSubscriptionId)) { $TargetSubscriptionId = $account.id }
55+
}
56+
4257
Write-Host "🔍 Compare — Compare source and target APIM instances"
4358
$compareArgs = @{
4459
SourceSubscriptionId = $SourceSubscriptionId

tests/integration/all-resource-types/run-roundtrip-test.ps1

Lines changed: 104 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,41 @@
11
<#
22
.SYNOPSIS
3-
Master orchestrator for the extract→publish round-trip integration test.
3+
Master orchestrator for the 5-phase round-trip integration workflow.
4+
.DESCRIPTION
5+
Single entry point that runs the full round-trip sequence:
6+
1) deploy source + target APIM instances,
7+
2) extract from source and validate extracted artifact structure,
8+
3) publish artifacts to target,
9+
4) compare source and target,
10+
5) teardown.
11+
12+
Works both locally and in CI (writes to GITHUB_OUTPUT when available).
13+
14+
A unique timestamp + random suffix is auto-generated for resource group and
15+
APIM names by default to avoid collisions when tests run in parallel.
16+
Supporting resource names inside each group are generated by Bicep.
17+
18+
Exit codes:
19+
0 — all phases passed
20+
1 — extract validation failed or verification diff detected
21+
2 — deployment, extract, or publish error
22+
23+
.PARAMETER HardDelete
24+
Controls whether teardown waits for resource group deletion and purges
25+
soft-deleted APIM instances. Defaults to $true.
26+
27+
.EXAMPLE
28+
# Full run (auto-generates unique resource group and APIM names)
29+
.\run-roundtrip-test.ps1 -PublisherEmail admin@contoso.com
30+
31+
# Full run with explicit resource groups (APIM names still auto-generated)
32+
.\run-roundtrip-test.ps1 -SourceResourceGroup rg-src -TargetResourceGroup rg-tgt -PublisherEmail admin@contoso.com
33+
34+
# Keep resources after test for debugging
35+
.\run-roundtrip-test.ps1 -PublisherEmail admin@contoso.com -SkipTeardown
36+
37+
# Disable hard-delete behavior on teardown (no purge wait)
38+
.\run-roundtrip-test.ps1 -PublisherEmail admin@contoso.com -HardDelete:$false
439
#>
540

641
#requires -Version 7.0
@@ -33,10 +68,10 @@ param(
3368
[ValidateSet('Info', 'Verbose', 'Debug')]
3469
[string]$LogLevel = 'Verbose',
3570

36-
[Parameter(Mandatory)]
37-
[string]$PublisherEmail,
71+
[Parameter()]
72+
[string]$PublisherEmail = 'publisher@example.com',
3873

39-
[string]$ExtractOutputDir = "$PSScriptRoot/extracted-artifacts",
74+
[string]$ExtractOutputDir,
4075

4176
[switch]$SkipTeardown,
4277

@@ -49,7 +84,7 @@ if (-not $PSBoundParameters.ContainsKey('HardDelete')) {
4984
$HardDelete = $true
5085
}
5186

52-
$timestamp = Get-Date -Format 'yyyyMMddHHmmss'
87+
$timestamp = Get-Date -Format 'yyyyMMdd-HHmmss'
5388
$random = -join ((97..122) | Get-Random -Count 3 | ForEach-Object { [char]$_ })
5489
$uniqueId = "$timestamp-$random"
5590

@@ -73,16 +108,6 @@ if (-not $TargetSubscriptionId) {
73108
$TargetSubscriptionId = $env:TARGET_SUBSCRIPTION_ID
74109
}
75110

76-
if (-not $SourceSubscriptionId -or -not $TargetSubscriptionId) {
77-
$account = az account show --output json 2>$null | ConvertFrom-Json
78-
if (-not $account) {
79-
Write-Error "Not logged in to Azure CLI. Run 'az login' first."
80-
exit 2
81-
}
82-
if (-not $SourceSubscriptionId) { $SourceSubscriptionId = $account.id }
83-
if (-not $TargetSubscriptionId) { $TargetSubscriptionId = $account.id }
84-
}
85-
86111
$phase1Script = Join-Path $PSScriptRoot 'run-roundtrip-phase1-deploy.ps1'
87112
$phase2Script = Join-Path $PSScriptRoot 'run-roundtrip-phase2-extract.ps1'
88113
$phase3Script = Join-Path $PSScriptRoot 'run-roundtrip-phase3-validate-extract.ps1'
@@ -100,65 +125,94 @@ foreach ($requiredFile in @($phase1Script, $phase2Script, $phase3Script, $phase4
100125
$exitCode = 0
101126

102127
try {
103-
& $phase1Script `
104-
-SourceResourceGroup $SourceResourceGroup `
105-
-TargetResourceGroup $TargetResourceGroup `
106-
-SourceApimName $SourceApimName `
107-
-TargetApimName $TargetApimName `
108-
-SourceSubscriptionId $SourceSubscriptionId `
109-
-TargetSubscriptionId $TargetSubscriptionId `
110-
-SkuName $SkuName `
111-
-Location $Location `
112-
-LogLevel $LogLevel `
113-
-PublisherEmail $PublisherEmail
128+
$phase1Args = @{
129+
SourceResourceGroup = $SourceResourceGroup
130+
TargetResourceGroup = $TargetResourceGroup
131+
SourceApimName = $SourceApimName
132+
TargetApimName = $TargetApimName
133+
SkuName = $SkuName
134+
Location = $Location
135+
LogLevel = $LogLevel
136+
PublisherEmail = $PublisherEmail
137+
}
138+
if (-not [string]::IsNullOrWhiteSpace($SourceSubscriptionId)) {
139+
$phase1Args.SourceSubscriptionId = $SourceSubscriptionId
140+
}
141+
if (-not [string]::IsNullOrWhiteSpace($TargetSubscriptionId)) {
142+
$phase1Args.TargetSubscriptionId = $TargetSubscriptionId
143+
}
144+
& $phase1Script @phase1Args
114145

115146
if ($LASTEXITCODE -ne 0) {
116147
$exitCode = $LASTEXITCODE
117148
exit $exitCode
118149
}
119150

120-
& $phase2Script `
121-
-SourceSubscriptionId $SourceSubscriptionId `
122-
-SourceResourceGroup $SourceResourceGroup `
123-
-SourceApimName $SourceApimName `
124-
-LogLevel $LogLevel `
125-
-ExtractOutputDir $ExtractOutputDir
151+
$phase2Args = @{
152+
SourceResourceGroup = $SourceResourceGroup
153+
SourceApimName = $SourceApimName
154+
SkuName = $SkuName
155+
LogLevel = $LogLevel
156+
}
157+
if (-not [string]::IsNullOrWhiteSpace($SourceSubscriptionId)) {
158+
$phase2Args.SourceSubscriptionId = $SourceSubscriptionId
159+
}
160+
if ($PSBoundParameters.ContainsKey('ExtractOutputDir')) {
161+
$phase2Args.ExtractOutputDir = $ExtractOutputDir
162+
}
163+
& $phase2Script @phase2Args
126164

127165
if ($LASTEXITCODE -ne 0) {
128166
$exitCode = $LASTEXITCODE
129167
exit $exitCode
130168
}
131169

132-
& $phase3Script `
133-
-SkuName $SkuName `
134-
-LogLevel $LogLevel `
135-
-ExtractOutputDir $ExtractOutputDir
170+
$phase3Args = @{
171+
SkuName = $SkuName
172+
LogLevel = $LogLevel
173+
}
174+
if ($PSBoundParameters.ContainsKey('ExtractOutputDir')) {
175+
$phase3Args.ExtractOutputDir = $ExtractOutputDir
176+
}
177+
& $phase3Script @phase3Args
136178

137179
if ($LASTEXITCODE -ne 0) {
138180
$exitCode = $LASTEXITCODE
139181
exit $exitCode
140182
}
141183

142-
& $phase4Script `
143-
-TargetSubscriptionId $TargetSubscriptionId `
144-
-TargetResourceGroup $TargetResourceGroup `
145-
-TargetApimName $TargetApimName `
146-
-LogLevel $LogLevel `
147-
-ExtractOutputDir $ExtractOutputDir
184+
$phase4Args = @{
185+
TargetResourceGroup = $TargetResourceGroup
186+
TargetApimName = $TargetApimName
187+
LogLevel = $LogLevel
188+
}
189+
if (-not [string]::IsNullOrWhiteSpace($TargetSubscriptionId)) {
190+
$phase4Args.TargetSubscriptionId = $TargetSubscriptionId
191+
}
192+
if ($PSBoundParameters.ContainsKey('ExtractOutputDir')) {
193+
$phase4Args.ExtractOutputDir = $ExtractOutputDir
194+
}
195+
& $phase4Script @phase4Args
148196

149197
if ($LASTEXITCODE -ne 0) {
150198
$exitCode = $LASTEXITCODE
151199
exit $exitCode
152200
}
153201

154-
& $phase5Script `
155-
-SourceSubscriptionId $SourceSubscriptionId `
156-
-SourceResourceGroup $SourceResourceGroup `
157-
-SourceApimName $SourceApimName `
158-
-TargetSubscriptionId $TargetSubscriptionId `
159-
-TargetResourceGroup $TargetResourceGroup `
160-
-TargetApimName $TargetApimName `
161-
-LogLevel $LogLevel
202+
$phase5Args = @{
203+
SourceResourceGroup = $SourceResourceGroup
204+
SourceApimName = $SourceApimName
205+
TargetResourceGroup = $TargetResourceGroup
206+
TargetApimName = $TargetApimName
207+
LogLevel = $LogLevel
208+
}
209+
if (-not [string]::IsNullOrWhiteSpace($SourceSubscriptionId)) {
210+
$phase5Args.SourceSubscriptionId = $SourceSubscriptionId
211+
}
212+
if (-not [string]::IsNullOrWhiteSpace($TargetSubscriptionId)) {
213+
$phase5Args.TargetSubscriptionId = $TargetSubscriptionId
214+
}
215+
& $phase5Script @phase5Args
162216

163217
$exitCode = $LASTEXITCODE
164218
}

0 commit comments

Comments
 (0)