diff --git a/ci/codebuild/amazonlinux-2017.03.yml b/ci/codebuild/amazonlinux-2017.03.yml index d182dff..eab1baf 100644 --- a/ci/codebuild/amazonlinux-2017.03.yml +++ b/ci/codebuild/amazonlinux-2017.03.yml @@ -9,9 +9,9 @@ phases: build: commands: - echo Build started on `date` - - ci/codebuild/build.sh -DENABLE_TESTS=ON - - ci/codebuild/run-tests.sh aws-lambda-package-lambda-test-fun - - ci/codebuild/run-tests.sh aws-lambda-package-lambda-test-fun-no-glibc + - ci/codebuild/build.sh -DENABLE_TESTS=ON -DTEST_RESOURCE_PREFIX=amzn201703 + - ci/codebuild/run-tests.sh aws-lambda-package-lambda-test-fun amzn201703 + - ci/codebuild/run-tests.sh aws-lambda-package-lambda-test-fun-no-glibc amzn201703 post_build: commands: - echo Build completed on `date` diff --git a/ci/codebuild/run-tests.sh b/ci/codebuild/run-tests.sh index 5232115..b25d0e3 100755 --- a/ci/codebuild/run-tests.sh +++ b/ci/codebuild/run-tests.sh @@ -6,6 +6,6 @@ cd $CODEBUILD_SRC_DIR cd build rm -rf *.zip ninja $1 -aws s3 cp tests/resources/lambda-test-fun.zip s3://aws-lambda-cpp-tests/lambda-test-fun.zip +aws s3 cp tests/resources/lambda-test-fun.zip s3://aws-lambda-cpp-tests/$2lambda-test-fun.zip ctest --output-on-failure diff --git a/ci/codebuild/ubuntu-18.04.yml b/ci/codebuild/ubuntu-18.04.yml index 9617587..5313f91 100644 --- a/ci/codebuild/ubuntu-18.04.yml +++ b/ci/codebuild/ubuntu-18.04.yml @@ -1,11 +1,16 @@ version: 0.1 # This uses the docker image specified in ci/docker/ubuntu-linux-18.04 phases: + pre_build: + commands: + - pip install awscli + - ci/codebuild/build-cpp-sdk.sh build: commands: - echo Build started on `date` - - ci/codebuild/build.sh -DCMAKE_CXX_CLANG_TIDY=clang-tidy -DCMAKE_EXPORT_COMPILE_COMMANDS=ON + - ci/codebuild/build.sh -DCMAKE_CXX_CLANG_TIDY=clang-tidy -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DENABLE_TESTS=ON -DTEST_RESOURCE_PREFIX=ubuntu1804 - ci/codebuild/format-check.sh + - ci/codebuild/run-tests.sh aws-lambda-package-lambda-test-fun ubuntu1804 post_build: commands: - echo Build completed on `date` diff --git a/ci/docker/amazon-linux-2017.03 b/ci/docker/amazon-linux-2017.03 index 2e400a2..f66919a 100644 --- a/ci/docker/amazon-linux-2017.03 +++ b/ci/docker/amazon-linux-2017.03 @@ -8,3 +8,5 @@ sh cmake-install --skip-license --prefix=/usr --exclude-subdirectory; RUN pip-3.6 install --upgrade pip +RUN git clone https://github.com/aws/aws-sdk-cpp.git + diff --git a/ci/docker/ubuntu-linux-18.04 b/ci/docker/ubuntu-linux-18.04 index 3561312..175ea82 100644 --- a/ci/docker/ubuntu-linux-18.04 +++ b/ci/docker/ubuntu-linux-18.04 @@ -1,6 +1,15 @@ FROM ubuntu:18.04 -RUN apt-get update; apt-get install git clang clang-tidy clang-format libcurl4-openssl-dev wget ninja-build -y +RUN apt-get update; apt-get install git clang clang-tidy clang-format zlib1g-dev libssl-dev libcurl4-openssl-dev wget \ +ninja-build python3-pip zip -y + RUN wget -O cmake-install https://github.com/Kitware/CMake/releases/download/v3.13.0/cmake-3.13.0-Linux-x86_64.sh; \ sh cmake-install --skip-license --prefix=/usr --exclude-subdirectory; + +RUN pip3 install --upgrade pip + +RUN git clone https://github.com/aws/aws-sdk-cpp.git + +RUN update-alternatives --set cc /usr/bin/clang +RUN update-alternatives --set c++ /usr/bin/clang++ diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 26a6d1c..ddec1a8 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,15 +1,16 @@ project(aws-lambda-runtime-tests LANGUAGES CXX) find_package(AWSSDK COMPONENTS lambda iam) -find_package(GTest REQUIRED) add_executable(${PROJECT_NAME} main.cpp runtime_tests.cpp - version_tests.cpp) + version_tests.cpp + gtest/gtest-all.cc) -target_link_libraries(${PROJECT_NAME} PRIVATE ${AWSSDK_LINK_LIBRARIES} aws-lambda-runtime GTest::GTest) +target_link_libraries(${PROJECT_NAME} PRIVATE ${AWSSDK_LINK_LIBRARIES} aws-lambda-runtime) -gtest_discover_tests(${PROJECT_NAME}) # requires CMake 3.10 or later +include(GoogleTest) +gtest_discover_tests(${PROJECT_NAME} EXTRA_ARGS "--aws_prefix=${TEST_RESOURCE_PREFIX}") # requires CMake 3.10 or later add_subdirectory(resources) diff --git a/tests/main.cpp b/tests/main.cpp index ff545d0..33c882f 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -1,6 +1,6 @@ #include -#include #include +#include "gtest/gtest.h" std::function()> GetConsoleLoggerFactory() { @@ -10,8 +10,23 @@ std::function()> GetCon }; } +std::string aws_prefix; + +void parse_args(int argc, char** argv) +{ + const std::string resourcePrefixOption = "--aws_prefix="; + for (int i = 1; i < argc; i++) { + std::string arg = argv[i]; + if (arg.find(resourcePrefixOption) == 0) { + aws_prefix = arg.substr(resourcePrefixOption.length()); // get whatever value after the '=' + break; + } + } +} + int main(int argc, char** argv) { + parse_args(argc, argv); Aws::SDKOptions options; options.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Warn; options.loggingOptions.logger_create_fn = GetConsoleLoggerFactory(); diff --git a/tests/runtime_tests.cpp b/tests/runtime_tests.cpp index cfca466..c5aaa74 100644 --- a/tests/runtime_tests.cpp +++ b/tests/runtime_tests.cpp @@ -70,11 +70,11 @@ struct LambdaRuntimeTest : public ::testing::Test { return {}; } - void create_function(Aws::String const& name) + void create_function(Aws::String const& function_name, Aws::String const& handler_name) { Model::CreateFunctionRequest createFunctionRequest; - createFunctionRequest.SetHandler(name); - createFunctionRequest.SetFunctionName(name); + createFunctionRequest.SetHandler(handler_name); + createFunctionRequest.SetFunctionName(function_name); // I ran into eventual-consistency issues when creating the role dynamically as part of the test. createFunctionRequest.SetRole(get_role_arn("integration-tests")); Model::FunctionCode funcode; @@ -83,16 +83,16 @@ struct LambdaRuntimeTest : public ::testing::Test { createFunctionRequest.SetRuntime(Aws::Lambda::Model::Runtime::provided); auto outcome = m_lambda_client.CreateFunction(createFunctionRequest); - ASSERT_TRUE(outcome.IsSuccess()) << "Failed to create function " << name; + ASSERT_TRUE(outcome.IsSuccess()) << "Failed to create function " << function_name; } - void delete_function(Aws::String const& name, bool assert = true) + void delete_function(Aws::String const& function_name, bool assert = true) { Model::DeleteFunctionRequest deleteFunctionRequest; - deleteFunctionRequest.SetFunctionName(name); + deleteFunctionRequest.SetFunctionName(function_name); auto outcome = m_lambda_client.DeleteFunction(deleteFunctionRequest); if (assert) { - ASSERT_TRUE(outcome.IsSuccess()) << "Failed to delete function " << name; + ASSERT_TRUE(outcome.IsSuccess()) << "Failed to delete function " << function_name; } } }; @@ -101,7 +101,7 @@ TEST_F(LambdaRuntimeTest, echo_success) { Aws::String const funcname = build_resource_name("echo_success"); char const payloadContent[] = "Hello, Lambda!"; - create_function(funcname); + create_function(funcname, "echo_success" /*handler_name*/); Model::InvokeRequest invokeRequest; invokeRequest.SetFunctionName(funcname); invokeRequest.SetInvocationType(Model::InvocationType::RequestResponse); @@ -132,7 +132,7 @@ TEST_F(LambdaRuntimeTest, echo_unicode) { Aws::String const funcname = build_resource_name("echo_success"); // re-use the echo method but with Unicode input char const payloadContent[] = "画像は1000語の価値がある"; - create_function(funcname); + create_function(funcname, "echo_success" /*handler_name*/); Model::InvokeRequest invokeRequest; invokeRequest.SetFunctionName(funcname); invokeRequest.SetInvocationType(Model::InvocationType::RequestResponse); @@ -162,7 +162,7 @@ TEST_F(LambdaRuntimeTest, echo_unicode) TEST_F(LambdaRuntimeTest, echo_failure) { Aws::String const funcname = build_resource_name("echo_failure"); - create_function(funcname); + create_function(funcname, "echo_failure" /*handler_name*/); Model::InvokeRequest invokeRequest; invokeRequest.SetFunctionName(funcname); invokeRequest.SetInvocationType(Model::InvocationType::RequestResponse); @@ -178,7 +178,7 @@ TEST_F(LambdaRuntimeTest, binary_response) { Aws::String const funcname = build_resource_name("binary_response"); unsigned long constexpr expected_length = 1451; - create_function(funcname); + create_function(funcname, "binary_response" /*handler_name*/); Model::InvokeRequest invokeRequest; invokeRequest.SetFunctionName(funcname); invokeRequest.SetInvocationType(Model::InvocationType::RequestResponse); @@ -190,3 +190,4 @@ TEST_F(LambdaRuntimeTest, binary_response) EXPECT_EQ(expected_length, invokeOutcome.GetResult().GetPayload().tellp()); delete_function(funcname); } +} // namespace diff --git a/tests/version_tests.cpp b/tests/version_tests.cpp index 5a2cc98..862c680 100644 --- a/tests/version_tests.cpp +++ b/tests/version_tests.cpp @@ -1,5 +1,5 @@ -#include #include +#include "gtest/gtest.h" using namespace aws::lambda_runtime;