@@ -599,6 +599,84 @@ func TestApplyContainerEdits(t *testing.T) {
599599 },
600600 result : & oci.Spec {},
601601 },
602+ {
603+ name : "apply mount edits do not change the order of original mounts" ,
604+ spec : & oci.Spec {
605+ Mounts : []oci.Mount {
606+ {
607+ Source : "/some/host/path1" ,
608+ Destination : "/dest/path/b" ,
609+ },
610+ {
611+ Source : "/some/host/path2" ,
612+ Destination : "/dest/path/a" ,
613+ },
614+ },
615+ },
616+ edits : & cdi.ContainerEdits {
617+ Mounts : []* cdi.Mount {
618+ {
619+ HostPath : "/some/host/path3" ,
620+ ContainerPath : "/dest/edit" ,
621+ },
622+ },
623+ },
624+ result : & oci.Spec {
625+ Mounts : []oci.Mount {
626+ {
627+ Source : "/some/host/path3" ,
628+ Destination : "/dest/edit" ,
629+ },
630+ {
631+ Source : "/some/host/path1" ,
632+ Destination : "/dest/path/b" ,
633+ },
634+ {
635+ Source : "/some/host/path2" ,
636+ Destination : "/dest/path/a" ,
637+ },
638+ },
639+ },
640+ },
641+ {
642+ name : "mount added by edit comes after existing ones of same number of path parts" ,
643+ spec : & oci.Spec {
644+ Mounts : []oci.Mount {
645+ {
646+ Source : "/some/host/path1" ,
647+ Destination : "/dest/path/c" ,
648+ },
649+ {
650+ Source : "/some/host/path2" ,
651+ Destination : "/dest/path/b" ,
652+ },
653+ },
654+ },
655+ edits : & cdi.ContainerEdits {
656+ Mounts : []* cdi.Mount {
657+ {
658+ HostPath : "/some/host/path3" ,
659+ ContainerPath : "/dest/path/a" ,
660+ },
661+ },
662+ },
663+ result : & oci.Spec {
664+ Mounts : []oci.Mount {
665+ {
666+ Source : "/some/host/path1" ,
667+ Destination : "/dest/path/c" ,
668+ },
669+ {
670+ Source : "/some/host/path2" ,
671+ Destination : "/dest/path/b" ,
672+ },
673+ {
674+ Source : "/some/host/path3" ,
675+ Destination : "/dest/path/a" ,
676+ },
677+ },
678+ },
679+ },
602680 } {
603681 t .Run (tc .name , func (t * testing.T ) {
604682 edits := ContainerEdits {tc .edits }
0 commit comments