55from django .contrib .auth import get_user_model
66from rest_framework .authtoken .models import Token
77
8- from api .models .app import App
98from api .tests import adapter , DryccTransactionTestCase
109
1110User = get_user_model ()
@@ -26,50 +25,6 @@ def tearDown(self):
2625 # make sure every test has a clean slate for k8s mocking
2726 cache .clear ()
2827
29- def test_healthchecks_validations (self , mock_requests ):
30- """
31- Test that healthchecks validations work
32- """
33- app_id = self .create_app ()
34-
35- # Set one of the values that require a numeric value to a string
36- response = self .client .post (
37- '/v2/apps/{app_id}/config' .format (** locals ()),
38- {'values' : json .dumps ({'HEALTHCHECK_INITIAL_DELAY' : 'horse' })}
39- )
40- self .assertEqual (response .status_code , 400 , response .data )
41-
42- # test URL - Path is the only allowed thing
43- # Try setting various things such as query param
44-
45- # query param
46- response = self .client .post (
47- '/v2/apps/{app_id}/config' .format (** locals ()),
48- {'values' : json .dumps ({'HEALTHCHECK_URL' : '/health?testing=0' })}
49- )
50- self .assertEqual (response .status_code , 400 , response .data )
51-
52- # fragment
53- response = self .client .post (
54- '/v2/apps/{app_id}/config' .format (** locals ()),
55- {'values' : json .dumps ({'HEALTHCHECK_URL' : '/health#db' })}
56- )
57- self .assertEqual (response .status_code , 400 , response .data )
58-
59- # netloc
60- response = self .client .post (
61- '/v2/apps/{app_id}/config' .format (** locals ()),
62- {'values' : json .dumps ({'HEALTHCHECK_URL' : 'http://someurl.com/health/' })}
63- )
64- self .assertEqual (response .status_code , 400 , response .data )
65-
66- # no path
67- response = self .client .post (
68- '/v2/apps/{app_id}/config' .format (** locals ()),
69- {'values' : json .dumps ({'HEALTHCHECK_URL' : 'http://someurl.com' })}
70- )
71- self .assertEqual (response .status_code , 400 , response .data )
72-
7328 def test_config_healthchecks (self , mock_requests ):
7429 """
7530 Test that healthchecks can be applied
@@ -171,85 +126,3 @@ def test_config_healthchecks_validations(self, mock_requests):
171126 {'httpGet' : {'path' : '/' }, 'initialDelaySeconds' : 1 }}})}
172127 )
173128 self .assertEqual (response .status_code , 400 , response .data )
174-
175- # set liveness success threshold to a non-1 value
176- # Don't set one of the mandatory value
177- response = self .client .post (
178- '/v2/apps/{app_id}/config' .format (** locals ()),
179- {'healthcheck' : {'web' : {'livenessProbe' :
180- {'httpGet' : {'path' : '/' , 'port' : 5000 },
181- 'successThreshold' : 5 }}}}
182- )
183- self .assertEqual (response .status_code , 400 , response .data )
184-
185- def test_config_healthchecks_legacy (self , mock_requests ):
186- """
187- Test that when a user uses `drycc config:set HEALTHCHECK_URL=/`, the config
188- object is rolled over to the `healthcheck` field.
189- """
190- app_id = self .create_app ()
191- app = App .objects .get (id = app_id )
192-
193- # Set healthcheck URL to get defaults set
194- response = self .client .post (
195- '/v2/apps/{app.id}/config' .format (** locals ()),
196- {'values' : json .dumps ({'HEALTHCHECK_URL' : '/health' })}
197- )
198- self .assertEqual (response .status_code , 201 , response .data )
199- # this gets migrated to the new healtcheck format
200- self .assertNotIn ('HEALTHCHECK_URL' , response .data ['values' ])
201- # legacy defaults
202- expected = {'web' : {
203- 'livenessProbe' : {
204- 'initialDelaySeconds' : 50 ,
205- 'timeoutSeconds' : 50 ,
206- 'periodSeconds' : 10 ,
207- 'successThreshold' : 1 ,
208- 'failureThreshold' : 3 ,
209- 'httpGet' : {
210- 'path' : '/health'
211- }
212- },
213- 'readinessProbe' : {
214- 'initialDelaySeconds' : 50 ,
215- 'timeoutSeconds' : 50 ,
216- 'periodSeconds' : 10 ,
217- 'successThreshold' : 1 ,
218- 'failureThreshold' : 3 ,
219- 'httpGet' : {
220- 'path' : '/health'
221- }
222- }
223- }
224- }
225- actual = app .config_set .latest ().healthcheck
226- self .assertEqual (actual , expected )
227- # Now set all the envvars and check to make sure they are written properly
228- response = self .client .post (
229- '/v2/apps/{app.id}/config' .format (** locals ()),
230- {
231- 'values' : json .dumps ({
232- 'HEALTHCHECK_URL' : '/health' ,
233- 'HEALTHCHECK_INITIAL_DELAY' : '25' ,
234- 'HEALTHCHECK_TIMEOUT' : '10' ,
235- 'HEALTHCHECK_PERIOD_SECONDS' : '5' ,
236- 'HEALTHCHECK_SUCCESS_THRESHOLD' : '2' ,
237- 'HEALTHCHECK_FAILURE_THRESHOLD' : '2' })
238- }
239- )
240- self .assertEqual (response .status_code , 201 , response .data )
241- # this gets migrated to the new healtcheck format
242- self .assertNotIn ('HEALTHCHECK_INITIAL_DELAY' , response .data ['values' ])
243- expected ['web' ]['livenessProbe' ] = {
244- 'initialDelaySeconds' : 25 ,
245- 'timeoutSeconds' : 10 ,
246- 'periodSeconds' : 5 ,
247- 'successThreshold' : 2 ,
248- 'failureThreshold' : 2 ,
249- 'httpGet' : {
250- 'path' : '/health'
251- }
252- }
253- expected ['web' ]['readinessProbe' ] = expected ['web' ]['livenessProbe' ]
254- actual = app .config_set .latest ().healthcheck
255- self .assertEqual (expected , actual )
0 commit comments