Skip to content

Commit

Permalink
refactor: rename message variable to output in RunAsync method and re…
Browse files Browse the repository at this point in the history
…lated tests (#113)

Signed-off-by: Nikolai Emil Damm <neq@energinet.dk>
  • Loading branch information
devantler authored Jan 25, 2025
1 parent 9775149 commit 7d72d9b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Devantler.AgeCLI.Tests/AgeKeygenTests/RunAsyncTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ public class RunAsyncTests
public async Task RunAsync_Version_ReturnsVersion()
{
// Act
var (exitCode, message) = await AgeKeygen.RunAsync(["--version"]);
var (exitCode, output) = await AgeKeygen.RunAsync(["--version"]);

// Assert
Assert.Equal(0, exitCode);
Assert.Matches(@"^v\d+\.\d+\.\d+$", message.Trim());
Assert.Matches(@"^v\d+\.\d+\.\d+$", output.Trim());
}
}
10 changes: 5 additions & 5 deletions Devantler.AgeCLI/AgeKeygen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,16 @@ internal static Command GetCommand(PlatformID? platformID = default, Architectur
[Obsolete("This method is deprecated. Use RunAsync instead.")]
public static async Task<AgeKey> InMemory(CancellationToken cancellationToken = default)
{
var (exitCode, message) = await RunAsync(
var (exitCode, output) = await RunAsync(
[],
silent: true,
includeStdErr: false,
cancellationToken: cancellationToken).ConfigureAwait(false);
if (exitCode != 0)
{
throw new InvalidOperationException($"Failed to generate key: {message}");
throw new InvalidOperationException($"Failed to generate key: {output}");
}
string[] lines = message.Split(Environment.NewLine);
string[] lines = output.Split(Environment.NewLine);
var createdAt = DateTime.Parse(lines[0].Split(" ")[2], CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal);
string publicKey = lines[1].Split(" ")[3];
string privateKey = lines[2];
Expand All @@ -101,10 +101,10 @@ public static async Task<AgeKey> InMemory(CancellationToken cancellationToken =
[Obsolete("This method is deprecated. Use RunAsync instead.")]
public static async Task<AgeKey> ToFile(string path, CancellationToken cancellationToken = default)
{
var (exitCode, message) = await RunAsync(["-o", path], silent: true, cancellationToken: cancellationToken).ConfigureAwait(false);
var (exitCode, output) = await RunAsync(["-o", path], silent: true, cancellationToken: cancellationToken).ConfigureAwait(false);
if (exitCode != 0)
{
throw new InvalidOperationException($"Failed to generate key: {message}");
throw new InvalidOperationException($"Failed to generate key: {output}");
}
string key = await File.ReadAllTextAsync(path, cancellationToken).ConfigureAwait(false);
string[] lines = key.Split("\n");
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ dotnet add package Devantler.AgeCLI
```csharp
using Devantler.AgeCLI;

var (exitCode, message) = await AgeKeygen.RunAsync(["arg1", "arg2"]);
var (exitCode, output) = await AgeKeygen.RunAsync(["arg1", "arg2"]);
```

0 comments on commit 7d72d9b

Please sign in to comment.