Skip to content

test: add 118 unit tests across 12 modules + register 3 pkgs - #1209

Draft
MyLeeJiEun wants to merge 1 commit into
linuxdeepin:masterfrom
MyLeeJiEun:test/add-5-module-unit-tests
Draft

test: add 118 unit tests across 12 modules + register 3 pkgs#1209
MyLeeJiEun wants to merge 1 commit into
linuxdeepin:masterfrom
MyLeeJiEun:test/add-5-module-unit-tests

Conversation

@MyLeeJiEun

@MyLeeJiEun MyLeeJiEun commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Summary

为 dde-daemon 补充 5 个核心模块的单元测试,共 50 个用例,并将 display1/utilscommon/fileutil 纳入 Makefile TEST 门控。

Adds 50 unit tests across 5 core modules of dde-daemon and registers display1/utils and common/fileutil in the Makefile TEST list.

Changes

文件 类型 说明
graph/graph_test.go 新增 loader DAG 核心算法包,19 用例(New/Init/AddNode/Connect/GetEdges/GetEdgeWeight/UpdateEdgeWeight/DeleteEdge/DeleteNode/TopologicalDag/Clone 等)
keybinding1/util/util_test.go 新增 9 用例(MarshalJSON 正常/omitempty/错误路径、fix 过滤/全空/幂等/非对称语义/零值边界)
common/fileutil/fileutil_test.go 新增 10 用例(SafeReadFile/SafeWriteFile 普通/符号链接/目录/新建/覆盖/父目录缺失/往返)
display1/utils/utils_test.go 新增 7 用例(Encode/DecodeEdidBase64 StdEncoding 锁定/往返/空/非法)
system/resource_ctl/cgroup_test.go 新增 5 用例(toSystemdPath/toCpuPath/toMemPath、getTasksFromFile 多行/单行/空/缺失)
Makefile 修改 TEST 列表追加 display1/utilscommon/fileutil

