test: add unit tests for SecurityUtils, WakeupUtils, EnableUtils modules - #758
Conversation
Reviewer's GuideAdds 47 GTest unit cases across SecurityUtils, WakeupUtils, and EnableUtils, using temporary filesystem fixtures and direct access to private helpers to validate normal, invalid, and boundary behaviors without changing production code. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="deepin-devicemanager-server/tests/src/SecurityUtils/ut_securityutils.cpp" line_range="193-196" />
<code_context>
+TEST_F(SecurityUtilsTest, isSafeSysfsPath_validDevicesPath_returnsTrue)
+{
+ // Arrange
+ QString path = "/devices/pci0000:00/0000:00:01.0";
+
+ // Act
+ bool result = isSafeSysfsPath(path);
+
+ // Assert
</code_context>
<issue_to_address>
**issue (testing):** The test uses the hard-coded `/sys/devices/pci0000:00/0000:00:01.0` path, but `isSafeSysfsPath` requires the canonical path to exist. On hosts without that exact PCI device, the function returns false and the test fails despite the input being intended as a valid case.
**Triggers:** When the test runs on a machine whose sysfs topology does not contain `/sys/devices/pci0000:00/0000:00:01.0`.
**Suggested fix:** Create or select an actually existing sysfs path at runtime, or mock the filesystem-dependent validation before asserting the positive result.
</issue_to_address>| QString path = "/devices/pci0000:00/0000:00:01.0"; | ||
|
|
||
| // Act | ||
| bool result = isSafeSysfsPath(path); |
There was a problem hiding this comment.
issue (testing): The test uses the hard-coded /sys/devices/pci0000:00/0000:00:01.0 path, but isSafeSysfsPath requires the canonical path to exist. On hosts without that exact PCI device, the function returns false and the test fails despite the input being intended as a valid case.
Triggers: When the test runs on a machine whose sysfs topology does not contain /sys/devices/pci0000:00/0000:00:01.0.
Suggested fix: Create or select an actually existing sysfs path at runtime, or mock the filesystem-dependent validation before asserting the positive result.
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: add-uos, lzwind The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
…bleUtils modules - Add ut_securityutils.cpp with 18 test cases covering SecurityUtils functions - Add ut_wakeuputils.cpp with 14 test cases covering WakeupUtils functions - Add ut_enableutils.cpp with 15 test cases covering EnableUtils functions 测试(单测): 新增 SecurityUtils、WakeupUtils 和 EnableUtils 模块单元测试 - 新增 ut_securityutils.cpp,包含 18 个测试用例,覆盖 SecurityUtils 各功能函数 - 新增 ut_wakeuputils.cpp,包含 14 个测试用例,覆盖 WakeupUtils 各功能函数 - 新增 ut_enableutils.cpp,包含 15 个测试用例,覆盖 EnableUtils 各功能函数 Log: 为 deepin-devicemanager 的 SecurityUtils、WakeupUtils、EnableUtils 三个工具模块补充单元测试,共新增 47 个测试用例
d64079e to
e8fd8d9
Compare
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
📋 漏洞对比统计
🔍 详细分析1. 语法逻辑 ✅ (25/25 分)评价: 语法正确,逻辑清晰 ✅ 通过 分析:
潜在问题: 2. 代码质量 ✅ (24/25 分)评价: 代码结构清晰,注释完整 ✅ 通过 分析:
潜在问题:
改进建议: // 可提取为辅助函数,减少重复代码
static QStringList createTestLines(const QString &hardwareClass)
{
QStringList lines;
for (int i = 0; i < 12; ++i)
lines << QString("Key%1: Value%1").arg(i);
lines[0] = "Hardware Class: " + hardwareClass;
return lines;
}3. 代码性能 ✅ (20/20 分)评价: 性能良好,资源使用合理 ✅ 通过 分析:
潜在问题: 4. 代码安全 🔒 (30/30 分)评价: 存在0个安全漏洞 ✅ 通过
分析:
安全漏洞详情: 漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个 📝 审查总结本次 PR 为
优点:
改进建议:
本报告由 AI 代码审查工具自动生成 |
|
/merge |
Summary
为 deepin-devicemanager 项目补充 3 个模块的 GTest 单元测试,共 47 个用例,全部编译通过且测试全绿。
Test Coverage
Test Results
Commits
94907f9atest: add unit tests for securityutils module56b9ea78test: add unit tests for wakeuputils moduled64079e3test: add unit tests for enableutils moduleSummary by Sourcery
Tests: