Skip to content

Refactor and consolidate module test files into a single directory#2997

Merged
redscholar merged 1 commit intokubesphere:mainfrom
redscholar:new-module
Feb 14, 2026
Merged

Refactor and consolidate module test files into a single directory#2997
redscholar merged 1 commit intokubesphere:mainfrom
redscholar:new-module

Conversation

@redscholar
Copy link
Contributor

What type of PR is this?

/kind feature

What this PR does / why we need it:

  • Deleted multiple individual test files for various modules (e.g., add_hostvars_test.go, assert_test.go, command_test.go, etc.) to streamline the testing framework.
  • Introduced a new consolidated test file for the add_hostvars module, which includes comprehensive test cases for argument parsing and execution scenarios.
  • This restructuring enhances maintainability and organization of the test suite, making it easier to manage and extend in the future.

Which issue(s) this PR fixes:

Fixes #

Special notes for reviewers:

Does this PR introduced a user-facing change?

Refactor and consolidate module test files into a single directory

Additional documentation, usage docs, etc.:


@kubesphere-prow kubesphere-prow bot added release-note kind/feature Categorizes issue or PR as related to a new feature. labels Feb 14, 2026
@kubesphere-prow
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: redscholar

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

@kubesphere-prow kubesphere-prow bot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Feb 14, 2026
@gemini-code-assist
Copy link

Summary of Changes

Hello @redscholar, 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 refactors the internal structure of the module system, focusing on improving code organization, maintainability, and testability. By moving each module into its own subdirectory and introducing a shared 'internal' package for common logic and testing utilities, the codebase becomes more modular and easier to navigate. This restructuring streamlines the development process, making it simpler to manage and extend individual modules and their associated tests, ultimately enhancing the overall quality and scalability of the project.

Highlights

  • Module Refactoring: Refactored all module implementations into dedicated subdirectories (e.g., 'pkg/modules/add_hostvars' for 'add_hostvars') to improve code organization and modularity.
  • Centralized Logic and Utilities: Introduced a new 'pkg/modules/internal' package to centralize common execution options, standard output/error constants, and test utilities, reducing redundancy across modules.
  • Enhanced Test Structure: Migrated all module-specific test files into their respective new subdirectories, ensuring that each module's code and tests are co-located for better maintainability.
  • Streamlined Module Registration: Removed redundant 'init()' functions from individual modules, centralizing the registration of all modules within 'pkg/modules/module.go' for a cleaner and more consistent approach.
  • Updated Module Implementations: Updated all module implementations to utilize the shared 'internal.ExecOptions' and standard error/output constants, promoting consistency and easier future modifications.
