34
34
35
35
import opengrok_tools .mirror
36
36
from 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
38
38
39
39
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 ])
40
49
@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 ):
42
51
"""
43
52
Test that the special CONTINUE_EXITVAL value bubbles all the way up to
44
53
the mirror.py return value.
45
54
"""
46
55
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
-
52
56
class MockResponse :
53
57
54
58
# mock json() method always returns a specific testing dictionary
@@ -65,7 +69,9 @@ def raise_for_status():
65
69
repo_path = os .path .join (source_root , repo_name )
66
70
cloned_repo_name = "cloned_repo"
67
71
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 )
69
75
70
76
os .mkdir (repo_path )
71
77
@@ -85,15 +91,25 @@ def mock_get_config_value(*args, **kwargs):
85
91
git_config .
set_value (
'user' ,
'email' ,
'[email protected] ' )
86
92
git_config .set_value ('user' , 'name' , 'John Doe' )
87
93
88
- new_file_path = os .path .join (repo_path , 'foo' )
94
+ # Add a file.
95
+ new_file_path = os .path .join (repo_path , 'newfile' )
89
96
with open (new_file_path , 'w' ):
90
97
pass
91
98
assert os .path .isfile (new_file_path )
92
99
index = repo .index
93
100
index .add ([new_file_path ])
94
101
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.
95
105
repo .clone (cloned_repo_path )
96
106
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
+
97
113
with monkeypatch .context () as m :
98
114
m .setattr (sys , 'argv' , ['prog' , "-I" , project_name ])
99
115
@@ -103,4 +119,9 @@ def mock_get_config_value(*args, **kwargs):
103
119
m .setattr ("opengrok_tools.utils.mirror.get_repos_for_project" , mock_get_repos )
104
120
m .setattr ("opengrok_tools.utils.mirror.do_api_call" , mock_get )
105
121
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