Skip to content

Commit

Permalink
Merge branch 'stable'
Browse files Browse the repository at this point in the history
* stable:
  (maint) formatting
  (spec) Ensure MockLogger is setup first in test suite
  (specs) Allow for nupkgs to finish copying
  (specs) use deep copy for config
  (GH-516) Fix: Log.InitializeWith doesn't clear cached loggers
  (GH-445) Only fail scripts on non-zero exit code
  (GH-510) allow silentargs in template
  • Loading branch information
ferventcoder committed Dec 23, 2015
2 parents 6f0b7be + 4643bab commit 01ea40d
Show file tree
Hide file tree
Showing 15 changed files with 280 additions and 55 deletions.
74 changes: 39 additions & 35 deletions src/chocolatey.tests.integration/NUnitSetup.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// 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.
Expand All @@ -15,10 +15,12 @@

namespace chocolatey.tests.integration
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;
using NUnit.Framework;
using SimpleInjector;
using chocolatey.infrastructure.app;
Expand All @@ -41,57 +43,59 @@ public override void BeforeEverything()
{
Container = SimpleInjectorContainer.Container;
fix_application_parameter_variables(Container);
var config = Container.GetInstance<ChocolateyConfiguration>();
config.Information.PlatformType = PlatformType.Windows;
//config.Information.IsInteractive = false;
//config.PromptForConfirmation = false;

var force = config.Force;
base.BeforeEverything();

// deep copy so we don't have the same configuration and
// don't have to worry about issues using it
var config = Container.GetInstance<ChocolateyConfiguration>().deep_copy();
config.Information.PlatformType = PlatformType.Windows;
config.Information.IsInteractive = false;
config.PromptForConfirmation = false;
config.Force = true;
unpack_self(Container, config);
build_packages(Container, config);
unpack_self(Container,config);
config.Force = force;

base.BeforeEverything();

ConfigurationBuilder.set_up_configuration(new List<string>(), config, Container.GetInstance<IFileSystem>(), Container.GetInstance<IXmlService>(), null);

MockLogger.reset();
}

/// <summary>
/// Most of the application parameters are already set by runtime and are readonly values.
/// They need to be updated, so we can do that with reflection.
/// Most of the application parameters are already set by runtime and are readonly values.
/// They need to be updated, so we can do that with reflection.
/// </summary>
private static void fix_application_parameter_variables(Container container)
{
var fileSystem = container.GetInstance<IFileSystem>();

var applicationLocation = fileSystem.get_directory_name(fileSystem.get_current_assembly_path());

var field = typeof (ApplicationParameters).GetField("InstallLocation");
var field = typeof(ApplicationParameters).GetField("InstallLocation");
field.SetValue(null, applicationLocation);

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

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

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

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

field = typeof (ApplicationParameters).GetField("PackageFailuresLocation");
field = typeof(ApplicationParameters).GetField("PackageFailuresLocation");
field.SetValue(null, fileSystem.combine_paths(ApplicationParameters.InstallLocation, "lib-bad"));

field = typeof(ApplicationParameters).GetField("PackageBackupLocation");
field.SetValue(null, fileSystem.combine_paths(ApplicationParameters.InstallLocation, "lib-bkp"));

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

field = typeof (ApplicationParameters).GetField("ChocolateyPackageInfoStoreLocation");
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
Expand All @@ -104,44 +108,44 @@ private static void fix_application_parameter_variables(Container container)

private void unpack_self(Container container, ChocolateyConfiguration config)
{
var unpackCommand = container.GetInstance<ChocolateyUnpackSelfCommand>();
var unpackCommand = container.GetInstance<ChocolateyUnpackSelfCommand>();
unpackCommand.run(config);
}

private void build_packages(Container container, ChocolateyConfiguration config)
{
var input = config.Input;

var fileSystem = container.GetInstance<IFileSystem>();
var contextDir = fileSystem.combine_paths(fileSystem.get_directory_name(fileSystem.get_current_assembly_path()), "context");

// short-circuit building packages if they are already there.
if (fileSystem.get_files(contextDir, "*.nupkg").Any())
{
System.Console.WriteLine("Packages have already been built. Skipping... - If you need to rebuild packages, delete all nupkg files in {0}.".format_with(contextDir));
Console.WriteLine("Packages have already been built. Skipping... - If you need to rebuild packages, delete all nupkg files in {0}.".format_with(contextDir));
return;
}

var files = fileSystem.get_files(contextDir, "*.nuspec", SearchOption.AllDirectories);
var command = container.GetInstance<ChocolateyPackCommand>();

var command = container.GetInstance<ChocolateyPackCommand>();
foreach (var file in files.or_empty_list_if_null())
{
config.Input = file;
System.Console.WriteLine("Building {0}".format_with(file));
Console.WriteLine("Building {0}".format_with(file));
command.run(config);
}

System.Console.WriteLine("Moving all nupkgs in {0} to context directory.".format_with(fileSystem.get_current_directory()));
Console.WriteLine("Moving all nupkgs in {0} to context directory.".format_with(fileSystem.get_current_directory()));
var nupkgs = fileSystem.get_files(fileSystem.get_current_directory(), "*.nupkg");

foreach (var nupkg in nupkgs.or_empty_list_if_null())
{
fileSystem.copy_file(nupkg,fileSystem.combine_paths(contextDir,fileSystem.get_file_name(nupkg)),overwriteExisting:true);
fileSystem.copy_file(nupkg, fileSystem.combine_paths(contextDir, fileSystem.get_file_name(nupkg)), overwriteExisting: true);
fileSystem.delete_file(nupkg);
}

config.Input = input;

//concurrency issues when packages are first built out during testing
Thread.Sleep(2000);
Console.WriteLine("Continuing with tests now after waiting for files to finish moving.");
}
}

Expand Down
23 changes: 7 additions & 16 deletions src/chocolatey.tests.integration/Scenario.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,13 @@ public static void install_package(ChocolateyConfiguration config, string packag
{
_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);
//}
var installConfig = config.deep_copy();

installConfig.PackageNames = packageId;
installConfig.Version = version;
_service.install_run(installConfig);

NUnitSetup.MockLogger.Messages.Clear();
}

private static ChocolateyConfiguration baseline_configuration()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,12 @@
<None Include="context\dependencies\isexactversiondependency\2.0.0\tools\chocolateyuninstall.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\nonterminatingerror\1.0\nonterminatingerror.nuspec">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\nonterminatingerror\1.0\tools\chocolateyInstall.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\testing.packages.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>nonterminatingerror</id>
<version>1.0</version>
<authors>Rob Reynolds</authors>
<owners>Rob Reynolds</owners>
<description>nonterminating - This package errors during install with a non-terminating error</description>
</metadata>
<files>
<file src="tools\**" target="tools" />
</files>
</package>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Write-Error "Oh no! An error"
Loading

0 comments on commit 01ea40d

Please sign in to comment.