From 4865431829b6918270ca21a6116416d5ed25ed26 Mon Sep 17 00:00:00 2001 From: borland Date: Thu, 28 Nov 2024 13:20:46 +1300 Subject: [PATCH 1/3] Switch from CliWrap to Shellfish --- .../Octopus.Tentacle.Tests.Integration.csproj | 4 ++-- .../Support/TentacleBuilder.cs | 14 ++++++-------- .../TentacleCommandLineTests.cs | 12 +++++------- .../Octopus.Tentacle.Tests.csproj | 2 +- source/Tentacle.sln.DotSettings | 1 + 5 files changed, 15 insertions(+), 18 deletions(-) diff --git a/source/Octopus.Tentacle.Tests.Integration/Octopus.Tentacle.Tests.Integration.csproj b/source/Octopus.Tentacle.Tests.Integration/Octopus.Tentacle.Tests.Integration.csproj index 97015e791..8bd15856c 100644 --- a/source/Octopus.Tentacle.Tests.Integration/Octopus.Tentacle.Tests.Integration.csproj +++ b/source/Octopus.Tentacle.Tests.Integration/Octopus.Tentacle.Tests.Integration.csproj @@ -24,7 +24,7 @@ - + @@ -39,7 +39,7 @@ - + diff --git a/source/Octopus.Tentacle.Tests.Integration/Support/TentacleBuilder.cs b/source/Octopus.Tentacle.Tests.Integration/Support/TentacleBuilder.cs index 952ed4bcd..7384f566b 100644 --- a/source/Octopus.Tentacle.Tests.Integration/Support/TentacleBuilder.cs +++ b/source/Octopus.Tentacle.Tests.Integration/Support/TentacleBuilder.cs @@ -9,12 +9,11 @@ using System.Threading.Tasks; using Autofac; using Autofac.Util; -using CliWrap; -using CliWrap.Exceptions; using Microsoft.Win32; using Nito.AsyncEx; using Nito.AsyncEx.Interop; using NUnit.Framework; +using Octopus.Shellfish; using Octopus.Tentacle.CommonTestUtils; using Octopus.Tentacle.Configuration; using Octopus.Tentacle.Tests.Integration.Util; @@ -489,22 +488,21 @@ async Task RunCommandOutOfProcess( ILogger logger, CancellationToken cancellationToken) { - async Task ProcessLogs(string s, CancellationToken ct) + void ProcessLogs(string s) { - await Task.CompletedTask; logger.Information($"[{commandName}] " + s); commandOutput(s); } try { - var commandResult = await RetryHelper.RetryAsync( - () => Cli.Wrap(targetFilePath) + var commandResult = await RetryHelper.RetryAsync( + () => new ShellCommand(targetFilePath) .WithArguments(args) .WithEnvironmentVariables(environmentVariables) .WithWorkingDirectory(tmp.DirectoryPath) - .WithStandardOutputPipe(PipeTarget.ToDelegate(ProcessLogs)) - .WithStandardErrorPipe(PipeTarget.ToDelegate(ProcessLogs)) + .WithStdOutTarget(ProcessLogs) + .WithStdErrTarget(ProcessLogs) .ExecuteAsync(cancellationToken)); if (cancellationToken.IsCancellationRequested) return; diff --git a/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs b/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs index fba7ceedb..b53a336fd 100644 --- a/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs +++ b/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs @@ -7,12 +7,11 @@ using System.Security.Principal; using System.Text; using System.Threading.Tasks; -using CliWrap; -using CliWrap.Exceptions; using FluentAssertions; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using NUnit.Framework; +using Octopus.Shellfish; using Octopus.Tentacle.CommonTestUtils; using Octopus.Tentacle.Tests.Integration.Support; using Octopus.Tentacle.Tests.Integration.Support.TestAttributes; @@ -727,12 +726,11 @@ FileVersionInfo GetVersionInfo(TentacleConfigurationTestCase tentacleConfigurati var output = new StringBuilder(); var errorOut = new StringBuilder(); - var result = await RetryHelper.RetryAsync( - () => Cli.Wrap(tentacleExe) + var result = await RetryHelper.RetryAsync( + () => new ShellCommand(tentacleExe) .WithArguments(arguments) - .WithValidation(CommandResultValidation.None) - .WithStandardOutputPipe(PipeTarget.ToStringBuilder(output)) - .WithStandardErrorPipe(PipeTarget.ToStringBuilder(errorOut)) + .WithStdOutTarget(output) + .WithStdErrTarget(errorOut) .WithEnvironmentVariables(environmentVariablesToRunTentacleWith) .ExecuteAsync(CancellationToken)); diff --git a/source/Octopus.Tentacle.Tests/Octopus.Tentacle.Tests.csproj b/source/Octopus.Tentacle.Tests/Octopus.Tentacle.Tests.csproj index 675416bb1..052bf9809 100644 --- a/source/Octopus.Tentacle.Tests/Octopus.Tentacle.Tests.csproj +++ b/source/Octopus.Tentacle.Tests/Octopus.Tentacle.Tests.csproj @@ -51,7 +51,7 @@ - + diff --git a/source/Tentacle.sln.DotSettings b/source/Tentacle.sln.DotSettings index 0e7802a6d..2c88b318a 100644 --- a/source/Tentacle.sln.DotSettings +++ b/source/Tentacle.sln.DotSettings @@ -183,6 +183,7 @@ True True True + True True True True From bd9f1fbd763f6c8d9c89b1d63b658e6bdea3d15d Mon Sep 17 00:00:00 2001 From: borland Date: Thu, 28 Nov 2024 13:57:30 +1300 Subject: [PATCH 2/3] TrimEnd; The process stdout has a trailing newline but the tests didn't consider it --- .../TentacleCommandLineTests.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs b/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs index b53a336fd..6977faea8 100644 --- a/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs +++ b/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs @@ -118,7 +118,7 @@ public async Task VersionCommandTextFormat(TentacleConfigurationTestCase tc) var expectedVersion = GetVersionInfo(tc); - stdout.Should().Be(expectedVersion.ProductVersion, "The version command should print the informational version as text"); + stdout.TrimEnd().Should().Be(expectedVersion.ProductVersion, "The version command should print the informational version as text"); stderr.Should().BeNullOrEmpty(); } @@ -266,7 +266,8 @@ public async Task CommandSpecificHelpAsJsonLooksSensibleToHumans(TentacleConfigu ""Description"": ""Show detailed help for this command"" } ] -}"); +} +"); } [Test] @@ -358,7 +359,7 @@ public async Task ShowThumbprintCommandText(TentacleConfigurationTestCase tc) "show-thumbprint", $"--instance={clientAndTentacle.RunningTentacle.InstanceName}"); exitCode.Should().Be(0, $"we expected the command to succeed.\r\nStdErr: '{stderr}'\r\nStdOut: '{stdout}'"); - stdout.Should().Be(TestCertificates.TentaclePublicThumbprint, "the thumbprint should be written directly to stdout"); + stdout.TrimEnd().Should().Be(TestCertificates.TentaclePublicThumbprint, "the thumbprint should be written directly to stdout"); stderr.Should().BeNullOrEmpty(); } @@ -376,7 +377,7 @@ public async Task ShowThumbprintCommandJson(TentacleConfigurationTestCase tc) "show-thumbprint", $"--instance={clientAndTentacle.RunningTentacle.InstanceName}", "--format=json"); exitCode.Should().Be(0, $"we expected the command to succeed.\r\nStdErr: '{stderr}'\r\nStdOut: '{stdout}'"); - stdout.Should().Be(JsonConvert.SerializeObject(new { Thumbprint = TestCertificates.TentaclePublicThumbprint }), "the thumbprint should be written directly to stdout as JSON"); + stdout.TrimEnd().Should().Be(JsonConvert.SerializeObject(new { Thumbprint = TestCertificates.TentaclePublicThumbprint }), "the thumbprint should be written directly to stdout as JSON"); stderr.Should().BeNullOrEmpty(); } From a144ea950538e81422bf9f486ec3ce4353eb96f2 Mon Sep 17 00:00:00 2001 From: borland Date: Thu, 28 Nov 2024 14:11:59 +1300 Subject: [PATCH 3/3] Update to latest shellfish --- .../Octopus.Tentacle.Tests.Integration.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/Octopus.Tentacle.Tests.Integration/Octopus.Tentacle.Tests.Integration.csproj b/source/Octopus.Tentacle.Tests.Integration/Octopus.Tentacle.Tests.Integration.csproj index 8bd15856c..373c15876 100644 --- a/source/Octopus.Tentacle.Tests.Integration/Octopus.Tentacle.Tests.Integration.csproj +++ b/source/Octopus.Tentacle.Tests.Integration/Octopus.Tentacle.Tests.Integration.csproj @@ -24,7 +24,7 @@ - +