9
9
"github.com/stretchr/testify/assert"
10
10
11
11
"github.com/osbuild/images/pkg/container"
12
+ "github.com/osbuild/images/pkg/rpmmd"
12
13
)
13
14
14
15
func TestSource_UnmarshalJSON (t * testing.T ) {
@@ -119,7 +120,7 @@ func TestSource_UnmarshalJSON(t *testing.T) {
119
120
}
120
121
121
122
func TestGenSourcesTrivial (t * testing.T ) {
122
- sources , err := GenSources (nil , nil , nil , nil )
123
+ sources , err := GenSources (SourceInputs {}, 0 )
123
124
assert .NoError (t , err )
124
125
125
126
jsonOutput , err := json .MarshalIndent (sources , "" , " " )
@@ -135,7 +136,7 @@ func TestGenSourcesContainerStorage(t *testing.T) {
135
136
LocalStorage : true ,
136
137
},
137
138
}
138
- sources , err := GenSources (nil , nil , nil , containers )
139
+ sources , err := GenSources (SourceInputs { Containers : containers }, 0 )
139
140
assert .NoError (t , err )
140
141
141
142
jsonOutput , err := json .MarshalIndent (sources , "" , " " )
@@ -159,7 +160,7 @@ func TestGenSourcesSkopeo(t *testing.T) {
159
160
ImageID : imageID ,
160
161
},
161
162
}
162
- sources , err := GenSources (nil , nil , nil , containers )
163
+ sources , err := GenSources (SourceInputs { Containers : containers }, 0 )
163
164
assert .NoError (t , err )
164
165
165
166
jsonOutput , err := json .MarshalIndent (sources , "" , " " )
@@ -190,7 +191,7 @@ func TestGenSourcesWithSkopeoIndex(t *testing.T) {
190
191
ImageID : imageID ,
191
192
},
192
193
}
193
- sources , err := GenSources (nil , nil , nil , containers )
194
+ sources , err := GenSources (SourceInputs { Containers : containers }, 0 )
194
195
assert .NoError (t , err )
195
196
196
197
jsonOutput , err := json .MarshalIndent (sources , "" , " " )
@@ -217,3 +218,79 @@ func TestGenSourcesWithSkopeoIndex(t *testing.T) {
217
218
}
218
219
}` )
219
220
}
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 TestGenSourcesRpmWithLibcurl (t * testing.T ) {
239
+ inputs := SourceInputs {
240
+ Packages : []rpmmd.PackageSpec {opensslPkg },
241
+ RpmRepos : fakeRepos ,
242
+ }
243
+ sources , err := GenSources (inputs , RpmDownloaderCurl )
244
+ assert .NoError (t , err )
245
+
246
+ jsonOutput , err := json .MarshalIndent (sources , "" , " " )
247
+ assert .NoError (t , err )
248
+ assert .Equal (t , string (jsonOutput ), `{
249
+ "org.osbuild.curl": {
250
+ "items": {
251
+ "sha256:fcf2515ec9115551c99d552da721803ecbca23b7ae5a974309975000e8bef666": {
252
+ "url": "https://example.com/repo/Packages/openssl-libs-3.0.1-5.el9.x86_64.rpm"
253
+ }
254
+ }
255
+ }
256
+ }` )
257
+ }
258
+
259
+ func TestGenSourcesRpmWithLibrepo (t * testing.T ) {
260
+ inputs := SourceInputs {
261
+ Packages : []rpmmd.PackageSpec {opensslPkg },
262
+ RpmRepos : fakeRepos ,
263
+ }
264
+ sources , err := GenSources (inputs , RpmDownloaderLibrepo )
265
+ assert .NoError (t , err )
266
+
267
+ jsonOutput , err := json .MarshalIndent (sources , "" , " " )
268
+ assert .NoError (t , err )
269
+ assert .Equal (t , string (jsonOutput ), `{
270
+ "org.osbuild.librepo": {
271
+ "items": {
272
+ "sha256:fcf2515ec9115551c99d552da721803ecbca23b7ae5a974309975000e8bef666": {
273
+ "path": "Packages/openssl-libs-3.0.1-5.el9.x86_64.rpm",
274
+ "mirror": "repo_id_metalink"
275
+ }
276
+ },
277
+ "options": {
278
+ "mirrors": {
279
+ "repo_id_metalink": {
280
+ "url": "http://example.com/metalink",
281
+ "type": "metalink"
282
+ }
283
+ }
284
+ }
285
+ }
286
+ }` )
287
+ }
288
+
289
+ func TestGenSourcesRpmBad (t * testing.T ) {
290
+ inputs := SourceInputs {
291
+ Packages : []rpmmd.PackageSpec {opensslPkg },
292
+ RpmRepos : fakeRepos ,
293
+ }
294
+ _ , err := GenSources (inputs , 99 )
295
+ assert .EqualError (t , err , "unknown rpm downloader 99" )
296
+ }
0 commit comments