@@ -65,3 +65,77 @@ def test_init_command_already_initialized(tmp_path):
65
65
assert result .exit_code == 1
66
66
assert "Failed to initialize: Configuration file" in result .stdout
67
67
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