Skip to content

libct: trim and de-mock container state unit tests - #5382

Open
kolyshkin wants to merge 1 commit into
opencontainers:mainfrom
kolyshkin:libct-test-demock
Open

libct: trim and de-mock container state unit tests#5382
kolyshkin wants to merge 1 commit into
opencontainers:mainfrom
kolyshkin:libct-test-demock

Conversation

@kolyshkin

@kolyshkin kolyshkin commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Related to opencontainers/cgroups#61.

The removal of mockCgroupManager is needed so oc/cgroups can add more methods without breaking runc.

Remove the useless tests:

  • TestGetContainerPids merely asserted that Container.Processes returns what the mock cgroup manager was configured to return;
  • TestGetContainerState reimplemented the namespace type to /proc file name mapping it was meant to verify, so it could only detect drift between the two copies.

Keep the useful one:

  • TestGetContainerStateAfterUpdate (initially added by commit e6e1c34)

The test round-trips the container state through a real state directory and is the only unit level coverage of Set, saveState, updateState, and currentState. Rewrite it to use real fs2 cgroup manager instead of a mock.

Package coverage goes from 7.4% to 7.3%.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR simplifies libcontainer’s container state unit tests by removing mock-based and redundant coverage, and rewriting the remaining meaningful test to use a real cgroup v2 (fs2) manager operating against a temporary directory (via cgroups.TestMode).

Changes:

  • Removed mockCgroupManager and two low-value tests (TestGetContainerPids, TestGetContainerState).
  • Added newFakeCgroupManager to create a real fs2 cgroup manager backed by a temp directory.
  • Updated TestGetContainerStateAfterUpdate to validate persisted state and confirm the updated memory limit is written to memory.max.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread libcontainer/container_linux_test.go Outdated
Comment on lines +59 to +61
t.Helper()
cgroups.TestMode = true
t.Cleanup(func() { cgroups.TestMode = false })

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Removal of mockCgroupManager is needed so that oc/cgroups can add more
methods without breaking runc compatibility.

Remove the useless tests:
- TestGetContainerPids merely asserted that Container.Processes returns
  what the mock cgroup manager was configured to return;
- TestGetContainerState reimplemented the namespace type to /proc file
  name mapping it was meant to verify, so it could only detect drift
  between the two copies.

Keep the useful one:
- TestGetContainerStateAfterUpdate (added by commit e6e1c34).

The test round-trips the container state through a real state directory
and is the only unit level coverage of Set, saveState, updateState, and
currentState. Rewrite it to use real fs2 cgroup manager instead of a
mock.

Package coverage goes from 7.4% to 7.3%.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants