Skip to content

Add version to test tool #1969

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .autover/changes/efa829ed-59af-46eb-a5e5-ef471698c82d.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"Projects": [
{
"Name": "Amazon.Lambda.TestTool",
"Type": "Patch",
"ChangelogMessages": [
"Add --version switch to allow integrators to check what version is installed"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you missed updating the changelog

]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

using System.Diagnostics;
using System.Text.Json;
using Amazon.Lambda.TestTool.Commands.Settings;
using Amazon.Lambda.TestTool.Extensions;
using Amazon.Lambda.TestTool.Models;
Expand All @@ -28,6 +29,12 @@ public override async Task<int> ExecuteAsync(CommandContext context, RunCommandS
{
try
{
if (settings.PrintVersionInfo)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add a unit test to

?

Also as a side note, do we want to enforce unit test coverage for future PRs as a check? What do we do for other projects that we have?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was being reluctant adding a mocking layer around stdout so I could reliable unit test this. Turns out we are already mocking stdout with IToolInteractiveService so I added the unit test.

{
PrintVersionInfo();
return CommandReturnCodes.Success;
}

EvaluateEnvironmentVariables(settings);

if (!settings.LambdaEmulatorPort.HasValue && !settings.ApiGatewayEmulatorPort.HasValue)
Expand Down Expand Up @@ -101,6 +108,15 @@ public override async Task<int> ExecuteAsync(CommandContext context, RunCommandS
}
}

private void PrintVersionInfo()
{
Utf8JsonWriter utf8JsonWriter = new Utf8JsonWriter(Console.OpenStandardOutput());
utf8JsonWriter.WriteStartObject();
utf8JsonWriter.WriteString("version", Utilities.Utils.DetermineToolVersion());
utf8JsonWriter.WriteEndObject();
utf8JsonWriter.Flush();
}

private void EvaluateEnvironmentVariables(RunCommandSettings settings)
{
var environmentVariables = environmentManager.GetEnvironmentVariables();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,11 @@ public sealed class RunCommandSettings : CommandSettings
[CommandOption("--api-gateway-emulator-port <PORT>")]
[Description("The port number used for the test tool's API Gateway emulator.")]
public int? ApiGatewayEmulatorPort { get; set; }

/// <summary>
/// When set the tool prints version information as a JSON document and then exits.
/// </summary>
[CommandOption("--version")]
[Description("When set the tool prints version information as a JSON document and then exits.")]
public bool PrintVersionInfo { get; set; }
}
Loading