3434
3535import opengrok_tools .mirror
3636from opengrok_tools .scm import get_repository
37- from opengrok_tools .utils .exitvals import CONTINUE_EXITVAL
37+ from opengrok_tools .utils .exitvals import CONTINUE_EXITVAL , SUCCESS_EXITVAL
3838
3939
40+ @pytest .fixture (scope = "module" , autouse = True )
41+ def setup ():
42+ # The default has changed for python 3.8 (see https://github.com/oracle/opengrok/issues/3296).
43+ # Because of the mocking we need to use the "fork" type to propagate all mocks to the
44+ # processes spawned by mirror command
45+ multiprocessing .set_start_method ('fork' )
46+
47+
48+ @pytest .mark .parametrize ('do_changes' , [True , False ])
4049@pytest .mark .skipif (not os .name .startswith ("posix" ), reason = "requires posix" )
41- def test_incoming_retval (monkeypatch ):
50+ def test_incoming_retval (monkeypatch , do_changes ):
4251 """
4352 Test that the special CONTINUE_EXITVAL value bubbles all the way up to
4453 the mirror.py return value.
4554 """
4655
47- # The default has changed for python 3.8 (see https://github.com/oracle/opengrok/issues/3296).
48- # Because of the mocking we need to use the "fork" type to propagate all mocks to the
49- # processes spawned by mirror command
50- multiprocessing .set_start_method ('fork' )
51-
5256 class MockResponse :
5357
5458 # mock json() method always returns a specific testing dictionary
@@ -65,7 +69,9 @@ def raise_for_status():
6569 repo_path = os .path .join (source_root , repo_name )
6670 cloned_repo_name = "cloned_repo"
6771 cloned_repo_path = os .path .join (source_root , cloned_repo_name )
68- project_name = "foo" # does not matter for this test
72+ # The project name does not matter for this test except for the lock file created by main()
73+ # so that both parametrized tests can run in parallel.
74+ project_name = "test_incoming_retval-" + str (do_changes )
6975
7076 os .mkdir (repo_path )
7177
@@ -85,15 +91,25 @@ def mock_get_config_value(*args, **kwargs):
8591 git_config .
set_value (
'user' ,
'email' ,
'[email protected] ' )
8692 git_config .set_value ('user' , 'name' , 'John Doe' )
8793
88- new_file_path = os .path .join (repo_path , 'foo' )
94+ # Add a file.
95+ new_file_path = os .path .join (repo_path , 'newfile' )
8996 with open (new_file_path , 'w' ):
9097 pass
9198 assert os .path .isfile (new_file_path )
9299 index = repo .index
93100 index .add ([new_file_path ])
94101 index .commit ("add file" )
102+
103+ # Clone the repository first so that any subsequent changes in the repo
104+ # will not be reflected in the clone.
95105 repo .clone (cloned_repo_path )
96106
107+ if do_changes :
108+ with open (new_file_path , 'w' ) as fp :
109+ fp .write ("foo" )
110+ index .add ([new_file_path ])
111+ index .commit ("change file" )
112+
97113 with monkeypatch .context () as m :
98114 m .setattr (sys , 'argv' , ['prog' , "-I" , project_name ])
99115
@@ -103,4 +119,9 @@ def mock_get_config_value(*args, **kwargs):
103119 m .setattr ("opengrok_tools.utils.mirror.get_repos_for_project" , mock_get_repos )
104120 m .setattr ("opengrok_tools.utils.mirror.do_api_call" , mock_get )
105121
106- assert opengrok_tools .mirror .main () == CONTINUE_EXITVAL
122+ if do_changes :
123+ expected_retval = SUCCESS_EXITVAL
124+ else :
125+ expected_retval = CONTINUE_EXITVAL
126+
127+ assert opengrok_tools .mirror .main () == expected_retval
0 commit comments