Skip to content

test(): Add dependency injection infrastructure for comprehensive unit testing#112

Open
Alokxk wants to merge 29 commits intokubeslice:masterfrom
Alokxk:tests/add-unit-test-setup
Open

test(): Add dependency injection infrastructure for comprehensive unit testing#112
Alokxk wants to merge 29 commits intokubeslice:masterfrom
Alokxk:tests/add-unit-test-setup

Conversation

@Alokxk
Copy link
Copy Markdown
Contributor

@Alokxk Alokxk commented Oct 13, 2025

Description

This PR introduces a testing infrastructure that makes the CLI testable without requiring external dependencies like helm, kubectl or actual filesystem operations.

Changes

Implemented dependency injection using interfaces to abstract external interactions. Now all system calls (commands, files, output, time) go through mockable interfaces.

  • interfaces.go - Defines interfaces (Executor, FileOperations, OutputWriter, Clock)
  • exec.go - Real implementations using actual system calls
  • testing.go - Test doubles (fakes) that can be controlled in tests

How Has This Been Tested?

go test ./pkg/internal -v
go test ./pkg/internal -cover

Checklist:

  • The title of the PR states what changed and the related issues number (used for the release note).
  • Does this PR requires documentation updates?
  • I've updated documentation as required by this PR.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have tested it for all user roles.
  • I have added all the required unit test cases.

Does this PR introduce a breaking change?

NONE - This PR only adds testing infrastructure and doesn't change any public APIs or behavior.

Alokxk added 11 commits October 13, 2025 01:57
…epo-add.go file

Signed-off-by: Alokzh <zhalok24@gmail.com>
Signed-off-by: Alokzh <zhalok24@gmail.com>
Signed-off-by: Alokzh <zhalok24@gmail.com>
Signed-off-by: Alokzh <zhalok24@gmail.com>
Signed-off-by: Alokzh <zhalok24@gmail.com>
…etion & configuration generation

Signed-off-by: Alokzh <zhalok24@gmail.com>
…gathering

Signed-off-by: Alokzh <zhalok24@gmail.com>
@Alokxk
Copy link
Copy Markdown
Contributor Author

Alokxk commented Nov 1, 2025

This PR started as dependency injection setup but evolved with addition of tests for the internal package. Here's what's bee added:

Test Files Added:

  1. helm-repo-add_test.go - Helm repo operations & credential handling
  2. cert-manager-setup_test.go - Cert-manager install/uninstall
  3. cluster-manifest_test.go - Manifest generation & cluster registration
  4. controller_test.go - Controller installation with different profiles
  5. values_test.go - YAML values file generation & merging
  6. enterprise_test.go - UI installation, endpoints & token retrieval
  7. verify-executables_test.go - Binary verification for different cluster types
  8. generate-kind-templates_test.go - Kind cluster configuration generation
  9. get-network-info_test.go - Network address gathering for clusters
  10. install-calico_test.go - Calico CNI installation & pod health verification
  11. install-iperf_test.go - iPerf deployment, service exports & rollout restarts
  12. kind-clusters_test.go - Kind cluster lifecycle & kubeconfig management
  13. project-manifest_test.go - KubeSlice project CRUD operations & user management
  14. print-next-steps.go - Refactored for testable kubectl command construction
  15. prometheus_test.go - Prometheus installation & cluster telemetry patching
  16. secrets_test.go - Worker cluster secret retrieval & validation
  17. file-generation_test.go - Directory operations & file dump testing
  18. serviceExport_test.go - ServiceExportConfig CRUD operations
  19. slice-config_test.go - Slice configuration generation & NodeIP verification
  20. worker_test.go - Worker installation, secret fetching & registration workflows

NOTE: Overall Coverage increased by 64.6%

Alokxk added 17 commits November 4, 2025 11:29
…verification

Signed-off-by: Alokzh <zhalok24@gmail.com>
…rification

Signed-off-by: Alokzh <zhalok24@gmail.com>
…ion & kubeconfig management

Signed-off-by: Alokzh <zhalok24@gmail.com>
…nagement functions

Signed-off-by: Alokzh <zhalok24@gmail.com>
… construction & added tests

Signed-off-by: Alokzh <zhalok24@gmail.com>
… Prometheus

Signed-off-by: Alokzh <zhalok24@gmail.com>
…nctions

Signed-off-by: Alokzh <zhalok24@gmail.com>
…ry creation & file writing scenarios

Signed-off-by: Alokzh <zhalok24@gmail.com>
…ation functions

Signed-off-by: Alokzh <zhalok24@gmail.com>
…tions

Signed-off-by: Alokzh <zhalok24@gmail.com>
…on, uninstallation & secret fetching

Signed-off-by: Alokzh <zhalok24@gmail.com>
…add_integration_test.go

Signed-off-by: Alokzh <zhalok24@gmail.com>
…s for verify-executables.go

Signed-off-by: Alokzh <zhalok24@gmail.com>
Signed-off-by: Alokzh <zhalok24@gmail.com>
…es for common functions

Signed-off-by: Alokzh <zhalok24@gmail.com>
Signed-off-by: Alokzh <zhalok24@gmail.com>
@Alokxk
Copy link
Copy Markdown
Contributor Author

Alokxk commented Nov 19, 2025

This PR has been updated to include a comprehensive Integration Test suite. While the Unit Tests mock dependencies, these new tests verify the public API against real-world binaries (kind, helm, kubectl, docker) to ensure end-to-end reliability.

Integration Test Files Added:

  • integration_helpers_test.go - Single Source of Truth for shared test helpers and harness setup
  • verify-executables_integration_test.go - Validates binary detection in the host environment ( Success & Failure paths )
  • helm-repo-add_integration_test.go - Validates Helm repo operations with real binaries ( Add, Skip, Fail )
  • kind-clusters_integration_test.go - Full cluster lifecycle testing: Creation, Idempotency check & Deletion
  • get-network-info_integration_test.go - Validates network discovery via docker inspect (Kind) & kubectl (Non-Kind).
  • kubernetes-operation_integration_test.go - Validates manifest application, resource retrieval & deletion on live clusters.

@Alokxk
Copy link
Copy Markdown
Contributor Author

Alokxk commented Nov 19, 2025

Coverage Report

The new tests resulted in 92.9% total coverage for pkg/internal.

Screenshot from 2025-11-19 18-49-33

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant