Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(GH-121) Capture And Remove Files Related to Package Installation #270

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Scenarios.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
* should install where install location reports
* should not create a shim for ignored executable in the bin directory
* should not create a shim for mismatched case ignored executable in the bin directory
* should not create an extensions folder for the pacakge
* should not create an extensions folder for the package
* should not have inconclusive package result
* should not have warning package result

Expand Down Expand Up @@ -315,7 +315,7 @@
* should not have inconclusive package result
* should not have warning package result

### ChocolateyUninstallCommand [ 12 Scenario(s), 82 Observation(s) ]
### ChocolateyUninstallCommand [ 12 Scenario(s), 83 Observation(s) ]

#### when force uninstalling a package

Expand Down Expand Up @@ -359,6 +359,7 @@
* should contain a warning message that it uninstalled successfully
* should delete a shim for console in the bin directory
* should delete a shim for graphical in the bin directory
* should delete any files created during the install
* should delete the rollback
* should have a successful package result
* should not have inconclusive package result
Expand Down
27 changes: 22 additions & 5 deletions src/chocolatey.tests.integration/Scenario.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@ namespace chocolatey.tests.integration
using chocolatey.infrastructure.app.configuration;
using chocolatey.infrastructure.app.domain;
using chocolatey.infrastructure.app.nuget;
using chocolatey.infrastructure.app.services;
using chocolatey.infrastructure.filesystem;

public class Scenario
{

private static IChocolateyPackageService _service;

private static readonly DotNetFileSystem _fileSystem = new DotNetFileSystem();

public static string get_top_level()
Expand Down Expand Up @@ -79,13 +83,26 @@ public static void add_packages_to_source_location(ChocolateyConfiguration confi

public static void install_package(ChocolateyConfiguration config, string packageId, string version)
{
var pattern = "{0}.{1}{2}".format_with(packageId, string.IsNullOrWhiteSpace(version) ? "*" : version, Constants.PackageExtension);
var files = _fileSystem.get_files(config.Sources, pattern);
foreach (var file in files)
if (_service == null)
{
var packageManager = NugetCommon.GetPackageManager(config,new ChocolateyNugetLogger(), null, null, false);
packageManager.InstallPackage(new OptimizedZipPackage(file), false,false);
_service= NUnitSetup.Container.GetInstance<IChocolateyPackageService>();
}

var originalPackageName = config.PackageNames;
var originalPackageVersion = config.Version;

config.PackageNames = packageId;
config.Version = version;
_service.install_run(config);
config.PackageNames = originalPackageName;
config.Version = originalPackageVersion;
//var pattern = "{0}.{1}{2}".format_with(packageId, string.IsNullOrWhiteSpace(version) ? "*" : version, Constants.PackageExtension);
//var files = _fileSystem.get_files(config.Sources, pattern);
//foreach (var file in files)
//{
// var packageManager = NugetCommon.GetPackageManager(config, new ChocolateyNugetLogger(), null, null, false);
// packageManager.InstallPackage(new OptimizedZipPackage(file), false,false);
//}
}

private static ChocolateyConfiguration baseline_configuration()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="infrastructure\commands\CommandExecutorSpecs.cs" />
<Compile Include="infrastructure\cryptography\CrytpoHashProviderSpecs.cs" />
<Compile Include="infrastructure\filesystem\DotNetFileSystemSpecs.cs" />
<Compile Include="MockEventSubscriptionManager.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
Write-Output "$env:PackageName $env:PackageVersion Installed"
$toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"
"simple file" | Out-File "$toolsDir\simplefile.txt" -force

Write-Output "$env:PackageName $env:PackageVersion Installed"

Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright © 2011 - Present 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.

namespace chocolatey.tests.integration.infrastructure.cryptography
{
using System;
using System.IO;
using System.Reflection;
using System.Security.Cryptography;
using Should;
using chocolatey.infrastructure.cryptography;
using chocolatey.infrastructure.filesystem;

public class CrytpoHashProviderSpecs
{
public abstract class CrytpoHashProviderSpecsBase : TinySpec
{
protected CrytpoHashProvider Provider;
protected DotNetFileSystem FileSystem;
protected string ContextDirectory;

public override void Context()
{
FileSystem = new DotNetFileSystem();
Provider = new CrytpoHashProvider(FileSystem,CryptoHashProviderType.Md5);
ContextDirectory = FileSystem.combine_paths(FileSystem.get_directory_name(Assembly.GetExecutingAssembly().CodeBase.Replace("file:///", string.Empty)), "context");
}
}

public class when_HashProvider_provides_a_hash : CrytpoHashProviderSpecsBase
{
private string result;
private string filePath;

public override void Context()
{
base.Context();
filePath = FileSystem.combine_paths(ContextDirectory, "testing.packages.config");
}

public override void Because()
{
result = Provider.hash_file(filePath);
}

[Fact]
public void should_provide_the_correct_hash_based_on_a_checksum()
{
var expected = BitConverter.ToString(MD5.Create().ComputeHash(File.ReadAllBytes(filePath))).Replace("-", string.Empty);

result.ShouldEqual(expected);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public override void Because()
{
if (FileSystem.directory_exists(TestDirectory))
{
Directory.Delete(TestDirectory);
Directory.Delete(TestDirectory, recursive: true);
}

FileSystem.create_directory(TestDirectory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,14 @@ public void should_delete_a_shim_for_graphical_in_the_bin_directory()
File.Exists(shimfile).ShouldBeFalse();
}

[Fact]
public void should_delete_any_files_created_during_the_install()
{
var generatedFile = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames,"simplefile.txt");

File.Exists(generatedFile).ShouldBeFalse();
}

[Fact]
public void should_contain_a_warning_message_that_it_uninstalled_successfully()
{
Expand Down
20 changes: 10 additions & 10 deletions src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1562,7 +1562,7 @@ public override void Context()
string dotChocolatey = Path.Combine(Scenario.get_top_level(), ".chocolatey");
if (Directory.Exists(dotChocolatey))
{
Directory.Delete(dotChocolatey);
Directory.Delete(dotChocolatey, recursive: true);
}
}

Expand All @@ -1584,8 +1584,8 @@ public void should_remove_the_legacy_folder_version_of_the_package()
{
var packageDir = Path.Combine(Scenario.get_top_level(), "lib", "isdependency.1.0.0");
Directory.Exists(packageDir).ShouldBeFalse();
}
}

[Fact]
public void should_replace_the_legacy_folder_version_of_the_package_with_a_lib_package_folder_that_has_no_version()
{
Expand All @@ -1599,15 +1599,15 @@ public void should_not_upgrade_the_parent_package()
var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "hasdependency.1.0.0", "hasdependency.1.0.0.nupkg");
var package = new OptimizedZipPackage(packageFile);
package.Version.Version.to_string().ShouldEqual("1.0.0.0");
}
}

[Fact]
public void should_not_add_a_versionless_parent_package_folder_to_the_lib_dir()
{
var packageDir = Path.Combine(Scenario.get_top_level(), "lib", "hasdependency");
Directory.Exists(packageDir).ShouldBeFalse();
}
}

[Fact]
public void should_leave_the_parent_package_as_legacy_folder()
{
Expand Down Expand Up @@ -1635,7 +1635,7 @@ public void should_not_add_a_versionless_exact_version_package_folder_to_the_lib
{
var packageDir = Path.Combine(Scenario.get_top_level(), "lib", "isexactversiondependency");
Directory.Exists(packageDir).ShouldBeFalse();
}
}

[Fact]
public void should_contain_a_message_the_dependency_upgraded_successfully()
Expand Down Expand Up @@ -1778,7 +1778,7 @@ public override void Context()
string dotChocolatey = Path.Combine(Scenario.get_top_level(), ".chocolatey");
if (Directory.Exists(dotChocolatey))
{
Directory.Delete(dotChocolatey);
Directory.Delete(dotChocolatey, recursive: true);
}
}

Expand Down Expand Up @@ -1853,7 +1853,7 @@ public void should_remove_the_legacy_folder_version_of_the_exact_version_package
{
var packageDir = Path.Combine(Scenario.get_top_level(), "lib", "isexactversiondependency.1.0.0");
Directory.Exists(packageDir).ShouldBeFalse();
}
}

