Showing content from http://cloud.google.com/cpp/docs/reference/storage/2.41.0/storage-mocking below:
C++ Client Libraries | Google Cloud
Skip to main content
- Overview
-
Library reference docs
- Google Cloud Storage C++ Client Library
-
Namespaces
-
google::cloud::storage
- Overview
-
Classes
-
Functions
- PublicAccessPreventionEnforced()
- PublicAccessPreventionInherited()
- PublicAccessPreventionUnspecified()
- TEAM_EDITORS()
- TEAM_OWNERS()
- TEAM_VIEWERS()
- AutoFinalizeEnabled()
- AutoFinalizeDisabled()
- RpoDefault()
- RpoAsyncTurbo()
- CreateRandomPrefixName(std::string const &)
- DeleteByPrefix(Client &, std::string const &, std::string const &, Options &&...)
- ComposeMany(Client &, std::string const &, std::vector< ComposeSourceObject >, std::string const &, std::string, bool, Options &&...)
- MakeGrpcClient(Options)
- ComputeMD5Hash(absl::string_view)
- ComputeMD5Hash(std::string const &)
- ComputeMD5Hash(char const *)
- EnableMD5Hash()
- ComputeCrc32cChecksum(absl::string_view)
- ComputeCrc32cChecksum(std::string const &)
- ComputeCrc32cChecksum(char const *)
- ObjectRetentionUnlocked()
- ObjectRetentionLocked()
- ParallelUploadFile(Client, std::string, std::string, std::string, std::string, bool, Options &&...)
- FormatDateForForm(PolicyDocumentV4Result const &)
- AddExtensionHeader(std::string, std::string)
- WithGeneration(std::uint64_t)
- WithGenerationMarker(std::uint64_t)
- WithUserProject(std::string)
- WithMarker(std::string)
- WithResponseContentDisposition(std::string)
- WithResponseContentType(std::string const &)
- WithAcl()
- WithBilling()
- WithCompose()
- WithCors()
- WithEncryption()
- WithEncryptionConfig()
- WithLifecycle()
- WithLocation()
- WithLogging()
- WithStorageClass()
- WithTagging()
- AddExtensionField(std::string, std::string)
- RestoreResumableUploadSession(std::string)
- NewResumableUploadSession()
- version_major()
- version_minor()
- version_patch()
- version_pre_release()
- version()
- version_string()
- x_goog_api_client()
- EncryptionDataFromBinaryKey(std::string const &)
- EncryptionDataFromBase64Key(std::string const &)
- CreateKeyFromGenerator(Generator &)
- AcceptEncodingGzip()
- AcceptEncodingIdentity()
-
Operators
- operator==(CorsEntry const &, CorsEntry const &)
- operator<(CorsEntry const &, CorsEntry const &)
- operator!=(CorsEntry const &, CorsEntry const &)
- operator>(CorsEntry const &, CorsEntry const &)
- operator<=(CorsEntry const &, CorsEntry const &)
- operator>=(CorsEntry const &, CorsEntry const &)
- operator==(BucketCustomPlacementConfig const &, BucketCustomPlacementConfig const &)
- operator<(BucketCustomPlacementConfig const &, BucketCustomPlacementConfig const &)
- operator!=(BucketCustomPlacementConfig const &, BucketCustomPlacementConfig const &)
- operator>(BucketCustomPlacementConfig const &, BucketCustomPlacementConfig const &)
- operator<=(BucketCustomPlacementConfig const &, BucketCustomPlacementConfig const &)
- operator>=(BucketCustomPlacementConfig const &, BucketCustomPlacementConfig const &)
- operator==(UniformBucketLevelAccess const &, UniformBucketLevelAccess const &)
- operator<(UniformBucketLevelAccess const &, UniformBucketLevelAccess const &)
- operator!=(UniformBucketLevelAccess const &, UniformBucketLevelAccess const &)
- operator>(UniformBucketLevelAccess const &, UniformBucketLevelAccess const &)
- operator<=(UniformBucketLevelAccess const &, UniformBucketLevelAccess const &)
- operator>=(UniformBucketLevelAccess const &, UniformBucketLevelAccess const &)
- operator==(BucketIamConfiguration const &, BucketIamConfiguration const &)
- operator<(BucketIamConfiguration const &, BucketIamConfiguration const &)
- operator!=(BucketIamConfiguration const &, BucketIamConfiguration const &)
- operator>(BucketIamConfiguration const &, BucketIamConfiguration const &)
- operator<=(BucketIamConfiguration const &, BucketIamConfiguration const &)
- operator>=(BucketIamConfiguration const &, BucketIamConfiguration const &)
- operator==(BucketLifecycle const &, BucketLifecycle const &)
- operator<(BucketLifecycle const &, BucketLifecycle const &)
- operator!=(BucketLifecycle const &, BucketLifecycle const &)
- operator>(BucketLifecycle const &, BucketLifecycle const &)
- operator<=(BucketLifecycle const &, BucketLifecycle const &)
- operator>=(BucketLifecycle const &, BucketLifecycle const &)
- operator<<(std::ostream &, AutoFinalize const &)
- operator<<(std::ostream &, BucketAccessControl const &)
- operator==(BucketAutoclass const &, BucketAutoclass const &)
- operator!=(BucketAutoclass const &, BucketAutoclass const &)
- operator<<(std::ostream &, BucketAutoclass const &)
- operator==(BucketBilling const &, BucketBilling const &)
- operator<(BucketBilling const &, BucketBilling const &)
- operator!=(BucketBilling const &, BucketBilling const &)
- operator>(BucketBilling const &, BucketBilling const &)
- operator<=(BucketBilling const &, BucketBilling const &)
- operator>=(BucketBilling const &, BucketBilling const &)
- operator<<(std::ostream &, CorsEntry const &)
- operator<<(std::ostream &, BucketCustomPlacementConfig const &)
- operator==(BucketEncryption const &, BucketEncryption const &)
- operator<(BucketEncryption const &, BucketEncryption const &)
- operator!=(BucketEncryption const &, BucketEncryption const &)
- operator>(BucketEncryption const &, BucketEncryption const &)
- operator<=(BucketEncryption const &, BucketEncryption const &)
- operator>=(BucketEncryption const &, BucketEncryption const &)
- operator==(BucketHierarchicalNamespace const &, BucketHierarchicalNamespace const &)
- operator!=(BucketHierarchicalNamespace const &, BucketHierarchicalNamespace const &)
- operator<<(std::ostream &, BucketHierarchicalNamespace const &)
- operator<<(std::ostream &, UniformBucketLevelAccess const &)
- operator<<(std::ostream &, BucketIamConfiguration const &)
- operator==(BucketLogging const &, BucketLogging const &)
- operator<(BucketLogging const &, BucketLogging const &)
- operator!=(BucketLogging const &, BucketLogging const &)
- operator>(BucketLogging const &, BucketLogging const &)
- operator<=(BucketLogging const &, BucketLogging const &)
- operator>=(BucketLogging const &, BucketLogging const &)
- operator<<(std::ostream &, BucketLogging const &)
- operator<<(std::ostream &, BucketMetadata const &)
- operator==(BucketObjectRetention const &, BucketObjectRetention const &)
- operator!=(BucketObjectRetention const &, BucketObjectRetention const &)
- operator<<(std::ostream &, BucketObjectRetention const &)
- operator==(BucketRetentionPolicy const &, BucketRetentionPolicy const &)
- operator<(BucketRetentionPolicy const &, BucketRetentionPolicy const &)
- operator!=(BucketRetentionPolicy const &, BucketRetentionPolicy const &)
- operator>(BucketRetentionPolicy const &, BucketRetentionPolicy const &)
- operator<=(BucketRetentionPolicy const &, BucketRetentionPolicy const &)
- operator>=(BucketRetentionPolicy const &, BucketRetentionPolicy const &)
- operator<<(std::ostream &, BucketRetentionPolicy const &)
- operator==(BucketSoftDeletePolicy const &, BucketSoftDeletePolicy const &)
- operator!=(BucketSoftDeletePolicy const &, BucketSoftDeletePolicy const &)
- operator<<(std::ostream &, BucketSoftDeletePolicy const &)
- operator==(BucketVersioning const &, BucketVersioning const &)
- operator<(BucketVersioning const &, BucketVersioning const &)
- operator!=(BucketVersioning const &, BucketVersioning const &)
- operator>(BucketVersioning const &, BucketVersioning const &)
- operator<=(BucketVersioning const &, BucketVersioning const &)
- operator>=(BucketVersioning const &, BucketVersioning const &)
- operator==(BucketWebsite const &, BucketWebsite const &)
- operator<(BucketWebsite const &, BucketWebsite const &)
- operator!=(BucketWebsite const &, BucketWebsite const &)
- operator>(BucketWebsite const &, BucketWebsite const &)
- operator<=(BucketWebsite const &, BucketWebsite const &)
- operator>=(BucketWebsite const &, BucketWebsite const &)
- operator<<(std::ostream &, ReadRangeData const &)
- operator==(HmacKeyMetadata const &, HmacKeyMetadata const &)
- operator!=(HmacKeyMetadata const &, HmacKeyMetadata const &)
- operator<<(std::ostream &, HmacKeyMetadata const &)
- operator<<(std::ostream &, NativeExpression const &)
- operator<<(std::ostream &, NativeIamBinding const &)
- operator<<(std::ostream &, NativeIamPolicy const &)
- operator==(LifecycleRuleAction const &, LifecycleRuleAction const &)
- operator<(LifecycleRuleAction const &, LifecycleRuleAction const &)
- operator!=(LifecycleRuleAction const &, LifecycleRuleAction const &)
- operator>(LifecycleRuleAction const &, LifecycleRuleAction const &)
- operator<=(LifecycleRuleAction const &, LifecycleRuleAction const &)
- operator>=(LifecycleRuleAction const &, LifecycleRuleAction const &)
- operator<<(std::ostream &, LifecycleRuleAction const &)
- operator==(LifecycleRuleCondition const &, LifecycleRuleCondition const &)
- operator<(LifecycleRuleCondition const &, LifecycleRuleCondition const &)
- operator!=(LifecycleRuleCondition const &, LifecycleRuleCondition const &)
- operator>(LifecycleRuleCondition const &, LifecycleRuleCondition const &)
- operator<=(LifecycleRuleCondition const &, LifecycleRuleCondition const &)
- operator>=(LifecycleRuleCondition const &, LifecycleRuleCondition const &)
- operator<<(std::ostream &, LifecycleRuleCondition const &)
- operator==(LifecycleRule const &, LifecycleRule const &)
- operator<(LifecycleRule const &, LifecycleRule const &)
- operator!=(LifecycleRule const &, LifecycleRule const &)
- operator>(LifecycleRule const &, LifecycleRule const &)
- operator<=(LifecycleRule const &, LifecycleRule const &)
- operator>=(LifecycleRule const &, LifecycleRule const &)
- operator<<(std::ostream &, LifecycleRule const &)
- operator==(NotificationMetadata const &, NotificationMetadata const &)
- operator<(NotificationMetadata const &, NotificationMetadata const &)
- operator!=(NotificationMetadata const &, NotificationMetadata const &)
- operator>(NotificationMetadata const &, NotificationMetadata const &)
- operator<=(NotificationMetadata const &, NotificationMetadata const &)
- operator>=(NotificationMetadata const &, NotificationMetadata const &)
- operator<<(std::ostream &, NotificationMetadata const &)
- operator<<(std::ostream &, ObjectAccessControl const &)
- operator<<(std::ostream &, ComposeSourceObject const &)
- operator==(CustomerEncryption const &, CustomerEncryption const &)
- operator<(CustomerEncryption const &, CustomerEncryption const &)
- operator!=(CustomerEncryption const &, CustomerEncryption const &)
- operator>(CustomerEncryption const &, CustomerEncryption const &)
- operator<=(CustomerEncryption const &, CustomerEncryption const &)
- operator>=(CustomerEncryption const &, CustomerEncryption const &)
- operator<<(std::ostream &, ObjectMetadata const &)
- operator==(ObjectRetention const &, ObjectRetention const &)
- operator!=(ObjectRetention const &, ObjectRetention const &)
- operator<<(std::ostream &, ObjectRetention const &)
- operator==(Owner const &, Owner const &)
- operator<(Owner const &, Owner const &)
- operator!=(Owner const &, Owner const &)
- operator>(Owner const &, Owner const &)
- operator<=(Owner const &, Owner const &)
- operator>=(Owner const &, Owner const &)
- operator==(PolicyDocumentCondition const &, PolicyDocumentCondition const &)
- operator<(PolicyDocumentCondition const &, PolicyDocumentCondition const &)
- operator!=(PolicyDocumentCondition const &, PolicyDocumentCondition const &)
- operator>(PolicyDocumentCondition const &, PolicyDocumentCondition const &)
- operator<=(PolicyDocumentCondition const &, PolicyDocumentCondition const &)
- operator>=(PolicyDocumentCondition const &, PolicyDocumentCondition const &)
- operator<<(std::ostream &, PolicyDocumentCondition const &)
- operator<<(std::ostream &, PolicyDocument const &)
- operator<<(std::ostream &, PolicyDocumentV4 const &)
- operator<<(std::ostream &, PolicyDocumentResult const &)
- operator<<(std::ostream &, PolicyDocumentV4Result const &)
- operator==(ProjectTeam const &, ProjectTeam const &)
- operator<(ProjectTeam const &, ProjectTeam const &)
- operator!=(ProjectTeam const &, ProjectTeam const &)
- operator>(ProjectTeam const &, ProjectTeam const &)
- operator<=(ProjectTeam const &, ProjectTeam const &)
- operator>=(ProjectTeam const &, ProjectTeam const &)
- operator==(ServiceAccount const &, ServiceAccount const &)
- operator<(ServiceAccount const &, ServiceAccount const &)
- operator!=(ServiceAccount const &, ServiceAccount const &)
- operator>(ServiceAccount const &, ServiceAccount const &)
- operator<=(ServiceAccount const &, ServiceAccount const &)
- operator>=(ServiceAccount const &, ServiceAccount const &)
- operator<<(std::ostream &, ServiceAccount const &)
- operator<<(std::ostream &, CustomHeader const &)
- operator<<(std::ostream &, EncryptionKey const &)
- operator<<(std::ostream &, SourceEncryptionKey const &)
-
google::cloud::storage::event_type
-
google::cloud::storage::oauth2
- Overview
-
Classes
-
AuthorizedUserCredentials<HttpRequestBuilderType, ClockType>
-
ComputeEngineCredentials<HttpRequestBuilderType, ClockType>
-
ServiceAccountCredentials<HttpRequestBuilderType, ClockType>
-
Functions
- CreateAnonymousCredentials()
- CreateAuthorizedUserCredentialsFromJsonFilePath(std::string const &)
- CreateAuthorizedUserCredentialsFromJsonContents(std::string const &, ChannelOptions const &)
- CreateServiceAccountCredentialsFromFilePath(std::string const &)
- CreateServiceAccountCredentialsFromFilePath(std::string const &, absl::optional< std::set< std::string > >, absl::optional< std::string >)
- CreateServiceAccountCredentialsFromJsonFilePath(std::string const &)
- CreateServiceAccountCredentialsFromJsonFilePath(std::string const &, absl::optional< std::set< std::string > >, absl::optional< std::string >, ChannelOptions const &)
- CreateServiceAccountCredentialsFromP12FilePath(std::string const &)
- CreateServiceAccountCredentialsFromP12FilePath(std::string const &, absl::optional< std::set< std::string > >, absl::optional< std::string >, ChannelOptions const &)
- ParseAuthorizedUserRefreshResponse(storage::internal::HttpResponse const &, std::chrono::system_clock::time_point)
- ParseAuthorizedUserCredentials(std::string const &, std::string const &, std::string const &)
- ParseMetadataServerResponse(storage::internal::HttpResponse const &)
- ParseComputeEngineRefreshResponse(storage::internal::HttpResponse const &, std::chrono::system_clock::time_point)
- GoogleOAuthAccessTokenLifetime()
- GoogleOAuthAccessTokenExpirationSlack()
- GoogleOAuthRefreshEndpoint()
- GoogleOAuthScopeCloudPlatform()
- GoogleAdcEnvVar()
- GoogleAdcFilePathFromEnvVarOrEmpty()
- GoogleAdcFilePathFromWellKnownPathOrEmpty()
- GoogleGcloudAdcFileEnvVar()
- GoogleAdcHomeEnvVar()
- GoogleDefaultCredentials(ChannelOptions const &)
- CreateServiceAccountCredentialsFromDefaultPaths(ChannelOptions const &)
- CreateServiceAccountCredentialsFromDefaultPaths(absl::optional< std::set< std::string > >, absl::optional< std::string >, ChannelOptions const &)
- CreateServiceAccountCredentialsFromJsonContents(std::string const &, ChannelOptions const &)
- CreateServiceAccountCredentialsFromJsonContents(std::string const &, absl::optional< std::set< std::string > >, absl::optional< std::string >, ChannelOptions const &)
- CreateComputeEngineCredentials()
- CreateComputeEngineCredentials(std::string const &)
- ParseServiceAccountCredentials(std::string const &, std::string const &, std::string const &)
- ParseServiceAccountP12File(std::string const &, std::string const &)
- ParseServiceAccountRefreshResponse(storage::internal::HttpResponse const &, std::chrono::system_clock::time_point)
- AssertionComponentsFromInfo(ServiceAccountCredentialsInfo const &, std::chrono::system_clock::time_point)
- MakeJWTAssertion(std::string const &, std::string const &, std::string const &)
- CreateServiceAccountRefreshPayload(ServiceAccountCredentialsInfo const &, std::string const &, std::chrono::system_clock::time_point)
- MakeSelfSignedJWT(ServiceAccountCredentialsInfo const &, std::chrono::system_clock::time_point)
- ServiceAccountUseOAuth(ServiceAccountCredentialsInfo const &)
-
google::cloud::storage::payload_format
-
google::cloud::storage::storage_class
-
google::cloud::storage_experimental
- Overview
-
Classes
-
AsyncClient
- Overview
-
Functions
- InsertObject(BucketName const &, std::string, Collection &&, Options)
- InsertObject(google::storage::v2::WriteObjectRequest, Collection &&, Options)
- InsertObject(google::storage::v2::WriteObjectRequest, WritePayload, Options)
- Open(BucketName const &, std::string, Options)
- Open(google::storage::v2::BidiReadObjectSpec, Options)
- ReadObject(BucketName const &, std::string, Options)
- ReadObject(google::storage::v2::ReadObjectRequest, Options)
- ReadObjectRange(BucketName const &, std::string, std::int64_t, std::int64_t, Options)
- ReadObjectRange(google::storage::v2::ReadObjectRequest, std::int64_t, std::int64_t, Options)
- StartAppendableObjectUpload(BucketName const &, std::string, Options)
- StartAppendableObjectUpload(google::storage::v2::BidiWriteObjectRequest, Options)
- ResumeAppendableObjectUpload(BucketName const &, std::string, std::int64_t, Options)
- StartBufferedUpload(BucketName const &, std::string, Options)
- StartBufferedUpload(google::storage::v2::StartResumableWriteRequest, Options)
- ResumeBufferedUpload(std::string, Options)
- ResumeBufferedUpload(google::storage::v2::QueryWriteStatusRequest, Options)
- StartUnbufferedUpload(BucketName const &, std::string, Options)
- StartUnbufferedUpload(google::storage::v2::StartResumableWriteRequest, Options)
- ResumeUnbufferedUpload(std::string, Options)
- ResumeUnbufferedUpload(google::storage::v2::QueryWriteStatusRequest, Options)
- ComposeObject(BucketName const &, std::string, std::vector< google::storage::v2::ComposeObjectRequest::SourceObject >, Options)
- ComposeObject(google::storage::v2::ComposeObjectRequest, Options)
- DeleteObject(BucketName const &, std::string, Options)
- DeleteObject(BucketName const &, std::string, std::int64_t, Options)
- DeleteObject(google::storage::v2::DeleteObjectRequest, Options)
- StartRewrite(BucketName const &, std::string, BucketName const &, std::string, Options)
- StartRewrite(google::storage::v2::RewriteObjectRequest, Options)
- ResumeRewrite(BucketName const &, std::string, BucketName const &, std::string, std::string, Options)
- ResumeRewrite(google::storage::v2::RewriteObjectRequest, Options)
-
google::cloud::storage_mocks
Stay organized with collections Save and categorize content based on your preferences.
Writing Tests with a Mock Client Mocking GCS bucket read and write
It is possible to mock GCS bucket read and write using gmock framework, this is specially useful for developer using GCS C++ client library.
Mocking Successful call of ReadObject()
Mocking of ReadObject can be achieved by mocking ObjectReadSource
. The following code snippet explains this
TEST(StorageMockingSamples, MockReadObject) {
namespace gcs = ::google::cloud::storage;
std::shared_ptr<gcs::testing::MockClient> mock =
std::make_shared<gcs::testing::MockClient>();
auto client = gcs::testing::UndecoratedClientFromMock(mock);
std::string const text = "this is a mock http response";
std::size_t offset = 0;
// Simulate a Read() call in the MockObjectReadSource object created below
auto simulate_read = [&text, &offset](void* buf, std::size_t n) {
auto const l = (std::min)(n, text.size() - offset);
std::memcpy(buf, text.data() + offset, l);
offset += l;
return gcs::internal::ReadSourceResult{
l, gcs::internal::HttpResponse{200, {}, {}}};
};
EXPECT_CALL(*mock, ReadObject)
.WillOnce([&](gcs::internal::ReadObjectRangeRequest const& request) {
EXPECT_EQ(request.bucket_name(), "mock-bucket-name") << request;
std::unique_ptr<gcs::testing::MockObjectReadSource> mock_source(
new gcs::testing::MockObjectReadSource);
::testing::InSequence seq;
EXPECT_CALL(*mock_source, IsOpen()).WillRepeatedly(Return(true));
EXPECT_CALL(*mock_source, Read).WillOnce(simulate_read);
EXPECT_CALL(*mock_source, IsOpen()).WillRepeatedly(Return(false));
return google::cloud::make_status_or(
std::unique_ptr<gcs::internal::ObjectReadSource>(
std::move(mock_source)));
});
gcs::ObjectReadStream stream =
client.ReadObject("mock-bucket-name", "mock-object-name");
// Reading the payload of http response stored in stream
std::string actual{std::istreambuf_iterator<char>(stream), {}};
EXPECT_EQ(actual, text);
stream.Close();
}
Mocking Failed call of ReadObject()
Mocking of ReadObject can be achieved by mocking ObjectReadSource
. The following code snippet explains this
TEST(StorageMockingSamples, MockReadObjectFailure) {
namespace gcs = ::google::cloud::storage;
std::shared_ptr<gcs::testing::MockClient> mock =
std::make_shared<gcs::testing::MockClient>();
auto client = gcs::testing::UndecoratedClientFromMock(mock);
std::string text = "this is a mock http response";
EXPECT_CALL(*mock, ReadObject)
.WillOnce([](gcs::internal::ReadObjectRangeRequest const& request) {
EXPECT_EQ(request.bucket_name(), "mock-bucket-name") << request;
auto* mock_source = new gcs::testing::MockObjectReadSource;
::testing::InSequence seq;
EXPECT_CALL(*mock_source, IsOpen).WillRepeatedly(Return(true));
EXPECT_CALL(*mock_source, Read)
.WillOnce(Return(google::cloud::Status(
google::cloud::StatusCode::kInvalidArgument,
"Invalid Argument")));
EXPECT_CALL(*mock_source, IsOpen).WillRepeatedly(Return(false));
std::unique_ptr<gcs::internal::ObjectReadSource> result(mock_source);
return google::cloud::make_status_or(std::move(result));
});
gcs::ObjectReadStream stream =
client.ReadObject("mock-bucket-name", "mock-object-name");
EXPECT_TRUE(stream.bad());
stream.Close();
}
Mocking Successful call of WriteObject()
Mocking of ReadObject can be achieved by mocking ObjectWriteStreambuf
. The following code snippet explains this
TEST(StorageMockingSamples, MockWriteObject) {
namespace gcs = ::google::cloud::storage;
std::shared_ptr<gcs::testing::MockClient> mock =
std::make_shared<gcs::testing::MockClient>();
auto client = gcs::testing::UndecoratedClientFromMock(mock);
gcs::ObjectMetadata expected_metadata;
using gcs::internal::CreateResumableUploadResponse;
using gcs::internal::QueryResumableUploadResponse;
EXPECT_CALL(*mock, CreateResumableUpload)
.WillOnce(Return(CreateResumableUploadResponse{"test-only-upload-id"}));
EXPECT_CALL(*mock, UploadChunk)
.WillOnce(Return(QueryResumableUploadResponse{
/*.committed_size=*/absl::nullopt,
/*.object_metadata=*/expected_metadata}));
auto stream = client.WriteObject("mock-bucket-name", "mock-object-name");
stream << "Hello World!";
stream.Close();
Mocking Failed call of WriteObject()
Mocking of ReadObject can be achieved by mocking ObjectWriteStreambuf
. The following code snippet explains this
TEST(StorageMockingSamples, MockWriteObjectFailure) {
namespace gcs = ::google::cloud::storage;
std::shared_ptr<gcs::testing::MockClient> mock =
std::make_shared<gcs::testing::MockClient>();
auto client = gcs::testing::UndecoratedClientFromMock(mock);
using gcs::internal::CreateResumableUploadResponse;
using gcs::internal::QueryResumableUploadResponse;
EXPECT_CALL(*mock, CreateResumableUpload)
.WillOnce(Return(CreateResumableUploadResponse{"test-only-upload-id"}));
EXPECT_CALL(*mock, UploadChunk)
.WillOnce(Return(google::cloud::Status{
google::cloud::StatusCode::kInvalidArgument, "Invalid Argument"}));
auto stream = client.WriteObject("mock-bucket-name", "mock-object-name");
stream << "Hello World!";
stream.Close();
EXPECT_TRUE(stream.bad());
}
The documentation for each member function in the Client class includes short snippets on how to call the function. The snippets for ReadObject(), WriteObject(), ListObjects(), and DeleteObject() are good places to continue learning about the library.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-14 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-14 UTC."],[],[]]
RetroSearch is an open source project built by @garambo
| Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4