docs(storage): user guide for mocking Storage#3483
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3483 +/- ##
==========================================
+ Coverage 95.84% 95.86% +0.02%
==========================================
Files 120 120
Lines 4789 4789
==========================================
+ Hits 4590 4591 +1
+ Misses 199 198 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
2a3e083 to
03a10cf
Compare
guide/src/storage/mocking.md
Outdated
| - Why the design of the `Storage` client deviates from the design of other | ||
| Google Cloud clients | ||
| - How to write testable interfaces using the `Storage` client | ||
| - How to mock reads | ||
| - How to mock writes |
There was a problem hiding this comment.
I think the why is important, but tutorials / guides should emphasize how to do things... Why is for "in-depth guides":
| - Why the design of the `Storage` client deviates from the design of other | |
| Google Cloud clients | |
| - How to write testable interfaces using the `Storage` client | |
| - How to mock reads | |
| - How to mock writes | |
| - How to write testable interfaces using the `Storage` client | |
| - How to mock reads | |
| - How to mock writes | |
| - Why the design of the `Storage` client deviates from the design of other | |
| Google Cloud clients |
guide/src/storage/mocking.md
Outdated
| mocking guide (which applies to the `StorageControl` client), see | ||
| [How to write tests using a client](../mock_a_client.md). | ||
|
|
||
| ## Design rationale |
There was a problem hiding this comment.
Consider moving this to the end or even a separate page.
guide/src/storage/mocking.md
Outdated
| forward requests from the client to their stub (which could be the real | ||
| implementation or a mock). | ||
|
|
||
| Because dynamic dispatch is used, the exact type of the stub does not need to be |
There was a problem hiding this comment.
| Because dynamic dispatch is used, the exact type of the stub does not need to be | |
| Because these clients use dynamic dispatch, the exact type of the stub does not need to be |
guide/src/storage/mocking.md
Outdated
| implementation or a mock). | ||
|
|
||
| Because dynamic dispatch is used, the exact type of the stub does not need to be | ||
| known by the compiler. The clients do not need to be templated on their stub. |
There was a problem hiding this comment.
"templated" is a C++-ism, "generic on"?
guide/src/storage/mocking.md
Outdated
| Applications that need to test their code, should write their interfaces in | ||
| terms of the generic `T`. |
There was a problem hiding this comment.
| Applications that need to test their code, should write their interfaces in | |
| terms of the generic `T`. | |
| Applications that need to test their code, should write their interfaces in | |
| terms of the generic `T` with the correct constraints. |
or maybe "constrained as needed"?
guide/src/storage/mocking.md
Outdated
|
|
||
| ## Mocking reads | ||
|
|
||
| Let's say we have an application function which downloads an object and counts |
There was a problem hiding this comment.
Check the style guide. Google docs use the second person singular... "In this guide you will test an application function ..."
There was a problem hiding this comment.
Used second person, singular.
I like saying "we" because it makes me feel like I am on the same team as the reader. It's fine though.
guide/src/storage/mocking.md
Outdated
| We want to test our code against a known response from the server. We can do | ||
| this by faking the `ReadObjectResponse`. |
There was a problem hiding this comment.
Here too, change to use "you".
guide/src/storage/mocking.md
Outdated
| {{#rustdoc_include ../../samples/tests/storage/mocking.rs:fake-read-object-resp}} | ||
| ``` | ||
|
|
||
| We define the mock as usual, using `mockall`. |
There was a problem hiding this comment.
I am not sure "as usual" is quite right. It is usual for us in this project, applications may use something else. Maybe "This guide uses the mockall crate to create a mock. You can use a different crate in your tests" ?
There was a problem hiding this comment.
Done. FWIW, I think mockall is the main mocking framework in the ecosystem.
03a10cf to
f9b01b1
Compare
guide/src/storage/mocking.md
Outdated
| - Why the design of the `Storage` client deviates from the design of other | ||
| Google Cloud clients | ||
| - How to write testable interfaces using the `Storage` client | ||
| - How to mock reads | ||
| - How to mock writes |
guide/src/storage/mocking.md
Outdated
| mocking guide (which applies to the `StorageControl` client), see | ||
| [How to write tests using a client](../mock_a_client.md). | ||
|
|
||
| ## Design rationale |
guide/src/storage/mocking.md
Outdated
| forward requests from the client to their stub (which could be the real | ||
| implementation or a mock). | ||
|
|
||
| Because dynamic dispatch is used, the exact type of the stub does not need to be |
guide/src/storage/mocking.md
Outdated
| implementation or a mock). | ||
|
|
||
| Because dynamic dispatch is used, the exact type of the stub does not need to be | ||
| known by the compiler. The clients do not need to be templated on their stub. |
guide/src/storage/mocking.md
Outdated
| Applications that need to test their code, should write their interfaces in | ||
| terms of the generic `T`. |
guide/src/storage/mocking.md
Outdated
|
|
||
| ## Mocking reads | ||
|
|
||
| Let's say we have an application function which downloads an object and counts |
There was a problem hiding this comment.
Used second person, singular.
I like saying "we" because it makes me feel like I am on the same team as the reader. It's fine though.
guide/src/storage/mocking.md
Outdated
| We want to test our code against a known response from the server. We can do | ||
| this by faking the `ReadObjectResponse`. |
guide/src/storage/mocking.md
Outdated
| {{#rustdoc_include ../../samples/tests/storage/mocking.rs:fake-read-object-resp}} | ||
| ``` | ||
|
|
||
| We define the mock as usual, using `mockall`. |
There was a problem hiding this comment.
Done. FWIW, I think mockall is the main mocking framework in the ecosystem.
Fixes #3226
mocking_storage.pdf