Skip to content

test(dconfig): add unit tests for dconfig-center - #158

Draft
MyLeeJiEun wants to merge 1 commit into
linuxdeepin:masterfrom
MyLeeJiEun:agent/dde/138c30fc68d7
Draft

test(dconfig): add unit tests for dconfig-center#158
MyLeeJiEun wants to merge 1 commit into
linuxdeepin:masterfrom
MyLeeJiEun:agent/dde/138c30fc68d7

Conversation

@MyLeeJiEun

@MyLeeJiEun MyLeeJiEun commented Sep 1, 2026

Copy link
Copy Markdown

Summary

补充 dde-app-services dconfig-center 单元测试代码,提升测试覆盖率。

Multica Issue: DDE-207

Changes

  • 新增 ut_dconfig_global.cpp — 全局工具函数测试(formatDBusObjectPath / getUserNameByUid 等)
  • 新增 ut_helper.cpp — 缓存管理器及辅助函数测试(ConfigSyncRequestCache / RefManager 等)
  • 扩展 ut_dconfigconn.cpp — 新增 8 个测试用例,修复 save 断言路径匹配问题
  • 扩展 ut_dconfigserver.cpp — 新增 9 个测试用例,修复 reload_withFileChange 路径解析
  • 改进 test_helper.hpp — 新增 MetaFileGuard RAII,EnvGuard 改用 rmpath 递归清理
  • 更新 CMakeLists.txt — ENABLE_COVERAGE 选项条件控制覆盖率,新增测试源文件

Test Results

  • 202 passed / 0 failed / 6 skipped
  • Coverage: 行 86.3% / 函数 96.9%(均 > 80%)

License

文件头版权声明年份已更新为 2026。

Summary by Sourcery

Expand dconfig-center unit-test coverage and improve test infrastructure for reliable isolation and coverage reporting.

Enhancements:

  • Expand dconfig-center unit-test coverage across global utilities, helpers, connections, resources, and server behavior.
  • Improve test isolation and cleanup with environment and metadata RAII guards and process-specific temporary paths.

Build:

  • Make coverage instrumentation opt-in through ENABLE_COVERAGE and add a coverage report target.

Tests:

  • Add comprehensive unit tests for dconfig-center utility functions, cache helpers, connection behavior, resource lifecycle, configuration reparsing, synchronization, and server operations.
  • Update existing connection and server tests to cover additional branches, persistence, reload behavior, permission changes, and user-data removal.

Chores:

  • Update test file copyright years through 2026.

1. Add ut_dconfig_global.cpp for global utility function tests
2. Add ut_helper.cpp for cache manager and helper function tests
3. Expand ut_dconfigconn.cpp with 8 new test cases
4. Expand ut_dconfigserver.cpp with 9 new test cases
5. Fix reload_withFileChange test path resolution in ut_dconfigserver
6. Add MetaFileGuard RAII and improve EnvGuard cleanup in test_helper
7. Update CMakeLists.txt with ENABLE_COVERAGE option and new sources

Influence:
1. Verify all 202 test cases pass with 0 failures
2. Check coverage meets line 86.3% and function 96.9% thresholds
3. Validate ENABLE_COVERAGE option defaults to OFF
4. Test reload_withFileChange with correct path resolution

test(dconfig): 补充 dconfig-center 单元测试

1. 新增 ut_dconfig_global.cpp 全局工具函数测试
2. 新增 ut_helper.cpp 缓存管理器及辅助函数测试
3. 扩展 ut_dconfigconn.cpp 新增 8 个测试用例
4. 扩展 ut_dconfigserver.cpp 新增 9 个测试用例
5. 修复 ut_dconfigserver 中 reload_withFileChange 测试路径解析问题
6. 新增 MetaFileGuard RAII 并改进 EnvGuard 清理逻辑
7. 更新 CMakeLists.txt 增加 ENABLE_COVERAGE 选项及新测试源文件

