@@ -248,6 +248,109 @@ func TestOCIRepository_Reconcile(t *testing.T) {
248248 }
249249}
250250
251+ func TestOCIRepository_Reconcile_MediaType (t * testing.T ) {
252+ g := NewWithT (t )
253+
254+ // Registry server with public images
255+ tmpDir := t .TempDir ()
256+ regServer , err := setupRegistryServer (ctx , tmpDir , registryOptions {})
257+ if err != nil {
258+ g .Expect (err ).ToNot (HaveOccurred ())
259+ }
260+
261+ podinfoVersions , err := pushMultiplePodinfoImages (regServer .registryHost , "6.1.4" , "6.1.5" , "6.1.6" )
262+
263+ tests := []struct {
264+ name string
265+ url string
266+ tag string
267+ mediaType string
268+ wantErr bool
269+ }{
270+ {
271+ name : "Works with no media type" ,
272+ url : podinfoVersions ["6.1.4" ].url ,
273+ tag : podinfoVersions ["6.1.4" ].tag ,
274+ },
275+ {
276+ name : "Works with Flux CLI media type" ,
277+ url : podinfoVersions ["6.1.5" ].url ,
278+ tag : podinfoVersions ["6.1.5" ].tag ,
279+ mediaType : "application/vnd.docker.image.rootfs.diff.tar.gzip" ,
280+ },
281+ {
282+ name : "Fails with unknown media type" ,
283+ url : podinfoVersions ["6.1.6" ].url ,
284+ tag : podinfoVersions ["6.1.6" ].tag ,
285+ mediaType : "application/invalid.tar.gzip" ,
286+ wantErr : true ,
287+ },
288+ }
289+
290+ for _ , tt := range tests {
291+ t .Run (tt .name , func (t * testing.T ) {
292+
293+ g := NewWithT (t )
294+
295+ ns , err := testEnv .CreateNamespace (ctx , "ocirepository-mediatype-test" )
296+ g .Expect (err ).ToNot (HaveOccurred ())
297+ defer func () { g .Expect (testEnv .Delete (ctx , ns )).To (Succeed ()) }()
298+
299+ obj := & sourcev1.OCIRepository {
300+ ObjectMeta : metav1.ObjectMeta {
301+ GenerateName : "ocirepository-reconcile" ,
302+ Namespace : ns .Name ,
303+ },
304+ Spec : sourcev1.OCIRepositorySpec {
305+ URL : tt .url ,
306+ Interval : metav1.Duration {Duration : 60 * time .Minute },
307+ Reference : & sourcev1.OCIRepositoryRef {
308+ Tag : tt .tag ,
309+ },
310+ LayerSelector : & sourcev1.OCILayerSelector {
311+ MediaType : tt .mediaType ,
312+ },
313+ },
314+ }
315+
316+ g .Expect (testEnv .Create (ctx , obj )).To (Succeed ())
317+
318+ key := client.ObjectKey {Name : obj .Name , Namespace : obj .Namespace }
319+
320+ // Wait for the finalizer to be set
321+ g .Eventually (func () bool {
322+ if err := testEnv .Get (ctx , key , obj ); err != nil {
323+ return false
324+ }
325+ return len (obj .Finalizers ) > 0
326+ }, timeout ).Should (BeTrue ())
327+
328+ // Wait for the object to be reconciled
329+ g .Eventually (func () bool {
330+ if err := testEnv .Get (ctx , key , obj ); err != nil {
331+ return false
332+ }
333+ readyCondition := conditions .Get (obj , meta .ReadyCondition )
334+ return readyCondition != nil
335+ }, timeout ).Should (BeTrue ())
336+
337+ g .Expect (conditions .IsReady (obj )).To (BeIdenticalTo (! tt .wantErr ))
338+ if tt .wantErr {
339+ g .Expect (conditions .Get (obj , meta .ReadyCondition ).Message ).Should (ContainSubstring ("failed to find layer with media type" ))
340+ }
341+
342+ // Wait for the object to be deleted
343+ g .Expect (testEnv .Delete (ctx , obj )).To (Succeed ())
344+ g .Eventually (func () bool {
345+ if err := testEnv .Get (ctx , key , obj ); err != nil {
346+ return apierrors .IsNotFound (err )
347+ }
348+ return false
349+ }, timeout ).Should (BeTrue ())
350+ })
351+ }
352+ }
353+
251354func TestOCIRepository_reconcileSource_authStrategy (t * testing.T ) {
252355 type secretOptions struct {
253356 username string
0 commit comments