Skip to content

Commit dae6eb4

Browse files
authored
Remove the need to have an S3 bucket to run the tests (#138)
* Remove the need to have an S3 bucket to run the tests * clang-format * i like to std::move it
1 parent 57ce686 commit dae6eb4

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

ci/codebuild/amazonlinux-2017.03.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ phases:
44
pre_build:
55
commands:
66
- alias cmake=cmake3
7-
- pip install awscli
87
- ci/codebuild/build-cpp-sdk.sh
98
build:
109
commands:

ci/codebuild/run-tests.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@ cd $CODEBUILD_SRC_DIR
66
cd build
77
rm -rf *.zip
88
ninja $1
9-
aws s3 cp tests/resources/lambda-test-fun.zip s3://aws-lambda-cpp-tests/$2lambda-test-fun.zip
109
ctest --output-on-failure
1110

ci/codebuild/ubuntu-18.04.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ version: 0.1
33
phases:
44
pre_build:
55
commands:
6-
- pip install awscli
76
- ci/codebuild/build-cpp-sdk.sh
87
build:
98
commands:

tests/runtime_tests.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <aws/core/client/ClientConfiguration.h>
2+
#include <aws/core/utils/Array.h>
23
#include <aws/core/utils/Outcome.h>
34
#include <aws/core/utils/memory/stl/AWSString.h>
45
#include <aws/core/utils/memory/stl/AWSStringStream.h>
@@ -12,6 +13,8 @@
1213
#include <aws/lambda/model/DeleteFunctionRequest.h>
1314
#include <aws/lambda/model/InvokeRequest.h>
1415
#include "gtest/gtest.h"
16+
#include <cstdio>
17+
#include <sys/stat.h>
1518
#include <unistd.h>
1619

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

2124
using namespace Aws::Lambda;
2225

23-
constexpr auto S3BUCKET = "aws-lambda-cpp-tests";
24-
constexpr auto S3KEY = "lambda-test-fun.zip";
26+
constexpr auto ZIP_FILE_PATH = "resources/lambda-test-fun.zip";
2527
constexpr auto REQUEST_TIMEOUT = 15 * 1000;
2628

2729
struct LambdaRuntimeTest : public ::testing::Test {
@@ -79,9 +81,18 @@ struct LambdaRuntimeTest : public ::testing::Test {
7981
create_function_request.SetFunctionName(function_name);
8082
// I ran into eventual-consistency issues when creating the role dynamically as part of the test.
8183
create_function_request.SetRole(get_role_arn("integration-tests"));
84+
85+
struct stat s;
86+
auto rc = stat(ZIP_FILE_PATH, &s);
87+
ASSERT_EQ(rc, 0) << std::string("file does not exist: ") + ZIP_FILE_PATH;
88+
Aws::Utils::CryptoBuffer zip_file_bytes(s.st_size);
89+
auto* zip_file = fopen(ZIP_FILE_PATH, "r");
90+
fread(zip_file_bytes.GetUnderlyingData(), sizeof(unsigned char), s.st_size, zip_file);
91+
fclose(zip_file);
92+
8293
Model::FunctionCode funcode;
83-
funcode.WithS3Bucket(S3BUCKET).WithS3Key(build_resource_name(S3KEY));
84-
create_function_request.SetCode(funcode);
94+
funcode.SetZipFile(std::move(zip_file_bytes));
95+
create_function_request.SetCode(std::move(funcode));
8596
create_function_request.SetRuntime(Aws::Lambda::Model::Runtime::provided);
8697

8798
auto outcome = m_lambda_client.CreateFunction(create_function_request);

0 commit comments

Comments
 (0)