|
1 | 1 | """Integration tests for the helm-values-manager CLI.""" |
2 | 2 |
|
| 3 | +import json |
3 | 4 | import os |
4 | 5 | import subprocess |
5 | 6 | from pathlib import Path |
@@ -85,3 +86,109 @@ def test_init_command(plugin_install, tmp_path): |
85 | 86 | assert "Successfully initialized helm-values configuration" in stdout |
86 | 87 | assert Path("helm-values.json").exists() |
87 | 88 | assert Path(".helm-values.lock").exists() |
| 89 | + |
| 90 | + |
| 91 | +def test_add_value_config_help_command(plugin_install): |
| 92 | + """Test that the add-value-config help command works and shows expected output.""" |
| 93 | + stdout, stderr, returncode = run_helm_command(["values-manager", "add-value-config", "--help"]) |
| 94 | + |
| 95 | + assert returncode == 0 |
| 96 | + assert "Add a new value configuration with metadata" in stdout |
| 97 | + assert "--path" in stdout |
| 98 | + assert "--description" in stdout |
| 99 | + assert "--required" in stdout |
| 100 | + assert "--sensitive" in stdout |
| 101 | + |
| 102 | + |
| 103 | +def test_add_value_config_command(plugin_install, tmp_path): |
| 104 | + """Test that the add-value-config command works correctly.""" |
| 105 | + # Change to temp directory to avoid conflicts |
| 106 | + os.chdir(tmp_path) |
| 107 | + |
| 108 | + # First initialize a configuration |
| 109 | + init_stdout, init_stderr, init_returncode = run_helm_command(["values-manager", "init", "-r", "test-app"]) |
| 110 | + assert init_returncode == 0 |
| 111 | + |
| 112 | + # Add a value configuration |
| 113 | + path = "app.replicas" |
| 114 | + description = "Number of application replicas" |
| 115 | + stdout, stderr, returncode = run_helm_command( |
| 116 | + ["values-manager", "add-value-config", "--path", path, "--description", description, "--required"] |
| 117 | + ) |
| 118 | + |
| 119 | + assert returncode == 0 |
| 120 | + assert f"Successfully added value config '{path}'" in stdout |
| 121 | + |
| 122 | + # Verify the configuration file was updated correctly |
| 123 | + with open("helm-values.json", "r") as f: |
| 124 | + config = json.load(f) |
| 125 | + |
| 126 | + # Check that the config contains our new value |
| 127 | + assert "config" in config |
| 128 | + assert len(config["config"]) == 1 |
| 129 | + assert config["config"][0]["path"] == path |
| 130 | + assert config["config"][0]["description"] == description |
| 131 | + assert config["config"][0]["required"] is True |
| 132 | + assert config["config"][0]["sensitive"] is False |
| 133 | + assert config["config"][0]["values"] == {} |
| 134 | + |
| 135 | + # Add another value configuration |
| 136 | + second_path = "app.image.tag" |
| 137 | + second_description = "Application image tag" |
| 138 | + stdout, stderr, returncode = run_helm_command( |
| 139 | + [ |
| 140 | + "values-manager", |
| 141 | + "add-value-config", |
| 142 | + "--path", |
| 143 | + second_path, |
| 144 | + "--description", |
| 145 | + second_description, |
| 146 | + "--sensitive", |
| 147 | + ] |
| 148 | + ) |
| 149 | + |
| 150 | + assert returncode == 0 |
| 151 | + assert f"Successfully added value config '{second_path}'" in stdout |
| 152 | + |
| 153 | + # Verify the configuration file was updated correctly |
| 154 | + with open("helm-values.json", "r") as f: |
| 155 | + config = json.load(f) |
| 156 | + |
| 157 | + # Check that the config contains both values |
| 158 | + assert "config" in config |
| 159 | + assert len(config["config"]) == 2 |
| 160 | + |
| 161 | + # Find the second added config |
| 162 | + second_config = next((c for c in config["config"] if c["path"] == second_path), None) |
| 163 | + assert second_config is not None |
| 164 | + assert second_config["description"] == second_description |
| 165 | + assert second_config["required"] is False |
| 166 | + assert second_config["sensitive"] is True |
| 167 | + assert second_config["values"] == {} |
| 168 | + |
| 169 | + |
| 170 | +def test_add_value_config_duplicate_path(plugin_install, tmp_path): |
| 171 | + """Test that adding a duplicate path fails with the correct error message.""" |
| 172 | + # Change to temp directory to avoid conflicts |
| 173 | + os.chdir(tmp_path) |
| 174 | + |
| 175 | + # First initialize a configuration |
| 176 | + init_stdout, init_stderr, init_returncode = run_helm_command(["values-manager", "init", "-r", "test-app"]) |
| 177 | + assert init_returncode == 0 |
| 178 | + |
| 179 | + # Add a value configuration |
| 180 | + path = "app.replicas" |
| 181 | + description = "Number of application replicas" |
| 182 | + stdout, stderr, returncode = run_helm_command( |
| 183 | + ["values-manager", "add-value-config", "--path", path, "--description", description] |
| 184 | + ) |
| 185 | + |
| 186 | + assert returncode == 0 |
| 187 | + |
| 188 | + # Try to add the same path again |
| 189 | + stdout, stderr, returncode = run_helm_command( |
| 190 | + ["values-manager", "add-value-config", "--path", path, "--description", "Another description"] |
| 191 | + ) |
| 192 | + |
| 193 | + assert returncode != 0 |
| 194 | + assert f"Path {path} already exists" in stderr |
0 commit comments