Skip to content

Commit 4e09aba

Browse files
committed
fix: dont run unit tests on codebuild
1 parent 78d5dbf commit 4e09aba

File tree

2 files changed

+36
-34
lines changed

2 files changed

+36
-34
lines changed

CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,10 @@ endif()
9393

9494

9595
#tests
96-
if (ENABLE_TESTS OR ENABLE_INTEGRATION_TESTS)
96+
if (ENABLE_TESTS AND DEFINED ENV{GITHUB_ACTIONS})
97+
enable_testing()
98+
add_subdirectory(tests)
99+
elseif (ENABLE_INTEGRATION_TESTS)
97100
enable_testing()
98101
add_subdirectory(tests)
99102
endif()

tests/CMakeLists.txt

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,36 @@
11
cmake_minimum_required(VERSION 3.11)
22
project(aws-lambda-runtime-tests LANGUAGES CXX)
33

4-
# Fetch Google Test
5-
# We're using the latest supported version which supports C++11 (https://github.com/google/googletest/releases/tag/release-1.12.0)
6-
include(FetchContent)
7-
FetchContent_Declare(gtest
8-
URL https://github.com/google/googletest/archive/v1.12.0.tar.gz
9-
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
10-
)
11-
# Configure build of googletest
12-
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
13-
set(BUILD_GMOCK OFF CACHE BOOL "" FORCE)
14-
set(INSTALL_GTEST OFF)
15-
FetchContent_MakeAvailable(gtest)
16-
17-
# Common test library setup
18-
add_library(test_common INTERFACE)
19-
target_link_libraries(test_common INTERFACE gtest_main)
20-
21-
# Unit tests executable
22-
add_executable(unit_tests
23-
unit/no_op_test.cpp)
24-
target_link_libraries(unit_tests PRIVATE test_common aws-lambda-runtime)
4+
# Only fetch and setup Google Test in GitHub Actions
5+
if(DEFINED ENV{GITHUB_RUN_ID})
6+
# Fetch Google Test for GitHub Actions
7+
include(FetchContent)
8+
FetchContent_Declare(gtest
9+
URL https://github.com/google/googletest/archive/v1.12.0.tar.gz
10+
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
11+
)
12+
# Configure build of googletest
13+
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
14+
set(BUILD_GMOCK OFF CACHE BOOL "" FORCE)
15+
set(INSTALL_GTEST OFF)
16+
FetchContent_MakeAvailable(gtest)
17+
18+
# Common test library setup
19+
add_library(test_common INTERFACE)
20+
target_link_libraries(test_common INTERFACE GTest::GTest GTest::Main)
21+
22+
# Unit tests executable
23+
add_executable(unit_tests
24+
unit/no_op_test.cpp)
25+
target_link_libraries(unit_tests PRIVATE test_common aws-lambda-runtime)
26+
27+
# Register unit tests with CTest
28+
include(GoogleTest)
29+
gtest_discover_tests(unit_tests
30+
PROPERTIES
31+
LABELS "unit"
32+
DISCOVERY_TIMEOUT 10)
33+
endif()
2534

2635
# Integration tests executable (only if enabled)
2736
if (ENABLE_INTEGRATION_TESTS)
@@ -32,26 +41,16 @@ if (ENABLE_INTEGRATION_TESTS)
3241
integration/version_tests.cpp)
3342
target_link_libraries(integration_tests
3443
PRIVATE
35-
test_common
3644
aws-lambda-runtime
3745
${AWSSDK_LINK_LIBRARIES})
38-
endif()
39-
40-
# Register tests with CTest
41-
include(GoogleTest)
42-
gtest_discover_tests(unit_tests
43-
PROPERTIES
44-
LABELS "unit"
45-
DISCOVERY_TIMEOUT 10)
4646

47-
if (ENABLE_INTEGRATION_TESTS)
47+
# Register integration tests with CTest
48+
include(GoogleTest)
4849
gtest_discover_tests(integration_tests
4950
PROPERTIES
5051
LABELS "integration"
5152
EXTRA_ARGS "--aws_prefix=${TEST_RESOURCE_PREFIX}")
52-
endif()
5353

54-
if (ENABLE_INTEGRATION_TESTS)
5554
add_subdirectory(resources)
5655
endif()
5756

0 commit comments

Comments
 (0)