Skip to content

chore: Add e2e tests #692

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 23 commits into from
Jan 14, 2025
Merged
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
81 changes: 0 additions & 81 deletions .github/workflows/e2e-infra-deploy.yml

This file was deleted.

43 changes: 0 additions & 43 deletions .github/workflows/e2e-infra-destroy.yml

This file was deleted.

167 changes: 130 additions & 37 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,14 @@ permissions:
contents: read

jobs:

deploy-core-stack:
runs-on: aws-powertools_ubuntu-latest_8-core
permissions:
id-token: write
contents: read
deploy-stack:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502
with:
role-to-assume: ${{ secrets.E2E_DEPLOY_ROLE }}
aws-region: us-east-1
Expand All @@ -42,23 +38,77 @@ jobs:
uses: actions/setup-dotnet@4d6c8fcf3c8f7a60068d26b594648e99df24cee3
with:
dotnet-version: '8.x'

- name: Setup Node.js
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version: "20.10.0"


- name: Install CDK
run: npm install -g aws-cdk

- name: Install AWS Lambda .NET CLI Tools
run: dotnet tool install -g Amazon.Lambda.Tools

- name: Deploy Core Stack
run: |
cd libraries/tests/e2e/infra
cdk deploy --require-approval never

# deploy-aot-stack:
# runs-on: ubuntu-latest
# strategy:
# fail-fast: false
# matrix:
# architecture: [ x86_64, arm64 ]
# steps:
# - name: Checkout code
# uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
#
# - name: Configure AWS credentials
# uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502
# with:
# role-to-assume: ${{ secrets.E2E_DEPLOY_ROLE }}
# aws-region: us-east-1
#
# - name: Set up .NET
# uses: actions/setup-dotnet@4d6c8fcf3c8f7a60068d26b594648e99df24cee3
# with:
# dotnet-version: '8.x'
#
# - name: Install CDK
# run: npm install -g aws-cdk
#
# - name: Install AWS Lambda .NET CLI Tools
# run: dotnet tool install -g Amazon.Lambda.Tools
#
# - name: Set up QEMU
# uses: docker/setup-qemu-action@53851d14592bedcffcf25ea515637cff71ef929a
# with:
# platforms: ${{ matrix.architecture }}
#
# - name: Set up Docker Buildx
# id: builder
# uses: docker/setup-buildx-action@6524bf65af31da8d45b59e8c27de4bd072b392f5 # v3.8.0
# with:
# install: true
# driver: docker
# platforms: linux/amd64,linux/arm64
#
# - name: Deploy AOT Stack
# run: |
# cd libraries/tests/e2e/infra-aot
# cdk deploy -c architecture=${{ matrix.architecture }} --require-approval never

run-tests:
runs-on: ubuntu-latest
needs: deploy-stack
steps:
- name: Checkout code
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502
with:
role-to-assume: ${{ secrets.E2E_DEPLOY_ROLE }}
aws-region: us-east-1
mask-aws-account-id: true

- name: Set up .NET
uses: actions/setup-dotnet@4d6c8fcf3c8f7a60068d26b594648e99df24cee3
with:
Expand All @@ -69,28 +119,71 @@ jobs:
cd libraries/tests/e2e/functions/core
dotnet test

# run-tests:
# runs-on: aws-powertools_ubuntu-latest_8-core
# # needs: [deploy-core-stack, deploy-aot-stack]
# # needs: [deploy-core-stack]
# steps:
# - name: Checkout code
# uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332

# - name: Set up .NET
# uses: actions/setup-dotnet@4d6c8fcf3c8f7a60068d26b594648e99df24cee3
# with:
# dotnet-version: '8.x'

# - name: Run Core Tests
# run: |
# cd libraries/tests/e2e/functions/core
# dotnet test

# - name: Destroy Core Stack
# if: always()
# uses: ./.github/workflows/e2e-infra-destroy.yml

# destroy-core-stack:
destroy-stack:
runs-on: ubuntu-latest
needs: run-tests
if: always()
steps:
- name: Checkout code
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502
with:
role-to-assume: ${{ secrets.E2E_DEPLOY_ROLE }}
aws-region: us-east-1
mask-aws-account-id: true

- name: Install CDK
run: npm install -g aws-cdk

- name: Install AWS Lambda .NET CLI Tools
run: dotnet tool install -g Amazon.Lambda.Tools

- name: Destroy Core Stack
run: |
cd libraries/tests/e2e/infra
cdk destroy --force

# destroy-aot-stack:
# runs-on: ubuntu-latest
# needs: run-tests
# uses: ./.github/workflows/e2e-infra-destroy.yml
# if: always()
# strategy:
# fail-fast: false
# matrix:
# architecture: [ x86_64, arm64 ]
# steps:
# - name: Checkout code
# uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
#
# - name: Configure AWS credentials
# uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502
# with:
# role-to-assume: ${{ secrets.E2E_DEPLOY_ROLE }}
# aws-region: us-east-1
# mask-aws-account-id: true
#
# - name: Install CDK
# run: npm install -g aws-cdk
#
# - name: Install AWS Lambda .NET CLI Tools
# run: dotnet tool install -g Amazon.Lambda.Tools
#
# - name: Set up QEMU
# uses: docker/setup-qemu-action@53851d14592bedcffcf25ea515637cff71ef929a
# with:
# platforms: ${{ matrix.architecture }}
#
# - name: Set up Docker Buildx
# id: builder
# uses: docker/setup-buildx-action@6524bf65af31da8d45b59e8c27de4bd072b392f5 # v3.8.0
# with:
# install: true
# driver: docker
# platforms: linux/amd64,linux/arm64
#
# - name: Destroy Core AOT Stack
# run: |
# cd libraries/tests/e2e/infra-aot
# cdk destroy -c architecture=${{ matrix.architecture }} --force
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.4"/>
<PackageReference Include="Amazon.Lambda.APIGatewayEvents" Version="2.7.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\..\..\..\..\src\AWS.Lambda.Powertools.Logging\AWS.Lambda.Powertools.Logging.csproj" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\..\Function\src\Function\TestHelper.cs">
<Link>TestHelper.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\..\..\..\..\src\AWS.Lambda.Powertools.Logging\AWS.Lambda.Powertools.Logging.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public FunctionTest(ITestOutputHelper testOutputHelper)
[InlineData("E2ETestLambda_ARM_NET6_logging")]
[InlineData("E2ETestLambda_X64_NET8_logging")]
[InlineData("E2ETestLambda_ARM_NET8_logging")]
[InlineData("E2ETestLambda_ARM_AOT_NET8_logging")]
// [InlineData("E2ETestLambda_ARM_AOT_NET8_logging")]
public async Task TestFunction(string functionName)
{
var request = new InvokeRequest
Expand Down Expand Up @@ -114,30 +114,6 @@ private void AssertEventLog(string functionName, bool isColdStart, string output
Assert.True(headersElement.TryGetProperty("Cache-Control", out JsonElement cacheControlElement));
Assert.Equal("max-age=0", cacheControlElement.GetString());

Assert.True(headersElement.TryGetProperty("CloudFront-Forwarded-Proto",
out JsonElement cloudFrontForwardedProtoElement));
Assert.Equal("https", cloudFrontForwardedProtoElement.GetString());

Assert.True(headersElement.TryGetProperty("CloudFront-Viewer-Country",
out JsonElement cloudFrontViewerCountryElement));
Assert.Equal("US", cloudFrontViewerCountryElement.GetString());

Assert.True(headersElement.TryGetProperty("Upgrade-Insecure-Requests",
out JsonElement upgradeInsecureRequestsElement));
Assert.Equal("1", upgradeInsecureRequestsElement.GetString());

Assert.True(headersElement.TryGetProperty("User-Agent", out JsonElement userAgentElement));
Assert.Equal("Custom User Agent String", userAgentElement.GetString());

Assert.True(headersElement.TryGetProperty("X-Forwarded-For", out JsonElement xForwardedForElement));
Assert.Equal("127.0.0.1, 127.0.0.2", xForwardedForElement.GetString());

Assert.True(headersElement.TryGetProperty("X-Forwarded-Port", out JsonElement xForwardedPortElement));
Assert.Equal("443", xForwardedPortElement.GetString());

Assert.True(headersElement.TryGetProperty("X-Forwarded-Proto", out JsonElement xForwardedProtoElement));
Assert.Equal("https", xForwardedProtoElement.GetString());

Assert.True(
messageElement.TryGetProperty("QueryStringParameters", out JsonElement queryStringParametersElement));
Assert.True(queryStringParametersElement.TryGetProperty("Foo", out JsonElement fooElement));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using Amazon.Lambda.APIGatewayEvents;
using Amazon.Lambda.Core;
using AWS.Lambda.Powertools.Metrics;
using Helpers;

// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]

namespace Helpers;
namespace Function;

public class Function
{
Expand Down
Loading
Loading