move UserAgent to git_command for wider user

We can't import the main module, so move the UserAgent helper out of
it and into the git_command module so it can be used in more places.

Bug: https://crbug.com/gerrit/11144
Change-Id: I8093c8a20bd1dc7d612d0e2a85180341817c0d86
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/231057
Tested-by: Mike Frysinger <vapier@google.com>
Reviewed-by: David Pursehouse <dpursehouse@collab.net>
This commit is contained in:
Mike Frysinger
2019-07-10 17:10:07 -04:00
parent e37aa5f331
commit 369814b4a7
3 changed files with 62 additions and 45 deletions

View File

@@ -18,6 +18,7 @@
from __future__ import print_function
import re
import unittest
import git_command
@@ -47,3 +48,15 @@ class GitCallUnitTest(unittest.TestCase):
self.assertLess(ver, (9999, 9999, 9999))
self.assertNotEqual('', ver.full)
class RepoUserAgentUnitTest(unittest.TestCase):
"""Tests the RepoUserAgent function."""
def test_smoke(self):
"""Make sure it returns something useful."""
ua = git_command.RepoUserAgent()
# We can't dive too deep because of OS/tool differences, but we can check
# the general form.
m = re.match(r'^git-repo/[^ ]+ ([^ ]+) git/[^ ]+ Python/[0-9.]+', ua)
self.assertIsNotNone(m)