Explorar o código

[git_auth] Add apply_global tests

Bug: b/351024645
Change-Id: I54e55545c27275165b3435707e2b47095c8fcac9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5739434
Reviewed-by: Yiwei Zhang <yiwzhang@google.com>
Commit-Queue: Allen Li <ayatane@chromium.org>
Allen Li hai 1 ano
pai
achega
a40df24c91
Modificáronse 1 ficheiros con 32 adicións e 1 borrados
  1. 32 1
      tests/git_auth_test.py

+ 32 - 1
tests/git_auth_test.py

@@ -9,6 +9,7 @@ import logging
 import os
 import os
 import sys
 import sys
 import unittest
 import unittest
+from typing import Iterable
 
 
 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
 
 
@@ -20,7 +21,12 @@ import scm_mock
 class TestConfigChanger(unittest.TestCase):
 class TestConfigChanger(unittest.TestCase):
 
 
     def setUp(self):
     def setUp(self):
-        scm_mock.GIT(self)
+        self._global_state_view: Iterable[tuple[str,
+                                                list[str]]] = scm_mock.GIT(self)
+
+    @property
+    def global_state(self):
+        return dict(self._global_state_view)
 
 
     def test_apply_new_auth(self):
     def test_apply_new_auth(self):
         git_auth.ConfigChanger(
         git_auth.ConfigChanger(
@@ -137,6 +143,31 @@ class TestConfigChanger(unittest.TestCase):
         }
         }
         self.assertEqual(scm.GIT._dump_config_state(), want)
         self.assertEqual(scm.GIT._dump_config_state(), want)
 
 
+    def test_apply_global_new_auth(self):
+        git_auth.ConfigChanger(
+            mode=git_auth.ConfigMode.NEW_AUTH,
+            remote_url=
+            'https://chromium.googlesource.com/chromium/tools/depot_tools.git',
+        ).apply_global('/some/fake/dir')
+        want = {
+            'credential.https://chromium.googlesource.com/.helper':
+            ['', 'luci'],
+        }
+        self.assertEqual(self.global_state, want)
+
+    def test_apply_global_new_auth_sso(self):
+        git_auth.ConfigChanger(
+            mode=git_auth.ConfigMode.NEW_AUTH_SSO,
+            remote_url=
+            'https://chromium.googlesource.com/chromium/tools/depot_tools.git',
+        ).apply_global('/some/fake/dir')
+        want = {
+            'protocol.sso.allow': ['always'],
+            'url.sso://chromium/.insteadof':
+            ['https://chromium.googlesource.com/'],
+        }
+        self.assertEqual(self.global_state, want)
+
 
 
 if __name__ == '__main__':
 if __name__ == '__main__':
     logging.basicConfig(
     logging.basicConfig(