Changelog
  • pkg/modules/add_hostvars.go
    • Renamed to pkg/modules/add_hostvars/add_hostvars.go.
    • Updated package name from 'modules' to 'add_hostvars'.
    • Removed 'utilruntime' import.
    • Imported 'internal' package.
    • Updated 'ExecOptions' and constants to use 'internal' types.
    • Removed the 'init()' function.
  • pkg/modules/add_hostvars/add_hostvars_test.go
    • Added new test file with comprehensive unit tests for the 'add_hostvars' module, covering argument parsing, template resolution, and variable merging.
  • pkg/modules/add_hostvars_test.go
    • Removed the old test file.
  • pkg/modules/assert.go
    • Renamed to pkg/modules/assert/assert.go.
    • Updated package name from 'modules' to 'assert'.
    • Removed 'utilruntime' import.
    • Imported 'internal' package.
    • Updated 'ExecOptions' and constants to use 'internal' types.
    • Removed the 'init()' function.
  • pkg/modules/assert/assert_test.go
    • Added new test file with comprehensive unit tests for the 'assert' module, covering argument parsing, condition evaluation, and message handling.
  • pkg/modules/assert_test.go
    • Removed the old test file.
  • pkg/modules/command.go
    • Renamed to pkg/modules/command/command.go.
    • Updated package name from 'modules' to 'command'.
    • Removed 'utilruntime' import.
    • Imported 'internal' package.
    • Updated 'ExecOptions' and constants to use 'internal' types.
    • Removed the 'init()' function.
  • pkg/modules/command/command_test.go
    • Added new test file with comprehensive unit tests for the 'command' module, covering argument parsing and template resolution.
  • pkg/modules/command_test.go
    • Removed the old test file.
  • pkg/modules/copy.go
    • Renamed to pkg/modules/copy/copy.go.
    • Updated package name from 'modules' to 'copy'.
    • Removed 'utilruntime' import.
    • Imported 'internal' package.
    • Updated 'ExecOptions' and constants to use 'internal' types.
    • Removed the 'init()' function.
  • pkg/modules/copy/copy_test.go
    • Added new test file with comprehensive unit tests for the 'copy' module, covering argument parsing and template resolution.
  • pkg/modules/copy_test.go
    • Removed the old test file.
  • pkg/modules/debug.go
    • Renamed to pkg/modules/debug/debug.go.
    • Updated package name from 'modules' to 'debug'.
    • Removed 'utilruntime' import.
    • Imported 'internal' package.
    • Updated 'ExecOptions' and constants to use 'internal' types.
    • Removed the 'init()' function.
  • pkg/modules/debug/debug_test.go
    • Added new test file with comprehensive unit tests for the 'debug' module, covering argument parsing, template resolution, and message printing.
  • pkg/modules/debug_test.go
    • Removed the old test file.
  • pkg/modules/fetch.go
    • Renamed to pkg/modules/fetch/fetch.go.
    • Updated package name from 'modules' to 'fetch'.
    • Removed 'utilruntime' import.
    • Imported 'internal' package.
    • Updated 'ExecOptions' and constants to use 'internal' types.
    • Removed the 'init()' function.
  • pkg/modules/fetch/fetch_test.go
    • Added new test file with comprehensive unit tests for the 'fetch' module, covering argument parsing and template resolution.
  • pkg/modules/fetch_test.go
    • Removed the old test file.
  • pkg/modules/gen_cert.go
    • Renamed to pkg/modules/gen_cert/gen_cert.go.
    • Updated package name from 'modules' to 'get_cert'.
    • Removed 'utilruntime' import.
    • Imported 'internal' package.
    • Updated 'ExecOptions' and constants to use 'internal' types.
    • Removed the 'init()' function.
  • pkg/modules/gen_cert/gen_cert_test.go
    • Added new test file with comprehensive unit tests for the 'gen_cert' module, covering argument parsing and template resolution.
  • pkg/modules/gen_cert_test.go
    • Removed the old test file.
  • pkg/modules/http_get_file.go
    • Renamed to pkg/modules/http_get_file/http_get_file.go.
    • Updated package name from 'modules' to 'http_get_file'.
    • Removed 'utilruntime' import.
    • Imported 'internal' package.
    • Updated 'ExecOptions' and constants to use 'internal' types.
    • Removed the 'init()' function.
  • pkg/modules/http_get_file/http_get_file_test.go
    • Added new test file with comprehensive unit tests for the 'http_get_file' module, covering argument parsing and template resolution.
  • pkg/modules/image.go
    • Renamed to pkg/modules/image/image.go.
    • Updated package name from 'modules' to 'image'.
    • Removed 'utilruntime' import.
    • Imported 'internal' package.
    • Updated 'ExecOptions' and constants to use 'internal' types.
    • Removed the 'init()' function.
  • pkg/modules/image/image_test.go
    • Added new test file with comprehensive unit tests for the 'image' module, covering argument parsing.
  • pkg/modules/image_test.go
    • Removed the old test file.
  • pkg/modules/include_vars.go
    • Renamed to pkg/modules/include_vars/include_vars.go.
    • Updated package name from 'modules' to 'include_vars'.
    • Removed 'utilruntime' import.
    • Imported 'internal' package.
    • Updated 'ExecOptions' and constants to use 'internal' types.
    • Removed the 'init()' function.
  • pkg/modules/include_vars/include_vars_test.go
    • Added new test file with comprehensive unit tests for the 'include_vars' module, covering argument parsing and template resolution.
  • pkg/modules/include_vars_test.go
    • Removed the old test file.
  • pkg/modules/internal/options.go
    • Added new file defining the 'ExecOptions' struct, 'GetAllVariables', 'GetConnector' methods, and the module registration mechanism ('RegisterModule', 'FindModule').
  • pkg/modules/internal/result.go
    • Added new file defining standard output constants ('StdoutSuccess', 'StdoutFailed', 'StdoutSkip') and standard error messages.
  • pkg/modules/internal/test.go
    • Added new file providing test utilities, including 'NewTestConnector' for mocking connector behavior and 'NewTestVariable' for setting up test variable contexts.
  • pkg/modules/module.go
    • Updated to import and re-export types and constants from the new 'internal' package.
    • Centralized the registration of all modules using 'internal.RegisterModule'.
  • pkg/modules/module_test.go
    • Removed the old test utility file.
  • pkg/modules/prometheus.go
    • Renamed to pkg/modules/prometheus/prometheus.go.
    • Updated package name from 'modules' to 'prometheus'.
    • Removed 'utilruntime' import.
    • Imported 'internal' package.
    • Updated 'ExecOptions' and constants to use 'internal' types.
    • Removed the 'init()' function.
  • pkg/modules/prometheus/prometheus_test.go
    • Added new test file with comprehensive unit tests for the 'prometheus' module, covering argument parsing and template resolution.
  • pkg/modules/prometheus_test.go
    • Removed the old test file.
  • pkg/modules/result.go
    • Renamed to pkg/modules/result/result.go.
    • Updated package name from 'modules' to 'result'.
    • Removed 'utilruntime' import.
    • Imported 'internal' package.
    • Updated 'ExecOptions' and constants to use 'internal' types.
    • Removed the 'init()' function.
  • pkg/modules/result/result_test.go
    • Added new test file with comprehensive unit tests for the 'result' module, covering argument parsing and variable merging.
  • pkg/modules/result_test.go
    • Removed the old test file.
  • pkg/modules/set_fact.go
    • Renamed to pkg/modules/set_fact/set_fact.go.
    • Updated package name from 'modules' to 'set_fact'.
    • Removed 'utilruntime' import.
    • Imported 'internal' package.
    • Updated 'ExecOptions' and constants to use 'internal' types.
    • Removed the 'init()' function.
  • pkg/modules/set_fact/set_fact_test.go
    • Added new test file with comprehensive unit tests for the 'set_fact' module, covering argument parsing, template resolution, and variable setting.
  • pkg/modules/set_fact_test.go
    • Removed the old test file.
  • pkg/modules/setup.go
    • Renamed to pkg/modules/setup/setup.go.
    • Updated package name from 'modules' to 'setup'.
    • Removed 'utilruntime' import.
    • Imported 'internal' package.
    • Updated 'ExecOptions' and constants to use 'internal' types.
    • Removed the 'init()' function.
  • pkg/modules/setup/setup_test.go
    • Added new test file with comprehensive unit tests for the 'setup' module, covering argument parsing.
  • pkg/modules/setup_test.go
    • Removed the old test file.
  • pkg/modules/template.go
    • Renamed to pkg/modules/template/template.go.
    • Updated package name from 'modules' to 'template'.
    • Removed 'utilruntime' import.
    • Imported 'internal' package.
    • Updated 'ExecOptions' and constants to use 'internal' types.
    • Removed the 'init()' function.
  • pkg/modules/template/template_test.go
    • Added new test file with comprehensive unit tests for the 'template' module, covering argument parsing and template resolution.
  • pkg/modules/template_test.go
    • Removed the old test file.
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.

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 refactors the module system by moving common functionalities and constants into a new pkg/modules/internal package. Each module (add_hostvars, assert, command, copy, debug, fetch, gen_cert, http_get_file, image, include_vars, prometheus, result, set_fact, setup, template) has been updated to use this internal package for ExecOptions, standard output/error constants, and module registration. This involves changing package names to match their directory, removing redundant utilruntime imports, updating function signatures to use internal.ExecOptions, and replacing direct constant references with those from the internal package. Additionally, all old test files have been replaced with new, more comprehensive unit tests for each module, and the module.go file now centrally registers all modules using the new internal.RegisterModule function. Review comments highlight an inconsistency in the gen_cert package name, suggesting it be renamed to gen_cert for Go convention, and recommend refactoring repeated LogOutput handling in the debug module for better code clarity and consistency.

@redscholar redscholar force-pushed the new-module branch 2 times, most recently from f98f1e0 to a810ebc Compare February 14, 2026 07:19
…ructure

- Deleted multiple individual test files for various modules (e.g., add_hostvars_test.go, assert_test.go, command_test.go, etc.) to streamline the testing framework.
- Introduced a new consolidated test file for the add_hostvars module, which includes comprehensive test cases for argument parsing and execution scenarios.
- This restructuring enhances maintainability and organization of the test suite, making it easier to manage and extend in the future.

Signed-off-by: redscholar <blacktiledhouse@gmail.com>
@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
12.0% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@redscholar redscholar merged commit 7fee91a into kubesphere:main Feb 14, 2026
5 of 7 checks passed
@redscholar redscholar deleted the new-module branch February 14, 2026 07:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/feature Categorizes issue or PR as related to a new feature. release-note size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant