## Helm Template Testing The Helm template testing for the Headlamp chart ensures that the Helm templates generate the expected Kubernetes manifest files under different scenarios. This testing is crucial for validating changes to the Helm chart and ensuring its correctness before deployment. ### Expected Templates (`charts/headlamp/tests/expected_templates`) The `expected_templates` directory contains YAML files representing the expected Kubernetes manifest files generated by the Helm templates. Each YAML file corresponds to a specific Helm template in the `charts/headlamp/templates` directory. These files serve as reference points for comparing the actual rendered templates during testing. Example: - `deployment.yaml`: Represents the expected Kubernetes Deployment manifest. - `service.yaml`: Represents the expected Kubernetes Service manifest. ### Test Cases (`charts/headlamp/tests/test_cases`) The `test_cases` directory contains YAML files representing different test scenarios or configurations for the Helm chart. Each test case specifies a set of values for Helm chart configuration parameters (defined in `values.yaml`) to test various aspects of the chart under different conditions. Example: - `volumes-added.yaml`: Tests the behavior of the Helm chart when additional volumes are specified. - `ingress-enabled.yaml`: Tests the behavior of the Helm chart when Ingress is enabled. The Helm template testing script (`charts/headlamp/tests/test.sh`) dynamically renders Helm templates for each test case using the specified configuration values and compares them against the corresponding expected templates. This ensures that the Helm chart behaves as expected under different configurations. ## Adding Test Cases and Expected Templates To enhance the coverage of the Helm template testing for the Headlamp chart, you can add more test cases and corresponding expected templates. Follow these guidelines to add new test cases and expected templates effectively: ### Test Cases 1. **Create a New Test Case Directory**: Inside the `charts/headlamp/tests/test_cases` directory, create a new directory representing the new test case. Choose a descriptive name for the directory that reflects the purpose or scenario of the test case. 2. **Define Test Case Configuration**: Within the new test case directory, create a `values.yaml` file with custom name to define the configuration parameters for the Helm chart under the specific test scenario. Customize the values in this file to match the desired configuration for the test case. ## Expected Templates 1. **Create Expected Templates**: Inside the `charts/headlamp/tests/expected_templates` directory, create YAML files representing the expected Kubernetes manifest files for the Helm templates under the new test scenarios. Each expected template file should correspond to a Helm template in the templates directory. 2. **Match Test Cases with Expected Templates**: Ensure that each test case directory in `test_cases` has a corresponding expected template file in `expected_templates`. The expected template file should have the same name as the test case directory to establish the association. ## Running Helm Template Testing To run the Helm template testing for the Headlamp chart, follow these steps: ### Prerequisites - [Helm](https://helm.sh/) must be installed on your system. ### Running the Tests 1. Run the Helm template testing using the provided Make directive from your root headlamp folder: ```bash make helm-template-test ``` This will execute the `charts/headlamp/tests/test.sh` script, which dynamically renders and compares Helm templates for different test cases against their expected templates. ## Updating Template Versions When changes are made to the Helm chart that intentionally modify the rendered templates (such as version updates, new features, or bug fixes), you'll need to update the expected templates to match the new output. The `helm-update-template-version` command simplifies this process. ### How Template Version Updates Work The template version update process: 1. Reads the current chart version and app version from `Chart.yaml` 2. Checks each expected template file for version references 3. Only updates files where versions are outdated 4. Provides concise output showing only which files required updates ### When to Use Template Version Updates You should run the template version update when: - You've updated the Helm chart version in `Chart.yaml` - You've updated the app version in `Chart.yaml` - You've made intentional changes to templates that affect their rendered output - The `helm-template-test` command fails with template differences that are expected ### Running Template Version Updates To update the expected templates with the current versions: ```bash make helm-update-template-version ``` This executes the `charts/headlamp/tests/update-version.sh` script, which renders templates with current versions and updates the expected templates accordingly. ### After Updating Template Versions After running the template version update: 1. Review the changes to ensure they're as expected 2. Run `helm-template-test` again to verify that tests now pass 3. Commit the updated expected templates along with your chart changes