Skip to content

Commit

Permalink
added cpp to ci
Browse files Browse the repository at this point in the history
  • Loading branch information
martinzink committed Mar 2, 2022
1 parent 08b3441 commit c5f55f7
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 42 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ jobs:
- lang: java
docker-image: openjdk:11
entrypoint: /bin/sh
- lang: cpp
docker-image: alpine
entrypoint: /bin/sh

name: test-${{ matrix.lang }}-example
runs-on: ubuntu-latest
Expand Down
13 changes: 13 additions & 0 deletions ci/run-cpp-example.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
set -e

./fake-gcs-server -backend memory -scheme http -port 8080 -external-url "http://localhost:8080" &

(
apk add abseil-cpp-dev gtest-dev cmake make g++ nlohmann-json curl-dev git
cd examples/cpp
mkdir build
cd build
cmake ..
make -j$(nproc)
./cpp-example
)
1 change: 1 addition & 0 deletions examples/cpp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*build*
27 changes: 20 additions & 7 deletions examples/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
cmake_minimum_required (VERSION 3.2)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD 11)
project (fake-gcs-server-cpp-examples)
include(FetchContent)

find_package(GTest REQUIRED)
find_package(absl CONFIG REQUIRED)

set(GOOGLE_CLOUD_CPP_ENABLE storage CACHE INTERNAL storage-api)
set(GOOGLE_CLOUD_CPP_ENABLE_MACOS_OPENSSL_CHECK OFF CACHE INTERNAL macos-openssl-check)
set(BUILD_TESTING OFF CACHE INTERNAL testing-off)
set(CRC32C_USE_GLOG OFF CACHE INTERNAL crc32c-glog-off)
set(CRC32C_BUILD_TESTS OFF CACHE INTERNAL crc32c-gtest-off)
set(CRC32C_BUILD_BENCHMARKS OFF CACHE INTERNAL crc32-benchmarks-off)
set(CRC32C_INSTALL ON CACHE INTERNAL crc32-install-on)
FetchContent_Declare(
crc32c
URL https://github.com/google/crc32c/archive/refs/tags/1.1.1.tar.gz
URL_HASH SHA256=a6533f45b1670b5d59b38a514d82b09c6fb70cc1050467220216335e873074e8
)
FetchContent_MakeAvailable(crc32c)
add_library(Crc32c::crc32c ALIAS crc32c)
#TODO replace b03448411402c83082c279b246548d578dee05c7 with the next release which contains it
FetchContent_Declare(google-cloud-cpp
GIT_REPOSITORY git@github.com:googleapis/google-cloud-cpp.git
GIT_REPOSITORY https://github.com/googleapis/google-cloud-cpp.git
GIT_TAG b03448411402c83082c279b246548d578dee05c7)
FetchContent_MakeAvailable(google-cloud-cpp)

add_executable(upload-example upload.cpp)
target_link_libraries(upload-example google-cloud-cpp::storage)

add_executable(list-bucket-example list_bucket.cpp)
target_link_libraries(list-bucket-example google-cloud-cpp::storage)
add_executable(cpp-example cpp-examples.cpp)
target_include_directories(cpp-example PUBLIC ${google-cloud-cpp_INCLUDE_DIRS})
target_link_libraries(cpp-example PUBLIC google-cloud-cpp::storage gtest)
gtest_add_tests(TARGET cpp-example)
26 changes: 26 additions & 0 deletions examples/cpp/cpp-examples.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <iostream>
#include "gtest/gtest.h"
#include "google/cloud/storage/client.h"

using namespace google::cloud::storage;

TEST(CppExamples, ResumableUploadTest) {
ClientOptions options(oauth2::CreateAnonymousCredentials());
options.set_endpoint("localhost:8080");
Client client(options, LimitedErrorCountRetryPolicy(2));
client.CreateBucket("my-bucket", BucketMetadata());
auto writer = client.WriteObject("my-bucket", "my-key");
writer << "hello world";
writer.Close();
auto result = writer.metadata();
ASSERT_TRUE(result.ok());
auto objects = client.ListObjects("my-bucket");
ASSERT_EQ(1, std::distance(objects.begin(), objects.end()));
ASSERT_TRUE(objects.begin()->ok());
EXPECT_EQ("my-key", objects.begin()->value().name());
}

int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
15 changes: 0 additions & 15 deletions examples/cpp/list_bucket.cpp

This file was deleted.

20 changes: 0 additions & 20 deletions examples/cpp/upload.cpp

This file was deleted.

0 comments on commit c5f55f7

Please sign in to comment.