@@ -11,14 +11,82 @@ import (
1111
1212 "github.com/google/go-cmp/cmp"
1313
14+ corev1 "k8s.io/api/core/v1"
1415 "k8s.io/apimachinery/pkg/runtime/schema"
1516 "k8s.io/apimachinery/pkg/util/sets"
1617 "k8s.io/utils/ptr"
1718
1819 configv1 "github.com/openshift/api/config/v1"
20+ imagev1 "github.com/openshift/api/image/v1"
1921 "github.com/openshift/library-go/pkg/manifest"
2022)
2123
24+ func TestImagesFromImageRef (t * testing.T ) {
25+ tests := []struct {
26+ name string
27+ imageRef * imagev1.ImageStream
28+ expected map [string ]string
29+ }{
30+ {
31+ name : "nil ImageStream returns empty map" ,
32+ imageRef : nil ,
33+ expected : map [string ]string {},
34+ },
35+ {
36+ name : "maps DockerImage tags to their names" ,
37+ imageRef : & imagev1.ImageStream {
38+ Spec : imagev1.ImageStreamSpec {
39+ Tags : []imagev1.TagReference {
40+ {
41+ Name : "console" ,
42+ From : & corev1.ObjectReference {Kind : "DockerImage" , Name : "quay.io/openshift/console:latest" },
43+ },
44+ {
45+ Name : "cluster-update-console-plugin" ,
46+ From : & corev1.ObjectReference {Kind : "DockerImage" , Name : "quay.io/openshift/plugin:v1" },
47+ },
48+ },
49+ },
50+ },
51+ expected : map [string ]string {
52+ "console" : "quay.io/openshift/console:latest" ,
53+ "cluster-update-console-plugin" : "quay.io/openshift/plugin:v1" ,
54+ },
55+ },
56+ {
57+ name : "skips non-DockerImage tags" ,
58+ imageRef : & imagev1.ImageStream {
59+ Spec : imagev1.ImageStreamSpec {
60+ Tags : []imagev1.TagReference {
61+ {
62+ Name : "docker-tag" ,
63+ From : & corev1.ObjectReference {Kind : "DockerImage" , Name : "example.com/img:v1" },
64+ },
65+ {
66+ Name : "image-stream-tag" ,
67+ From : & corev1.ObjectReference {Kind : "ImageStreamTag" , Name : "other:latest" },
68+ },
69+ {
70+ Name : "no-from" ,
71+ },
72+ },
73+ },
74+ },
75+ expected : map [string ]string {
76+ "docker-tag" : "example.com/img:v1" ,
77+ },
78+ },
79+ }
80+ for _ , tt := range tests {
81+ t .Run (tt .name , func (t * testing.T ) {
82+ actual := imagesFromImageRef (tt .imageRef )
83+ if diff := cmp .Diff (tt .expected , actual ); diff != "" {
84+ t .Errorf ("imagesFromImageRef mismatch (-want +got):\n %s" , diff )
85+ }
86+ })
87+ }
88+ }
89+
2290func TestRenderManifest (t * testing.T ) {
2391
2492 tests := []struct {
0 commit comments