-
Notifications
You must be signed in to change notification settings - Fork 383
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
Support mocking for the storage library without exposing implementation details #7142
Labels
api: storage
Issues related to the Cloud Storage API.
cpp: backlog
While desirable, we do not have time to work on this for the foreseeable future.
type: cleanup
An internal cleanup or hygiene concern.
Comments
coryan
added
api: storage
Issues related to the Cloud Storage API.
type: cleanup
An internal cleanup or hygiene concern.
labels
Aug 9, 2021
We still want this, but I have made no progress. May be easier with the move to |
This was referenced May 8, 2022
This will be needed for the retry header work (2022-Q4) |
This was referenced Sep 21, 2022
We need to revisit this before the end of 2023-H1. |
Still want to do this before we create a 3.0 release. |
Punt. |
We don't have time to do this. We are focusing on the async client. |
dbolduc
added
the
cpp: backlog
While desirable, we do not have time to work on this for the foreseeable future.
label
Apr 3, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
api: storage
Issues related to the Cloud Storage API.
cpp: backlog
While desirable, we do not have time to work on this for the foreseeable future.
type: cleanup
An internal cleanup or hygiene concern.
Background
Some customers need to "mock" the storage library for their own testing. We have examples on how to to this, but they use names in the
google::cloud::storage::internal::
namespace:google-cloud-cpp/google/cloud/storage/examples/storage_client_mock_samples.cc
Lines 116 to 145 in ee2e0e5
Normally
gcs::internal::
would be reserved for implementation details, and would be subject to change without notice. Exposing and documenting how they work muddles the message to our customers ("don't useinternal
because it changes, except for these bits, maybe") and complicate the life for the library developers ("these bits ofinternal
need to remain backwards compatible").Even when the types and functions do not change, the sequence of calls may change, possibly breaking a mock, for an example see #6983 and #7042.
Overview
I think we should change the mechanism used to mock the
gcs::Client
class. We should define a public API for mocking. Keeping in mind that there are 50 odd RPCs in the GCS surface, we should also try to avoid defining one*Request
and*Response
type for each RPC. Specially considering there are half a dozen or more "optional" parameters with each RPC.I think we should define the following APIs.
First, a class that applications can use to mock
gcs::Client
, the class would live in a public namespace, such as:Note that this class does not require an interface. It does not expose any of the APIs defined in
gcs::internal
.Second, a factory function to use this class from testing code:
Applications do not need to know how a
MockClient
is mapped to a client (we will describe that below), but once they have agcs::Client
object they can use it in their test code as usual.Third, all the methods for
MockClient
will have exactly the same signature:The
HttpResponse
andHttpRequest
classes are provided as part of the mocking library. I think we should just clone the API (but not the implementation) from the functions framework:These are inspired by the analogous classes in the functions framework:
https://github.com/GoogleCloudPlatform/functions-framework-cpp/blob/bf2ba9a4365a583a95e948e26d1bfff4db6a491f/google/cloud/functions/http_request.h#L31-L116
https://github.com/GoogleCloudPlatform/functions-framework-cpp/blob/bf2ba9a4365a583a95e948e26d1bfff4db6a491f/google/cloud/functions/http_response.h#L38-L81
Mocking
ReadObject
ReadObject
is a "streaming" RPC. For this proposal I think we should just consider it a regular RPC with one addition: theHttpResponse
class needs a "close status" member function that indicates the status at the end of the stream it should be possible to return a payload and a failure, to simulate errors where the download is interrupted:This will need to be handled by the wrapper around
MockClient
(see below).The
MakeMockClient
FunctionThis function would wrap the
MockClient
class with ainternal::RawClient
class each member function would look similar, so we illustrate the design using justGetObjectMetadata()
. Note that most of this functionality, such as creating HTTP requests, and parsing the HTTP response, already exist as part of the HTTP implementation. And we have no plans to remove this implementation.MockRawClient
and streaming RPCsThe one function that is more interesting in
MockRawClient
isReadObject
. It needs to return a customObjectReadSource
:The text was updated successfully, but these errors were encountered: