Skip to content

Commit

Permalink
BREAKING CHANGES: Make ProcessLauncher internal
Browse files Browse the repository at this point in the history
  • Loading branch information
cezarypiatek committed Jul 25, 2023
1 parent a02890b commit 0f3ad49
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 13 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ A library to support Helm Chart installation in Kubernetes cluster from .NET cod
## Sample usage

```cs
var chartInstaller = new ChartInstaller(new ProcessLauncher());
var chartInstaller = new ChartInstaller();
await using var release = await chartInstaller.Install
(
chart: new ChartFromLocalPath("./charts/mysamplechart"),
Expand Down Expand Up @@ -50,7 +50,7 @@ Built on top of helm chart provided by https://github.com/microsoft/mssql-docker
[Test]
public async Task install_mssql()
{
var chartInstaller = new ChartInstaller(new ProcessLauncher());
var chartInstaller = new ChartInstaller();
await using var release = await chartInstaller.Install
(
chart: new ChartFromLocalPath("./charts/mssql"),
Expand Down
15 changes: 14 additions & 1 deletion src/SmoothSailing.Tests/Examples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ namespace SmoothSailing.Tests;

public class Examples
{
public Examples()
{
ChartInstaller.DefaultOutputWriter = new NUnitOutputWriter();
}

[Test]
public async Task install_mssql()
{
var chartInstaller = new ChartInstaller(new ProcessLauncher());

var chartInstaller = new ChartInstaller();
await using var release = await chartInstaller.Install
(
chart: new ChartFromLocalPath("./charts/mssql"),
Expand All @@ -27,3 +33,10 @@ public async Task install_mssql()
Console.WriteLine($"SqlServer available at {localPort}");
}
}

class NUnitOutputWriter:IProcessOutputWriter
{
public void Write(string text) => TestContext.Progress.WriteLine(text);

public void WriteError(string text) => TestContext.Progress.WriteLine(text);
}
6 changes: 4 additions & 2 deletions src/SmoothSailing/ChartInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ namespace SmoothSailing;

public class ChartInstaller
{
public static IProcessOutputWriter DefaultOutputWriter { get; set; } = new ConsoleProcessOutputWriter();

private readonly IProcessLauncher _processLauncher;

public ChartInstaller(IProcessLauncher processLauncher)
public ChartInstaller(IProcessOutputWriter? processOutputWriter = null)
{
_processLauncher = processLauncher;
_processLauncher = new ProcessLauncher(processOutputWriter ?? DefaultOutputWriter);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/SmoothSailing/IProcessLauncher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace SmoothSailing;

public interface IProcessLauncher
internal interface IProcessLauncher
{
IAsyncEnumerable<string> Execute(string command, string parameters, CancellationToken token);
}
9 changes: 4 additions & 5 deletions src/SmoothSailing/ProcessLauncher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@

namespace SmoothSailing
{
public class ProcessLauncher : IProcessLauncher
internal class ProcessLauncher : IProcessLauncher
{
private readonly IProcessOutputWriter _processOutputWriter;

public static IProcessOutputWriter DefaultOutputWriter { get; set; } = new ConsoleProcessOutputWriter();
public ProcessLauncher(IProcessOutputWriter? processOutputWriter = null)

public ProcessLauncher(IProcessOutputWriter processOutputWriter)
{
_processOutputWriter = processOutputWriter ?? DefaultOutputWriter;
_processOutputWriter = processOutputWriter;
}

public async IAsyncEnumerable<string> Execute(string command, string parameters, [EnumeratorCancellation] CancellationToken token)
Expand Down
2 changes: 1 addition & 1 deletion src/SmoothSailing/ProcessLauncherExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace SmoothSailing;

public static class ProcessLauncherExtensions
internal static class ProcessLauncherExtensions
{
public static async Task<string> ExecuteToEnd(this IProcessLauncher @this, string command, string parameters, CancellationToken token)
{
Expand Down
2 changes: 1 addition & 1 deletion src/SmoothSailing/Release.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class Release : IAsyncDisposable
private readonly IProcessLauncher _processExecutor;
private readonly List<(Task, CancellationTokenSource)> _portForwards = new();

public Release(string deploymentName, IProcessLauncher processExecutor)
internal Release(string deploymentName, IProcessLauncher processExecutor)
{
DeploymentName = deploymentName;
_processExecutor = processExecutor;
Expand Down

0 comments on commit 0f3ad49

Please sign in to comment.