with one click
cpp-test-service
将 Drogon 插件测试从旧插件 API 迁移到新的基于 Service 的架构
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Menu
将 Drogon 插件测试从旧插件 API 迁移到新的基于 Service 的架构
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Build Drogon payment plugin with correct Release mode configuration
Create comprehensive production readiness documentation package for software projects. Use this skill whenever the user mentions production readiness, deployment docs, operations manual, preparing for release, going to production, or needs deployment guide, monitoring setup, security checklist, or runbook creation. This skill generates the complete documentation ecosystem needed for production deployment including deployment guides, operations manuals, monitoring configuration, security checklists, CI/CD setup, and operational automation scripts.
Build Drogon payment plugin with correct Release mode configuration
Standardize and organize C++ project file structure. Use this skill whenever the user mentions cleaning up project files, organizing documentation, archiving old files, removing backups, standardizing file layout, restructuring docs, cleaning up repository, or says things like "my project is messy" or "too many files in my docs folder". This skill handles creating archive directories, moving backup/temporary files to archive, updating .gitignore, creating documentation indexes, and general project file organization for C/C++ projects.
Migrate Drogon plugin tests from old plugin API to new Service-based architecture. Use this skill whenever the user mentions migrating tests, updating to Service API, converting plugin calls, refactoring Drogon tests, or needs to update test code to use PaymentService, RefundService, CallbackService, etc. This skill handles the API migration pattern from plugin.method(req, callback) to service->method(request, key, callback) with Promise/Future for async handling.
针对 Drogon 项目的自动化代码审查流程 (Format, Lint, Arch)
Based on SOC occupation classification
| name | cpp-test-service |
| description | 将 Drogon 插件测试从旧插件 API 迁移到新的基于 Service 的架构 |
| user-invocable | false |
将 Drogon 插件测试迁移到 Service API 时,遵循以下模式:
旧模式(插件 API):
plugin->createPayment(request);
plugin->refund(request);
plugin->handleWechatCallback(body, signature);
plugin->queryOrder(orderNo);
plugin->reconcileSummary(startTime, endTime);
新模式(Service API):
paymentService->createPayment(request);
refundService->createRefund(request);
callbackService->handleCallback(body, signature);
paymentService->queryOrder(orderNo);
reconciliationService->reconcileSummary(startTime, endTime);
旧模式:
auto mockPlugin = std::make_shared<MockPayPlugin>();
新模式:
auto mockFactory = std::make_shared<MockServiceFactory>();
auto paymentService = mockFactory->getPaymentService();
auto refundService = mockFactory->getRefundService();
auto callbackService = mockFactory->getCallbackService();
重要原则:
# 从 PayBackend/ 目录运行
./build/Release/test_payplugin.exe --gtest_filter="*TestName*"
# 或运行特定测试套件
./build/Release/test_payplugin.exe --gtest_filter="*CreatePayment*"
./build/Release/test_payplugin.exe --gtest_filter="*Refund*"
./build/Release/test_payplugin.exe --gtest_filter="*Callback*"
| 旧插件 API | 新 Service API | Service 类 |
|---|---|---|
plugin->createPayment() | paymentService->createPayment() | PaymentService |
plugin->refund() | refundService->createRefund() | RefundService |
plugin->handleWechatCallback() | callbackService->handleCallback() | CallbackService |
plugin->queryOrder() | paymentService->queryOrder() | PaymentService |
plugin->refundQuery() | refundService->queryRefund() | RefundService |
plugin->reconcileSummary() | reconciliationService->reconcileSummary() | ReconciliationService |
参考以下已迁移的测试文件:
PayBackend/test/CreatePaymentIntegrationTest.cc
plugin->createPayment() 迁移到 paymentService->createPayment()PayBackend/test/QueryOrderTest.cc
plugin->queryOrder() 迁移到 paymentService->queryOrder()PayBackend/test/RefundQueryTest.cc
plugin->refund() 和 plugin->refundQuery() 迁移到 refundService// 在测试设置中
void SetUp() override {
mockFactory = std::make_shared<MockServiceFactory>();
paymentService = mockFactory->getPaymentService();
refundService = mockFactory->getRefundService();
// 配置 mock 行为
EXPECT_CALL(*paymentService, createPayment(_))
.WillOnce(Return(expectedResponse));
}
// 旧模式
plugin->handleWechatCallback(body, signature, [](const drogon::HttpResponsePtr& resp) {
// 处理响应
});
// 新模式
callbackService->handleCallback(body, signature)
.then([](const drogon::HttpResponsePtr& resp) {
// 处理响应
});
// 保持错误检查逻辑不变
auto response = paymentService->createPayment(request);
ASSERT_NE(response, nullptr);
EXPECT_EQ(response->getStatusCode(), drogon::k200OK);
在完成测试迁移后,验证:
plugin->* 调用已替换为 Service 调用解决: 确保包含正确的头文件:
#include "services/PaymentService.h"
#include "services/RefundService.h"
#include "services/CallbackService.h"
解决: 检查 mock 期望的参数匹配器:
// 使用正确的参数匹配器
EXPECT_CALL(*paymentService, createPayment(_))
.WillOnce(Return(response));
// 或使用具体值
EXPECT_CALL(*paymentService, createPayment(RequestMatcher(req)))
.WillOnce(Return(response));
解决: Service API 可能使用异步模式,添加适当的等待:
// 使用同步等待或回调
std::promise<drogon::HttpResponsePtr> p;
auto f = p.get_future();
callbackService->handleCallback(body, signature)
.then([&p](const auto& resp) {
p.set_value(resp);
});
auto response = f.get();
PayBackend/test/*.ccPayBackend/services/*.hscripts/build.bat