aws-lambda-dotnet icon indicating copy to clipboard operation
aws-lambda-dotnet copied to clipboard

WebApplicationFactory alternative for Annotations framework

Open Dreamescaper opened this issue 2 years ago • 4 comments

Describe the feature

Microsoft provides WebApplicationFactory for AspNetCore in-memory integration testing. I think something similar could be done for AspNetCore lambdas. It would parse generated (or created manually / via CDK) cloud formation template, and create an HttpClientHandler, which would route requests to corresponding lambda handlers instead of making actual http requests.

It should also be possible to replace configured services in DI container (in order to be possible to mock external services).

Use Case

Integration testing for lambda serverless application project.

Proposed Solution

No response

Other Information

No response

Acknowledgements

  • [X] I may be able to implement this feature request
  • [ ] This feature might incur a breaking change

AWS .NET SDK and/or Package version used

Amazon.Lambda.Annotations 0.5.0-preview

Targeted .NET Platform

.NET 6

Operating System and version

Any

Dreamescaper avatar Apr 20 '22 20:04 Dreamescaper

@Dreamescaper Thanks for submitting feature request. While we could not commit on the timeline by which this request could be reviewed, feel free to contribute a PR that could be reviewed by the team.

ashishdhingra avatar Apr 20 '22 20:04 ashishdhingra

@ashishdhingra @Dreamescaper Hi and hope all is well. I'm wondering if there is anything that can be done to gain some traction on this?

My use case is that I have a Lambda that is invoked with a lot of DI-config. This lambda will reach out to several APIs, a Postgres DB and a Graph DB -> this is all well and easy to set up with Testcontainers.

The problem I'm having is that I actually need to ensure that the DI is set up correctly due to the complexity (i.e. that the function runs when it's invoked). Further I require dependencies. My solution right now is (and please don't judge as it's nasty) to use Testcontainers to build a docker image where I generate a zipped artifact, copy that artifact from the image, create a Lambda function in Localstack, set up my dependencies, and fire off a request to that localstack lambda. Then I get to asserting.

As I'm sure you can imagine, there is no step through debugging here so it's pure TDD with one setup, tons of debug logging, plenty of assertions and a "hail Mary please work" in between.

I'm hoping the implementation of this can remove that last step of this somewhat uncomfortable and nasty implementation.

/T

tsanton avatar May 03 '24 16:05 tsanton

Tagging you here @philasmar hoping you can have a look over the issue and the PR-draft, and provide some feedback on what it would take to get this implemented (if it's deemed to be in scope of the library) :)

/T

tsanton avatar May 05 '24 10:05 tsanton