Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ca0c214
Add dependency injection infrastructure & improve coverage for helm-r…
Alokxk Oct 12, 2025
285eff5
Move Sleep & Now functions to interfaces.go
Alokxk Oct 12, 2025
0b956c1
Refactor cert-manager-setup.go file for testing
Alokxk Oct 26, 2025
27dbae3
Add unit tests for cert-manager installation & uninstallation
Alokxk Oct 26, 2025
3817b96
Refactor cluster-manifest file & add unit tests for the operations
Alokxk Oct 27, 2025
3b7f7e5
Refactored controller.go file & added tests for controller functions
Alokxk Oct 28, 2025
da0a230
Refactored values.go & add tests for generateValueFile function
Alokxk Oct 29, 2025
1a6584e
Refactor enterprise.go & add tests for ui installation & uninstallation
Alokxk Oct 30, 2025
be7a053
Refactor verify-executables.go & add tests for executable verification
Alokxk Oct 31, 2025
60daef7
Refactored generate-kind-templates.go & added tests for directory del…
Alokxk Oct 31, 2025
d8e8bd4
Refactored get-network-info.go & added tests for network information …
Alokxk Nov 1, 2025
8a99c9f
Refactored install-calico.go & added tests for Calico installation &…
Alokxk Nov 4, 2025
08ea708
Refactored install-iperf.go & added tests for iPerf installation & ve…
Alokxk Nov 4, 2025
ebaa312
Refactored kind-clusters.go & added tests for cluster creation, delet…
Alokxk Nov 5, 2025
544c7f7
Refactored project-manifest.go & added tests for KubeSlice project ma…
Alokxk Nov 6, 2025
ea8ef2f
Refactored print-next-steps.go to use buildKubectlCommand for command…
Alokxk Nov 7, 2025
80325cc
Refactored prometheus.go & added tests for installation & patching of…
Alokxk Nov 7, 2025
ce1440f
Refactored secrets.go & added tests for GetSecrets & GetSecretName fu…
Alokxk Nov 8, 2025
4becd8b
Refactored file-generation_test.go to improve & add tests for directo…
Alokxk Nov 8, 2025
04ae3db
Refactored serviceExport.go & added tests for service export configur…
Alokxk Nov 8, 2025
889511f
Refactored slice-config.go & added tests for slice configuration func…
Alokxk Nov 9, 2025
2724007
Refactored worker.go & added worker_test.go with tests for installati…
Alokxk Nov 9, 2025
81e6cca
Added integration tests for AddHelmCharts functionality in helm-repo-…
Alokxk Nov 14, 2025
df032a9
Improved helm-repo-add integration tests & added new Integration test…
Alokxk Nov 17, 2025
c563db0
Added integration tests for Kind cluster creation & deletion
Alokxk Nov 17, 2025
6250e1d
Refactored integration tests to improve checks & created a helper fil…
Alokxk Nov 17, 2025
4a912ef
Added integration tests for GatherNetworkInformation functionality
Alokxk Nov 18, 2025
7f73e09
Added Unit & Integration tests for kubectl operations
Alokxk Nov 19, 2025
0d34717
Added comprehensive testing strategy documentation for kubeslice-cli
Alokxk Nov 19, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions TESTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Testing Strategy

This document outlines the testing strategy for `kubeslice-cli`. We use a two-layered approach: **Unit Tests** for logic isolation & **Integration Tests** for real-world verification.

## 1. Test Architecture

| Type | Location | Purpose | Methodology |
| :--- | :--- | :--- | :--- |
| **Unit Tests** | `_test.go` | Verify internal logic, argument parsing & error handling. | Uses **Fakes** (`FakeExecutor`, `FakeFileSystem`) to test in isolation. |
| **Integration Tests** | `_integration_test.go` | Verify interaction with the host system & external binaries. | Uses **Real Binaries** (`kind`, `helm`, `kubectl`, `docker`) and real file system operations. |

---

## 2. Integration Test Scenarios

The following scenarios are covered by the integration suite in `pkg/internal/`. These tests run against a live environment to ensure end-to-end reliability.

### A. Environment Verification (`verify-executables`)
* **Kind Profile:** Verifies that `kind`, `kubectl`, `docker`, & `helm` are correctly detected on the host.
* **Non-Kind Profile:** Verifies that only `kubectl` and `helm` are checked when `kind` is not required.
* **Failure Handling:** Simulates a missing binary to ensure the CLI exits gracefully with the correct error message.

### B. Helm Repo Operations (`helm-repo-add`)
* **Add Repo:** Verifies the CLI can successfully add a public Helm repository using the real `helm` binary.
* **Local Skip:** Verifies that the `UseLocal: true` configuration correctly skips helm operations.
* **Failure Handling:** Verifies that adding a non-existent repository URL triggers a failure.

### C. Cluster Lifecycle (`kind-clusters`)
* **Create Cluster:** Uses the `kind` binary to spin up real Docker containers for the cluster.
* **Idempotency:** Runs creation twice to ensure the CLI correctly **skips** clusters that already exist.
* **Delete Cluster:** Verifies successful deletion of clusters.
* **Kubeconfig:** Verifies the generation of the `kubeconfig.yaml` file on the real file system.
* **Environment:** Verifies the `KUBECONFIG` environment variable is set correctly.

### D. Network Discovery (`get-network-info`)
* **Kind Path:** Verifies retrieval of the Control Plane IP using `docker inspect` (used for Kind clusters).
* **Non-Kind Path:** Verifies retrieval of connection info using `kubectl config view` and `kubectl get nodes` (used for Cloud/DC clusters).
* **Failure Handling:** Verifies the CLI fails correctly when inspecting a non-existent cluster.

### E. Kubernetes Operations (`kubernetes-operation`)
* **Apply Manifest:** Applies a real Kubernetes manifest (ConfigMap) to a running cluster.
* **Get Resources:** Uses `kubectl get` to verify resources were created successfully.
* **Describe Resources:** Uses `kubectl describe` to inspect system resources.
* **Delete Resources:** Deletes a resource and verifies it is removed from the cluster.

---

## 3. How to Run Tests

### Prerequisites
Ensure the following tools are installed and in your `$PATH`:
* `go` (v1.17+)
* `docker` (Daemon must be running)
* `kind`
* `kubectl`
* `helm`

### Commands

**Run Unit Tests Only** (Fast)
```bash
make test-unit
```

**Run Integration Tests Only** (Slower)
```bash
make test-integration
```

**Run All Tests**
```bash
make test
```
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ go 1.17
require (
github.com/go-yaml/yaml v2.1.0+incompatible
github.com/spf13/cobra v1.6.1
github.com/stretchr/testify v1.11.1
gopkg.in/yaml.v2 v2.4.0
sigs.k8s.io/yaml v1.2.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/tidwall/gjson v1.14.2 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

require (
Expand Down
14 changes: 14 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-yaml/yaml v2.1.0+incompatible h1:RYi2hDdss1u4YE7GwixGzWwVo47T8UQwnTLB6vQiq+o=
github.com/go-yaml/yaml v2.1.0+incompatible/go.mod h1:w2MrLa16VYP0jy6N7M5kHaCkaLENm+P+Tv+MfurjSw0=
github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc=
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA=
github.com/spf13/cobra v1.6.1/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/tidwall/gjson v1.14.2 h1:6BBkirS0rAHjumnjHF6qgy5d2YAJ1TLIaFE2lzfOLqo=
github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
Expand All @@ -23,6 +35,8 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
10 changes: 6 additions & 4 deletions pkg/internal/cert-manager-setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package internal

import (
"fmt"
"log"
"time"

"github.com/kubeslice/kubeslice-cli/util"
)

// Function variable for testing - Allows mocking PodVerification in tests
var podVerificationFunc = PodVerification

func InstallCertManager(ApplicationConfiguration *ConfigurationSpecs) {

cc := ApplicationConfiguration.Configuration.ClusterConfiguration
Expand All @@ -16,10 +18,10 @@ func InstallCertManager(ApplicationConfiguration *ConfigurationSpecs) {

installCertManager(cc.ControllerCluster, hc)
util.Printf("%s Successfully installed helm chart %s/%s", util.Tick, hc.RepoAlias, hc.CertManagerChart.ChartName)
time.Sleep(200 * time.Millisecond)
util.Sleep(200 * time.Millisecond)

util.Printf("%s Waiting for Cert Manager Pods to be Healthy...", util.Wait)
PodVerification("Waiting for Cert Manager Pods to be Healthy", cc.ControllerCluster, "cert-manager")
podVerificationFunc("Waiting for Cert Manager Pods to be Healthy", cc.ControllerCluster, "cert-manager")

util.Printf("%s Successfully installed cert manager.\n", util.Tick)

Expand Down Expand Up @@ -47,7 +49,7 @@ func installCertManager(cluster Cluster, hc HelmChartConfiguration) {
}
err := util.RunCommand("helm", args...)
if err != nil {
log.Fatalf("Process failed %v", err)
util.Fatalf("Process failed %v", err)
}
}
func uninstallCertManager(cluster Cluster, hc HelmChartConfiguration) error {
Expand Down
Loading