Skip to content

feat: add unit tests in ci #201

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 49 commits into from
Apr 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
5796aad
feat: add unit tests in ci
maxday Aug 14, 2024
546eebb
feat: add unit tests in ci
maxday Aug 14, 2024
95e7534
feat: add unit tests in ci
maxday Aug 14, 2024
599c14d
feat: add unit tests in ci
maxday Aug 14, 2024
cfa5fa0
feat: add unit tests in ci
maxday Aug 14, 2024
abae00c
feat: cleanup tests
maxday Apr 28, 2025
87ba5ec
feat: cleanup warnings
maxday Apr 28, 2025
9f3ad22
feat: update readme
maxday Apr 28, 2025
4c0a99e
feat: cleanup
maxday Apr 28, 2025
993674e
fix: git tag
maxday Apr 28, 2025
cefebd1
fix: git url
maxday Apr 28, 2025
bebce5f
fix: tests
maxday Apr 28, 2025
ff417e6
feat: use a matrix job instead of duplicating workflow code
maxday Apr 28, 2025
8871d12
fix: bump required version
maxday Apr 28, 2025
739cc01
fix: add debug cmake version
maxday Apr 28, 2025
2d9c900
fix: bump cmake version
maxday Apr 28, 2025
75ec781
fix: use latest version of gtest which support cpp11
maxday Apr 28, 2025
d065cbc
fix: use latest version of gtest which support cpp11
maxday Apr 28, 2025
d3c4741
fix: add docs
maxday Apr 28, 2025
4ab0bef
fix: github url
maxday Apr 28, 2025
f616b69
fix: bump gcc version
maxday Apr 28, 2025
8a4a5b3
fix: remove outdated tests
maxday Apr 28, 2025
8260b7f
fix: add tar
maxday Apr 28, 2025
118c69f
fix: alpine 3.15
maxday Apr 29, 2025
053c0fb
fix: alpine 3.15
maxday Apr 29, 2025
473958a
fix: update 1.12.0
maxday Apr 29, 2025
ce2b3ad
fix: update 1.12.0
maxday Apr 29, 2025
98743cf
fix: amzn linux2
maxday Apr 29, 2025
58b828e
fix: amzn linux2
maxday Apr 29, 2025
4493fa9
fix: amzn linux2
maxday Apr 29, 2025
4ca5783
fix: amzn linux2
maxday Apr 29, 2025
178b739
fix: amzn linux2
maxday Apr 29, 2025
e9631b1
fix: amzn linux2
maxday Apr 29, 2025
78d5dbf
fix: amzn linux2
maxday Apr 29, 2025
4e09aba
fix: dont run unit tests on codebuild
maxday Apr 29, 2025
009ed2c
fix: revert codebuild changes
maxday Apr 29, 2025
81650f4
fix: revert codebuild changes
maxday Apr 29, 2025
36381b8
fix: revert codebuild changes
maxday Apr 29, 2025
cf506b2
fix: CMakeLists
maxday Apr 29, 2025
d7dd03f
fix: remove log files
maxday Apr 29, 2025
3f4cd33
fix: unit tests
maxday Apr 29, 2025
d6cc24b
fix: unit tests
maxday Apr 29, 2025
4b79e8d
fix: path
maxday Apr 29, 2025
2f05f44
fix: path
maxday Apr 29, 2025
bf3cd2c
fix: cleanup
maxday Apr 29, 2025
028d14c
fix: cleanup
maxday Apr 29, 2025
30ca9d6
fix: cleanup
maxday Apr 29, 2025
269e680
Merge branch 'master' into maxday/add-unit-tests-in-ci
maxday Apr 29, 2025
2e36b99
Merge branch 'master' into maxday/add-unit-tests-in-ci
maxday Apr 29, 2025
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
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Checks:
-modernize-use-trailing-return-type,-bugprone-easily-swappable-parameters,-readability-identifier-length'
WarningsAsErrors: '*'
HeaderFilterRegex: 'include/aws/.*\.h$'
ExcludeHeaderFilter: 'build/_deps/gtest-src.*'
FormatStyle: 'none'
CheckOptions:
- key: modernize-pass-by-value.ValuesOnly
Expand Down
35 changes: 8 additions & 27 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,24 @@ env:

jobs:
build:
# The CMake configure and build commands are platform agnostic and should work equally
# well on Windows or Mac. You can convert this to a matrix build if you need
# cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ubuntu-latest
strategy:
matrix:
arch: [ubuntu-latest, ubuntu-24.04-arm]
runs-on: ${{ matrix.arch }}

steps:
- uses: actions/checkout@v3

- name: Install Dependencies
run: sudo apt-get update && sudo apt-get install -y clang-tidy libcurl4-openssl-dev

- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_CXX_CLANG_TIDY=clang-tidy
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_CXX_CLANG_TIDY=clang-tidy -DENABLE_TESTS=ON

- name: Build It
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}

build-on-arm-too:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: uraimo/run-on-arch-action@v2
with:
arch: aarch64
distro: ubuntu20.04
run: |
apt-get update && apt-get install -y cmake g++ clang-tidy libcurl4-openssl-dev
cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_CXX_CLANG_TIDY=clang-tidy
cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
- name: Test It
run: cd build && make && ctest

build-demo:
runs-on: ubuntu-latest
Expand All @@ -68,15 +53,11 @@ jobs:
cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=~/lambda-install
make
make aws-lambda-package-demo



format:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Check Formatting
run: ./ci/codebuild/format-check.sh


17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,23 @@ $ cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=~/lambda-install
$ make && make install
```

### Running Unit Tests Locally

To run the unit tests locally, follow these steps to build:

```bash
$ cd aws-lambda-cpp
$ mkdir build
$ cd build
$ cmake .. -DCMAKE_BUILD_TYPE=Debug -DENABLE_TESTS=ON
$ make
```

Run unit tests:
```bash
$ ctest
```

To consume this library in a project that is also using CMake, you would do:

```cmake
Expand Down
53 changes: 43 additions & 10 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,50 @@
cmake_minimum_required(VERSION 3.11)
project(aws-lambda-runtime-tests LANGUAGES CXX)

find_package(AWSSDK COMPONENTS lambda iam)
if(DEFINED ENV{GITHUB_ACTIONS})
# Fetch Google Test for unit tests
include(FetchContent)
FetchContent_Declare(gtest
URL https://github.com/google/googletest/archive/v1.12.0.tar.gz
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
)
# Configure build of googletest
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
set(BUILD_GMOCK OFF CACHE BOOL "" FORCE)
set(INSTALL_GTEST OFF)
FetchContent_MakeAvailable(gtest)

add_executable(${PROJECT_NAME}
main.cpp
runtime_tests.cpp
version_tests.cpp
gtest/gtest-all.cc)
add_executable(unit_tests
unit/no_op_test.cpp)
target_link_libraries(unit_tests PRIVATE gtest_main aws-lambda-runtime)

target_link_libraries(${PROJECT_NAME} PRIVATE ${AWSSDK_LINK_LIBRARIES} aws-lambda-runtime)
# Register unit tests
include(GoogleTest)
gtest_discover_tests(unit_tests
PROPERTIES
LABELS "unit"
DISCOVERY_TIMEOUT 10)
else()
message(STATUS "Unit tests skipped: Not in GitHub Actions environment")
endif()

include(GoogleTest)
gtest_discover_tests(${PROJECT_NAME} EXTRA_ARGS "--aws_prefix=${TEST_RESOURCE_PREFIX}") # requires CMake 3.10 or later

add_subdirectory(resources)
find_package(AWSSDK COMPONENTS lambda iam QUIET)

if(AWSSDK_FOUND)
add_executable(${PROJECT_NAME}
integration/main.cpp
integration/runtime_tests.cpp
integration/version_tests.cpp
gtest/gtest-all.cc)

target_link_libraries(${PROJECT_NAME} PRIVATE ${AWSSDK_LINK_LIBRARIES} aws-lambda-runtime)

include(GoogleTest)
gtest_discover_tests(${PROJECT_NAME} EXTRA_ARGS "--aws_prefix=${TEST_RESOURCE_PREFIX}")

add_subdirectory(resources)
else()
message(STATUS "Integration tests skipped: AWS SDK not found or not in GitHub Actions environment")
endif()

2 changes: 1 addition & 1 deletion tests/main.cpp → tests/integration/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <aws/core/Aws.h>
#include <aws/core/utils/logging/ConsoleLogSystem.h>
#include "gtest/gtest.h"
#include "../gtest/gtest.h"

std::function<std::shared_ptr<Aws::Utils::Logging::LogSystemInterface>()> get_console_logger_factory()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <aws/lambda/model/CreateFunctionRequest.h>
#include <aws/lambda/model/InvokeRequest.h>
#include <aws/core/utils/base64/Base64.h>
#include "gtest/gtest.h"
#include "../gtest/gtest.h"
#include <aws/lambda/model/LogType.h>
#include <cstdio>
#include <iostream>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <aws/lambda-runtime/version.h>
#include "gtest/gtest.h"
#include "../gtest/gtest.h"

using namespace aws::lambda_runtime;

Expand Down
6 changes: 6 additions & 0 deletions tests/unit/no_op_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <gtest/gtest.h>

TEST(noop, dummy_test)
{
ASSERT_EQ(0, 0);
}