Skip to content

Commit e7147d8

Browse files
committed
test: Add unit tests for add-value-config CLI function
Added unit tests for the add-value-config CLI function to improve test coverage: - Test for successful addition of a value configuration - Test for handling duplicate paths - Test for handling empty paths These tests ensure that the CLI interface for the add-value-config command works correctly and handles error cases appropriately.
1 parent 6bb1ecd commit e7147d8

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

tests/unit/test_cli.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,77 @@ def test_init_command_already_initialized(tmp_path):
6565
assert result.exit_code == 1
6666
assert "Failed to initialize: Configuration file" in result.stdout
6767
assert "already exists" in result.stdout
68+
69+
70+
def test_add_value_config_command(tmp_path):
71+
"""Test add-value-config command."""
72+
# Change to temp directory
73+
os.chdir(tmp_path)
74+
75+
# First initialize a configuration
76+
init_result = runner.invoke(app, ["init", "--release", "test-release"], catch_exceptions=False)
77+
assert init_result.exit_code == 0
78+
79+
# Add a value configuration
80+
path = "app.replicas"
81+
description = "Number of application replicas"
82+
result = runner.invoke(
83+
app, ["add-value-config", "--path", path, "--description", description, "--required"], catch_exceptions=False
84+
)
85+
86+
assert result.exit_code == 0
87+
assert f"Successfully added value config '{path}'" in result.stdout
88+
89+
# Verify the configuration file was updated correctly
90+
config_file = Path("helm-values.json")
91+
with config_file.open() as file:
92+
config_data = json.load(file)
93+
94+
assert "config" in config_data
95+
assert len(config_data["config"]) == 1
96+
assert config_data["config"][0]["path"] == path
97+
assert config_data["config"][0]["description"] == description
98+
assert config_data["config"][0]["required"] is True
99+
assert config_data["config"][0]["sensitive"] is False
100+
assert config_data["config"][0]["values"] == {}
101+
102+
103+
def test_add_value_config_duplicate_path(tmp_path):
104+
"""Test add-value-config command with duplicate path."""
105+
# Change to temp directory
106+
os.chdir(tmp_path)
107+
108+
# First initialize a configuration
109+
init_result = runner.invoke(app, ["init", "--release", "test-release"], catch_exceptions=False)
110+
assert init_result.exit_code == 0
111+
112+
# Add a value configuration
113+
path = "app.replicas"
114+
description = "Number of application replicas"
115+
first_result = runner.invoke(
116+
app, ["add-value-config", "--path", path, "--description", description], catch_exceptions=False
117+
)
118+
119+
assert first_result.exit_code == 0
120+
121+
# Try to add the same path again
122+
second_result = runner.invoke(app, ["add-value-config", "--path", path, "--description", "Another description"])
123+
124+
assert second_result.exit_code == 1
125+
assert f"Failed to add value config: Path {path} already exists" in second_result.stdout
126+
127+
128+
def test_add_value_config_empty_path(tmp_path):
129+
"""Test add-value-config command with empty path."""
130+
# Change to temp directory
131+
os.chdir(tmp_path)
132+
133+
# First initialize a configuration
134+
init_result = runner.invoke(app, ["init", "--release", "test-release"], catch_exceptions=False)
135+
assert init_result.exit_code == 0
136+
137+
# Try to add a value configuration with empty path
138+
result = runner.invoke(app, ["add-value-config", "--path", "", "--description", "Some description"])
139+
140+
assert result.exit_code == 1
141+
assert "Failed to add value config: Path cannot be empty" in result.stdout

0 commit comments

Comments
 (0)