Skip to content

Remove the need to have an S3 bucket to run the tests #138

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 4 commits into from
Dec 2, 2021
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
1 change: 0 additions & 1 deletion ci/codebuild/amazonlinux-2017.03.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ phases:
pre_build:
commands:
- alias cmake=cmake3
- pip install awscli
- ci/codebuild/build-cpp-sdk.sh
build:
commands:
Expand Down
1 change: 0 additions & 1 deletion ci/codebuild/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ 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/$2lambda-test-fun.zip
ctest --output-on-failure

1 change: 0 additions & 1 deletion ci/codebuild/ubuntu-18.04.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ version: 0.1
phases:
pre_build:
commands:
- pip install awscli
- ci/codebuild/build-cpp-sdk.sh
build:
commands:
Expand Down
19 changes: 15 additions & 4 deletions tests/runtime_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <aws/core/client/ClientConfiguration.h>
#include <aws/core/utils/Array.h>
#include <aws/core/utils/Outcome.h>
#include <aws/core/utils/memory/stl/AWSString.h>
#include <aws/core/utils/memory/stl/AWSStringStream.h>
Expand All @@ -12,6 +13,8 @@
#include <aws/lambda/model/DeleteFunctionRequest.h>
#include <aws/lambda/model/InvokeRequest.h>
#include "gtest/gtest.h"
#include <cstdio>
#include <sys/stat.h>
#include <unistd.h>

extern std::string aws_prefix;
Expand All @@ -20,8 +23,7 @@ namespace {

using namespace Aws::Lambda;

constexpr auto S3BUCKET = "aws-lambda-cpp-tests";
constexpr auto S3KEY = "lambda-test-fun.zip";
constexpr auto ZIP_FILE_PATH = "resources/lambda-test-fun.zip";
constexpr auto REQUEST_TIMEOUT = 15 * 1000;

struct LambdaRuntimeTest : public ::testing::Test {
Expand Down Expand Up @@ -79,9 +81,18 @@ struct LambdaRuntimeTest : public ::testing::Test {
create_function_request.SetFunctionName(function_name);
// I ran into eventual-consistency issues when creating the role dynamically as part of the test.
create_function_request.SetRole(get_role_arn("integration-tests"));

struct stat s;
auto rc = stat(ZIP_FILE_PATH, &s);
ASSERT_EQ(rc, 0) << std::string("file does not exist: ") + ZIP_FILE_PATH;
Aws::Utils::CryptoBuffer zip_file_bytes(s.st_size);
auto* zip_file = fopen(ZIP_FILE_PATH, "r");
fread(zip_file_bytes.GetUnderlyingData(), sizeof(unsigned char), s.st_size, zip_file);
fclose(zip_file);

Model::FunctionCode funcode;
funcode.WithS3Bucket(S3BUCKET).WithS3Key(build_resource_name(S3KEY));
create_function_request.SetCode(funcode);
funcode.SetZipFile(std::move(zip_file_bytes));
create_function_request.SetCode(std::move(funcode));
create_function_request.SetRuntime(Aws::Lambda::Model::Runtime::provided);

auto outcome = m_lambda_client.CreateFunction(create_function_request);
Expand Down