diff --git a/tests/chocolatey-tests/commands/choco-install.Tests.ps1 b/tests/chocolatey-tests/commands/choco-install.Tests.ps1 index ae6fa5db05..6ceaaab799 100644 --- a/tests/chocolatey-tests/commands/choco-install.Tests.ps1 +++ b/tests/chocolatey-tests/commands/choco-install.Tests.ps1 @@ -1626,6 +1626,70 @@ Describe "choco install" -Tag Chocolatey, InstallCommand { } } + Context 'Installing a package with unsupported nuspec elements shows a warning' { + + BeforeDiscovery { + $testCases = @( + '' + '' + '' + '' + '' + ) + } + + BeforeAll { + Restore-ChocolateyInstallSnapshot + $nuspec = @' + + + + unsupportedmetadata + 1.0.0 + unsupportedmetadata (Install) + Chocolatey Software + unsupportedmetadata + + MIT + + + + readme.md + + true + + Test of unsupported metadata + Some metadata fields are not supported by chocolatey. `choco pack` should fail to pack them, while `choco install` or `upgrade` should allow them with a warning. + + +'@ + $tempPath = "$env:TEMP/$(New-Guid)" + $packageName = 'unsupportedmetadata' + $nuspecPath = "$tempPath/$packageName/$packageName.nuspec" + + $null = New-Item -Path "$tempPath/$packageName" -ItemType Directory + $nuspec | Set-Content -Path $nuspecPath + "readme content" | Set-Content -Path "$tempPath/$packageName/readme.md" + + $null = Invoke-Choco install nuget.commandline + $null = & "$env:ChocolateyInstall/bin/nuget.exe" pack $nuspecPath + + $Output = Invoke-Choco install $packageName --source $tempPath + } + + AfterAll { + Remove-Item $tempPath -Recurse -Force + } + + It 'Installs successfully and exits with success (0)' { + $Output.ExitCode | Should -Be 0 + } + + It 'Shows a warning about the unsupported nuspec metadata element "<_>"' -TestCases $testCases { + $Output.String | Should -Match "$_ elements are not supported in Chocolatey CLI" + } + } + # This needs to be the last test in this block, to ensure NuGet configurations aren't being created. Test-NuGetPaths } diff --git a/tests/chocolatey-tests/commands/choco-pack.Tests.ps1 b/tests/chocolatey-tests/commands/choco-pack.Tests.ps1 index b9814fc89f..a282fa8199 100644 --- a/tests/chocolatey-tests/commands/choco-pack.Tests.ps1 +++ b/tests/chocolatey-tests/commands/choco-pack.Tests.ps1 @@ -369,6 +369,62 @@ Describe "choco pack" -Tag Chocolatey, PackCommand { } } + Context 'Attempting to pack a package with unsupported nuspec elements throws an error' { + + BeforeDiscovery { + $testCases = @( + '' + '' + '' + '' + '' + ) + } + + BeforeAll { + Restore-ChocolateyInstallSnapshot + $nuspec = @' + + + + unsupportedmetadata + 1.0.0 + unsupportedmetadata (Install) + Chocolatey Software + unsupportedmetadata + + MIT + + + + readme.md + + true + + Test of unsupported metadata + Some metadata fields are not supported by chocolatey. `choco pack` should fail to pack them, while `choco install` or `upgrade` should allow them with a warning. + + +'@ + $packageName = 'unsupportedmetadata' + $nuspecPath = "$packageName\$packageName.nuspec" + + $null = New-Item -Path $packageName -ItemType Directory + $nuspec | Set-Content -Path $nuspecPath + "readme content" | Set-Content -Path "$packageName\readme.md" + + $Output = Invoke-Choco pack $nuspecPath + } + + It 'Fails to pack and exits with an error (1)' { + $Output.ExitCode | Should -Be 1 + } + + It 'Shows an error about the unsupported nuspec metadata element "<_>"' -TestCases $testCases { + $Output.String | Should -Match "$_ elements are not supported in Chocolatey CLI" + } + } + # This needs to be the last test in this block, to ensure NuGet configurations aren't being created. Test-NuGetPaths } diff --git a/tests/chocolatey-tests/commands/choco-upgrade.Tests.ps1 b/tests/chocolatey-tests/commands/choco-upgrade.Tests.ps1 index 48134ddcb4..28b0f29839 100644 --- a/tests/chocolatey-tests/commands/choco-upgrade.Tests.ps1 +++ b/tests/chocolatey-tests/commands/choco-upgrade.Tests.ps1 @@ -258,7 +258,70 @@ Describe "choco upgrade" -Tag Chocolatey, UpgradeCommand { } } + Context 'Upgrading a package with unsupported nuspec elements shows a warning' { + BeforeDiscovery { + $testCases = @( + '' + '' + '' + '' + '' + ) + } + + BeforeAll { + Restore-ChocolateyInstallSnapshot + $nuspec = @' + + + + unsupportedmetadata + 1.0.0 + unsupportedmetadata (Install) + Chocolatey Software + unsupportedmetadata + + MIT + + + + readme.md + + true + + Test of unsupported metadata + Some metadata fields are not supported by chocolatey. `choco pack` should fail to pack them, while `choco install` or `upgrade` should allow them with a warning. + + +'@ + $tempPath = "$env:TEMP/$(New-Guid)" + $packageName = 'unsupportedmetadata' + $nuspecPath = "$tempPath/$packageName/$packageName.nuspec" + + $null = New-Item -Path "$tempPath/$packageName" -ItemType Directory + $nuspec | Set-Content -Path $nuspecPath + "readme content" | Set-Content -Path "$tempPath/$packageName/readme.md" + + $null = Invoke-Choco install nuget.commandline + $null = & "$env:ChocolateyInstall/bin/nuget.exe" pack $nuspecPath + + $Output = Invoke-Choco upgrade $packageName --source $tempPath + } + + AfterAll { + Remove-Item $tempPath -Recurse -Force + } + + It 'Installs successfully and exits with success (0)' { + $Output.ExitCode | Should -Be 0 + } + + It 'Shows a warning about the unsupported nuspec metadata element "<_>"' -TestCases $testCases { + $Output.String | Should -Match "$_ elements are not supported in Chocolatey CLI" + } + } + # This needs to be the last test in this block, to ensure NuGet configurations aren't being created. Test-NuGetPaths }