@@ -24,8 +24,8 @@ def docker_compose_file(pytestconfig):
24
24
return os .path .join (str (pytestconfig .rootdir ), "tests" , "docker-compose.yml" )
25
25
26
26
27
- @pytest .fixture (scope = "session " )
28
- def gitlab (docker_ip , docker_services , tmp_path_factory , pytestconfig ):
27
+ @pytest .fixture (scope = "function " )
28
+ def gitlab (docker_ip , docker_services , tmp_path_factory , pytestconfig , tmpdir ):
29
29
"""Manage a GitLab instance and return an object which can interact with it."""
30
30
http_url = "http://%s:%s/" % (docker_ip , docker_services .port_for ("gitlab" , 80 ))
31
31
git_url = "git+ssh://git@%s:%s/" % (docker_ip , docker_services .port_for ("gitlab" , 22 ))
@@ -154,7 +154,28 @@ def make_project(self, **kwargs):
154
154
)
155
155
response .raise_for_status ()
156
156
data = response .json ()
157
- return data ["id" ], self .git_url + data ["path_with_namespace" ] + ".git"
157
+
158
+ path = data ["path_with_namespace" ]
159
+ testing_project_path = tmpdir / path
160
+ testing_project_path .ensure (dir = True )
161
+
162
+ class TestRepo :
163
+ def __init__ (self , path , remote ):
164
+ self .path = path
165
+ self .remote = remote
166
+ self .git ("init" , "." )
167
+ self .git ("remote" , "add" , "origin" , remote )
168
+ self .
git (
"config" ,
"--local" ,
"user.email" ,
"[email protected] " )
169
+ self .git ("config" , "--local" , "user.name" , "Tester" )
170
+
171
+ def git (self , * args , ** kwargs ):
172
+ kwargs .setdefault ("check" , True )
173
+ kwargs .setdefault ("universal_newlines" , True )
174
+ return subprocess .run (["git" , "-C" , str (self .path ), * args ], ** kwargs )
175
+
176
+ repo = TestRepo (testing_project_path , self .git_url + data ["path_with_namespace" ] + ".git" )
177
+
178
+ return data ["id" ], repo
158
179
159
180
def delete_project (self , project_id ):
160
181
"""Make a project and return (id, ssh url)."""
@@ -172,17 +193,34 @@ def delete_project(self, project_id):
172
193
yield Info ()
173
194
174
195
175
- def test_mirror (gitlab ):
196
+ def test_mirror (gitlab , tmp_path_factory ):
176
197
"""Check that a sync runs first time."""
177
198
gitlab_sync = gitlab .make_runner ()
178
- project_id , _ = gitlab .make_project (name = "lulz" )
199
+ project_id , repo = gitlab .make_project (name = "lulz" )
200
+
201
+ # make sure empty repositories work
179
202
gitlab_sync ("local-update" , check = True )
180
203
project_absolute_path = gitlab .sync_root / gitlab .username / "lulz"
181
204
assert project_absolute_path .is_dir ()
182
205
206
+ # one file
207
+ repo .git ("init" , "." )
208
+ (repo .path / "README.md" ).write_text ("Hello" , "UTF8" )
209
+ repo .git ("add" , "README.md" )
210
+ repo .git ("commit" , "--message=Initial commit" )
211
+ repo .git ("push" , "--set-upstream" , "origin" , "master" )
212
+ gitlab_sync ("local-update" , check = True )
213
+ assert (project_absolute_path / "README.md" ).is_file ()
214
+
215
+ # remote the file
216
+ repo .git ("rm" , "README.md" )
217
+ repo .git ("commit" , "--message=Remote README.md" )
218
+ repo .git ("push" )
183
219
gitlab_sync ("local-update" , check = True )
184
220
assert project_absolute_path .is_dir ()
221
+ assert not (project_absolute_path / "README.md" ).is_file ()
185
222
223
+ # remote the project
186
224
gitlab .delete_project (project_id )
187
225
gitlab_sync ("local-update" , check = True )
188
226
assert not project_absolute_path .is_dir ()
0 commit comments