From d686365449ade2480a23f86531a5b6630fcbb7a0 Mon Sep 17 00:00:00 2001 From: Sam Saccone Date: Tue, 15 Nov 2022 23:57:22 +0000 Subject: Extract env building into a testable helper. Previously env dict building was untested and mixed with other mutative actions. Extract the dict building into a dedicated function and author tests to ensure the functionality is working as expected. BUG: b/255376186 BUG: https://crbug.com/gerrit/16247 Change-Id: I0c88e53eb285c5c3fb27f8e6b3a903aedb8e02a8 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/351874 Reviewed-by: LaMont Jones Tested-by: Sam Saccone --- tests/test_git_command.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'tests/test_git_command.py') diff --git a/tests/test_git_command.py b/tests/test_git_command.py index 93300a6f..aaf21219 100644 --- a/tests/test_git_command.py +++ b/tests/test_git_command.py @@ -15,6 +15,7 @@ """Unittests for the git_command.py module.""" import re +import os import unittest try: @@ -26,6 +27,38 @@ import git_command import wrapper +class GitCommandTest(unittest.TestCase): + """Tests the GitCommand class (via git_command.git).""" + + def setUp(self): + + def realpath_mock(val): + return val + + mock.patch.object(os.path, 'realpath', side_effect=realpath_mock).start() + + def tearDown(self): + mock.patch.stopall() + + def test_alternative_setting_when_matching(self): + r = git_command._build_env( + objdir = 'zap/objects', + gitdir = 'zap' + ) + + self.assertIsNone(r.get('GIT_ALTERNATE_OBJECT_DIRECTORIES')) + self.assertEqual(r.get('GIT_OBJECT_DIRECTORY'), 'zap/objects') + + def test_alternative_setting_when_different(self): + r = git_command._build_env( + objdir = 'wow/objects', + gitdir = 'zap' + ) + + self.assertEqual(r.get('GIT_ALTERNATE_OBJECT_DIRECTORIES'), 'zap/objects') + self.assertEqual(r.get('GIT_OBJECT_DIRECTORY'), 'wow/objects') + + class GitCallUnitTest(unittest.TestCase): """Tests the _GitCall class (via git_command.git).""" -- cgit v1.2.3-54-g00ecf