Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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/f18b48b1-83b3-4d62-accf-4dbfa4373537.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"Projects": [
{
"Name": "Amazon.Lambda.TestTool",
"Type": "Patch",
"ChangelogMessages": [
"Report missing Test Tool startup options as a user error"
]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public override async Task<int> ExecuteAsync(CommandContext context, RunCommandS

if (!settings.LambdaEmulatorPort.HasValue && !settings.ApiGatewayEmulatorPort.HasValue && !settings.ApiGatewayEmulatorHttpsPort.HasValue && string.IsNullOrEmpty(settings.SQSEventSourceConfig) && string.IsNullOrEmpty(settings.DynamoDBStreamsEventSourceConfig))
{
throw new ArgumentException("At least one of the following parameters must be set: " +
"--lambda-emulator-port, --api-gateway-emulator-port, --api-gateway-emulator-https-port, --sqs-eventsource-config or --dynamodbstreams-eventsource-config");
throw new InvalidRunCommandSettingsException("At least one of the following parameters must be set: " +
"--lambda-emulator-port, --api-gateway-emulator-port, --api-gateway-emulator-https-port, --sqs-eventsource-config or --dynamodbstreams-eventsource-config");
}

var tasks = new List<Task>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ namespace Amazon.Lambda.TestTool.Models;
public abstract class TestToolException(string message, Exception? innerException = null)
: Exception(message, innerException);

/// <summary>
/// Thrown if the run command settings are invalid.
/// </summary>
/// <param name="message">The message used in the exception.</param>
/// <param name="innerException">The inner exception, if any.</param>
public class InvalidRunCommandSettingsException(string message, Exception? innerException = null)
: TestToolException(message, innerException);

/// <summary>
/// Thrown if the API Gateway Emulator mode was not provided,
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,30 @@ public class RunCommandTests
private readonly Mock<IToolInteractiveService> _mockInteractiveService = new Mock<IToolInteractiveService>();
private readonly Mock<IRemainingArguments> _mockRemainingArgs = new Mock<IRemainingArguments>();

[Fact]
public async Task ExecuteAsync_NoEmulatorConfiguration_ReturnsUserError()
{
// Arrange
var cancellationSource = new CancellationTokenSource();
var settings = new RunCommandSettings();
var command = new RunCommand(_mockInteractiveService.Object, _mockEnvironmentManager.Object);
var context = new CommandContext(new List<string>(), _mockRemainingArgs.Object, "run", null);

// Act
var result = await command.ExecuteAsync(context, settings, cancellationSource);

// Assert
Assert.Equal(CommandReturnCodes.UserError, result);
_mockInteractiveService.Verify(
service => service.WriteErrorLine(It.Is<string?>(message =>
message != null && message.Contains("At least one of the following parameters must be set"))),
Times.Once);
_mockInteractiveService.Verify(
service => service.WriteErrorLine(It.Is<string?>(message =>
message != null && message.Contains("This is a bug"))),
Times.Never);
}

[Fact]
public async Task ExecuteAsync_LambdaRuntimeApi_SuccessfulLaunch()
{
Expand Down Expand Up @@ -54,7 +78,7 @@ public async Task ExecuteAsync_ApiGatewayEmulator_SuccessfulLaunch()
cancellationSource.CancelAfter(5000);
var lambdaPort = TestHelpers.GetNextLambdaRuntimePort();
var gatewayPort = TestHelpers.GetNextApiGatewayPort();
var settings = new RunCommandSettings { LambdaEmulatorPort = lambdaPort, ApiGatewayEmulatorPort = gatewayPort, ApiGatewayEmulatorMode = ApiGatewayEmulatorMode.HttpV2, NoLaunchWindow = true};
var settings = new RunCommandSettings { LambdaEmulatorPort = lambdaPort, ApiGatewayEmulatorPort = gatewayPort, ApiGatewayEmulatorMode = ApiGatewayEmulatorMode.HttpV2, NoLaunchWindow = true };
var command = new RunCommand(_mockInteractiveService.Object, _mockEnvironmentManager.Object);
var context = new CommandContext(new List<string>(), _mockRemainingArgs.Object, "run", null);
var apiUrl = $"http://{settings.LambdaEmulatorHost}:{settings.ApiGatewayEmulatorPort}/__lambda_test_tool_apigateway_health__";
Expand Down