Skip to content
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

Make http status code available #1504

Merged
merged 4 commits into from
May 5, 2023

Conversation

kabaluk
Copy link
Contributor

@kabaluk kabaluk commented May 4, 2023

Issue #1468

Made HttpStatusCode available for ease of testing.

Common Usage scenario:
Testing if you got the right Status result from a function returning IHttpResult.
Currently no easy way of checking the actual result.
Exposing the HttpStatusCode solves the below scenario.

public class Functions
{
    [LambdaFunction]
    [HttpApi(LambdaHttpMethod.Get, "/resource/{type}")]
    public IHttpResult GetResponse(string type, ILambdaContext context)
    {
        return type == "good" ?
            HttpResults.Ok() :
            HttpResults.BadRequest();
    }
}

public class HtttpResultsStatusCodeUsage
{
    [Fact]
    public void UsageOfIHttpResultStatusCode()
    {
        var sut = new Functions();

        var result = sut.GetResponse("good", null);

        Assert.Equal(HttpStatusCode.OK, result.StatusCode);

        result = sut.GetResponse("not good", null);

        Assert.Equal(HttpStatusCode.BadRequest, result.StatusCode);
    }
}

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@ashovlin ashovlin requested review from ashovlin and normj May 4, 2023 20:36
Copy link
Member

@normj normj left a comment

Choose a reason for hiding this comment

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

Looks good!

Copy link
Member

@ashovlin ashovlin left a comment

Choose a reason for hiding this comment

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

Thanks! "Source Generator CI" is expected to fail because this is from a fork, but not concerned.

@ashovlin ashovlin changed the base branch from master to dev May 4, 2023 21:15
@chrispaynter
Copy link

Nice!

@normj normj merged commit 2a33107 into aws:dev May 5, 2023
@normj
Copy link
Member

normj commented May 8, 2023

Version 0.13.3 is out with this PR. Thanks again for the PR!

@kabaluk kabaluk deleted the make-http-status-code-available branch September 3, 2023 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants