-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
08b3441
commit c5f55f7
Showing
7 changed files
with
63 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*build* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.