Skip to content

Conversation

@adity1raut
Copy link
Contributor

@adity1raut adity1raut commented Nov 29, 2025

Description

This PR adds comprehensive unit test coverage for the pkg/controller/netns package to improve code quality and maintainability.

Fixed Isuue #1540

Changes

  • ✅ Added netns_test.go with comprehensive test coverage
  • ✅ Fixed linting issue: uncapitalized error message in FindNetnsForPod
  • ✅ Implemented table-driven tests for all public and helper functions
  • ✅ Added mock filesystem support using fstest.MapFS
  • ✅ Created mock DirEntry implementation for testing

Test Coverage

The new tests cover:

  • GetNodeNSpath() - Node namespace path generation
  • GetPodNSpath() - Pod namespace path retrieval
  • builtinOrDir() - Filesystem selection logic
  • isNotNumber() - Character validation helper
  • isProcess() - Process directory identification
  • processEntry() - Entry processing with mocked filesystem
  • FindNetnsForPod() - Main pod namespace discovery function

Files Changed

  • pkg/controller/netns/netns_test.go - New comprehensive test suite

Why This Matters

  • Improved Code Quality: Better test coverage helps catch regressions early
  • Documentation: Tests serve as usage examples for the package
  • Maintainability: Makes refactoring safer and easier
  • CI/CD Ready: Automated testing can be integrated into build pipelines

Checklist

  • Tests pass locally
  • All linting errors resolved
  • Code follows project style guidelines
  • Documentation updated (test comments)
  • No breaking changes

@gemini-code-assist
Copy link

Summary of Changes

Hello @adity1raut, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the quality and maintainability of the pkg/controller/netns package by introducing extensive unit test coverage. The new tests validate the behavior of key functions related to network namespace discovery and path generation, ensuring greater reliability and easier future refactoring. Additionally, it addresses and resolves several existing linting issues.

Highlights

  • New Unit Tests: Added a comprehensive unit test suite in netns_test.go for the pkg/controller/netns package, covering all public and helper functions.
  • Table-Driven Tests: Implemented table-driven tests for improved readability and maintainability of test cases.
  • Mock Filesystem Support: Incorporated fstest.MapFS and a custom mockDirEntry to simulate filesystem interactions, enabling robust testing without actual file operations.
  • Linting Fixes: Resolved several linting issues, including uncapitalized error messages (ST1005), unhandled os.RemoveAll errors (errcheck), and suppressed an unused warning.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


A test file new, a bug takes flight, Code now robust, shining bright. With mocks and maps, paths defined, No more errors, peace of mind.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a comprehensive suite of unit tests for the netns package, which is a valuable addition for improving code quality and maintainability. The use of table-driven tests and fstest.MapFS for mocking is a good approach. However, my review has identified several critical issues where tests are either incomplete or designed to fail, which undermines their purpose. Key functions like FindNetnsForPod and GetPodNSpath are missing tests for their success paths, and some mocks are insufficient for the code they are intended to test. Additionally, an edge case in the isProcess function is handled incorrectly. I have provided specific feedback on how to address these points to ensure the test suite is robust and effectively validates the package's functionality.

@adity1raut adity1raut changed the title Add unit tests for network namespace functions in netns.go Add unit tests for /pkg/controller/netns/netns.go Nov 29, 2025
@codecov
Copy link

codecov bot commented Nov 29, 2025

Codecov Report

❌ Patch coverage is 25.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 39.31%. Comparing base (6d531a8) to head (b85e001).
⚠️ Report is 23 commits behind head on main.

Files with missing lines Patch % Lines
pkg/controller/netns/netns.go 25.00% 2 Missing and 1 partial ⚠️
Files with missing lines Coverage Δ
pkg/controller/netns/netns.go 63.63% <25.00%> (+63.63%) ⬆️

... and 3 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 352bd8d...b85e001. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

Copilot AI left a comment

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 adds comprehensive unit test coverage for the pkg/controller/netns package, implementing table-driven tests for all public functions and helper utilities that manage network namespace paths for Kubernetes pods.

Key Changes:

  • Added netns_test.go with 7 test functions covering the public API and internal helper functions
  • Created mock filesystem support using fstest.MapFS and custom mockDirEntry implementation
  • Implemented table-driven test patterns consistent with the codebase conventions

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

Signed-off-by: adity1raut <araut7798@gmail.com>
@adity1raut
Copy link
Contributor Author

@hzxuzhonghu
Can You Tack a Look On This PR Thank You

Signed-off-by: adity1raut <araut7798@gmail.com>
Copilot AI review requested due to automatic review settings December 9, 2025 13:19
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 11 comments.


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

Signed-off-by: adity1raut <araut7798@gmail.com>
Signed-off-by: adity1raut <araut7798@gmail.com>
Copilot AI review requested due to automatic review settings December 10, 2025 01:50
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.


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

Signed-off-by: adity1raut <araut7798@gmail.com>
@adity1raut
Copy link
Contributor Author

@hzxuzhonghu Can You tack a Look This PR Ready TO merge

Copy link
Member

@hzxuzhonghu hzxuzhonghu left a comment

Choose a reason for hiding this comment

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

/lgtm

@kmesh-bot kmesh-bot added the lgtm label Dec 10, 2025
@kmesh-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hzxuzhonghu

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

The pull request process is described 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

@kmesh-bot kmesh-bot merged commit 232fb70 into kmesh-net:main Dec 10, 2025
11 of 14 checks passed
@adity1raut adity1raut deleted the TestCoverage2 branch December 10, 2025 02:51
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.

3 participants