[Fact]
public void should_contain_a_message_that_everything_upgraded_successfully()
Expand Down
3 changes: 3 additions & 0 deletions src/chocolatey.tests/chocolatey.tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,14 @@
<Compile Include="infrastructure.app\commands\ChocolateyUpgradeCommandSpecs.cs" />
<Compile Include="infrastructure.app\configuration\ConfigurationOptionsSpec.cs" />
<Compile Include="infrastructure.app\services\AutomaticUninstallerServiceSpecs.cs" />
<Compile Include="infrastructure.app\services\FilesServiceSpecs.cs" />
<Compile Include="infrastructure.app\services\NugetServiceSpecs.cs" />
<Compile Include="infrastructure\commands\ExternalCommandArgsBuilderSpecs.cs" />
<Compile Include="infrastructure\commandline\InteractivePromptSpecs.cs" />
<Compile Include="infrastructure\commands\CommandExecutorSpecs.cs" />
<Compile Include="infrastructure\commands\PowershellExecutorSpecs.cs" />
<Compile Include="infrastructure\configuration\ConfigSpecs.cs" />
<Compile Include="infrastructure\cryptography\CrytpoHashProvider.cs" />
<Compile Include="infrastructure\events\context\FakeEvent.cs" />
<Compile Include="infrastructure\events\context\FakeSubscriber.cs" />
<Compile Include="infrastructure\events\EventSubscriptionManagerSpecs.cs" />
Expand Down
Loading