Skip to content

Commit

Permalink
(chocolatey#2787) Add tests for side-by-side deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
AdmiringWorm committed Sep 15, 2022
1 parent c3de6e7 commit 9e4c4bc
Show file tree
Hide file tree
Showing 7 changed files with 258 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/CodeMaid.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="SteveCadwallader.CodeMaid.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</sectionGroup>
</configSections>
<userSettings>
<SteveCadwallader.CodeMaid.Properties.Settings>
<setting name="Cleaning_UpdateFileHeader_HeaderUpdateMode" serializeAs="String">
<value>1</value>
</setting>
<setting name="Cleaning_UpdateFileHeaderCSharp" serializeAs="String">
<value>// Copyright © 2017 - 2022 Chocolatey Software, Inc
// Copyright © 2011 - 2017 RealDimensions Software, LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
//
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.</value>
</setting>
<setting name="Cleaning_AutoCleanupOnFileSave" serializeAs="String">
<value>True</value>
</setting>
<setting name="Cleaning_InsertEndOfFileTrailingNewLine" serializeAs="String">
<value>True</value>
</setting>
</SteveCadwallader.CodeMaid.Properties.Settings>
</userSettings>
</configuration>
16 changes: 16 additions & 0 deletions src/chocolatey.tests.integration/scenarios/InstallScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1408,6 +1408,22 @@ public void should_contain_a_warning_message_that_it_installed_successfully()
installedSuccessfully.ShouldBeTrue();
}

[Fact]
public void should_contain_a_warning_message_that_installing_package_with_multiple_versions_being_deprecated()
{
const string expected = "Installing the same package with multiple versions is deprecated and will be removed in v2.0.0.";

foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).or_empty_list_if_null())
{
if (message.Contains(expected))
{
return;
}
}

Assert.Fail("No warning message about side by side deprecation outputted");
}

[Fact]
public void should_have_a_successful_package_result()
{
Expand Down
17 changes: 17 additions & 0 deletions tests/chocolatey-tests/choco-info.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,21 @@ Describe "choco info" -Tag Chocolatey, InfoCommand {
$Output.Lines | Should -Contain "${Title}: $Value"
}
}

Context "Listing package information about local side by side installed package" {
BeforeAll {
$null = Invoke-Choco install 'isdependency' --confirm --sxs

$Output = Invoke-Choco info 'isdependency' --local-only
}

It "Exits with Success (0)" {
$Output.ExitCode | Should -Be 0
}

It "Outputs a warning message that installed side by side package is deprecated" {
$Output.Lines | Should -Contain "isdependency has been installed as a side by side installation." -Because $Output.String
$Output.Lines | Should -Contain "Side by side installations are deprecated and is pending removal in v2.0.0." -Because $Output.String
}
}
}
17 changes: 17 additions & 0 deletions tests/chocolatey-tests/choco-install.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,10 @@ Describe "choco install" -Tag Chocolatey, InstallCommand {
$XML.package.metadata.version | Should -Be "1.0.0"
}

It "Outputs a warning message about side by side installs are deprecated" {
$Output.Lines | Should -Contain "Installing the same package with multiple versions is deprecated and will be removed in v2.0.0." -Because $Output.String
}

It "Outputs a message indicating that it installed the package successfully" {
$Output.Lines | Should -Contain "Chocolatey installed 1/1 packages."
}
Expand Down Expand Up @@ -599,6 +603,10 @@ Describe "choco install" -Tag Chocolatey, InstallCommand {
$XML.package.metadata.version | Should -Be "1.0.0"
}

It "Outputs a warning message about side by side installs are deprecated" {
$Output.Lines | Should -Contain "Installing the same package with multiple versions is deprecated and will be removed in v2.0.0." -Because $Output.String
}

It "Outputs a message indicating that it installed the package successfully" {
$Output.Lines | Should -Contain "Chocolatey installed 1/1 packages."
}
Expand Down Expand Up @@ -629,6 +637,15 @@ Describe "choco install" -Tag Chocolatey, InstallCommand {
$XML.package.metadata.version | Should -Be "1.0.0"
}

It "Does not output a warning message about side by side installs are deprecated" {
$Output.Lines | Should -Not -Contain "Installing the same package with multiple versions is deprecated and will be removed in v2.0.0." -Because $Output.String
}

It "Does not output a warning message that installed side by side package is deprecated" {
$Output.Lines | Should -Not -Contain "installpackage has been installed as a side by side installation." -Because $Output.String
$Output.Lines | Should -Not -Contain "Side by side installations are deprecated and is pending removal in v2.0.0." -Because $Output.String
}

It "Outputs a message indicating that it installed the package successfully" {
$Output.Lines | Should -Contain "Chocolatey installed 1/1 packages."
}
Expand Down
5 changes: 5 additions & 0 deletions tests/chocolatey-tests/choco-list.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ Describe "choco <_>" -ForEach $Command -Tag Chocolatey, ListCommand, SearchComma
It "Shows version <_> of local package" -ForEach @("2.0.0"; "1.1.0") {
$Output.Lines | Should -Contain "isdependency $_"
}

It "Outputs a warning message that installed side by side package is deprecated" {
$Output.Lines | Should -Contain "isdependency has been installed as a side by side installation."
$Output.Lines | Should -Contain "Side by side installations are deprecated and is pending removal in v2.0.0."
}
}

Context "Searching packages with Verbose" {
Expand Down
43 changes: 43 additions & 0 deletions tests/chocolatey-tests/choco-uninstall.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Import-Module helpers/common-helpers

Describe "choco uninstall" -Tag Chocolatey, UninstallCommand {
BeforeAll {
Initialize-ChocolateyTestInstall

New-ChocolateyInstallSnapshot
}

AfterAll {
Remove-ChocolateyTestInstall
}

Context "Uninstalling a side-by-side Package" {
BeforeAll {
Restore-ChocolateyInstallSnapshot

$PackageUnderTest = "installpackage"

$null = Invoke-Choco upgrade $PackageUnderTest --confirm --allowmultipleversions

$Output = Invoke-Choco uninstall $PackageUnderTest --confirm
}

It "Exits with Success (0)" {
$Output.ExitCode | Should -Be 0
}

It "Removed a package to the lib directory" {
"$env:ChocolateyInstall\lib\$($PackageUnderTest).1.0.0" | Should -Not -Exist
"$env:ChocolateyInstall\lib-bad\$($PackageUnderTest).1.0.0" | Should -Not -Exist
}

It "Outputs a warning message that installed side by side package is deprecated" {
$Output.Lines | Should -Contain "$PackageUnderTest has been installed as a side by side installation." -Because $Output.String
$Output.Lines | Should -Contain "Side by side installations are deprecated and is pending removal in v2.0.0." -Because $Output.String
}

It "Outputs a message indicating that it uninstalled the package successfully" {
$Output.Lines | Should -Contain "Chocolatey uninstalled 1/1 packages." -Because $Output.String
}
}
}
122 changes: 122 additions & 0 deletions tests/chocolatey-tests/choco-upgrade.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
Import-Module helpers/common-helpers

Describe "choco upgrade" -Tag Chocolatey, UpgradeCommand {
BeforeAll {
Initialize-ChocolateyTestInstall

New-ChocolateyInstallSnapshot
}

AfterAll {
Remove-ChocolateyTestInstall
}

Context "Upgrading a side-by-side Package (non-existing)" {
BeforeAll {
Restore-ChocolateyInstallSnapshot

$PackageUnderTest = "installpackage"

$Output = Invoke-Choco upgrade $PackageUnderTest --confirm --allowmultipleversions
}

It "Exits with Success (0)" {
$Output.ExitCode | Should -Be 0
}

It "Installed a package to the lib directory" {
"$env:ChocolateyInstall\lib\$($PackageUnderTest).1.0.0" | Should -Exist
}

It "Installs the expected version of the package" {
"$env:ChocolateyInstall\lib\$($PackageUnderTest).1.0.0\$($PackageUnderTest).1.0.0.nuspec" | Should -Exist
[xml]$XML = Get-Content "$env:ChocolateyInstall\lib\$($PackageUnderTest).1.0.0\$($PackageUnderTest).1.0.0.nuspec"
$XML.package.metadata.version | Should -Be "1.0.0"
}

It "Outputs a warning message about side by side installs are deprecated" {
$Output.Lines | Should -Contain "Upgrading the same package with multiple versions is deprecated and will be removed in v2.0.0." -Because $Output.String
}

It "Outputs a message indicating that it upgraded the package successfully" {
$Output.Lines | Should -Contain "Chocolatey upgraded 1/1 packages." -Because $Output.String
}
}

Context "Switching a normal Package to a side-by-side Package" {
BeforeAll {
Restore-ChocolateyInstallSnapshot

$PackageUnderTest = "installpackage"

$null = Invoke-Choco install $PackageUnderTest --confirm

$Output = Invoke-Choco upgrade $PackageUnderTest --confirm --force --allowmultipleversions
}

It "Exits with Success (0)" {
$Output.ExitCode | Should -Be 0
}

It "Installed the package to the lib directory" {
"$env:ChocolateyInstall\lib\$($PackageUnderTest).1.0.0" | Should -Exist
}

It "Removed the previous version of the package from the lib directory" {
"$env:ChocolateyInstall\lib\$($PackageUnderTest)" | Should -Not -Exist
}

It "Installs the expected version of the package" {
"$env:ChocolateyInstall\lib\$($PackageUnderTest).1.0.0\$($PackageUnderTest).1.0.0.nuspec" | Should -Exist
[xml]$XML = Get-Content "$env:ChocolateyInstall\lib\$($PackageUnderTest).1.0.0\$($PackageUnderTest).1.0.0.nuspec"
$XML.package.metadata.version | Should -Be "1.0.0"
}

It "Outputs a warning message about side by side installs are deprecated" {
$Output.Lines | Should -Contain "Upgrading the same package with multiple versions is deprecated and will be removed in v2.0.0." -Because $Output.String
}

It "Outputs a message indicating that it upgraded the package successfully" {
$Output.Lines | Should -Contain "Chocolatey upgraded 1/1 packages." -Because $Output.String
}
}

Context "Switching a side-by-side Package to a normal Package" {
BeforeAll {
Restore-ChocolateyInstallSnapshot

$PackageUnderTest = "installpackage"

$null = Invoke-Choco install $PackageUnderTest --confirm --allowmultipleversion

$Output = Invoke-Choco upgrade $PackageUnderTest --confirm --force
}

It "Exits with Success (0)" {
$Output.ExitCode | Should -Be 0
}

It "Installed the package to the lib directory" {
"$env:ChocolateyInstall\lib\$($PackageUnderTest)" | Should -Exist
}

It "Installs the expected version of the package" {
"$env:ChocolateyInstall\lib\$($PackageUnderTest)\$($PackageUnderTest).nuspec" | Should -Exist
[xml]$XML = Get-Content "$env:ChocolateyInstall\lib\$($PackageUnderTest)\$($PackageUnderTest).nuspec"
$XML.package.metadata.version | Should -Be "1.0.0"
}

It "Does not output a warning message about side by side installs are deprecated" {
$Output.Lines | Should -Not -Contain "Upgrading the same package with multiple versions is deprecated and will be removed in v2.0.0." -Because $Output.String
}

It "Does not output a warning message that installed side by side package is deprecated" {
$Output.Lines | Should -Not -Contain "installpackage has been installed as a side by side installation." -Because $Output.String
$Output.Lines | Should -Not -Contain "Side by side installations are deprecated and is pending removal in v2.0.0." -Because $Output.String
}

It "Outputs a message indicating that it upgraded the package successfully" {
$Output.Lines | Should -Contain "Chocolatey upgraded 1/1 packages." -Because $Output.String
}
}
}

0 comments on commit 9e4c4bc

Please sign in to comment.