Repository navigation
Expand file tree
/
Copy pathpackaging.tests.ps1
More file actions
217 lines (188 loc) · 8.83 KB
/
Copy pathpackaging.tests.ps1
File metadata and controls
217 lines (188 loc) · 8.83 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
Describe "Packaging Module Functions" {
BeforeAll {
Import-Module $PSScriptRoot/../../build.psm1 -Force
Import-Module $PSScriptRoot/../../tools/packaging/packaging.psm1 -Force
}
Context "Test-IsPreview function" {
It "Should return True for preview versions" {
Test-IsPreview -Version "7.6.0-preview.6" | Should -Be $true
Test-IsPreview -Version "7.5.0-rc.1" | Should -Be $true
}
It "Should return False for stable versions" {
Test-IsPreview -Version "7.6.0" | Should -Be $false
Test-IsPreview -Version "7.5.0" | Should -Be $false
}
It "Should return False for LTS builds regardless of version string" {
Test-IsPreview -Version "7.6.0-preview.6" -IsLTS | Should -Be $false
Test-IsPreview -Version "7.5.0" -IsLTS | Should -Be $false
}
}
Context "Azure Linux RPM packaging" {
BeforeAll {
$afterInstallScript = Join-Path $TestDrive "after-install.sh"
$afterRemoveScript = Join-Path $TestDrive "after-remove.sh"
"echo installed" | Set-Content -Path $afterInstallScript
"echo removed" | Set-Content -Path $afterRemoveScript
$linkInfo = & (Get-Module packaging) {
[LinkInfo] @{
Source = "/tmp/pwsh"
Destination = "/usr/bin/pwsh"
}
}
}
It "Should target Azure Linux 3 and 4 for framework-dependent RPMs" {
$distributions = & (Get-Module packaging) { $Script:RedhatFddDistributions }
$distributions | Should -Be @("cm", "azl4")
}
It "Should generate an Azure Linux 4 RPM file name for <HostArchitecture>" -TestCases @(
@{
HostArchitecture = "x86_64"
Expected = "powershell-preview-7.7.0_preview.5-1.azl4.x86_64.rpm"
}
@{
HostArchitecture = "aarch64"
Expected = "powershell-preview-7.7.0_preview.5-1.azl4.aarch64.rpm"
}
) {
param($HostArchitecture, $Expected)
Get-RpmPackageFileName `
-Name "powershell-preview" `
-Version "7.7.0-preview.5" `
-Iteration "1" `
-Distribution "azl4" `
-HostArchitecture $HostArchitecture |
Should -BeExactly $Expected
}
It "Should write the Azure Linux 4 RPM Release metadata for <HostArchitecture>" -TestCases @(
@{ HostArchitecture = "x86_64" }
@{ HostArchitecture = "aarch64" }
) {
param($HostArchitecture)
$spec = New-RpmSpec `
-Name "powershell-preview" `
-Version "7.7.0-preview.5" `
-Iteration "1" `
-Description "PowerShell test package" `
-Staging "/tmp/staging" `
-Destination "/opt/microsoft/powershell/7-preview" `
-ManGzipFile "/tmp/pwsh.1.gz" `
-ManDestination "/usr/share/man/man1/pwsh-preview.1.gz" `
-LinkInfo $linkInfo `
-Dependencies @("glibc") `
-AfterInstallScript $afterInstallScript `
-AfterRemoveScript $afterRemoveScript `
-Distribution "azl4" `
-HostArchitecture $HostArchitecture
$spec | Should -Match "(?m)^Release:\s+1\.azl4\r?$"
$spec | Should -Match "(?m)^\* .+ - 7\.7\.0_preview\.5-1\.azl4\r?$"
}
It "Should select the current master dependencies for <Distribution> with runtime <Runtime>" -TestCases @(
@{ Distribution = "cm"; Runtime = "linux-x64"; IncludeDotnetRuntime = $false }
@{ Distribution = "azl4"; Runtime = "linux-arm64"; IncludeDotnetRuntime = $false }
@{ Distribution = "cm"; Runtime = "fxdependent-linux-x64"; IncludeDotnetRuntime = $true }
@{ Distribution = "azl4"; Runtime = "fxdependent-linux-arm64"; IncludeDotnetRuntime = $true }
) {
param($Distribution, $Runtime, $IncludeDotnetRuntime)
$dependencies = & (Get-Module packaging) {
param($Distribution, $Runtime)
$previousOptions = $Script:Options
try {
$Script:Options = [pscustomobject] @{ Runtime = $Runtime }
@(Get-PackageDependencies -Distribution $Distribution)
}
finally {
$Script:Options = $previousOptions
}
} $Distribution $Runtime
$expectedDependencies = @(
"ca-certificates"
"glibc"
"icu"
"libgcc"
"libstdc++"
"openssl-libs"
"tzdata"
)
if ($IncludeDotnetRuntime) {
$expectedDependencies += "dotnet-runtime-11.0"
}
$dependencies | Should -BeExactly $expectedDependencies
}
}
Context "Azure Linux PMC mappings" {
BeforeAll {
$mappingPath = Join-Path $PSScriptRoot "../../tools/packages.microsoft.com/mapping.json"
$mapping = Get-Content -Path $mappingPath -Raw | ConvertFrom-Json
}
It "Should map <Channel> <Architecture> packages to <Url>" -TestCases @(
@{
Channel = "preview"
Architecture = "x86_64"
Url = "azurelinux-4-preview-microsoft-x86_64"
}
@{
Channel = "preview"
Architecture = "aarch64"
Url = "azurelinux-4-preview-microsoft-aarch64"
}
@{
Channel = "stable"
Architecture = "x86_64"
Url = "azurelinux-4-prod-microsoft-x86_64"
}
@{
Channel = "stable"
Architecture = "aarch64"
Url = "azurelinux-4-prod-microsoft-aarch64"
}
) {
param($Channel, $Architecture, $Url)
$mappedPackage = @($mapping.Packages | Where-Object url -EQ $Url)
$mappedPackage.Count | Should -Be 1
$mappedPackage[0].channel | Should -BeExactly $Channel
$mappedPackage[0].distribution | Should -BeExactly @("azl")
$mappedPackage[0].PackageFormat |
Should -BeExactly "PACKAGE_NAME-POWERSHELL_RELEASE-1.azl4.$Architecture.rpm"
}
It "Should remove the Azure Linux 4 beta mappings" {
@($mapping.Packages | Where-Object url -Like "azurelinux-4.0-beta-*").Count | Should -Be 0
}
It "Should retain all Azure Linux 3 .cm mappings" {
$azureLinux3Mappings = @($mapping.Packages | Where-Object url -Like "azurelinux-3.0-*")
$azureLinux3Mappings.Count | Should -Be 4
$azureLinux3Mappings.PackageFormat | Should -Match "\.cm\.(x86_64|aarch64)\.rpm$"
}
}
Context "Get-MacOSPackageIdentifierInfo function (New-MacOSPackage logic)" {
It "Should detect preview builds and return preview identifier" {
$result = Get-MacOSPackageIdentifierInfo -Version "7.6.0-preview.6" -LTS:$false
$result.IsPreview | Should -Be $true
$result.PackageIdentifier | Should -Be "com.microsoft.powershell-preview"
}
It "Should detect stable builds and return stable identifier" {
$result = Get-MacOSPackageIdentifierInfo -Version "7.6.0" -LTS:$false
$result.IsPreview | Should -Be $false
$result.PackageIdentifier | Should -Be "com.microsoft.powershell"
}
It "Should treat LTS builds as stable even with preview version string" {
$result = Get-MacOSPackageIdentifierInfo -Version "7.4.0-preview.1" -LTS:$true
$result.IsPreview | Should -Be $false
$result.PackageIdentifier | Should -Be "com.microsoft.powershell"
}
It "Should NOT use package name for preview detection (bug fix verification) - <Name>" -TestCases @(
@{ Version = "7.6.0-preview.6"; Name = "Preview" }
@{ Version = "7.6.0-rc.1"; Name = "RC" }
) {
# This test verifies the fix for issue #26673
# The bug was using ($Name -like '*-preview') which always returned false
# because preview builds use Name="powershell" not "powershell-preview"
param($Version)
# The CORRECT logic (the fix): uses version string
$result = Get-MacOSPackageIdentifierInfo -Version $Version -LTS:$false
$result.IsPreview | Should -Be $true -Because "Version string correctly identifies preview"
$result.PackageIdentifier | Should -Be "com.microsoft.powershell-preview"
}
}
}