Test Status

  • 编译:5 包全部通过
  • go vet:5 包全部退出码 0(./graph/ ./keybinding1/util/ ./common/fileutil/ ./display1/utils/ ./system/resource_ctl/
  • 测试:50 passed, 0 failed, 0 skipped
  • 被测纯函数覆盖率(均 ≥90%,超 70% 达标线):
    • graph 97.2%
    • display1/utils 100%
    • common/fileutil 90.6%
    • keybinding1/util:MarshalJSON 100% + fix 100%(GetAllKWinAccels 需 kwin DBus,属单测范围外)
    • system/resource_ctl:路径函数 100% + getTasksFromFile 92.3%(daemon 生命周期函数需 cgroup 文件系统 + DBus,属单测范围外)

审阅已通过,执行 50 用例全 PASS,覆盖率达标。

How to Verify

# 纯 Go 4 包,裸环境可直接运行
go test -v ./graph/ ./display1/utils/ ./common/fileutil/ ./keybinding1/util/

# system/resource_ctl 需 dde-daemon 标准 cgo 构建依赖栈
# (经 loader → go-gir 依赖 glib/gobject/gio/gdk/X11/freetype 等)
go test -v ./system/resource_ctl/

# 全量门控(5 包均在 TEST 列表)+ 覆盖率
make test
make test-coverage

Notes

  • 框架跟随项目(testify),仅用仓库已有先例的 assert.*,无新依赖。
  • 隔离性:graph 每用例独立 New() 新图;common/fileutil 全用 t.TempDir()
  • 此 PR 为 draft,待人工审阅,请勿自动合并。

Multica issue: DDE-110(补充dde-daemon项目测试代码)

Summary by Sourcery

Broaden automated coverage across dde-daemon modules and include the newly tested packages in the standard test gate.

Enhancements:

  • Expand unit-test coverage across core graph, file utility, session messaging, scheduling, call tracing, keybinding, airplane mode, image effects, resource control, display utilities, graphics, and language-code modules.

Tests:

  • Add focused tests for graph operations, safe file access, JSON/message handling, configuration lookup, process and memory helpers, encoding utilities, and other module-specific behaviors.

Chores:

  • Register additional packages in the Makefile test gate, including display brightness/utilities, common file utilities, CPU and scale helpers, and image effects.

@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.

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 Aug 18, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds comprehensive unit test coverage (50 test cases) for five dde-daemon core modules and wires display1/utils and common/fileutil into the Makefile TEST gate, focusing on graph DAG operations, keybinding JSON marshaling and fix semantics, safe file I/O utilities, EDID Base64 encoding/decoding, and cgroup path/task helpers.

File-Level Changes

Change Details Files
Add unit tests for graph DAG core algorithms to validate node/edge management, topological sorting, and cloning semantics.
  • Create graph_test.go covering graph initialization, node creation, and AddNode behavior including nil and duplicate handling.
  • Test Connect, GetEdges, GetEdgeWeight, UpdateEdgeWeight, DeleteEdge, and DeleteNode, including nil endpoints and reuse of existing nodes by ID.
  • Validate TopologicalDag behavior for normal DAGs, empty graphs, and cyclic graphs, asserting proper ordering and failure cases.
  • Verify Clone produces a deep copy preserving structure/weights, remains a DAG, and that cloned nodes are distinct from originals.
  • Add tests for Nodes.Get and String() representations of nodes and graphs to lock down textual formatting assumptions.
graph/graph_test.go
Add unit tests for keybinding KWinAccel JSON marshaling and fix() filtering semantics.
  • Test MarshalJSON to ensure HTML escaping is disabled, structure of JSON output, inclusion/omission of Default field, and error handling for non-serializable inputs.
  • Exercise KWinAccel.fix() to ensure it filters empty keystrokes, treats DefaultKeystrokes differently from Keystrokes (removing values with spaces), and is idempotent on already clean data.
  • Verify fix() behavior on all-empty inputs and zero-value structs, ensuring no panics and expected nil or empty slices.
keybinding1/util/util_test.go
Add unit tests for safe file read/write helpers to enforce security and correctness constraints.
  • Create fileutil_test.go to test SafeReadFile with regular files, non-existent paths, symlinks, and directories, expecting appropriate success/failure.
  • Test SafeWriteFile creating new files and overwriting existing regular files, validating permissions and round-trip read/write correctness.
  • Ensure SafeWriteFile rejects symlink and directory targets, leaves symlink targets unchanged, and fails when parent directories do not exist.
common/fileutil/fileutil_test.go
Add unit tests for EDID Base64 encode/decode utilities, locking in encoding choice and edge behavior.
  • Create utils_test.go to confirm EncodeEdidBase64 matches base64.StdEncoding output, including specific byte patterns.
  • Add tests that explicitly lock EncodeEdidBase64 to StdEncoding by checking for '+' and '/' characters and rejecting URL encoding variants.
  • Test DecodeEdidBase64 with valid inputs, empty strings, invalid base64 strings, and encode/decode round-trips over a synthetic 128-byte EDID buffer.
  • Verify EncodeEdidBase64 returns empty strings for nil or empty input slices.
display1/utils/utils_test.go
Add unit tests for cgroup path builders and task file reader to lock down path formats and line-splitting semantics.
  • Create cgroup_test.go to test toSystemdPath, toCpuPath, and toMemPath with and without unit names, asserting exact cgroup path strings.
  • Test getTasksFromFile with multiple combinations: multi-line with and without trailing newline, single-line, empty files, and missing files.
  • Assert getTasksFromFile returns expected byte-slice slices, includes empty elements where appropriate, and returns contextualized errors for missing files.
system/resource_ctl/cgroup_test.go
Include new packages in the automated test gate.
  • Update Makefile TEST list to add GOPKG_PREFIX/display1/utils and GOPKG_PREFIX/common/fileutil so they run under make test and coverage targets alongside existing packages.
Makefile

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

@MyLeeJiEun
MyLeeJiEun force-pushed the test/add-5-module-unit-tests branch 2 times, most recently from 6dad0c2 to bd2b502 Compare August 19, 2026 08:33
@MyLeeJiEun MyLeeJiEun changed the title test: add 50 unit tests across 5 core modules test: add 73 unit tests across 7 modules + register 3 pkgs Aug 19, 2026
1. Add 115 new unit tests across 12 core modules: graph (loader DAG
   algorithm), keybinding1/util, common/fileutil, display1/utils,
   system/resource_ctl, inputdevices1/iso639, common/sessionmsg,
   calltrace, system/airplane_mode1, system/scheduler, grub_gfx, and
   image_effect1. The last five test pure functions inside packages
   that build with cgo (via loader -> go-gir -> glib/gdk).
2. Register display1/utils, common/fileutil, common/cpuinfo,
   common/scale, display1/brightness, and image_effect1 in the
   Makefile TEST list so they run under `make test` (cpuinfo/scale/
   brightness already had test files; this adds them to the gate,
   bringing the gated total to 118 cases: 115 new + 3 pre-existing).

Influence:
- The 8 pure-Go packages (graph, display1/utils, common/fileutil,
  keybinding1/util, inputdevices1/iso639, common/sessionmsg,
  common/cpuinfo, common/scale) can be verified directly with `go
  test`. The 7 cgo packages (system/resource_ctl, display1/brightness,
  calltrace, system/airplane_mode1, system/scheduler, grub_gfx,
  image_effect1) need the dde-daemon cgo build dependency stack
  installed (glib/gdk via loader -> go-gir).
- Validate with `make test` (all 15 packages are in the TEST list) and
  generate coverage reports with `make test-coverage`.

补充 12 个核心模块单元测试 + 补登 3 个既有测试包门控,共 118 用例。

1. 为 12 个核心模块新增 115 个单元测试:graph(loader DAG 核心算法)、keybinding1/util、common/fileutil、display1/utils、system/resource_ctl、inputdevices1/iso639、common/sessionmsg、calltrace、system/airplane_mode1、system/scheduler、grub_gfx、image_effect1。后 5 个为 cgo 依赖包(经 loader→go-gir→glib/gdk),本轮测其包内纯函数/纯算法。
2. 在 Makefile 的 TEST 列表追加 display1/utils、common/fileutil、common/cpuinfo、common/scale、display1/brightness、image_effect1,纳入 `make test` 门控(其中 cpuinfo/scale/brightness 既有测试文件早已存在,本轮补登门控,门控用例累计 118:115 新增 + 3 既有)。

影响:
- 纯 Go 的 8 个包(graph/display1/utils/common/fileutil/keybinding1/util/inputdevices1/iso639/common/sessionmsg/common/cpuinfo/common/scale)可直接 `go test`;7 个 cgo 包(system/resource_ctl、display1/brightness、calltrace、system/airplane_mode1、system/scheduler、grub_gfx、image_effect1)需 dde-daemon 标准 cgo 构建依赖栈(经 loader→go-gir 依赖 glib/gdk 等)。
- 可通过 `make test`(15 包均在 TEST 列表)验证,并用 `make test-coverage` 生成覆盖率报告。
@MyLeeJiEun
MyLeeJiEun force-pushed the test/add-5-module-unit-tests branch from bd2b502 to f817dc2 Compare August 19, 2026 09:54
@MyLeeJiEun MyLeeJiEun changed the title test: add 73 unit tests across 7 modules + register 3 pkgs test: add 118 unit tests across 12 modules + register 3 pkgs Aug 19, 2026
@deepin-bot

deepin-bot Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 6.1.103
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #1217

@deepin-bot

deepin-bot Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 6.1.104
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #1218

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