@@ -76,31 +76,65 @@ def test_config_healthchecks(self, mock_requests):
7676 Test that healthchecks can be applied
7777 """
7878 app_id = self .create_app ()
79- readiness_probe = {'healthcheck' : {'readinessProbe' : {'httpGet' : {'port' : 5000 }}}}
79+ readiness_probe = {'healthcheck' : {'web/cmd' : {'readinessProbe' :
80+ {'httpGet' : {'port' : 5000 }}}}}
8081
8182 response = self .client .post (
8283 '/v2/apps/{app_id}/config' .format (** locals ()),
8384 readiness_probe )
8485 self .assertEqual (response .status_code , 201 , response .data )
85- self .assertIn ('readinessProbe' , response .data ['healthcheck' ])
86+ self .assertIn ('readinessProbe' , response .data ['healthcheck' ][ 'web/cmd' ] )
8687 self .assertEqual (response .data ['healthcheck' ], readiness_probe ['healthcheck' ])
8788
88- liveness_probe = {'healthcheck' : {'livenessProbe' :
89+ liveness_probe = {'healthcheck' : {'web/cmd' : { ' livenessProbe' :
8990 {'httpGet' : {'port' : 5000 },
90- 'successThreshold' : 1 }}}
91+ 'successThreshold' : 1 }}}}
9192 response = self .client .post (
9293 '/v2/apps/{app_id}/config' .format (** locals ()),
9394 liveness_probe )
9495 self .assertEqual (response .status_code , 201 , response .data )
95- self .assertIn ('livenessProbe' , response .data ['healthcheck' ])
96+ self .assertIn ('livenessProbe' , response .data ['healthcheck' ][ 'web/cmd' ] )
9697 self .assertEqual (
97- response .data ['healthcheck' ]['livenessProbe' ],
98- liveness_probe ['healthcheck' ]['livenessProbe' ])
98+ response .data ['healthcheck' ]['web/cmd' ][ ' livenessProbe' ],
99+ liveness_probe ['healthcheck' ]['web/cmd' ][ ' livenessProbe' ])
99100 # check that the readiness probe is still there too!
100- self .assertIn ('readinessProbe' , response .data ['healthcheck' ])
101+ self .assertIn ('readinessProbe' , response .data ['healthcheck' ][ 'web/cmd' ] )
101102 self .assertEqual (
102- response .data ['healthcheck' ]['readinessProbe' ],
103- readiness_probe ['healthcheck' ]['readinessProbe' ])
103+ response .data ['healthcheck' ]['web/cmd' ]['readinessProbe' ],
104+ readiness_probe ['healthcheck' ]['web/cmd' ]['readinessProbe' ])
105+
106+ # check that config fails if trying to unset non-existing healthcheck
107+ response = self .client .post (
108+ '/v2/apps/{app_id}/config' .format (** locals ()),
109+ {'healthcheck' : {'invalid_proctype' : None }})
110+ self .assertEqual (response .status_code , 422 , response .data )
111+
112+ # remove a probeType
113+ response = self .client .post (
114+ '/v2/apps/{app_id}/config' .format (** locals ()),
115+ {'healthcheck' : {'web/cmd' : {'livenessProbe' : None }}})
116+ self .assertEqual (response .status_code , 201 , response .data )
117+ self .assertNotIn ('livenessProbe' , response .data ['healthcheck' ]['web/cmd' ])
118+ self .assertIn ('readinessProbe' , response .data ['healthcheck' ]['web/cmd' ])
119+
120+ # check that config fails if trying to unset non-existing probeType
121+ response = self .client .post (
122+ '/v2/apps/{app_id}/config' .format (** locals ()),
123+ {'healthcheck' : {'web/cmd' : {'livenessProbe' : None }}})
124+ self .assertEqual (response .status_code , 422 , response .data )
125+
126+ # check that config fails if trying to unset non-existing probeType
127+ response = self .client .post (
128+ '/v2/apps/{app_id}/config' .format (** locals ()),
129+ {'healthcheck' : {'invalid_proctype' : {'livenessProbe' : None }}})
130+ self .assertEqual (response .status_code , 422 , response .data )
131+
132+ # check that config fails if trying to unset non-existing probeType
133+ response = self .client .post (
134+ '/v2/apps/{app_id}/config' .format (** locals ()),
135+ {'healthcheck' : {'web/cmd' : None }})
136+ self .assertEqual (response .status_code , 201 , response .data )
137+ self .assertNotIn ('web/cmd' , response .data ['healthcheck' ])
104138
105139 # post a new build
106140 response = self .client .post (
@@ -115,29 +149,37 @@ def test_config_healthchecks_validations(self, mock_requests):
115149 """
116150 app_id = self .create_app ()
117151
152+ # Set a probe different from liveness/readiness
153+ response = self .client .post (
154+ '/v2/apps/{app_id}/config' .format (** locals ()),
155+ {'healthcheck' : json .dumps ({'web/cmd' : {'testProbe' :
156+ {'httpGet' : {'port' : '50' }, 'initialDelaySeconds' : "1" }}})}
157+ )
158+ self .assertEqual (response .status_code , 400 , response .data )
159+
118160 # Set one of the values that require a numeric value to a string
119161 response = self .client .post (
120162 '/v2/apps/{app_id}/config' .format (** locals ()),
121- {'healthcheck' : json .dumps ({'livenessProbe' :
122- {'httpGet' : {'port' : '50' }, 'initialDelaySeconds' : "t" }})}
163+ {'healthcheck' : json .dumps ({'web/cmd' : { ' livenessProbe' :
164+ {'httpGet' : {'port' : '50' }, 'initialDelaySeconds' : "t" }}} )}
123165 )
124166 self .assertEqual (response .status_code , 400 , response .data )
125167
126168 # Don't set one of the mandatory value
127169 response = self .client .post (
128170 '/v2/apps/{app_id}/config' .format (** locals ()),
129- {'healthcheck' : json .dumps ({'livenessProbe' :
130- {'httpGet' : {'path' : '/' }, 'initialDelaySeconds' : 1 }})}
171+ {'healthcheck' : json .dumps ({'web/cmd' : { ' livenessProbe' :
172+ {'httpGet' : {'path' : '/' }, 'initialDelaySeconds' : 1 }}} )}
131173 )
132174 self .assertEqual (response .status_code , 400 , response .data )
133175
134176 # set liveness success threshold to a non-1 value
135177 # Don't set one of the mandatory value
136178 response = self .client .post (
137179 '/v2/apps/{app_id}/config' .format (** locals ()),
138- {'healthcheck' : {'livenessProbe' :
180+ {'healthcheck' : {'web/cmd' : { ' livenessProbe' :
139181 {'httpGet' : {'path' : '/' , 'port' : 5000 },
140- 'successThreshold' : 5 }}}
182+ 'successThreshold' : 5 }}}}
141183 )
142184 self .assertEqual (response .status_code , 400 , response .data )
143185
@@ -158,7 +200,7 @@ def test_config_healthchecks_legacy(self, mock_requests):
158200 # this gets migrated to the new healtcheck format
159201 self .assertNotIn ('HEALTHCHECK_URL' , response .data ['values' ])
160202 # legacy defaults
161- expected = {
203+ expected = {'web/cmd' : {
162204 'livenessProbe' : {
163205 'initialDelaySeconds' : 50 ,
164206 'timeoutSeconds' : 50 ,
@@ -179,6 +221,7 @@ def test_config_healthchecks_legacy(self, mock_requests):
179221 'path' : '/health'
180222 }
181223 }
224+ }
182225 }
183226 actual = app .config_set .latest ().healthcheck
184227 self .assertEqual (actual , expected )
@@ -198,7 +241,7 @@ def test_config_healthchecks_legacy(self, mock_requests):
198241 self .assertEqual (response .status_code , 201 , response .data )
199242 # this gets migrated to the new healtcheck format
200243 self .assertNotIn ('HEALTHCHECK_INITIAL_DELAY' , response .data ['values' ])
201- expected ['livenessProbe' ] = {
244+ expected ['web/cmd' ][ ' livenessProbe' ] = {
202245 'initialDelaySeconds' : 25 ,
203246 'timeoutSeconds' : 10 ,
204247 'periodSeconds' : 5 ,
@@ -208,6 +251,6 @@ def test_config_healthchecks_legacy(self, mock_requests):
208251 'path' : '/health'
209252 }
210253 }
211- expected ['readinessProbe' ] = expected ['livenessProbe' ]
254+ expected ['web/cmd' ][ ' readinessProbe' ] = expected [ 'web/cmd' ] ['livenessProbe' ]
212255 actual = app .config_set .latest ().healthcheck
213256 self .assertEqual (expected , actual )
0 commit comments