@@ -26,28 +26,46 @@ def build_npm_app(app_path: Path) -> ContainerTestLib:
2626 app_path = app_path ,
2727 s2i_args = f"--pull-policy=never { container_lib .build_s2i_npm_variables ()} " ,
2828 src_image = VARS .IMAGE_NAME ,
29- dst_image = f"{ VARS .IMAGE_NAME } -testapp"
29+ dst_image = f"{ VARS .IMAGE_NAME } -testapp" ,
3030 )
3131 return s2i_app
3232
3333
3434def build_s2i_app (app_path : Path , container_args : str = "" ) -> ContainerTestLib :
35+ """
36+ Build S2I Container based on the app_path input
37+ :param: app_path: path to example directory
38+ :param: container_args: additional container arguments
39+ :return new instance of ContainerTestLib
40+ """
3541 container_lib = ContainerTestLib (VARS .IMAGE_NAME )
3642 app_name = app_path .name
3743 s2i_app = container_lib .build_as_df (
3844 app_path = app_path ,
3945 s2i_args = f"--pull-policy=never { container_args } { container_lib .build_s2i_npm_variables ()} " ,
4046 src_image = VARS .IMAGE_NAME ,
41- dst_image = f"{ VARS .IMAGE_NAME } -{ app_name } "
47+ dst_image = f"{ VARS .IMAGE_NAME } -{ app_name } " ,
4248 )
4349 return s2i_app
4450
4551
4652class TestPerlSampleTestAppContainer :
53+ """
54+ Test class checks specific applications and response works as expected.
55+ See parametrized parameters for more details.
56+ """
57+
4758 def setup_method (self ):
59+ """
60+ Build S2I Container based on the sample_test_app input
61+ :return new instance of ContainerTestLib
62+ """
4863 self .s2i_app = build_s2i_app (sample_test_app )
4964
5065 def teardown_method (self ):
66+ """
67+ Cleanup the S2I Container
68+ """
5169 self .s2i_app .cleanup ()
5270
5371 def test_run_s2i_usage (self ):
@@ -62,51 +80,62 @@ def test_docker_run_usage(self):
6280 """
6381 Test checks if `docker run` script works properly and do not fail
6482 """
65- assert PodmanCLIWrapper .call_podman_command (
66- cmd = f"run --rm { VARS .IMAGE_NAME } &>/dev/null" ,
67- return_output = False
68- ) == 0
69-
70- @pytest .mark .parametrize (
71- "container_arg" ,
72- [
73- "" ,
74- "-u 12345"
75- ]
76- )
83+ assert (
84+ PodmanCLIWrapper .call_podman_command (
85+ cmd = f"run --rm { VARS .IMAGE_NAME } &>/dev/null" , return_output = False
86+ )
87+ == 0
88+ )
89+
90+ @pytest .mark .parametrize ("container_arg" , ["" , "-u 12345" ])
7791 def test_run_app_test (self , container_arg ):
7892 """
7993 Test checks if we are able to run a container as deamon
8094 and response works as expected
8195 """
8296 cid_file_name = self .s2i_app .app_name
83- assert self .s2i_app .create_container (cid_file_name = cid_file_name , container_args = container_arg )
97+ assert self .s2i_app .create_container (
98+ cid_file_name = cid_file_name , container_args = container_arg
99+ )
84100 assert ContainerImage .wait_for_cid (cid_file_name = cid_file_name )
85101 cid = self .s2i_app .get_cid (cid_file_name = cid_file_name )
86102 assert cid
87103 cip = self .s2i_app .get_cip (cid_file_name = cid_file_name )
88104 assert cip
89- assert self .s2i_app .test_response (
90- url = f"http://{ cip } " , expected_code = 200
91- )
105+ assert self .s2i_app .test_response (url = f"http://{ cip } " , expected_code = 200 )
92106
93107
94108@pytest .mark .parametrize (
95109 "application_path,container_args,page,expected_output" ,
96110 [
97111 (bin_app , "" , "/" , "Usage" ),
98112 (psgi , "" , "/" , "<title>Web::Paste::Simple" ),
99- (psgi_variables , "--env=PSGI_FILE=./application2.psgi --env=PSGI_URI_PATH=/path" ,
100- "/path" , "<title>Web::Paste::Simple" ),
101- (psgi_variables , "--env=PSGI_FILE=./application2.psgi --env=PSGI_URI_PATH=/path" ,
102- "/cpanfile" , "requires" ),
113+ (
114+ psgi_variables ,
115+ "--env=PSGI_FILE=./application2.psgi --env=PSGI_URI_PATH=/path" ,
116+ "/path" ,
117+ "<title>Web::Paste::Simple" ,
118+ ),
119+ (
120+ psgi_variables ,
121+ "--env=PSGI_FILE=./application2.psgi --env=PSGI_URI_PATH=/path" ,
122+ "/cpanfile" ,
123+ "requires" ,
124+ ),
103125 (warningonstderr , "" , "/" , "Text in HTTP body" ),
104126 (fcgi , "" , "/" , "Index FCGI script" ),
105127 (fcgi , "" , "/another.fcgi" , "Another FCGI script" ),
106- ]
128+ ],
107129)
108130class TestPerlExampleAppContainer :
109- def test_run_app_test (self , application_path , container_args , page , expected_output ):
131+ """
132+ Test class checks specific applications and response works as expected.
133+ See parametrized parameters for more details.
134+ """
135+
136+ def test_run_app_test (
137+ self , application_path , container_args , page , expected_output
138+ ):
110139 """
111140 Test class checks specific applications
112141 and response works as expected. See parametrized parameters for more
@@ -115,7 +144,8 @@ def test_run_app_test(self, application_path, container_args, page, expected_out
115144 self .s2i_app = build_s2i_app (application_path , container_args = container_args )
116145 cid_file_name = self .s2i_app .app_name
117146 assert self .s2i_app .create_container (
118- cid_file_name = cid_file_name , container_args = f"--user=100001 { container_args } "
147+ cid_file_name = cid_file_name ,
148+ container_args = f"--user=100001 { container_args } " ,
119149 )
120150 assert ContainerImage .wait_for_cid (cid_file_name = cid_file_name )
121151 cid = self .s2i_app .get_cid (cid_file_name = cid_file_name )
@@ -124,22 +154,41 @@ def test_run_app_test(self, application_path, container_args, page, expected_out
124154 assert cip
125155 if application_path == warningonstderr :
126156 assert self .s2i_app .test_response (
127- url = f"http://{ cip } " , expected_code = 200 , expected_output = expected_output , page = page , debug = True
157+ url = f"http://{ cip } " ,
158+ expected_code = 200 ,
159+ expected_output = expected_output ,
160+ page = page ,
161+ debug = True ,
128162 )
129163 output_logs = self .s2i_app .get_logs (cid_file_name = cid_file_name )
130- assert re .search ('GET / HTTP/1.1\ " 200' , output_logs )
164+ assert re .search ('GET / HTTP/1.1" 200' , output_logs )
131165 assert re .search ("Warning on stderr" , output_logs )
132166 else :
133167 assert self .s2i_app .test_response (
134- url = f"http://{ cip } " , expected_code = 200 , expected_output = expected_output , page = page , debug = True
168+ url = f"http://{ cip } " ,
169+ expected_code = 200 ,
170+ expected_output = expected_output ,
171+ page = page ,
172+ debug = True ,
135173 )
136174
137175
138176class TestPerlNPMtestContainer :
177+ """
178+ Test class checks if NPM works in container.
179+ """
180+
139181 def setup_method (self ):
182+ """
183+ Build S2I Container based on the sample_test_app input
184+ :return new instance of ContainerTestLib
185+ """
140186 self .s2i_app = build_npm_app (sample_test_app )
141187
142188 def teardown_method (self ):
189+ """
190+ Cleanup the S2I Container
191+ """
143192 self .s2i_app .cleanup ()
144193
145194 def test_npm_works (self ):
@@ -154,18 +203,24 @@ def test_npm_works(self):
154203 [
155204 (psgi_hot_deploy , "--env=PSGI_FILE=./index.psgi" , False ),
156205 (psgi_hot_deploy , "--env=PSGI_FILE=./index.psgi --env=PSGI_RELOAD=1" , True ),
157- ]
206+ ],
158207)
159208class TestPerlHotDeployAppContainer :
209+ """
210+ Test class checks hot deploy application
211+ It checks what is present in HTTP response
212+ """
213+
160214 def test_run_app_test (self , application_path , container_args , hot_deploy ):
161215 """
162- Test checks hot deploy application
163- It checks what is present in HTTP response
216+ Test class checks hot deploy application and response works as expected.
217+ See parametrized parameters for more details.
164218 """
165219 self .s2i_app = build_s2i_app (application_path , container_args = container_args )
166220 cid_file_name = self .s2i_app .app_name
167221 assert self .s2i_app .create_container (
168- cid_file_name = cid_file_name , container_args = f"--user=100001 { container_args } "
222+ cid_file_name = cid_file_name ,
223+ container_args = f"--user=100001 { container_args } " ,
169224 )
170225 assert ContainerImage .wait_for_cid (cid_file_name = cid_file_name )
171226 cid = self .s2i_app .get_cid (cid_file_name = cid_file_name )
@@ -185,18 +240,12 @@ def test_run_app_test(self, application_path, container_args, hot_deploy):
185240 sleep (3 )
186241 PodmanCLIWrapper .podman_exec_shell_command (
187242 cid_file_name = cid ,
188- cmd = "sed -ie 's/old initial value/new initial value/' lib/My/Test.pm" ,
189- used_shell = "/bin/sh"
243+ cmd = "./replace_value.sh" ,
190244 )
191245 if hot_deploy :
192246 # We need to wait couple seconds till container
193247 # does not update page. HotDeploy needs at least 3 seconds
194248 sleep (3 )
195- assert PodmanCLIWrapper .podman_exec_shell_command (
196- cid_file_name = cid ,
197- cmd = "grep 'new initial' lib/My/Test.pm" ,
198- used_shell = "/bin/sh"
199- )
200249 assert self .s2i_app .test_response (
201250 url = f"http://{ cip } " , expected_output = "new initial value: 0"
202251 )
0 commit comments