@@ -673,6 +673,33 @@ func TestExtendedCopyGraph_FilterAnnotationWithRegex(t *testing.T) {
673
673
copiedIndice := []int {0 , 2 , 3 }
674
674
uncopiedIndice := []int {1 , 4 , 5 }
675
675
verifyCopy (dst , copiedIndice , uncopiedIndice )
676
+
677
+ // test FilterAnnotation with key unavailable in predecessors' annotation
678
+ // should return nothing
679
+ dst = memory .New ()
680
+ opts = oras.ExtendedCopyGraphOptions {}
681
+ exp = "black."
682
+ regex = regexp .MustCompile (exp )
683
+ opts .FilterAnnotation ("bar1" , regex )
684
+
685
+ if err := oras .ExtendedCopyGraph (ctx , src , dst , descs [0 ], opts ); err != nil {
686
+ t .Fatalf ("ExtendedCopyGraph() error = %v, wantErr %v" , err , false )
687
+ }
688
+ copiedIndice = []int {0 }
689
+ uncopiedIndice = []int {1 , 2 , 3 , 4 , 5 }
690
+ verifyCopy (dst , copiedIndice , uncopiedIndice )
691
+
692
+ //test FilterAnnotation with key available in predecessors' annotation, regex equal to nil
693
+ //should return all predecessors with the provided key
694
+ dst = memory .New ()
695
+ opts = oras.ExtendedCopyGraphOptions {}
696
+ opts .FilterAnnotation ("bar" , nil )
697
+ if err := oras .ExtendedCopyGraph (ctx , src , dst , descs [0 ], opts ); err != nil {
698
+ t .Fatalf ("ExtendedCopyGraph() error = %v, wantErr %v" , err , false )
699
+ }
700
+ copiedIndice = []int {0 , 1 , 2 , 3 , 4 , 5 }
701
+ uncopiedIndice = []int {}
702
+ verifyCopy (dst , copiedIndice , uncopiedIndice )
676
703
}
677
704
678
705
func TestExtendedCopyGraph_FilterAnnotationWithMultipleRegex (t * testing.T ) {
@@ -746,6 +773,39 @@ func TestExtendedCopyGraph_FilterAnnotationWithMultipleRegex(t *testing.T) {
746
773
copiedIndice := []int {0 , 2 }
747
774
uncopiedIndice := []int {1 , 3 , 4 , 5 , 6 }
748
775
verifyCopy (dst , copiedIndice , uncopiedIndice )
776
+
777
+ // test extended copy by descs[0] with three annotation filters, nil included
778
+ dst = memory .New ()
779
+ opts = oras.ExtendedCopyGraphOptions {}
780
+ exp1 = "black."
781
+ exp2 = ".pink|red"
782
+ regex1 = regexp .MustCompile (exp1 )
783
+ regex2 = regexp .MustCompile (exp2 )
784
+ opts .FilterAnnotation ("bar" , regex1 )
785
+ opts .FilterAnnotation ("bar" , nil )
786
+ opts .FilterAnnotation ("bar" , regex2 )
787
+ if err := oras .ExtendedCopyGraph (ctx , src , dst , descs [0 ], opts ); err != nil {
788
+ t .Fatalf ("ExtendedCopyGraph() error = %v, wantErr %v" , err , false )
789
+ }
790
+ copiedIndice = []int {0 , 2 }
791
+ uncopiedIndice = []int {1 , 3 , 4 , 5 , 6 }
792
+ verifyCopy (dst , copiedIndice , uncopiedIndice )
793
+
794
+ // test extended copy by descs[0] with two annotation filters, the second filter has an unavailable key
795
+ dst = memory .New ()
796
+ opts = oras.ExtendedCopyGraphOptions {}
797
+ exp1 = "black."
798
+ exp2 = ".pink|red"
799
+ regex1 = regexp .MustCompile (exp1 )
800
+ regex2 = regexp .MustCompile (exp2 )
801
+ opts .FilterAnnotation ("bar" , regex1 )
802
+ opts .FilterAnnotation ("test" , regex2 )
803
+ if err := oras .ExtendedCopyGraph (ctx , src , dst , descs [0 ], opts ); err != nil {
804
+ t .Fatalf ("ExtendedCopyGraph() error = %v, wantErr %v" , err , false )
805
+ }
806
+ copiedIndice = []int {0 }
807
+ uncopiedIndice = []int {1 , 2 , 3 , 4 , 5 , 6 }
808
+ verifyCopy (dst , copiedIndice , uncopiedIndice )
749
809
}
750
810
751
811
func TestExtendedCopyGraph_FilterAnnotationWithRegexNoAnnotationInDescriptor (t * testing.T ) {
@@ -887,6 +947,14 @@ func TestExtendedCopyGraph_FilterArtifactTypeWithRegex(t *testing.T) {
887
947
copiedIndice := []int {0 , 1 , 3 , 4 }
888
948
uncopiedIndice := []int {2 , 5 }
889
949
verifyCopy (dst , copiedIndice , uncopiedIndice )
950
+
951
+ // test extended copy by descs[0] with no regex
952
+ // type matches exp.
953
+ opts = oras.ExtendedCopyGraphOptions {}
954
+ opts .FilterArtifactType (nil )
955
+ if opts .FindPredecessors != nil {
956
+ t .Fatal ("FindPredecessors not nil!" )
957
+ }
890
958
}
891
959
892
960
func TestExtendedCopyGraph_FilterArtifactTypeWithMultipleRegex (t * testing.T ) {
@@ -962,6 +1030,24 @@ func TestExtendedCopyGraph_FilterArtifactTypeWithMultipleRegex(t *testing.T) {
962
1030
copiedIndice := []int {0 , 3 , 4 }
963
1031
uncopiedIndice := []int {1 , 2 , 5 }
964
1032
verifyCopy (dst , copiedIndice , uncopiedIndice )
1033
+
1034
+ // test extended copy by descs[0], include the predecessors whose artifact
1035
+ // type matches exp1 and exp2 and nil
1036
+ exp1 = ".foo|bar."
1037
+ exp2 = "bad."
1038
+ dst = memory .New ()
1039
+ opts = oras.ExtendedCopyGraphOptions {}
1040
+ regex1 = regexp .MustCompile (exp1 )
1041
+ regex2 = regexp .MustCompile (exp2 )
1042
+ opts .FilterArtifactType (regex1 )
1043
+ opts .FilterArtifactType (regex2 )
1044
+ opts .FilterArtifactType (nil )
1045
+ if err := oras .ExtendedCopyGraph (ctx , src , dst , descs [0 ], opts ); err != nil {
1046
+ t .Errorf ("ExtendedCopyGraph() error = %v, wantErr %v" , err , false )
1047
+ }
1048
+ copiedIndice = []int {0 , 3 , 4 }
1049
+ uncopiedIndice = []int {1 , 2 , 5 }
1050
+ verifyCopy (dst , copiedIndice , uncopiedIndice )
965
1051
}
966
1052
967
1053
func TestExtendedCopyGraph_FilterArtifactTypeByReferrersWithMultipleRegex (t * testing.T ) {
0 commit comments