知识卡片
分离请求构造与发送
SDK 方法通常先用 builder 组装请求,再异步发送。可以把不访问远端的构造代码抽成单独函数,接收已解析的配置、返回填好的 builder。书中以构造 Lambda 创建请求为例,内存、超时、代码位置或处理器名的映射可以在本地检查,网络调用集中到 .send().await。
请求构造测试可以快速确认字段是否正确。服务是否接受这些参数、资源是否建成,仍需在请求发送后核验。
相关卡片 [[桶事件如何触发函数]]、[[端到端测试验证宏副作用]]。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Writing an infrastructure DSL 配置 SDK 客户端与事件连接 · 查看原书依据
To make the method more unit testable, you could extract the builder, which is pure, into a separate function that contains most of the code and has no need for mocking.
参考来源
- 位置:《Write Powerful Rust Macros》第09章《Writing an infrastructure DSL》(book-source:extracted/Write Powerful Rust Macros/_epub-src/OEBPS/Text/chapter-9.xhtml#p140)
- 结论依据:原书把 builder 称作纯构造,建议将它从 send 中抽出以便无 mock 地单元测试。
- 原始内容:To make the method more unit testable, you could extract the builder, which is pure, into a separate function that contains most of the code and has no need for mocking.