@@ -387,6 +387,81 @@ def test_add_existing_ecosystem_to_exempt_list(self):
387
387
for ecosystem in exempt_ecosystems :
388
388
self .assertIn (ecosystem , exempt_ecosystems )
389
389
390
+ def test_build_dependabot_file_for_multiple_repos_with_few_existing_config (self ):
391
+ """
392
+ Test the case where there are multiple repos with few existing dependabot config
393
+ """
394
+ existing_config_repo = MagicMock ()
395
+ existing_config_repo .file_contents .side_effect = (
396
+ lambda f , filename = "Gemfile" : f == filename
397
+ )
398
+
399
+ existing_config = MagicMock ()
400
+ existing_config .decoded = b'---\n version: 2\n updates:\n - package-ecosystem: "bundler"\n \
401
+ directory: "/"\n schedule:\n interval: "weekly"\n commit-message:\n prefix: "chore(deps)"\n '
402
+ exempt_ecosystems = []
403
+ result = build_dependabot_file (
404
+ existing_config_repo , False , exempt_ecosystems , {}, existing_config
405
+ )
406
+ self .assertEqual (result , None )
407
+
408
+ no_existing_config_repo = MagicMock ()
409
+ filename_list = ["package.json" , "package-lock.json" , "yarn.lock" ]
410
+ for filename in filename_list :
411
+ no_existing_config_repo .file_contents .side_effect = (
412
+ lambda f , filename = filename : f == filename
413
+ )
414
+ expected_result = """---
415
+ version: 2
416
+ updates:
417
+ - package-ecosystem: 'npm'
418
+ directory: '/'
419
+ schedule:
420
+ interval: 'weekly'
421
+ """
422
+ result = build_dependabot_file (
423
+ no_existing_config_repo , False , exempt_ecosystems , {}, None
424
+ )
425
+ self .assertEqual (result , expected_result )
426
+
427
+ def test_check_multiple_repos_with_no_dependabot_config (self ):
428
+ """
429
+ Test the case where there is a single repo
430
+ """
431
+ mock_repo_1 = MagicMock ()
432
+ mock_repo_1 .file_contents .side_effect = lambda filename : filename == "go.mod"
433
+
434
+ expected_result = """---
435
+ version: 2
436
+ updates:
437
+ - package-ecosystem: 'gomod'
438
+ directory: '/'
439
+ schedule:
440
+ interval: 'weekly'
441
+ """
442
+ exempt_ecosystems = []
443
+ result = build_dependabot_file (mock_repo_1 , False , exempt_ecosystems , {}, None )
444
+ self .assertEqual (result , expected_result )
445
+
446
+ no_existing_config_repo = MagicMock ()
447
+ filename_list = ["package.json" , "package-lock.json" , "yarn.lock" ]
448
+ for filename in filename_list :
449
+ no_existing_config_repo .file_contents .side_effect = (
450
+ lambda f , filename = filename : f == filename
451
+ )
452
+ expected_result = """---
453
+ version: 2
454
+ updates:
455
+ - package-ecosystem: 'npm'
456
+ directory: '/'
457
+ schedule:
458
+ interval: 'weekly'
459
+ """
460
+ result = build_dependabot_file (
461
+ no_existing_config_repo , False , exempt_ecosystems , {}, None
462
+ )
463
+ self .assertEqual (result , expected_result )
464
+
390
465
391
466
if __name__ == "__main__" :
392
467
unittest .main ()
0 commit comments