import unittest from dependabro.utils import parse_source_url class TestParseSourceUrl(unittest.TestCase): def test_parse_source_url(self): test_cases = [ # Normal repo with ref ( "git@github.com:org/repo.git?ref=v1.0.0", "git@github.com:org/repo.git//", "v1.0.0", ), # Normal repo without ref (should default to master) ("git@github.com:org/repo.git", "git@github.com:org/repo.git//", "master"), # Repo without .git but with ref (normalize with .git) ( "git@github.com:org/repo?ref=v1.0.0", "git@github.com:org/repo.git//", "v1.0.0", ), # Repo with empty Terraform module path and ref ( "git@github.com:org/repo.git//?ref=v1.0.0", "git@github.com:org/repo.git//", "v1.0.0", ), # Repo with empty Terraform module path (default to master) ( "git@github.com:org/repo.git//", "git@github.com:org/repo.git//", "master", ), # Repo without .git, empty module path, and ref (normalize .git) ( "git@github.com:org/repo//?ref=v1.0.0", "git@github.com:org/repo.git//", "v1.0.0", ), # Repo with Terraform module path and ref ( "git@github.com:org/repo.git//module/path?ref=v1.0.0", "git@github.com:org/repo.git//module/path", "v1.0.0", ), # Repo with Terraform module path and ref (with trailing `/`) ( "git@github.com:org/repo.git//module/path/?ref=v1.0.0", "git@github.com:org/repo.git//module/path/", "v1.0.0", ), # Repo with Terraform module path (default to master) ( "git@github.com:org/repo.git//module/path/", "git@github.com:org/repo.git//module/path/", "master", ), # Repo without .git but with module path (normalize to .git) ( "git@github.com:org/repo//module/path/", "git@github.com:org/repo.git//module/path/", "master", ), # Repo without .git, with module path and ref ( "git@github.com:org/repo//module/path/?ref=v1.0.0", "git@github.com:org/repo.git//module/path/", "v1.0.0", ), ] for source, expected_git_url, expected_ref in test_cases: with self.subTest(source=source): git_url, ref = parse_source_url(source) self.assertEqual(git_url, expected_git_url) self.assertEqual(ref, expected_ref) if __name__ == "__main__": unittest.main()