Skip to content

Commit

Permalink
Merge branch 'stable'
Browse files Browse the repository at this point in the history
* stable: (27 commits)
  (maint) formatting
  (GH-170) Add outdated command
  (maint) move magic string to constants
  (maint) Command specs for new options
  (maint) harden removing install files
  (GH-121) backup changed files
  (GH-121) IFilesService capture files by directory
  (GH-121) Remove package checksum
  (maint) renaming results to appropriate singular
  (GH-121) Remove empty directories / scenarios
  (maint) comment
  (maint) prefix "[NuGet]" on Nuget logger
  (GH-121) Remove unchanged files on uninstall
  (GH-121) Specs and Files Service hardening
  (GH-121) Capture file hashes
  (GH-121) specs for Md5HashProvider
  (GH-121) Add hash provider
  (GH-121) IFileSystem.read_file_bytes
  (GH-121) PkgInfoService files service interaction
  (GH-121) Add files service
  ...
  • Loading branch information
ferventcoder committed May 15, 2015
2 parents a7de809 + 9c1bfe1 commit e2c46c3
Show file tree
Hide file tree
Showing 44 changed files with 1,729 additions and 116 deletions.
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
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,10 @@ param(
# only set if urls are different
if ($url32bit -ne $url64bit) {
$checksum = $checksum64
if ($checkSumType64 -ne '') {
$checksumType = $checksumType64
}
}

$checksumType = $checksumType64
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ param(
[string] $packageName,
[string] $url,
[string] $unzipLocation,
[string] $url64bit = $url,
[string] $url64bit = '',
[string] $specificFolder ="",
[string] $checksum = '',
[string] $checksumType = '',
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
4 changes: 4 additions & 0 deletions src/chocolatey.tests/chocolatey.tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
<Compile Include="infrastructure.app\commands\ChocolateyInstallCommandSpecs.cs" />
<Compile Include="infrastructure.app\commands\ChocolateyListCommandSpecs.cs" />
<Compile Include="infrastructure.app\commands\ChocolateyNewCommandSpecs.cs" />
<Compile Include="infrastructure.app\commands\ChocolateyOutdatedCommandSpecs.cs" />
<Compile Include="infrastructure.app\commands\ChocolateyPackCommandSpecs.cs" />
<Compile Include="infrastructure.app\commands\ChocolateyPinCommandSpecs.cs" />
<Compile Include="infrastructure.app\commands\ChocolateyPushCommandSpecs.cs" />
Expand All @@ -77,11 +78,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
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,31 @@ public void should_add_short_version_of_skippowershell_to_the_option_set()
{
optionSet.Contains("n").ShouldBeTrue();
}

[Fact]
public void should_add_user_to_the_option_set()
{
optionSet.Contains("user").ShouldBeTrue();
}

[Fact]
public void should_add_short_version_of_user_to_the_option_set()
{
optionSet.Contains("u").ShouldBeTrue();
}

[Fact]
public void should_add_password_to_the_option_set()
{
optionSet.Contains("password").ShouldBeTrue();
}

[Fact]
public void should_add_short_version_of_password_to_the_option_set()
{
optionSet.Contains("p").ShouldBeTrue();
}

}

public class when_handling_additional_argument_parsing : ChocolateyInstallCommandSpecsBase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,31 @@ public void should_add_short_version_of_allversions_to_the_option_set()
{
optionSet.Contains("a").ShouldBeTrue();
}

[Fact]
public void should_add_user_to_the_option_set()
{
optionSet.Contains("user").ShouldBeTrue();
}

[Fact]
public void should_add_short_version_of_user_to_the_option_set()
{
optionSet.Contains("u").ShouldBeTrue();
}

[Fact]
public void should_add_password_to_the_option_set()
{
optionSet.Contains("password").ShouldBeTrue();
}

[Fact]
public void should_add_short_version_of_password_to_the_option_set()
{
optionSet.Contains("p").ShouldBeTrue();
}

}

public class when_handling_additional_argument_parsing : ChocolateyListCommandSpecsBase
Expand Down
Loading

0 comments on commit e2c46c3

Please sign in to comment.