Skip to content

Commit 7acbd15

Browse files
committed
(chocolatey#1092) Add tests for dependencies' beforeModify
This test added ensures that when we are upgrading a package, both its own and any dependencies' beforeModify are run so that we can properly update dependencies which might need to shut down a long-running service before being upgraded. (cherry picked from commit 49cc8d7) # Conflicts: # src/chocolatey.tests.integration/chocolatey.tests.integration.csproj # src/chocolatey.tests.integration/scenarios/InstallScenarios.cs # src/chocolatey.tests.integration/scenarios/UninstallScenarios.cs # src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs
1 parent 89ea677 commit 7acbd15

23 files changed

+447
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
3+
<metadata>
4+
<id>hasdependencywithbeforemodify</id>
5+
<version>1.0.0</version>
6+
<title>hasdependencywithbeforemodify</title>
7+
<authors>__REPLACE_AUTHORS_OF_SOFTWARE__</authors>
8+
<owners>__REPLACE_YOUR_NAME__</owners>
9+
<requireLicenseAcceptance>false</requireLicenseAcceptance>
10+
<description>__REPLACE__</description>
11+
<summary>__REPLACE__</summary>
12+
<releaseNotes />
13+
<copyright />
14+
<tags>hasdependencywithbeforemodify admin</tags>
15+
<dependencies>
16+
<dependency id="isdependencywithbeforemodify" version="[1.0.0, 2.0.0.0)" />
17+
</dependencies>
18+
</metadata>
19+
<files>
20+
<file src="tools\**" target="tools" />
21+
</files>
22+
</package>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Write-Output "Ran BeforeModify: $env:PackageName $env:PackageVersion"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Write-Output "$env:PackageName $env:PackageVersion Installed"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Write-Output "$env:PackageName $env:PackageVersion Uninstalled"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This package is used to test out upgrade behaviour with beforeModify scripts in play for the main package and dependencies.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
3+
<metadata>
4+
<id>hasdependencywithbeforemodify</id>
5+
<version>2.0.0</version>
6+
<title>hasdependencywithbeforemodify</title>
7+
<authors>__REPLACE_AUTHORS_OF_SOFTWARE__</authors>
8+
<owners>__REPLACE_YOUR_NAME__</owners>
9+
<requireLicenseAcceptance>false</requireLicenseAcceptance>
10+
<description>__REPLACE__</description>
11+
<summary>__REPLACE__</summary>
12+
<releaseNotes />
13+
<copyright />
14+
<tags>hasdependencywithbeforemodify admin</tags>
15+
<dependencies>
16+
<dependency id="isdependencywithbeforemodify" version="[2.0.0, 3.0.0.0)" />
17+
</dependencies>
18+
</metadata>
19+
<files>
20+
<file src="tools\**" target="tools" />
21+
</files>
22+
</package>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Write-Output "Ran BeforeModify: $env:PackageName $env:PackageVersion"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Write-Output "$env:PackageName $env:PackageVersion Installed"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Write-Output "$env:PackageName $env:PackageVersion Uninstalled"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This package is used to test out upgrade behaviour with beforeModify scripts in play for the main package and dependencies.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0"?>
2+
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
3+
<metadata>
4+
<id>isdependencywithbeforemodify</id>
5+
<version>1.0.0</version>
6+
<title>isdependencywithbeforemodify</title>
7+
<authors>__REPLACE_AUTHORS_OF_SOFTWARE__</authors>
8+
<owners>__REPLACE_YOUR_NAME__</owners>
9+
<requireLicenseAcceptance>false</requireLicenseAcceptance>
10+
<description>__REPLACE__</description>
11+
<summary>__REPLACE__</summary>
12+
<releaseNotes />
13+
<tags>isdependencywithbeforemodify admin</tags>
14+
</metadata>
15+
<files>
16+
<file src="tools\**" target="tools" />
17+
</files>
18+
</package>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Write-Output "Ran BeforeModify: $env:PackageName $env:PackageVersion"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Write-Output "$env:PackageName $env:PackageVersion Installed"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Write-Output "$env:PackageName $env:PackageVersion Uninstalled"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This package is used to test out upgrade behaviour with beforeModify scripts in play for the main package and dependencies.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0"?>
2+
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
3+
<metadata>
4+
<id>isdependencywithbeforemodify</id>
5+
<version>2.0.0</version>
6+
<title>isdependencywithbeforemodify</title>
7+
<authors>__REPLACE_AUTHORS_OF_SOFTWARE__</authors>
8+
<owners>__REPLACE_YOUR_NAME__</owners>
9+
<requireLicenseAcceptance>false</requireLicenseAcceptance>
10+
<description>__REPLACE__</description>
11+
<summary>__REPLACE__</summary>
12+
<releaseNotes />
13+
<tags>isdependencywithbeforemodify admin</tags>
14+
</metadata>
15+
<files>
16+
<file src="tools\**" target="tools" />
17+
</files>
18+
</package>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Write-Output "Ran BeforeModify: $env:PackageName $env:PackageVersion"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Write-Output "$env:PackageName $env:PackageVersion Installed"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Write-Output "$env:PackageName $env:PackageVersion Uninstalled"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This package is used to test out upgrade behaviour with beforeModify scripts in play for the main package and dependencies.

src/chocolatey.tests.integration/scenarios/InstallScenarios.cs

+99
Original file line numberDiff line numberDiff line change
@@ -5461,5 +5461,104 @@ public override void Context()
54615461
Configuration.Version = NonNormalizedVersion;
54625462
}
54635463
}
5464+
5465+
public class when_installing_a_package_that_requires_updating_a_dependency : ScenariosBase
5466+
{
5467+
private const string TargetPackageName = "hasdependencywithbeforemodify";
5468+
private const string DependencyName = "isdependencywithbeforemodify";
5469+
5470+
public override void Context()
5471+
{
5472+
base.Context();
5473+
5474+
Scenario.add_packages_to_source_location(Configuration, "{0}.*".format_with(TargetPackageName) + NuGetConstants.PackageExtension);
5475+
Scenario.add_packages_to_source_location(Configuration, "{0}.*".format_with(DependencyName) + NuGetConstants.PackageExtension);
5476+
Scenario.install_package(Configuration, DependencyName, "1.0.0");
5477+
5478+
Configuration.PackageNames = Configuration.Input = TargetPackageName;
5479+
}
5480+
5481+
public override void Because()
5482+
{
5483+
Results = Service.install_run(Configuration);
5484+
}
5485+
5486+
[Fact]
5487+
public void should_install_the_package()
5488+
{
5489+
var packageFile = Path.Combine(Scenario.get_top_level(), "lib", TargetPackageName, "{0}.nupkg".format_with(TargetPackageName));
5490+
using (var packageReader = new PackageArchiveReader(packageFile))
5491+
{
5492+
packageReader.NuspecReader.GetVersion().to_string().ShouldEqual("2.0.0");
5493+
}
5494+
}
5495+
5496+
[Fact]
5497+
public void should_upgrade_the_minimum_version_dependency()
5498+
{
5499+
var packageFile = Path.Combine(Scenario.get_top_level(), "lib", DependencyName, "{0}.nupkg".format_with(DependencyName));
5500+
using (var packageReader = new PackageArchiveReader(packageFile))
5501+
{
5502+
packageReader.NuspecReader.GetVersion().to_string().ShouldEqual("2.0.0");
5503+
}
5504+
}
5505+
5506+
[Fact]
5507+
public void should_contain_a_message_that_everything_installed_successfully()
5508+
{
5509+
MockLogger.contains_message("installed 2/2", LogLevel.Warn).ShouldBeTrue();
5510+
}
5511+
5512+
[Fact]
5513+
[WindowsOnly]
5514+
[Platform(Exclude = "Mono")]
5515+
public void should_not_run_target_package_beforeModify_for_upgraded_version()
5516+
{
5517+
MockLogger.contains_message("Ran BeforeModify: {0} {1}".format_with(TargetPackageName, "2.0.0"), LogLevel.Info).ShouldBeFalse();
5518+
}
5519+
5520+
[Fact]
5521+
[WindowsOnly]
5522+
[Platform(Exclude = "Mono")]
5523+
public void should_run_already_installed_dependency_package_beforeModify()
5524+
{
5525+
MockLogger.contains_message("Ran BeforeModify: {0} {1}".format_with(DependencyName, "1.0.0"), LogLevel.Info).ShouldBeTrue();
5526+
}
5527+
5528+
[Fact]
5529+
[WindowsOnly]
5530+
[Platform(Exclude = "Mono")]
5531+
public void should_not_run_dependency_package_beforeModify_for_upgraded_version()
5532+
{
5533+
MockLogger.contains_message("Ran BeforeModify: {0} {1}".format_with(DependencyName, "2.0.0"), LogLevel.Info).ShouldBeFalse();
5534+
}
5535+
5536+
[Fact]
5537+
public void should_have_a_successful_package_result()
5538+
{
5539+
foreach (var packageResult in Results)
5540+
{
5541+
packageResult.Value.Success.ShouldBeTrue();
5542+
}
5543+
}
5544+
5545+
[Fact]
5546+
public void should_not_have_inconclusive_package_result()
5547+
{
5548+
foreach (var packageResult in Results)
5549+
{
5550+
packageResult.Value.Inconclusive.ShouldBeFalse();
5551+
}
5552+
}
5553+
5554+
[Fact]
5555+
public void should_not_have_warning_package_result()
5556+
{
5557+
foreach (var packageResult in Results)
5558+
{
5559+
packageResult.Value.Warning.ShouldBeFalse();
5560+
}
5561+
}
5562+
}
54645563
}
54655564
}

