Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- DotNetFileSystem.when_setting_file_attributes_with_dotNetFileSystem
-
DotNetFileSystem.when_removing_readonly_attributes_with_dotNetFileSystem
- UpgradeScenarios.when_upgrading_a_package_with_readonly_files
- UninstallScenarios.when_uninstalling_a_package_with_readonly_files
  • Loading branch information
ferventcoder committed Sep 17, 2015
1 parent f7b750a commit 61a6dfc
Show file tree
Hide file tree
Showing 7 changed files with 288 additions and 10 deletions.
26 changes: 24 additions & 2 deletions Scenarios.md
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@
* should not have inconclusive package result
* should not have warning package result

### ChocolateyUninstallCommand [ 12 Scenario(s), 84 Observation(s) ]
### ChocolateyUninstallCommand [ 13 Scenario(s), 90 Observation(s) ]

#### when force uninstalling a package

Expand Down Expand Up @@ -464,11 +464,20 @@
* should not have inconclusive package result
* should not have warning package result

#### when uninstalling a package with readonly files

* should contain a message that it uninstalled successfully
* should delete the rollback
* should have a successful package result
* should not have inconclusive package result
* should not have warning package result
* should uninstall the package from the lib directory

#### when uninstalling packages with packages config

* should throw an error that it is not allowed

### ChocolateyUpgradeCommand [ 25 Scenario(s), 204 Observation(s) ]
### ChocolateyUpgradeCommand [ 26 Scenario(s), 214 Observation(s) ]

#### when force upgrading a package

Expand Down Expand Up @@ -708,6 +717,19 @@
* should upgrade the minimum version dependency
* should upgrade the package

#### when upgrading a package with readonly files

* should contain a warning message that it upgraded successfully
* should contain a warning message with old and new versions
* should contain newer version in directory
* should delete the rollback
* should have a successful package result
* should not have inconclusive package result
* should not have warning package result
* should upgrade a package in the lib directory
* should upgrade the package
* should upgrade where install location reports

#### when upgrading a package with unavailable dependencies

* should contain a message that it was unable to upgrade anything
Expand Down
16 changes: 8 additions & 8 deletions src/chocolatey.tests.integration/Scenario.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ public static void reset(ChocolateyConfiguration config)
string backupPackagesPath = get_package_install_path() + "-bkp";
string shimsPath = ApplicationParameters.ShimsLocation;

_fileSystem.delete_directory_if_exists(config.CacheLocation, recursive: true);
_fileSystem.delete_directory_if_exists(config.Sources, recursive: true);
_fileSystem.delete_directory_if_exists(packagesInstallPath, recursive: true);
_fileSystem.delete_directory_if_exists(shimsPath, recursive: true);
_fileSystem.delete_directory_if_exists(badPackagesPath, recursive: true);
_fileSystem.delete_directory_if_exists(backupPackagesPath, recursive: true);
_fileSystem.delete_directory_if_exists(_fileSystem.combine_paths(get_top_level(), ".chocolatey"), recursive: true);
_fileSystem.delete_directory_if_exists(_fileSystem.combine_paths(get_top_level(), "extensions"), recursive: true);
_fileSystem.delete_directory_if_exists(config.CacheLocation, recursive: true, overrideAttributes: true);
_fileSystem.delete_directory_if_exists(config.Sources, recursive: true, overrideAttributes: true);
_fileSystem.delete_directory_if_exists(packagesInstallPath, recursive: true, overrideAttributes: true);
_fileSystem.delete_directory_if_exists(shimsPath, recursive: true, overrideAttributes: true);
_fileSystem.delete_directory_if_exists(badPackagesPath, recursive: true, overrideAttributes: true);
_fileSystem.delete_directory_if_exists(backupPackagesPath, recursive: true, overrideAttributes: true);
_fileSystem.delete_directory_if_exists(_fileSystem.combine_paths(get_top_level(), ".chocolatey"), recursive: true, overrideAttributes: true);
_fileSystem.delete_directory_if_exists(_fileSystem.combine_paths(get_top_level(), "extensions"), recursive: true, overrideAttributes: true);

_fileSystem.create_directory(config.CacheLocation);
_fileSystem.create_directory(config.Sources);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@
<Content Include="infrastructure\filesystem\MoveMe.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="infrastructure\filesystem\context\attributes.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="infrastructure\filesystem\Slipsum.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,57 @@ public void GetDirectories_should_return_a_string_array_with_directories()
}
}

[Category("Integration")]
public class when_setting_file_attributes_with_dotNetFileSystem : DotNetFileSystemSpecsBase
{
public override void Context()
{
base.Context();
SourceFile = Path.Combine(DestinationPath, "attributes.txt");
File.SetAttributes(SourceFile, (FileSystem.get_file_info_for(SourceFile).Attributes | FileAttributes.Hidden));
}

public override void Because()
{
FileSystem.ensure_file_attribute_set(SourceFile,FileAttributes.Hidden);
}

[Fact]
public void visible_file_should_now_be_hidden()
{
(FileSystem.get_file_info_for(SourceFile).Attributes & FileAttributes.Hidden).ShouldEqual(FileAttributes.Hidden);
}

public override void AfterObservations()
{
base.AfterObservations();
File.SetAttributes(SourceFile, (FileSystem.get_file_info_for(SourceFile).Attributes | FileAttributes.Hidden));
}
}


[Category("Integration")]
public class when_removing_readonly_attributes_with_dotNetFileSystem : DotNetFileSystemSpecsBase
{
public override void Context()
{
base.Context();
SourceFile = Path.Combine(DestinationPath, "attributes.txt");
File.SetAttributes(SourceFile, (FileSystem.get_file_info_for(SourceFile).Attributes | FileAttributes.ReadOnly));
}

public override void Because()
{
FileSystem.ensure_file_attribute_removed(SourceFile,FileAttributes.ReadOnly);
}

[Fact]
public void readonly_file_should_no_longer_be_readonly()
{
(FileSystem.get_file_info_for(SourceFile).Attributes & FileAttributes.ReadOnly).ShouldNotEqual(FileAttributes.ReadOnly);
}
}

[Category("Integration")]
public class when_running_fileMove_with_dotNetFileSystem : DotNetFileSystemSpecsBase
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!-- start slipsum code -->

The path of the righteous man is beset on all sides by the iniquities of the selfish and the tyranny of evil men. Blessed is he who, in the name of charity and good will, shepherds the weak through the valley of darkness, for he is truly his brother's keeper and the finder of lost children. And I will strike down upon thee with great vengeance and furious anger those who would attempt to poison and destroy My brothers. And you will know My name is the Lord when I lay My vengeance upon thee.

You see? It's curious. Ted did figure it out - time travel. And when we get back, we gonna tell everyone. How it's possible, how it's done, what the dangers are. But then why fifty years in the future when the spacecraft encounters a black hole does the computer call it an 'unknown entry event'? Why don't they know? If they don't know, that means we never told anyone. And if we never told anyone it means we never made it back. Hence we die down here. Just as a matter of deductive logic.

You see? It's curious. Ted did figure it out - time travel. And when we get back, we gonna tell everyone. How it's possible, how it's done, what the dangers are. But then why fifty years in the future when the spacecraft encounters a black hole does the computer call it an 'unknown entry event'? Why don't they know? If they don't know, that means we never told anyone. And if we never told anyone it means we never made it back. Hence we die down here. Just as a matter of deductive logic.

The lysine contingency - it's intended to prevent the spread of the animals is case they ever got off the island. Dr. Wu inserted a gene that makes a single faulty enzyme in protein metabolism. The animals can't manufacture the amino acid lysine. Unless they're continually supplied with lysine by us, they'll slip into a coma and die.

Do you see any Teletubbies in here? Do you see a slender plastic tag clipped to my shirt with my name printed on it? Do you see a little Asian child with a blank expression on his face sitting outside on a mechanical helicopter that shakes when you put quarters in it? No? Well, that's what you see at a toy store. And you must think you're in a toy store, because you're here shopping for an infant named Jeb.

Yeah, I like animals better than people sometimes... Especially dogs. Dogs are the best. Every time you come home, they act like they haven't seen you in a year. And the good thing about dogs... is they got different dogs for different people. Like pit bulls. The dog of dogs. Pit bull can be the right man's best friend... or the wrong man's worst enemy. You going to give me a dog for a pet, give me a pit bull. Give me... Raoul. Right, Omar? Give me Raoul.

Like you, I used to think the world was this great place where everybody lived by the same standards I did, then some kid with a nail showed me I was living in his world, a world where chaos rules not order, a world where righteousness is not rewarded. That's Cesar's world, and if you're not willing to play by his rules, then you're gonna have to pay the price.

The lysine contingency - it's intended to prevent the spread of the animals is case they ever got off the island. Dr. Wu inserted a gene that makes a single faulty enzyme in protein metabolism. The animals can't manufacture the amino acid lysine. Unless they're continually supplied with lysine by us, they'll slip into a coma and die.

You see? It's curious. Ted did figure it out - time travel. And when we get back, we gonna tell everyone. How it's possible, how it's done, what the dangers are. But then why fifty years in the future when the spacecraft encounters a black hole does the computer call it an 'unknown entry event'? Why don't they know? If they don't know, that means we never told anyone. And if we never told anyone it means we never made it back. Hence we die down here. Just as a matter of deductive logic.

You think water moves fast? You should see ice. It moves like it has a mind. Like it knows it killed the world once and got a taste for murder. After the avalanche, it took us a week to climb out. Now, I don't know exactly when we turned on each other, but I know that seven of us survived the slide... and only five made it out. Now we took an oath, that I'm breaking now. We said we'd say it was the snow that killed the other two, but it wasn't. Nature is lethal but it doesn't hold a candle to man.

Like you, I used to think the world was this great place where everybody lived by the same standards I did, then some kid with a nail showed me I was living in his world, a world where chaos rules not order, a world where righteousness is not rewarded. That's Cesar's world, and if you're not willing to play by his rules, then you're gonna have to pay the price.

Do you see any Teletubbies in here? Do you see a slender plastic tag clipped to my shirt with my name printed on it? Do you see a little Asian child with a blank expression on his face sitting outside on a mechanical helicopter that shakes when you put quarters in it? No? Well, that's what you see at a toy store. And you must think you're in a toy store, because you're here shopping for an infant named Jeb.

<!-- please do not remove this line -->

<div style="display:none;">
<a href="http://slipsum.com">lorem ipsum</a></div>

<!-- end slipsum code -->
68 changes: 68 additions & 0 deletions src/chocolatey.tests.integration/scenarios/UninstallScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace chocolatey.tests.integration.scenarios
using chocolatey.infrastructure.app.configuration;
using chocolatey.infrastructure.app.services;
using chocolatey.infrastructure.commands;
using chocolatey.infrastructure.filesystem;
using chocolatey.infrastructure.results;
using IFileSystem = chocolatey.infrastructure.filesystem.IFileSystem;

Expand Down Expand Up @@ -328,6 +329,73 @@ public void should_throw_an_error_that_it_is_not_allowed()
}
}

[Concern(typeof(ChocolateyUninstallCommand))]
public class when_uninstalling_a_package_with_readonly_files : ScenariosBase
{
private PackageResult _packageResult;

public override void Context()
{
base.Context();
var fileToSetReadOnly = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, "tools", "chocolateyInstall.ps1");
var fileSystem = new DotNetFileSystem();
fileSystem.ensure_file_attribute_set(fileToSetReadOnly, FileAttributes.ReadOnly);
}

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

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

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

[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_a_message_that_it_uninstalled_successfully()
{
bool expectedMessage = false;
foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).or_empty_list_if_null())
{
if (message.Contains("uninstalled 1/1")) expectedMessage = true;
}

expectedMessage.ShouldBeTrue();
}

[Fact]
public void should_have_a_successful_package_result()
{
_packageResult.Success.ShouldBeTrue();
}

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

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

[Concern(typeof (ChocolateyUninstallCommand))]
public class when_uninstalling_a_package_with_a_read_and_delete_share_locked_file : ScenariosBase
{
Expand Down
102 changes: 102 additions & 0 deletions src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace chocolatey.tests.integration.scenarios
using chocolatey.infrastructure.app.commands;
using chocolatey.infrastructure.app.configuration;
using chocolatey.infrastructure.app.services;
using chocolatey.infrastructure.filesystem;
using chocolatey.infrastructure.results;

public class UpgradeScenarios
Expand Down Expand Up @@ -615,6 +616,107 @@ public void should_throw_an_error_that_it_is_not_allowed()
}
}

[Concern(typeof(ChocolateyUpgradeCommand))]
public class when_upgrading_a_package_with_readonly_files : ScenariosBase
{
private PackageResult _packageResult;


public override void Context()
{
base.Context();
var fileToSetReadOnly = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, "tools", "chocolateyInstall.ps1");
var fileSystem = new DotNetFileSystem();
fileSystem.ensure_file_attribute_set(fileToSetReadOnly, FileAttributes.ReadOnly);
}

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_upgrade_the_package()
{
var packageFile = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, Configuration.PackageNames + Constants.PackageExtension);
var package = new OptimizedZipPackage(packageFile);
package.Version.Version.to_string().ShouldEqual("1.1.0.0");
}

[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_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();
}

[Fact]
public void should_have_a_successful_package_result()
{
_packageResult.Success.ShouldBeTrue();
}

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

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

[Concern(typeof (ChocolateyUpgradeCommand))]
public class when_upgrading_a_package_with_a_read_and_delete_share_locked_file : ScenariosBase
{
Expand Down

0 comments on commit 61a6dfc

Please sign in to comment.