Skip to content

Commit

Permalink
Merge branch 'stable'
Browse files Browse the repository at this point in the history
* stable:
  (specs) Upgrade Scenarios
  PkgSvc - Fault tolerance failure location
  (specs) fix upgrade scenario specs
  Warn about locked files
  Invoke continue action w/error / catch upgrade error
  (maint) formatting/comment
  PkgSvc - Check to see if Install Location exists
  PkgInfoSvc - do nothing if IPackage is null
  Only run posh if packageResult is successful
  (GH-10) Backup configuration files
  IFileSystem Get Files by multiple extensions
  (specs) Reduce retries on filesystem for specs
  IFileSystem - convert to Enumerate Files/Directories
  Remove container binding log initialization
  (doc) fix xml comment
  • Loading branch information
ferventcoder committed Feb 21, 2015
2 parents c59646f + 3851d9a commit 8593f6d
Show file tree
Hide file tree
Showing 13 changed files with 345 additions and 81 deletions.
7 changes: 7 additions & 0 deletions src/chocolatey.tests.integration/NUnitSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ private static void fix_application_parameter_variables(Container container)

field = typeof (ApplicationParameters).GetField("ChocolateyPackageInfoStoreLocation");
field.SetValue(null, fileSystem.combine_paths(ApplicationParameters.InstallLocation, ".chocolatey"));

// we need to speed up specs a bit, so only try filesystem locking operations twice
field = fileSystem.GetType().GetField("TIMES_TO_TRY_OPERATION", BindingFlags.Instance | BindingFlags.NonPublic);
if (field != null)
{
field.SetValue(fileSystem, 2);
}
}

private void unpack_self(Container container, ChocolateyConfiguration config)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace chocolatey.tests.integration.infrastructure.filesystem
{
using System;
using System.IO;
using System.Linq;
using NUnit.Framework;
using Should;
using chocolatey.infrastructure.filesystem;
Expand Down Expand Up @@ -80,11 +81,11 @@ public void GetFiles_should_return_files_that_meet_the_pattern()
string filePath = FileSystem.combine_paths(ContextPath, "chocolateyInstall.ps1");

FileSystem.write_file(filePath, "yo");
var actual = FileSystem.get_files(ContextPath, "chocolateyInstall.ps1", SearchOption.AllDirectories);
var actual = FileSystem.get_files(ContextPath, "chocolateyInstall.ps1", SearchOption.AllDirectories).ToList();
FileSystem.delete_file(filePath);

actual.ShouldNotBeEmpty();
actual.Count.ShouldEqual(1);
actual.Count().ShouldEqual(1);
}

[Fact]
Expand All @@ -93,11 +94,11 @@ public void GetFiles_should_return_files_that_meet_the_pattern_regardless_of_cas
string filePath = FileSystem.combine_paths(ContextPath, "chocolateyInstall.ps1");

FileSystem.write_file(filePath, "yo");
var actual = FileSystem.get_files(ContextPath, "chocolateyinstall.ps1", SearchOption.AllDirectories);
var actual = FileSystem.get_files(ContextPath, "chocolateyinstall.ps1", SearchOption.AllDirectories).ToList();
FileSystem.delete_file(filePath);

actual.ShouldNotBeEmpty();
actual.Count.ShouldEqual(1);
actual.Count().ShouldEqual(1);
}

[Fact]
Expand Down
223 changes: 201 additions & 22 deletions src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ public void should_upgrade_a_package_in_the_lib_directory()
var packageDir = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames);

Directory.Exists(packageDir).ShouldBeTrue();
}
}

[Fact]
public void should_delete_the_rollback()
{
Expand Down Expand Up @@ -315,8 +315,8 @@ public void should_upgrade_a_package_in_the_lib_directory()
var packageDir = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames);

Directory.Exists(packageDir).ShouldBeTrue();
}
}

[Fact]
public void should_delete_the_rollback()
{
Expand Down Expand Up @@ -403,7 +403,7 @@ public override void Because()
Results = Service.upgrade_run(Configuration);
_packageResult = Results.FirstOrDefault().Value;
}

[Fact]
public void should_contain_a_message_that_you_have_the_latest_version_available()
{
Expand Down Expand Up @@ -435,15 +435,15 @@ public void should_not_create_a_rollback()

Directory.Exists(packageDir).ShouldBeFalse();
}

[Fact]
public void should_not_remove_the_package_from_the_lib_directory()
{
var packageDir = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames);

Directory.Exists(packageDir).ShouldBeTrue();
}
}

[Fact]
public void should_have_a_successful_package_result()
{
Expand All @@ -461,7 +461,7 @@ public void should_not_have_warning_package_result()
{
_packageResult.Warning.ShouldBeFalse();
}

[Fact]
public void should_match_the_existing_version_of_one_dot_zero_dot_zero()
{
Expand All @@ -482,11 +482,10 @@ public override void Context()

public override void Because()
{
MockLogger.LogMessagesToConsole = true;
Results = Service.upgrade_run(Configuration);
_packageResult = Results.FirstOrDefault().Value;
}

[Fact]
public void should_contain_a_message_that_you_have_the_latest_version_available()
{
Expand Down Expand Up @@ -518,15 +517,15 @@ public void should_not_create_a_rollback()

Directory.Exists(packageDir).ShouldBeFalse();
}

[Fact]
public void should_not_remove_the_package_from_the_lib_directory()
{
var packageDir = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames);

Directory.Exists(packageDir).ShouldBeTrue();
}
}

[Fact]
public void should_have_a_successful_package_result()
{
Expand All @@ -544,7 +543,7 @@ public void should_not_have_warning_package_result()
{
_packageResult.Warning.ShouldBeFalse();
}

[Fact]
public void should_match_the_existing_version_of_one_dot_zero_dot_zero()
{
Expand Down Expand Up @@ -573,6 +572,185 @@ public void should_throw_an_error_that_it_is_not_allowed()
}
}

public class when_upgrading_an_existing_package_with_a_read_and_delete_share_locked_file : ScenariosBase
{
private PackageResult _packageResult;

private FileStream fileStream;

public override void Context()
{
base.Context();
var fileToOpen = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, "tools", "chocolateyInstall.ps1");
fileStream = new FileStream(fileToOpen, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read | FileShare.Delete);
}

public override void AfterObservations()
{
base.AfterObservations();
fileStream.Close();
}

public override void Because()
{
Results = Service.upgrade_run(Configuration);
_packageResult = Results.FirstOrDefault().Value;
}

[Fact]
public void should_upgrade_where_install_location_reports()
{
Directory.Exists(_packageResult.InstallLocation).ShouldBeTrue();
}

[Fact]
public void should_upgrade_a_package_in_the_lib_directory()
{
var packageDir = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames);

Directory.Exists(packageDir).ShouldBeTrue();
}

[Fact]
public void should_not_be_able_delete_the_rollback()
{
var packageDir = Path.Combine(Scenario.get_top_level(), "lib-bkp", Configuration.PackageNames);

Directory.Exists(packageDir).ShouldBeTrue();
}

[Fact]
public void should_contain_newer_version_in_directory()
{
var shimFile = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, "tools", "console.exe");

File.ReadAllText(shimFile).ShouldEqual("1.1.0");
}

[Fact]
public void should_contain_a_warning_message_that_it_upgraded_successfully()
{
bool upgradedSuccessMessage = false;
foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).or_empty_list_if_null())
{
if (message.Contains("upgraded 1/1")) upgradedSuccessMessage = true;
}

upgradedSuccessMessage.ShouldBeTrue();
}

[Fact]
public void should_contain_a_warning_message_with_old_and_new_versions()
{
bool upgradeMessage = false;
foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).or_empty_list_if_null())
{
if (message.Contains("You have upgradepackage v1.0.0 installed. Version 1.1.0 is available based on your source")) upgradeMessage = true;
}

upgradeMessage.ShouldBeTrue();
}
}

public class when_upgrading_an_existing_package_with_an_exclusively_locked_file : ScenariosBase
{
private PackageResult _packageResult;

private FileStream fileStream;

public override void Context()
{
base.Context();
var fileToOpen = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, "tools", "chocolateyInstall.ps1");
fileStream = new FileStream(fileToOpen, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
}

public override void AfterObservations()
{
base.AfterObservations();
fileStream.Close();
}

public override void Because()
{
Results = Service.upgrade_run(Configuration);
_packageResult = Results.FirstOrDefault().Value;
}

[Fact]
public void should_upgrade_where_install_location_reports()
{
Directory.Exists(_packageResult.InstallLocation).ShouldBeTrue();
}

[Fact]
public void should_upgrade_a_package_in_the_lib_directory()
{
var packageDir = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames);

Directory.Exists(packageDir).ShouldBeTrue();
}

[Fact]
public void should_delete_the_rollback()
{
var packageDir = Path.Combine(Scenario.get_top_level(), "lib-bkp", Configuration.PackageNames);

Directory.Exists(packageDir).ShouldBeFalse();
}

[Fact]
public void should_contain_old_version_in_directory()
{
var shimFile = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, "tools", "console.exe");

File.ReadAllText(shimFile).ShouldEqual("1.0.0");
}

[Fact]
public void should_contain_a_warning_message_that_it_was_not_able_to_upgrade()
{
bool upgradedSuccessMessage = false;
foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).or_empty_list_if_null())
{
if (message.Contains("upgraded 0/1")) upgradedSuccessMessage = true;
}

upgradedSuccessMessage.ShouldBeTrue();
}

[Fact]
public void should_contain_a_warning_message_with_old_and_new_versions()
{
bool upgradeMessage = false;
foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).or_empty_list_if_null())
{
if (message.Contains("You have upgradepackage v1.0.0 installed. Version 1.1.0 is available based on your source")) upgradeMessage = true;
}

upgradeMessage.ShouldBeTrue();
}

[Fact]
public void should_not_have_a_successful_package_result()
{
_packageResult.Success.ShouldBeFalse();
}

[Fact]
public void should_not_have_inconclusive_package_result()
{
_packageResult.Inconclusive.ShouldBeFalse();
}

[Fact]
public void should_not_have_warning_package_result()
{
_packageResult.Warning.ShouldBeFalse();
}

}

public class when_upgrading_a_package_with_added_files : ScenariosBase
{
private PackageResult _packageResult;
Expand All @@ -597,7 +775,7 @@ public void should_keep_the_added_file()

File.Exists(fileAdded).ShouldBeTrue();
}

[Fact]
public void should_contain_newer_version_in_directory()
{
Expand Down Expand Up @@ -641,8 +819,8 @@ public void should_match_the_upgrade_version_of_one_dot_one_dot_zero()
{
_packageResult.Version.ShouldEqual("1.1.0");
}
}
}

public class when_upgrading_a_package_with_changed_files : ScenariosBase
{
private PackageResult _packageResult;
Expand All @@ -665,9 +843,9 @@ public void should_update_the_changed_file()
{
var fileChanged = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, "tools", "chocolateyInstall.ps1");

File.ReadAllText(fileChanged).ShouldEqual("hellow");
File.ReadAllText(fileChanged).ShouldNotEqual("hellow");
}

[Fact]
public void should_contain_newer_version_in_directory()
{
Expand Down Expand Up @@ -742,12 +920,12 @@ public void should_contain_a_message_the_package_was_not_found()
}

[Fact]
public void should_contain_a_message_that_no_packages_can_be_upgraded()
public void should_contain_a_message_that_no_packages_were_upgraded()
{
bool expectedMessage = false;
foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).or_empty_list_if_null())
{
if (message.Contains("upgraded 0/0")) expectedMessage = true;
if (message.Contains("upgraded 0/1")) expectedMessage = true;
}

expectedMessage.ShouldBeTrue();
Expand Down Expand Up @@ -891,5 +1069,6 @@ public void should_have_expected_error_in_package_result()
//pinned package upgrade scenario
//open a file in package folder (holding lock)
//upgrade dependencies
//when upgrading a file that has locked dependency
}
}
2 changes: 1 addition & 1 deletion src/chocolatey/GetChocolatey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private void set_defaults()
/// <summary>
/// This is an optional helper to give you the correct settings for a logger. You can still set this in the set by calling propConfig.Logger without having to call this method.
/// </summary>
/// <param name="logger">This is the logger you want RoundhousE to also use.</param>
/// <param name="logger">This is the logger you want Chocolatey to also use.</param>
/// <returns></returns>
public GetChocolatey SetCustomLogging(ILog logger)
{
Expand Down
Loading

0 comments on commit 8593f6d

Please sign in to comment.