From aa10db6abf554c6032813b155bc6844e24623027 Mon Sep 17 00:00:00 2001 From: Zack Koppert Date: Fri, 31 May 2024 10:09:31 -0700 Subject: [PATCH 1/2] ci: Add test for Terraform dependabot config Signed-off-by: Zack Koppert --- test_dependabot_file.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/test_dependabot_file.py b/test_dependabot_file.py index a5ed65a..847a115 100644 --- a/test_dependabot_file.py +++ b/test_dependabot_file.py @@ -251,6 +251,41 @@ def test_build_dependabot_file_with_docker(self): result = build_dependabot_file(repo, False, [], None) self.assertEqual(result, expected_result) + def test_build_dependabot_file_with_terraform(self): + """Test that the dependabot.yml file is built correctly with Terraform""" + repo = MagicMock() + response = MagicMock() + response.status_code = 404 + repo.file_contents.side_effect = github3.exceptions.NotFoundError(resp=response) + repo.directory_contents.side_effect = lambda path: ( + [("main.tf", None)] if path == "/" else [] + ) + + expected_result = """--- +version: 2 +updates: + - package-ecosystem: 'terraform' + directory: '/' + schedule: + interval: 'weekly' +""" + result = build_dependabot_file(repo, False, [], None) + self.assertEqual(result, expected_result) + + # Test absence of Terraform files + repo.directory_contents.side_effect = lambda path: [] if path == "/" else [] + result = build_dependabot_file(repo, False, [], None) + self.assertIsNone(result) + + # Test empty repository + response = MagicMock() + response.status_code = 404 + repo.directory_contents.side_effect = github3.exceptions.NotFoundError( + resp=response + ) + result = build_dependabot_file(repo, False, [], None) + self.assertIsNone(result) + def test_build_dependabot_file_with_groups(self): """Test that the dependabot.yml file is built correctly with grouped dependencies""" repo = MagicMock() From 9c10b1344efbd52c76362355f499dd8483b91139 Mon Sep 17 00:00:00 2001 From: Zack Koppert Date: Fri, 31 May 2024 10:37:17 -0700 Subject: [PATCH 2/2] chore: split tests into affirmative and negative Signed-off-by: Zack Koppert --- test_dependabot_file.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test_dependabot_file.py b/test_dependabot_file.py index 847a115..61bdc94 100644 --- a/test_dependabot_file.py +++ b/test_dependabot_file.py @@ -251,7 +251,7 @@ def test_build_dependabot_file_with_docker(self): result = build_dependabot_file(repo, False, [], None) self.assertEqual(result, expected_result) - def test_build_dependabot_file_with_terraform(self): + def test_build_dependabot_file_with_terraform_with_files(self): """Test that the dependabot.yml file is built correctly with Terraform""" repo = MagicMock() response = MagicMock() @@ -272,6 +272,13 @@ def test_build_dependabot_file_with_terraform(self): result = build_dependabot_file(repo, False, [], None) self.assertEqual(result, expected_result) + def test_build_dependabot_file_with_terraform_without_files(self): + """Test that the dependabot.yml file is built correctly with Terraform""" + repo = MagicMock() + response = MagicMock() + response.status_code = 404 + repo.file_contents.side_effect = github3.exceptions.NotFoundError(resp=response) + # Test absence of Terraform files repo.directory_contents.side_effect = lambda path: [] if path == "/" else [] result = build_dependabot_file(repo, False, [], None)