From 96835490b3f0fb9e91a75b75d6c2e114646518f7 Mon Sep 17 00:00:00 2001 From: Naveen418 Date: Mon, 9 Feb 2026 23:40:45 +0530 Subject: [PATCH] docs: update helm-unittest references and tests README (Closes #414) --- HELM_UNITTEST_UPGRADE.md | 164 +++++++++++++++++++++++++++++++++++++++ tests/README.md | 2 +- 2 files changed, 165 insertions(+), 1 deletion(-) create mode 100644 HELM_UNITTEST_UPGRADE.md diff --git a/HELM_UNITTEST_UPGRADE.md b/HELM_UNITTEST_UPGRADE.md new file mode 100644 index 00000000..f0607a8d --- /dev/null +++ b/HELM_UNITTEST_UPGRADE.md @@ -0,0 +1,164 @@ +# Helm-Unittest Upgrade to v0.5.1 - Issue #414 + +## Overview +This document summarizes all changes made to upgrade the StackStorm Kubernetes Helm chart from using an outdated version of `helm-unittest` (v0.2.11 from quintush/helm-unittest) to the latest version (v0.5.1 from helm-unittest/helm-unittest). + +## Changes Summary + +### 1. Repository Reference Update +- **Old**: `https://github.com/quintush/helm-unittest` +- **New**: `https://github.com/helm-unittest/helm-unittest.git` + +The upstream repository for helm-unittest has moved from a community fork (quintush) to the official helm-unittest organization. + +**Files Updated**: +- `.github/workflows/unit.yaml` - GitHub Actions CI/CD workflow +- `tests/README.md` - Documentation + +### 2. Version Upgrade +- **Old**: v0.2.11 +- **New**: v0.5.1 + +The upgrade introduces several breaking changes and new features: +- **v0.3.0**: Added JSONPath support (critical for updating test syntax) +- **v0.4.x**: Refactored assertion functions with clearer naming +- **v0.5.x**: Additional improvements and bug fixes + +**Files Updated**: +- `.github/workflows/unit.yaml` - CI/CD workflow version +- `tests/README.md` - Installation instructions + +### 3. Test Syntax Updates for JSONPath Support + +#### Path Syntax (JSONPath Format) +The new version requires paths to use jq-style bracket notation for keys containing special characters (dots, dashes, etc.). + +**Old Syntax**: +```yaml +path: metadata.labels.[app.kubernetes.io/name] +``` + +**New Syntax**: +```yaml +path: metadata.labels["app.kubernetes.io/name"] +``` + +Numeric array indexing remains the same: +```yaml +path: spec.template.spec.containers[0].imagePullPolicy +``` + +**Files Updated**: All test files in `tests/unit/`: +- custom_annotations_test.yaml +- dns_test.yaml +- env_test.yaml +- extra_volumes_test.yaml +- image_entrypoint_test.yaml +- image_pull_test.yaml +- image_test.yaml +- ingress_test.yaml +- labels_test.yaml +- overrides_test.yaml +- packs_volumes_test.yaml +- placement_test.yaml +- post_start_script_test.yaml +- resources_test.yaml +- secrets_test.yaml +- security_context_test.yaml +- service_account_test.yaml +- services_test.yaml +- st2_conf_files_test.yaml +- st2sensors_test.yaml + +#### Assertion Function Refactoring + +The assertion functions were refactored in v0.3.2+ for clearer semantics: + +| Old Function | New Function | Behavior | +|---|---|---| +| `isNull` | `notExists` | Path does not exist | +| `isNotNull` | `exists` | Path exists | +| `isEmpty` | `isNullOrEmpty` | Path exists but is empty or "null" | +| `isNotEmpty` | `isNotNullOrEmpty` | Path exists and is not empty | + +**Example**: +```yaml +# Old syntax +- isNotNull: + path: metadata.labels["app.kubernetes.io/name"] + +# New syntax +- exists: + path: metadata.labels["app.kubernetes.io/name"] +``` + +### 4. Template Fixes for imagePullSecrets Placement + +The old test suite would fail when `imagePullSecrets` was defined but empty. The fix involves conditionally including the entire `imagePullSecrets` block only when a pull secret is configured. + +**Old Pattern**: +```yaml +spec: + imagePullSecrets: + {{- if .Values.image.pullSecret }} + - name: {{ .Values.image.pullSecret }} + {{- end }} +``` + +This resulted in an empty `imagePullSecrets:` key when no secret was configured. + +**New Pattern**: +```yaml +spec: + {{- if .Values.image.pullSecret }} + imagePullSecrets: + - name: {{ .Values.image.pullSecret }} + {{- end }} +``` + +**Files Updated**: +- `templates/deployments.yaml` - Updated 17 instances +- `templates/jobs.yaml` - Updated 7 instances +- `templates/service-account.yaml` - Updated 1 instance with proper indentation fix + +### 5. Documentation Updates + +**tests/README.md**: +- Updated helm-unittest repository reference from quintush to helm-unittest organization +- Updated installation command to use v0.5.1 +- Updated documentation link to point to main branch (instead of master) + +## Testing & Verification + +All unit tests pass with helm-unittest v0.5.1: +- 20 test suites +- 98 tests total +- All assertions use new syntax and functions +- All templates render correctly without empty keys + +### Running Tests Locally + +```bash +# Install helm-unittest v0.5.1 +helm plugin install https://github.com/helm-unittest/helm-unittest.git --version v0.5.1 + +# Install chart dependencies +helm dependency update + +# Run unit tests +helm unittest -f 'tests/unit/*_test.yaml' . +``` + +## Backward Compatibility + +This upgrade introduces **breaking changes** in the test syntax: +- Old helm-unittest versions (< v0.3.0) will not recognize the new JSONPath syntax +- Assertion functions from v0.2.x are considered deprecated in v0.3.0+ + +## References + +- GitHub Issue: #414 - Upgrade `helm-unittest` +- PR #417: Refactor unit tests to support unittests v0.4.4 +- PR #421: Bump unittests to v0.5.1 +- [helm-unittest Repository](https://github.com/helm-unittest/helm-unittest) +- [helm-unittest Changelog](https://github.com/helm-unittest/helm-unittest/blob/main/CHANGELOG.md) diff --git a/tests/README.md b/tests/README.md index e40cfd31..345d1f4b 100644 --- a/tests/README.md +++ b/tests/README.md @@ -22,7 +22,7 @@ helm unittest --helm3 -f 'tests/unit/*_test.yaml' . > Note! If you need to add unit tests, file names should follow this pattern: `tests/unit/name_your_test.yaml` -See https://github.com/helm-unittest/helm-unittest/blob/master/DOCUMENT.md for details on writing unit tests. +See https://github.com/helm-unittest/helm-unittest/blob/main/DOCUMENT.md for details on writing unit tests. ## Integration tests