Skip to content

Commit

Permalink
Added Homebrew uninstall
Browse files Browse the repository at this point in the history
- Added uninstall provider methods
- Added unit tests
- Added integration tests
  • Loading branch information
RLittlesII committed Mar 24, 2018
1 parent 6ca48e4 commit c849585
Show file tree
Hide file tree
Showing 11 changed files with 389 additions and 33 deletions.
1 change: 1 addition & 0 deletions recipe.cake
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ BuildParameters.SetParameters(context: Context,
repositoryName: "Cake.Homebrew",
appVeyorAccountName: "RLittlesII",
shouldRunInspectCode: false,
shouldRunDupFinder: false,
shouldRunDotNetCorePack: true,
shouldRunCodecov: false,
integrationTestScriptPath: "./tests/integration/test.cake");
Expand Down
72 changes: 59 additions & 13 deletions src/Cake.Homebrew.Tests/HomebrewProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,52 +12,98 @@ public sealed class HomebrewProviderTests
{
private static ICakeContext Context => Substitute.For<ICakeContext>();

public sealed class TheInstallMethod
public sealed class TheConstructor
{
[OSXFact]
public void Should_Throw_If_Context_Null()
public void Should_Throw_If_Context_Null_OSX()
{
// Given
var provider = new HomebrewProvider(null);
// Given, When
var result = Record.Exception(() =>
{
var provider = new HomebrewProvider(null);
});

// When
var result = Record.Exception(() => provider.Install(new HomebrewSettings()));
//Then
Assert.IsType<ArgumentNullException>(result);
Assert.Equal("Value cannot be null.\nParameter name: context", result.Message);
}

[WindowsFact]
public void Should_Throw_If_Context_Null_Windows()
{
// Given, When
var result = Record.Exception(() =>
{
var provider = new HomebrewProvider(null);
});

//Then
Assert.IsType<ArgumentNullException>(result);
Assert.Equal("Value cannot be null.\nParameter name: _context", result.Message);
Assert.Equal("Value cannot be null.\r\nParameter name: context", result.Message);
}
}

public sealed class TheInstallActionMethod
{

[OSXFact]
public void Should_Throw_If_Context_Null()
public void Should_Throw_If_Configurator_Null_OSX()
{
// Given
var provider = new HomebrewProvider(null);
var provider = new HomebrewProvider(Context);

// When
var result = Record.Exception(() => provider.Install(new HomebrewSettings()));
var result = Record.Exception(() => provider.Install((Action<HomebrewSettings>)null));

//Then
Assert.IsType<ArgumentNullException>(result);
Assert.Equal("Value cannot be null.\nParameter name: _context", result.Message);
Assert.Equal("Value cannot be null.\nParameter name: configurator", result.Message);
}

[OSXFact]
public void Should_Throw_If_Configurator_Null()
[WindowsFact]
public void Should_Throw_If_Configurator_Null_Windows()
{
// Given
var provider = new HomebrewProvider(Context);

// When
var result = Record.Exception(() => provider.Install((Action<HomebrewSettings>)null));

//Then
Assert.IsType<ArgumentNullException>(result);
Assert.Equal("Value cannot be null.\r\nParameter name: configurator", result.Message);
}
}

public sealed class TheUninstallActionMethod
{
[OSXFact]
public void Should_Throw_If_Configurator_Null_OSX()
{
// Given
var provider = new HomebrewProvider(Context);

// When
var result = Record.Exception(() => provider.Uninstall((Action<HomebrewSettings>)null));

//Then
Assert.IsType<ArgumentNullException>(result);
Assert.Equal("Value cannot be null.\nParameter name: configurator", result.Message);
}

[WindowsFact]
public void Should_Throw_If_Configurator_Null_Windows()
{
// Given
var provider = new HomebrewProvider(Context);

// When
var result = Record.Exception(() => provider.Uninstall((Action<HomebrewSettings>)null));

//Then
Assert.IsType<ArgumentNullException>(result);
Assert.Equal("Value cannot be null.\r\nParameter name: configurator", result.Message);
}
}
}
}
20 changes: 19 additions & 1 deletion src/Cake.Homebrew.Tests/OSFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Cake.Homebrew.Tests
{
public sealed class OSXFact : FactAttribute
internal sealed class OSXFact : FactAttribute
{
private static readonly PlatformFamily Family;

Expand All @@ -23,4 +23,22 @@ public OSXFact(string reason = null)
}
}
}

internal sealed class WindowsFact : FactAttribute
{
private static readonly PlatformFamily Family;

static WindowsFact()
{
Family = EnvironmentHelper.GetPlatformFamily();
}

public WindowsFact(string reason = null)
{
if (Family != PlatformFamily.Windows)
{
Skip = reason ?? "Windows test.";
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Cake.Homebrew.Tests.Runner;

namespace Cake.Homebrew.Tests.Uninstall
{
internal class HomebrewUninstallRunnerFixture : HomebrewRunnerFixture
{
public HomebrewUninstallRunnerFixture() : base("uninstall")
{
}
}
}
157 changes: 157 additions & 0 deletions src/Cake.Homebrew.Tests/Uninstall/HomebrewUninstallRunnerTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
using System;
using Cake.Core;
using Cake.Homebrew.Tests.Install;
using Cake.Testing;
using Xunit;

namespace Cake.Homebrew.Tests.Uninstall
{
public sealed class HomebrewUninstallRunnerTests
{
public sealed class TheRunMethod
{
[Theory]
[InlineData("/bin/tools/Homebrew/Homebrew.exe", "/bin/tools/Homebrew/Homebrew.exe")]
[InlineData("./tools/Homebrew/Homebrew.exe", "/Working/tools/Homebrew/Homebrew.exe")]
public void Should_Use_Homebrew_Runner_From_Tool_Path_If_Provided(string toolPath, string expected)
{
// Given
var fixture = new HomebrewUninstallRunnerFixture();
fixture.Settings.ToolPath = toolPath;
fixture.GivenSettingsToolPathExist();

// When
var result = fixture.Run();

// Then
Assert.Equal(expected, result.Path.FullPath);
}

[Fact]
public void Should_Find_Homebrew_Runner_If_Tool_Path_Not_Provided()
{
// Given
var fixture = new HomebrewUninstallRunnerFixture();

// When
var result = fixture.Run();

// Then
Assert.Equal("/Working/tools/brew", result.Path.FullPath);
}

[Fact]
public void Should_Set_Working_Directory()
{
// Given
var fixture = new HomebrewUninstallRunnerFixture();

// When
var result = fixture.Run();

// Then
Assert.Equal("/Working", result.Process.WorkingDirectory.FullPath);
}

[Fact]
public void Should_Throw_If_Homebrew_Runner_Was_Not_Found()
{
// Given
var fixture = new HomebrewUninstallRunnerFixture();
fixture.GivenDefaultToolDoNotExist();

// When
var result = Record.Exception(() => fixture.Run());

// Then
Assert.IsType<CakeException>(result);
Assert.Equal("brew: Could not locate executable.", result?.Message);
}

[Fact]
public void Should_Throw_If_Process_Has_A_Non_Zero_Exit_Code()
{
// Given
var fixture = new HomebrewUninstallRunnerFixture();
fixture.GivenProcessExitsWithCode(1);

// When
var result = Record.Exception(() => fixture.Run());

// Then
Assert.IsType<CakeException>(result);
Assert.Equal("brew: Process returned an error (exit code 1).", result?.Message);
}

[Fact]
public void Should_Throw_If_Process_Was_Not_Started()
{
// Given
var fixture = new HomebrewUninstallRunnerFixture();
fixture.GivenProcessCannotStart();

// When
var result = Record.Exception(() => fixture.Run());

// Then
Assert.IsType<CakeException>(result);
Assert.Equal("brew: Process was not started.", result?.Message);
}

[Fact]
public void Should_Throw_If_Settings_Is_Null()
{
// Given
var fixture = new HomebrewUninstallRunnerFixture();
fixture.Settings = null;

// When
var result = Record.Exception(() => fixture.Run());

// Then
Assert.IsType<ArgumentNullException>(result);
}

[Fact]
public void Should_Add_Formula_If_Provided()
{
// Given
var fixure = new HomebrewUninstallRunnerFixture();

// When
var result = fixure.Run();

// Then
Assert.Equal("uninstall cake", result.Args);
}

[Fact]
public void Should_Add_Force_If_Provided()
{
// Given
var fixure = new HomebrewUninstallRunnerFixture();
fixure.Settings.Force = true;

// When
var result = fixure.Run();

// Then
Assert.Equal("uninstall cake --force", result.Args);
}

[Fact]
public void Should_Add_Ignore_Dependencies_If_Provided()
{
// Given
var fixure = new HomebrewUninstallRunnerFixture();
fixure.Settings.IgnoreDependencies = true;

// When
var result = fixure.Run();

// Then
Assert.Equal("uninstall cake --ignore-dependencies", result.Args);
}
}
}
}
Loading

0 comments on commit c849585

Please sign in to comment.