Influence:
1. 验证全部 202 个测试用例通过且无失败
2. 检查覆盖率达标(行 86.3%,函数 96.9%)
3. 验证 ENABLE_COVERAGE 选项默认关闭
4. 测试 reload_withFileChange 路径解析正确性
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: MyLeeJiEun

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@deepin-ci-robot

Copy link
Copy Markdown

Hi @MyLeeJiEun. Thanks for your PR. 😃

@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
  • 检测到敏感词unset变动
详情
    {
    "unset": {
        "dconfig-center/tests/test_helper.hpp": {
            "b": [
                "            qunsetenv(m_name);"
            ]
        },
        "dconfig-center/tests/ut_dconfigconn.cpp": {
            "b": [
                "        qunsetenv(\"STATE_DIRECTORY\");",
                "        qunsetenv(\"STATE_DIRECTORY\");",
                "// Branch: isDefaultValue() returns true for unset key (default)"
            ]
        },
        "dconfig-center/tests/ut_helper.cpp": {
            "b": [
                "        qunsetenv(\"DSG_CONFIG_CONNECTION_DISABLE_DBUS\");"
            ]
        }
    }
}

@deepin-ci-robot

Copy link
Copy Markdown

Hi @MyLeeJiEun. Thanks for your PR.

I'm waiting for a linuxdeepin member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@sourcery-ai

sourcery-ai Bot commented Sep 1, 2026

Copy link
Copy Markdown

Reviewer's Guide

This PR substantially broadens dconfig-center unit coverage by adding utility/helper suites and extensive connection, resource, and server branch tests, while improving fixture isolation and introducing opt-in lcov report generation; the reported result is 202 passing, 0 failing, and 6 skipped tests with 86.3% line and 96.9% function coverage.

File-Level Changes

Change Details Files
Expanded dconfig-center unit-test coverage across global utilities, helper functions, connection/resource behavior, and server lifecycle, synchronization, cache, and reload paths.
  • Added focused tests for path/key conversion, configuration ID parsing, user/process lookup, object pooling, filesystem discovery, QVariant/DBus conversion, validation, translation, and user enumeration.
  • Added connection/resource assertions for metadata access, permissions, signals, cache behavior, persistence, reparsing, resource queries, and branch/error handling.
  • Added server tests for user-data removal, lifecycle and exit behavior, path validation, reload/update/sync handling, cache synchronization, resource release, and invalid inputs.
dconfig-center/tests/ut_dconfig_global.cpp
dconfig-center/tests/ut_helper.cpp
dconfig-center/tests/ut_dconfigconn.cpp
dconfig-center/tests/ut_dconfigserver.cpp
Improved test isolation and cleanup for environment variables, temporary state, and modified metadata files.
  • Added MetaFileGuard RAII restoration for metadata fixtures.
  • Updated EnvGuard to restore unset variables correctly and recursively remove directories created by tests.
  • Moved tests to per-process temporary paths and cleaned state after test suites.
dconfig-center/tests/test_helper.hpp
dconfig-center/tests/ut_dconfigconn.cpp
dconfig-center/tests/ut_dconfigserver.cpp
dconfig-center/tests/ut_helper.cpp
Made coverage instrumentation opt-in and added a CMake coverage-report target.
  • Replaced the unconditional unit-test coverage flag with ENABLE_COVERAGE.
  • Added lcov filtering and genhtml report generation when tools are available.
  • Registered the new test sources and enabled private/protected member access for tests.
dconfig-center/tests/CMakeLists.txt
Updated SPDX copyright year ranges in the modified test infrastructure and sources.
  • Updated file headers through 2026.
dconfig-center/tests/CMakeLists.txt
dconfig-center/tests/test_helper.hpp
dconfig-center/tests/ut_dconfig_global.cpp
dconfig-center/tests/ut_dconfigconn.cpp
dconfig-center/tests/ut_dconfigserver.cpp
dconfig-center/tests/ut_helper.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants