@@ -977,6 +977,45 @@ func TestCriteriaGetWithComponentName(t *testing.T) {
977977 componentName : "my-component" ,
978978 expected : []string {"test.image_check" , "test.component_check" , "*" },
979979 },
980+ {
981+ name : "Multi-arch expanded component matches original component name" ,
982+ criteria : & Criteria {
983+ digestItems : map [string ][]string {},
984+ componentItems : map [string ][]string {
985+ "my-component" : {"test.component_check" },
986+ },
987+ defaultItems : []string {"*" },
988+ },
989+ imageRef : "quay.io/repo/img@sha256:1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef" ,
990+ componentName : "my-component-sha256:abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890-arm64" ,
991+ expected : []string {"test.component_check" , "*" },
992+ },
993+ {
994+ name : "Multi-arch expanded component with noarch suffix" ,
995+ criteria : & Criteria {
996+ digestItems : map [string ][]string {},
997+ componentItems : map [string ][]string {
998+ "my-component" : {"test.component_check" },
999+ },
1000+ defaultItems : []string {"*" },
1001+ },
1002+ imageRef : "quay.io/repo/img@sha256:1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef" ,
1003+ componentName : "my-component-sha256:abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890-noarch-2" ,
1004+ expected : []string {"test.component_check" , "*" },
1005+ },
1006+ {
1007+ name : "Similar component name not incorrectly matched" ,
1008+ criteria : & Criteria {
1009+ digestItems : map [string ][]string {},
1010+ componentItems : map [string ][]string {
1011+ "my-component" : {"test.component_check" },
1012+ },
1013+ defaultItems : []string {"*" },
1014+ },
1015+ imageRef : "quay.io/repo/img@sha256:1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef" ,
1016+ componentName : "my-component-libs" ,
1017+ expected : []string {"*" },
1018+ },
9801019 }
9811020
9821021 for _ , tt := range tests {
@@ -986,3 +1025,53 @@ func TestCriteriaGetWithComponentName(t *testing.T) {
9861025 })
9871026 }
9881027}
1028+
1029+ func TestOriginalComponentName (t * testing.T ) {
1030+ tests := []struct {
1031+ name string
1032+ input string
1033+ expected string
1034+ }{
1035+ {
1036+ name : "plain component name unchanged" ,
1037+ input : "my-component" ,
1038+ expected : "my-component" ,
1039+ },
1040+ {
1041+ name : "multi-arch arm64 suffix stripped" ,
1042+ input : "my-component-sha256:abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890-arm64" ,
1043+ expected : "my-component" ,
1044+ },
1045+ {
1046+ name : "multi-arch amd64 suffix stripped" ,
1047+ input : "my-component-sha256:abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890-amd64" ,
1048+ expected : "my-component" ,
1049+ },
1050+ {
1051+ name : "multi-arch noarch suffix stripped" ,
1052+ input : "my-component-sha256:abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890-noarch-2" ,
1053+ expected : "my-component" ,
1054+ },
1055+ {
1056+ name : "similar name without digest not stripped" ,
1057+ input : "my-component-libs" ,
1058+ expected : "my-component-libs" ,
1059+ },
1060+ {
1061+ name : "similar name with sha prefix but no digest not stripped" ,
1062+ input : "my-component-sha256" ,
1063+ expected : "my-component-sha256" ,
1064+ },
1065+ {
1066+ name : "empty string unchanged" ,
1067+ input : "" ,
1068+ expected : "" ,
1069+ },
1070+ }
1071+
1072+ for _ , tt := range tests {
1073+ t .Run (tt .name , func (t * testing.T ) {
1074+ require .Equal (t , tt .expected , originalComponentName (tt .input ))
1075+ })
1076+ }
1077+ }
0 commit comments