Skip to content

Commit 43dfcbb

Browse files
SCAN4NET-101 Run tests for package generation script (#2215)
1 parent 0481189 commit 43dfcbb

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

azure-pipelines.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ stages:
105105
SM_API_KEY: $(SM_API_KEY)
106106
SM_CERT: $(SM_CERT)
107107
108-
109108
- powershell: .\scripts\promote-project-version.ps1
110109
displayName: 'Promote project version'
111110

@@ -225,6 +224,11 @@ stages:
225224
inputs:
226225
secureFile: 'maven-settings.xml'
227226

227+
- powershell: |
228+
Install-Module -Name Pester -Force -SkipPublisherCheck # https://pester.dev/docs/introduction/installation#windows
229+
Invoke-Pester -Output Detailed -CI -Script .\scripts\generate-packages.tests.ps1
230+
displayName: 'Test package generation script'
231+
228232
- powershell: |
229233
. .\scripts\generate-packages.ps1
230234
Run

scripts/generate-packages.ps1

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,17 @@
1313
# Due to this, when calling `choco pack` the version should not contain the build number (9.0.0-rc).
1414
# At the same time the the url inside the ps1 file that downloads the scanner should be correct and contain the build number.
1515

16+
[CmdletBinding()]
1617
param (
17-
[string] $sourcesDirectory = $env:BUILD_SOURCESDIRECTORY,
18-
[string] $buildId = $env:BUILD_BUILDID
18+
[Parameter()]
19+
[AllowNull()]
20+
[string]
21+
$sourcesDirectory = $env:BUILD_SOURCESDIRECTORY,
22+
23+
[Parameter()]
24+
[AllowNull()]
25+
[string]
26+
$buildId = $env:BUILD_BUILDID
1927
)
2028

2129
function Update-Choco-Package([string] $scannerZipFileName, [string] $runtimeSuffix) {

scripts/generate-packages.tests.ps1

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,22 +69,19 @@ Describe 'Choco package generation' {
6969
@{ Version = '1.2.3'; PreReleaseSuffix = '-rc'; ExpectedShortVersion = '1.2.3-rc'; ExpectedFullVersion = '1.2.3-rc.99116' }
7070
@{ Version = '1.2.3'; PreReleaseSuffix = ''; ExpectedShortVersion = '1.2.3'; ExpectedFullVersion = '1.2.3.99116' }
7171
) {
72+
$unzipLocation = '$(Split-Path -parent $MyInvocation.MyCommand.Definition)'
73+
$expectedChocoInstallContents = @('Install-ChocolateyZipPackage "sonarscanner-net-framework" `',
74+
" -Url ""https://github.com/SonarSource/sonar-scanner-msbuild/releases/download/$ExpectedFullVersion/sonar-scanner-$ExpectedFullVersion-net-framework.zip"" ``",
75+
" -UnzipLocation ""$unzipLocation"" ``",
76+
" -ChecksumType 'sha256' ``",
77+
" -Checksum E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855")
7278
Set-Version $Version $PreReleaseSuffix
73-
7479
. $PSScriptRoot/generate-packages.ps1 -sourcesDirectory . -buildId 99116
7580

76-
Update-Choco-Package $netFrameworkScannerZipPath 'net-framework'
77-
78-
$unzipLocation = '$(Split-Path -parent $MyInvocation.MyCommand.Definition)'
79-
Get-Content -Raw 'nuspec/chocolatey/chocolateyInstall-net-framework.ps1' | Should -BeExactly "Install-ChocolateyZipPackage ""sonarscanner-net-framework"" ``
80-
-Url ""https://github.com/SonarSource/sonar-scanner-msbuild/releases/download/$ExpectedFullVersion/sonar-scanner-$ExpectedFullVersion-net-framework.zip"" ``
81-
-UnzipLocation ""$unzipLocation"" ``
82-
-ChecksumType 'sha256' ``
83-
-Checksum E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855
84-
"
81+
Update-Choco-Package "$PSScriptRoot/testcontext/build/sonarscanner-net-framework.zip" 'net-framework'
8582

83+
Get-Content 'nuspec/chocolatey/chocolateyInstall-net-framework.ps1' | Should -Be $expectedChocoInstallContents
8684
"build/sonarscanner-net-framework.$ExpectedShortVersion.nupkg" | Should -Exist
87-
8885
CheckVersion "sonarscanner-net-framework.$ExpectedShortVersion.nupkg" 'sonarscanner-net-framework.nuspec' "<version>$ExpectedShortVersion</version>"
8986
}
9087
}

0 commit comments

Comments
 (0)