77import pytest
88
99FIXTURES_DIR = Path (__file__ ).parent / 'fixtures'
10+ POPULATED_REPO = FIXTURES_DIR / 'populated'
11+ POPULATED_RPM = Path (
12+ POPULATED_REPO ,
13+ 'x86_64' ,
14+ 'Packages' ,
15+ 'r' ,
16+ 'ros-dev-tools-1.0.1-1.el9.noarch.rpm' ,
17+ )
1018
1119
1220def test_version ():
1321 assert createrepo_agent .__version__
1422
1523
1624def test_add (tmp_path ):
17- packages_path = FIXTURES_DIR / 'populated' / 'x86_64' / 'Packages'
18- rpm_path = packages_path / 'r' / 'ros-dev-tools-1.0.1-1.el9.noarch.rpm'
25+ rpm_path = str (POPULATED_RPM )
1926
2027 with createrepo_agent .Server (str (tmp_path )):
2128 with createrepo_agent .Client (str (tmp_path )) as c :
2229 with pytest .raises (TypeError ):
23- c .add (str ( rpm_path ), 1 )
30+ c .add (None )
2431 with pytest .raises (TypeError ):
25- c .add (str (rpm_path ), (1 ,))
32+ c .add (rpm_path , 1 )
33+ with pytest .raises (TypeError ):
34+ c .add (rpm_path , (1 ,))
2635 c .set_invalidate_dependants (True )
2736 c .set_invalidate_family (True )
28- c .add (str ( rpm_path ) , ('x86_64' ,))
37+ c .add (rpm_path , ('x86_64' ,))
2938 c .commit ()
3039
31- assert (tmp_path / 'x86_64' / 'repodata' / 'repomd.xml' ).is_file ()
40+ arch_path = tmp_path / 'x86_64'
41+ repomd_path = arch_path / 'repodata' / 'repomd.xml'
42+
43+ assert repomd_path .is_file ()
44+ assert (arch_path / 'Packages' / 'r' / POPULATED_RPM .name ).is_file ()
3245
3346
3447def test_commit_nothing (tmp_path ):
@@ -45,3 +58,63 @@ def test_server_socket_collision(tmp_path):
4558 with pytest .raises (OSError ):
4659 with createrepo_agent .Server (str (tmp_path )):
4760 pass
61+
62+
63+ def test_sync_all (tmp_path ):
64+ base_url = POPULATED_REPO .as_uri ()
65+ with createrepo_agent .Server (str (tmp_path )):
66+ with createrepo_agent .Client (str (tmp_path )) as c :
67+ with pytest .raises (TypeError ):
68+ c .sync (None )
69+ with pytest .raises (TypeError ):
70+ c .sync (base_url , arches = 1 )
71+ with pytest .raises (TypeError ):
72+ c .sync (base_url , arches = (1 ,))
73+ c .sync (base_url , arches = ('x86_64' ,))
74+ c .commit ()
75+
76+ arch_path = tmp_path / 'x86_64'
77+ repomd_path = arch_path / 'repodata' / 'repomd.xml'
78+
79+ assert repomd_path .is_file ()
80+ assert (arch_path / 'Packages' / 'r' / POPULATED_RPM .name ).is_file ()
81+
82+ # Performing the same operation again results in no changes, so CRA shouldn't
83+ # make any changes to the metadata at all.
84+
85+ old_repomd_contents = repomd_path .read_text ()
86+
87+ with createrepo_agent .Server (str (tmp_path )):
88+ with createrepo_agent .Client (str (tmp_path )) as c :
89+ c .sync (base_url , arches = ('x86_64' ,))
90+ c .commit ()
91+
92+ assert old_repomd_contents == repomd_path .read_text ()
93+
94+
95+ def test_sync_pattern_hit (tmp_path ):
96+ base_url = POPULATED_REPO .as_uri ()
97+ pattern = POPULATED_RPM .name [:3 ] + '.*'
98+ with createrepo_agent .Server (str (tmp_path )):
99+ with createrepo_agent .Client (str (tmp_path )) as c :
100+ c .sync (base_url , pattern , ('x86_64' ,))
101+ c .commit ()
102+
103+ arch_path = tmp_path / 'x86_64'
104+ repomd_path = arch_path / 'repodata' / 'repomd.xml'
105+
106+ assert repomd_path .is_file ()
107+ assert (arch_path / 'Packages' / 'r' / POPULATED_RPM .name ).is_file ()
108+
109+
110+ def test_sync_pattern_miss (tmp_path ):
111+ base_url = POPULATED_REPO .as_uri ()
112+ pattern = 'does-not-match'
113+ with createrepo_agent .Server (str (tmp_path )):
114+ with createrepo_agent .Client (str (tmp_path )) as c :
115+ c .sync (base_url , pattern , ('x86_64' ,))
116+ c .commit ()
117+
118+ arch_path = tmp_path / 'x86_64'
119+
120+ assert not (arch_path / 'Packages' / 'r' / POPULATED_RPM .name ).is_file ()
0 commit comments