Skip to content

Commit

Permalink
Merge pull request #155 from github/terraform-tests
Browse files Browse the repository at this point in the history
ci: Add test for Terraform dependabot config
  • Loading branch information
zkoppert authored May 31, 2024
2 parents b350eab + 9c10b13 commit f4d83c1
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions test_dependabot_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,48 @@ 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_with_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)
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)

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)
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()
Expand Down

0 comments on commit f4d83c1

Please sign in to comment.