@@ -52,60 +52,81 @@ def test_try_image_invalid_combinations(self, container_args):
5252 )
5353
5454 @pytest .mark .parametrize (
55- "container_args " ,
55+ "mysql_user, mysql_password, mysql_database, mysql_root_password " ,
5656 [
57- ["-e " , "MYSQL_USER=user " , "-e " , "MYSQL_PASSWORD=pass " ],
57+ ["user " , "pass " , "" , "" ],
5858 [
59- "-e MYSQL_USER= $invalid" ,
60- "-e MYSQL_PASSWORD= pass" ,
61- "-e MYSQL_DATABASE= db" ,
62- "-e MYSQL_ROOT_PASSWORD= root_pass" ,
59+ "$invalid" ,
60+ "pass" ,
61+ "db" ,
62+ "root_pass" ,
6363 ],
6464 [
65- f"-e MYSQL_USER= { VARS .VERY_LONG_USER_NAME } " ,
66- "-e MYSQL_PASSWORD= pass" ,
67- "-e MYSQL_DATABASE= db" ,
68- "-e MYSQL_ROOT_PASSWORD= root_pass" ,
65+ VARS .VERY_LONG_USER_NAME ,
66+ "pass" ,
67+ "db" ,
68+ "root_pass" ,
6969 ],
7070 [
71- "-e MYSQL_USER= user" ,
72- "-e MYSQL_PASSWORD= " ,
73- "-e MYSQL_DATABASE= db" ,
74- "-e MYSQL_ROOT_PASSWORD= root_pass" ,
71+ "user" ,
72+ "" ,
73+ "db" ,
74+ "root_pass" ,
7575 ],
7676 [
77- "-e MYSQL_USER= user" ,
78- "-e MYSQL_PASSWORD= pass" ,
79- "-e MYSQL_DATABASE= $invalid" ,
80- "-e MYSQL_ROOT_PASSWORD= root_pass" ,
77+ "user" ,
78+ "pass" ,
79+ "$invalid" ,
80+ "root_pass" ,
8181 ],
8282 [
83- "-e MYSQL_USER= user" ,
84- "-e MYSQL_PASSWORD= pass" ,
85- f"-e MYSQL_DATABASE= { VARS .VERY_LONG_DB_NAME } " ,
86- "-e MYSQL_ROOT_PASSWORD= root_pass" ,
83+ "user" ,
84+ "pass" ,
85+ VARS .VERY_LONG_DB_NAME ,
86+ "root_pass" ,
8787 ],
8888 [
89- "-e MYSQL_USER= user" ,
90- "-e MYSQL_PASSWORD= pass" ,
91- "-e MYSQL_DATABASE= db" ,
92- "-e MYSQL_ROOT_PASSWORD= " ,
89+ "user" ,
90+ "pass" ,
91+ "db" ,
92+ "" ,
9393 ],
9494 [
95- "-e MYSQL_USER= root" ,
96- "-e MYSQL_PASSWORD= pass" ,
97- "-e MYSQL_DATABASE= db" ,
98- "-e MYSQL_ROOT_PASSWORD= pass" ,
95+ "root" ,
96+ "pass" ,
97+ "db" ,
98+ "pass" ,
9999 ],
100100 ],
101101 )
102- def test_invalid_configuration_tests (self , container_args ):
102+ def test_invalid_configuration_tests (
103+ self , mysql_user , mysql_password , mysql_database , mysql_root_password
104+ ):
103105 """
104106 Test invalid configuration combinations for MySQL container.
105107 """
106108 cid_config_test = "invalid_configuration_tests"
109+ mysql_user_arg = f"-e MYSQL_USER={ mysql_user } " if mysql_user else ""
110+ mysql_password_arg = (
111+ f"-e MYSQL_PASSWORD={ mysql_password } " if mysql_password else ""
112+ )
113+ mysql_database_arg = (
114+ f"-e MYSQL_DATABASE={ mysql_database } " if mysql_database else ""
115+ )
116+ mysql_root_password_arg = (
117+ f"-e MYSQL_ROOT_PASSWORD={ mysql_root_password } "
118+ if mysql_root_password
119+ else ""
120+ )
107121 assert self .db .assert_container_creation_fails (
108- cid_file_name = cid_config_test , container_args = container_args , command = ""
122+ cid_file_name = cid_config_test ,
123+ container_args = [
124+ mysql_user_arg ,
125+ mysql_password_arg ,
126+ mysql_database_arg ,
127+ mysql_root_password_arg ,
128+ ],
129+ command = "" ,
109130 )
110131
111132
@@ -119,7 +140,6 @@ def setup_method(self):
119140 Setup the test environment.
120141 """
121142 self .db_config = ContainerTestLib (image_name = VARS .IMAGE_NAME )
122- self .db_config .set_new_db_type (db_type = "mysql" )
123143 self .db_api = DatabaseWrapper (image_name = VARS .IMAGE_NAME )
124144
125145 def teardown_method (self ):
@@ -131,6 +151,12 @@ def teardown_method(self):
131151 def test_configuration_auto_calculated_settings (self ):
132152 """
133153 Test MySQL container configuration auto-calculated settings.
154+ Steps are:
155+ 1. Create a container with the given arguments
156+ 2. Check if the container is created successfully
157+ 3. Check if the database connection works
158+ 4. Check if the database configurations are correct
159+ 5. Stop the container
134160 """
135161 cid_config_test = "auto-config_test"
136162 username = "config_test_user"
@@ -146,30 +172,29 @@ def test_configuration_auto_calculated_settings(self):
146172 ],
147173 docker_args = "--memory=512m" ,
148174 )
149- cip = self .db_config .get_cip (cid_file_name = cid_config_test )
150- assert cip
175+ cip , cid = self .db_config .get_cip_cid (cid_file_name = cid_config_test )
176+ assert cip , cid
151177 assert self .db_config .test_db_connection (
152178 container_ip = cip ,
153179 username = username ,
154180 password = password ,
155181 max_attempts = 10 ,
156182 )
157- cid = self .db_config .get_cid (cid_file_name = cid_config_test )
158183 db_configuration = PodmanCLIWrapper .podman_exec_shell_command (
159184 cid_file_name = cid ,
160185 cmd = "cat /etc/my.cnf /etc/my.cnf.d/*" ,
161186 )
162- words = [
163- "key_buffer_size\\ s*=\ \ s*51M" ,
164- "read_buffer_size\\ s*=\ \ s*25M" ,
165- "innodb_buffer_pool_size\\ s*=\ \ s*256M" ,
166- "innodb_log_file_size\\ s*=\ \ s*76M" ,
167- "innodb_log_buffer_size\\ s*=\ \ s*76M" ,
168- "authentication_policy\\ s*=\ \ s*'caching_sha2_password,,'" ,
187+ expected_values = [
188+ r "key_buffer_size\s*=\s*51M" ,
189+ r "read_buffer_size\s*=\s*25M" ,
190+ r "innodb_buffer_pool_size\s*=\s*256M" ,
191+ r "innodb_log_file_size\s*=\s*76M" ,
192+ r "innodb_log_buffer_size\s*=\s*76M" ,
193+ r "authentication_policy\s*=\s*'caching_sha2_password,,'" ,
169194 ]
170- for word in words :
171- assert re .search (word , db_configuration ), (
172- f"Word { word } not found in { db_configuration } "
195+ for value in expected_values :
196+ assert re .search (value , db_configuration ), (
197+ f"Expected value { value } not found in { db_configuration } "
173198 )
174199 # do some real work to test replication in practice
175200 self .db_api .run_sql_command (
@@ -192,6 +217,7 @@ def test_configuration_auto_calculated_settings(self):
192217 assert "COLLATE=latin2_czech_cs" in show_table_output
193218 PodmanCLIWrapper .call_podman_command (cmd = f"stop { cid } " )
194219
220+ # FIX
195221 def test_configuration_options_settings (self ):
196222 """
197223 Test MySQL container configuration options.
@@ -218,44 +244,39 @@ def test_configuration_options_settings(self):
218244 "--env MYSQL_INNODB_BUFFER_POOL_SIZE=16M" ,
219245 "--env MYSQL_INNODB_LOG_FILE_SIZE=4M" ,
220246 "--env MYSQL_INNODB_LOG_BUFFER_SIZE=4M" ,
221- "--env MYSQL_AUTHENTICATION_POLICY=sha256_password" ,
247+ "--env MYSQL_AUTHENTICATION_POLICY=sha256_password,," ,
248+ "--env WORKAROUND_DOCKER_BUG_14203=" ,
222249 ],
223250 )
224- cip = self .db_config .get_cip (cid_file_name = cid_config_test )
225- assert cip
226- assert self .db_config .test_db_connection (
227- container_ip = cip , username = username , password = password
228- )
229- cip = self .db_config .get_cip (cid_file_name = cid_config_test )
230- assert cip
251+ cip , cid = self .db_config .get_cip_cid (cid_file_name = cid_config_test )
252+ assert cip , cid
231253 assert self .db_config .test_db_connection (
232254 container_ip = cip ,
233255 username = username ,
234256 password = password ,
235257 max_attempts = 10 ,
236258 )
237- cid = self .db_config .get_cid (cid_file_name = cid_config_test )
238259 db_configuration = PodmanCLIWrapper .podman_exec_shell_command (
239260 cid_file_name = cid ,
240261 cmd = "cat /etc/my.cnf /etc/my.cnf.d/*" ,
241262 )
242- words = [
243- "lower_case_table_names\\ s*=\ \ s*1" ,
244- "general_log\\ s*=\ \ s*1" ,
245- "max_connections\\ s*=\ \ s*1337" ,
246- "ft_min_word_len\\ s*=\ \ s*8" ,
247- "ft_max_word_len\\ s*=\ \ s*15" ,
248- "max_allowed_packet\\ s*=\ \ s*10M" ,
249- "table_open_cache\\ s*=\ \ s*100" ,
250- "sort_buffer_size\\ s*=\ \ s*256K" ,
251- "key_buffer_size\\ s*=\ \ s*16M" ,
252- "read_buffer_size\\ s*=\ \ s*16M" ,
253- "innodb_log_file_size\\ s*=\ \ s*4M" ,
254- "innodb_log_buffer_size\\ s*=\ \ s*4M" ,
255- "authentication_policy\\ s*=\\ s*'sha256_password'" ,
263+ expected_values = [
264+ r "lower_case_table_names\s*=\s*1" ,
265+ r "general_log\s*=\s*1" ,
266+ r "max_connections\s*=\s*1337" ,
267+ r "ft_min_word_len\s*=\s*8" ,
268+ r "ft_max_word_len\s*=\s*15" ,
269+ r "max_allowed_packet\s*=\s*10M" ,
270+ r "table_open_cache\s*=\s*100" ,
271+ r "sort_buffer_size\s*=\s*256K" ,
272+ r "key_buffer_size\s*=\s*16M" ,
273+ r "read_buffer_size\s*=\s*16M" ,
274+ r "innodb_log_file_size\s*=\s*4M" ,
275+ r "innodb_log_buffer_size\s*=\s*4M" ,
276+ r "authentication_policy\s*=\s*'sha256_password,, '" ,
256277 ]
257- for word in words :
258- assert re .search (word , db_configuration ), (
259- f"Word { word } not found in { db_configuration } "
278+ for value in expected_values :
279+ assert re .search (value , db_configuration ), (
280+ f"Expected value { value } not found in { db_configuration } "
260281 )
261282 PodmanCLIWrapper .call_podman_command (cmd = f"stop { cid } " )
0 commit comments