Skip to content

Commit f4d83c1

Browse files
authored
Merge pull request #155 from github/terraform-tests
ci: Add test for Terraform dependabot config
2 parents b350eab + 9c10b13 commit f4d83c1

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

test_dependabot_file.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,48 @@ def test_build_dependabot_file_with_docker(self):
251251
result = build_dependabot_file(repo, False, [], None)
252252
self.assertEqual(result, expected_result)
253253

254+
def test_build_dependabot_file_with_terraform_with_files(self):
255+
"""Test that the dependabot.yml file is built correctly with Terraform"""
256+
repo = MagicMock()
257+
response = MagicMock()
258+
response.status_code = 404
259+
repo.file_contents.side_effect = github3.exceptions.NotFoundError(resp=response)
260+
repo.directory_contents.side_effect = lambda path: (
261+
[("main.tf", None)] if path == "/" else []
262+
)
263+
264+
expected_result = """---
265+
version: 2
266+
updates:
267+
- package-ecosystem: 'terraform'
268+
directory: '/'
269+
schedule:
270+
interval: 'weekly'
271+
"""
272+
result = build_dependabot_file(repo, False, [], None)
273+
self.assertEqual(result, expected_result)
274+
275+
def test_build_dependabot_file_with_terraform_without_files(self):
276+
"""Test that the dependabot.yml file is built correctly with Terraform"""
277+
repo = MagicMock()
278+
response = MagicMock()
279+
response.status_code = 404
280+
repo.file_contents.side_effect = github3.exceptions.NotFoundError(resp=response)
281+
282+
# Test absence of Terraform files
283+
repo.directory_contents.side_effect = lambda path: [] if path == "/" else []
284+
result = build_dependabot_file(repo, False, [], None)
285+
self.assertIsNone(result)
286+
287+
# Test empty repository
288+
response = MagicMock()
289+
response.status_code = 404
290+
repo.directory_contents.side_effect = github3.exceptions.NotFoundError(
291+
resp=response
292+
)
293+
result = build_dependabot_file(repo, False, [], None)
294+
self.assertIsNone(result)
295+
254296
def test_build_dependabot_file_with_groups(self):
255297
"""Test that the dependabot.yml file is built correctly with grouped dependencies"""
256298
repo = MagicMock()

0 commit comments

Comments
 (0)