99 "github.com/stretchr/testify/assert"
1010
1111 "github.com/osbuild/images/pkg/container"
12+ "github.com/osbuild/images/pkg/rpmmd"
1213)
1314
1415func TestSource_UnmarshalJSON (t * testing.T ) {
@@ -119,7 +120,7 @@ func TestSource_UnmarshalJSON(t *testing.T) {
119120}
120121
121122func TestGenSourcesTrivial (t * testing.T ) {
122- sources , err := GenSources (nil , nil , nil , nil )
123+ sources , err := GenSources (SourceInputs {}, 0 )
123124 assert .NoError (t , err )
124125
125126 jsonOutput , err := json .MarshalIndent (sources , "" , " " )
@@ -135,7 +136,7 @@ func TestGenSourcesContainerStorage(t *testing.T) {
135136 LocalStorage : true ,
136137 },
137138 }
138- sources , err := GenSources (nil , nil , nil , containers )
139+ sources , err := GenSources (SourceInputs { Containers : containers }, 0 )
139140 assert .NoError (t , err )
140141
141142 jsonOutput , err := json .MarshalIndent (sources , "" , " " )
@@ -159,7 +160,7 @@ func TestGenSourcesSkopeo(t *testing.T) {
159160 ImageID : imageID ,
160161 },
161162 }
162- sources , err := GenSources (nil , nil , nil , containers )
163+ sources , err := GenSources (SourceInputs { Containers : containers }, 0 )
163164 assert .NoError (t , err )
164165
165166 jsonOutput , err := json .MarshalIndent (sources , "" , " " )
@@ -190,7 +191,7 @@ func TestGenSourcesWithSkopeoIndex(t *testing.T) {
190191 ImageID : imageID ,
191192 },
192193 }
193- sources , err := GenSources (nil , nil , nil , containers )
194+ sources , err := GenSources (SourceInputs { Containers : containers }, 0 )
194195 assert .NoError (t , err )
195196
196197 jsonOutput , err := json .MarshalIndent (sources , "" , " " )
@@ -217,3 +218,92 @@ func TestGenSourcesWithSkopeoIndex(t *testing.T) {
217218 }
218219}` )
219220}
221+
222+ // TODO: move into a common "rpmtest" package
223+ var opensslPkg = rpmmd.PackageSpec {
224+ Name : "openssl-libs" ,
225+ RemoteLocation : "https://example.com/repo/Packages/openssl-libs-3.0.1-5.el9.x86_64.rpm" ,
226+ Checksum : "sha256:fcf2515ec9115551c99d552da721803ecbca23b7ae5a974309975000e8bef666" ,
227+ Path : "Packages/openssl-libs-3.0.1-5.el9.x86_64.rpm" ,
228+ RepoID : "repo_id_metalink" ,
229+ }
230+
231+ var fakeRepos = []rpmmd.RepoConfig {
232+ {
233+ Id : "repo_id_metalink" ,
234+ Metalink : "http://example.com/metalink" ,
235+ },
236+ }
237+
238+ func TestGenSourcesRpmDefaultRpmDownloaderIsCurl (t * testing.T ) {
239+ inputs := SourceInputs {
240+ Packages : []rpmmd.PackageSpec {opensslPkg },
241+ RpmRepos : fakeRepos ,
242+ }
243+ var defaultRpmDownloader RpmDownloader
244+ sources , err := GenSources (inputs , defaultRpmDownloader )
245+ assert .NoError (t , err )
246+
247+ assert .NotNil (t , sources ["org.osbuild.curl" ])
248+ assert .Nil (t , sources ["org.osbuild.librepo" ])
249+ }
250+
251+ func TestGenSourcesRpmWithLibcurl (t * testing.T ) {
252+ inputs := SourceInputs {
253+ Packages : []rpmmd.PackageSpec {opensslPkg },
254+ RpmRepos : fakeRepos ,
255+ }
256+ sources , err := GenSources (inputs , RpmDownloaderCurl )
257+ assert .NoError (t , err )
258+
259+ jsonOutput , err := json .MarshalIndent (sources , "" , " " )
260+ assert .NoError (t , err )
261+ assert .Equal (t , string (jsonOutput ), `{
262+ "org.osbuild.curl": {
263+ "items": {
264+ "sha256:fcf2515ec9115551c99d552da721803ecbca23b7ae5a974309975000e8bef666": {
265+ "url": "https://example.com/repo/Packages/openssl-libs-3.0.1-5.el9.x86_64.rpm"
266+ }
267+ }
268+ }
269+ }` )
270+ }
271+
272+ func TestGenSourcesRpmWithLibrepo (t * testing.T ) {
273+ inputs := SourceInputs {
274+ Packages : []rpmmd.PackageSpec {opensslPkg },
275+ RpmRepos : fakeRepos ,
276+ }
277+ sources , err := GenSources (inputs , RpmDownloaderLibrepo )
278+ assert .NoError (t , err )
279+
280+ jsonOutput , err := json .MarshalIndent (sources , "" , " " )
281+ assert .NoError (t , err )
282+ assert .Equal (t , string (jsonOutput ), `{
283+ "org.osbuild.librepo": {
284+ "items": {
285+ "sha256:fcf2515ec9115551c99d552da721803ecbca23b7ae5a974309975000e8bef666": {
286+ "path": "Packages/openssl-libs-3.0.1-5.el9.x86_64.rpm",
287+ "mirror": "repo_id_metalink"
288+ }
289+ },
290+ "options": {
291+ "mirrors": {
292+ "repo_id_metalink": {
293+ "url": "http://example.com/metalink",
294+ "type": "metalink"
295+ }
296+ }
297+ }
298+ }
299+ }` )
300+ }
301+
302+ func TestGenSourcesRpmBad (t * testing.T ) {
303+ inputs := SourceInputs {
304+ Packages : []rpmmd.PackageSpec {opensslPkg },
305+ RpmRepos : fakeRepos ,
306+ }
307+ _ , err := GenSources (inputs , 99 )
308+ assert .EqualError (t , err , "unknown rpm downloader 99" )
309+ }
0 commit comments