src/chocolatey.tests.integration/scenarios/UninstallScenarios.cs

+88
Original file line numberDiff line numberDiff line change
@@ -1527,5 +1527,93 @@ public void should_have_executed_chocolateyUninstall_script()
15271527
MockLogger.contains_message("upgradepackage {0} Uninstalled".format_with(NonNormalizedVersion), LogLevel.Info).ShouldBeTrue();
15281528
}
15291529
}
1530+
1531+
public class when_uninstalling_a_package_with_remove_dependencies_with_beforeModify : ScenariosBase
1532+
{
1533+
private const string TargetPackageName = "hasdependencywithbeforemodify";
1534+
private const string DependencyName = "isdependencywithbeforemodify";
1535+
1536+
public override void Context()
1537+
{
1538+
base.Context();
1539+
1540+
Scenario.add_packages_to_source_location(Configuration, "{0}.*".format_with(TargetPackageName) + NuGetConstants.PackageExtension);
1541+
Scenario.add_packages_to_source_location(Configuration, "{0}.*".format_with(DependencyName) + NuGetConstants.PackageExtension);
1542+
Scenario.install_package(Configuration, TargetPackageName, "1.0.0");
1543+
Scenario.install_package(Configuration, DependencyName, "1.0.0");
1544+
1545+
Configuration.PackageNames = Configuration.Input = TargetPackageName;
1546+
Configuration.ForceDependencies = true;
1547+
}
1548+
1549+
public override void Because()
1550+
{
1551+
Results = Service.uninstall_run(Configuration);
1552+
}
1553+
1554+
[Fact]
1555+
public void should_uninstall_the_package()
1556+
{
1557+
var packageFile = Path.Combine(Scenario.get_top_level(), "lib", TargetPackageName, "{0}.nupkg".format_with(TargetPackageName));
1558+
File.Exists(packageFile).ShouldBeFalse();
1559+
}
1560+
1561+
[Fact]
1562+
public void should_uninstall_the_dependency()
1563+
{
1564+
var packageFile = Path.Combine(Scenario.get_top_level(), "lib", DependencyName, "{0}.nupkg".format_with(DependencyName));
1565+
File.Exists(packageFile).ShouldBeFalse();
1566+
}
1567+
1568+
[Fact]
1569+
public void should_contain_a_message_that_everything_uninstalled_successfully()
1570+
{
1571+
MockLogger.contains_message("uninstalled 2/2", LogLevel.Warn).ShouldBeTrue();
1572+
}
1573+
1574+
[Fact]
1575+
[WindowsOnly]
1576+
[Platform(Exclude = "Mono")]
1577+
public void should_run_target_package_beforeModify()
1578+
{
1579+
MockLogger.contains_message("Ran BeforeModify: {0} {1}".format_with(TargetPackageName, "1.0.0"), LogLevel.Info).ShouldBeTrue();
1580+
}
1581+
1582+
[Fact]
1583+
[WindowsOnly]
1584+
[Platform(Exclude = "Mono")]
1585+
public void should_run_dependency_package_beforeModify()
1586+
{
1587+
MockLogger.contains_message("Ran BeforeModify: {0} {1}".format_with(DependencyName, "1.0.0"), LogLevel.Info).ShouldBeTrue();
1588+
}
1589+
1590+
[Fact]
1591+
public void should_have_a_successful_package_result()
1592+
{
1593+
foreach (var packageResult in Results)
1594+
{
1595+
packageResult.Value.Success.ShouldBeTrue();
1596+
}
1597+
}
1598+
1599+
[Fact]
1600+
public void should_not_have_inconclusive_package_result()
1601+
{
1602+
foreach (var packageResult in Results)
1603+
{
1604+
packageResult.Value.Inconclusive.ShouldBeFalse();
1605+
}
1606+
}
1607+
1608+
[Fact]
1609+
public void should_not_have_warning_package_result()
1610+
{
1611+
foreach (var packageResult in Results)
1612+
{
1613+
packageResult.Value.Warning.ShouldBeFalse();
1614+
}
1615+
1616+
}
1617+
}
15301618
}
15311619
}

0 commit comments

Comments
 (0)