@@ -30,16 +30,32 @@ func TestImageStreamByAnnotationSearcherAndResolver(t *testing.T) {
3030 streams , images := fakeImageStreams (
3131 & fakeImageStreamDesc {
3232 name : "ruby" ,
33- supports : map [string ]string {
34- "ruby20" : "ruby:2.0,ruby:2.1,ruby" ,
35- "ruby19" : "ruby:1.9,ruby:1.9.4,ruby" ,
33+ tags : map [string ]imageapi.TagReference {
34+ "ruby20" : {
35+ Annotations : map [string ]string {
36+ "supports" : "ruby:2.0,ruby:2.1,ruby" ,
37+ },
38+ },
39+ "ruby19" : {
40+ Annotations : map [string ]string {
41+ "supports" : "ruby:1.9,ruby:1.9.4,ruby" ,
42+ },
43+ },
3644 },
3745 },
3846 & fakeImageStreamDesc {
3947 name : "wildfly" ,
40- supports : map [string ]string {
41- "v8" : "wildfly:8.0,java,jee" ,
42- "v7" : "wildfly:7.0,java" ,
48+ tags : map [string ]imageapi.TagReference {
49+ "v8" : {
50+ Annotations : map [string ]string {
51+ "supports" : "wildfly:8.0,java,jee" ,
52+ },
53+ },
54+ "v7" : {
55+ Annotations : map [string ]string {
56+ "supports" : "wildfly:7.0,java" ,
57+ },
58+ },
4359 },
4460 },
4561 )
@@ -93,17 +109,56 @@ func TestImageStreamByAnnotationSearcherAndResolver(t *testing.T) {
93109
94110func TestImageStreamSearcher (t * testing.T ) {
95111 streams , images := fakeImageStreams (
112+ & fakeImageStreamDesc {
113+ name : "nodejs1" ,
114+ tags : map [string ]imageapi.TagReference {
115+ "0.10" : {
116+ Annotations : map [string ]string {
117+ "supports" : "nodejs1:0.10,nodejs1:0.1,nodejs1" ,
118+ "tags" : "hidden" ,
119+ },
120+ },
121+ "4" : {
122+ Annotations : map [string ]string {
123+ "supports" : "nodejs1:4,nodejs1" ,
124+ },
125+ },
126+ },
127+ },
128+ & fakeImageStreamDesc {
129+ name : "nodejs2" ,
130+ tags : map [string ]imageapi.TagReference {
131+ "0.10" : {
132+ Annotations : map [string ]string {
133+ "supports" : "nodejs2:0.10,nodejs2:0.1,nodejs2" ,
134+ "tags" : "hidden" ,
135+ },
136+ },
137+ },
138+ },
96139 & fakeImageStreamDesc {
97140 name : "ruby20" ,
98- supports : map [string ]string {
99- "stable" : "ruby:1.9,ruby:1.9.4" ,
141+ tags : map [string ]imageapi.TagReference {
142+ "stable" : {
143+ Annotations : map [string ]string {
144+ "supports" : "ruby:1.9,ruby:1.9.4" ,
145+ },
146+ },
100147 },
101148 },
102149 & fakeImageStreamDesc {
103150 name : "wildfly" ,
104- supports : map [string ]string {
105- "v8" : "java,jee" ,
106- "v7" : "java" ,
151+ tags : map [string ]imageapi.TagReference {
152+ "v8" : {
153+ Annotations : map [string ]string {
154+ "supports" : "java,jee" ,
155+ },
156+ },
157+ "v7" : {
158+ Annotations : map [string ]string {
159+ "supports" : "java" ,
160+ },
161+ },
107162 },
108163 latest : "v8" ,
109164 },
@@ -130,6 +185,15 @@ func TestImageStreamSearcher(t *testing.T) {
130185 expectMatch : true ,
131186 expectTag : "v8" ,
132187 },
188+ {
189+ value : "nodejs1" ,
190+ expectMatch : true ,
191+ expectTag : "4" ,
192+ },
193+ {
194+ value : "nodejs2" ,
195+ expectMatch : false ,
196+ },
133197 }
134198
135199 for _ , test := range tests {
@@ -138,15 +202,15 @@ func TestImageStreamSearcher(t *testing.T) {
138202 t .Errorf ("Expected a search match for %s. Got none: %v" , test .value , errs )
139203 }
140204 if len (searchResults ) == 1 && ! test .expectMatch {
141- t .Errorf ("Did not expect search a match for %s. Got a match: %#v" , test .value , searchResults [0 ])
205+ t .Errorf ("Did not expect a search match for %s. Got a match: %#v" , test .value , searchResults [0 ])
142206 }
143207
144208 result , err := resolver .Resolve (test .value )
145209 if err != nil && test .expectMatch {
146210 t .Errorf ("Expected a resolve match for %s. Got none: %v" , test .value , err )
147211 }
148212 if err == nil && ! test .expectMatch {
149- t .Errorf ("Did not expect resolve a match for %s. Got a match: %v" , test .value , err )
213+ t .Errorf ("Did not expect a resolve match for %s. Got a match: %# v" , test .value , result )
150214 }
151215 if err != nil {
152216 continue
@@ -218,11 +282,26 @@ func TestMatchSupportsAnnotation(t *testing.T) {
218282}
219283
220284func TestAnnotationMatches (t * testing.T ) {
221- stream , images := fakeImageStream ("builder" , map [string ]string {
222- "ruby" : "ruby,ruby:2.0,ruby:1.9" ,
223- "java" : "java,jee,wildfly" ,
224- "wildfly" : "wildfly:8.0" ,
225- }, "" )
285+ stream , images := fakeImageStream (& fakeImageStreamDesc {
286+ name : "builder" ,
287+ tags : map [string ]imageapi.TagReference {
288+ "ruby" : {
289+ Annotations : map [string ]string {
290+ "supports" : "ruby,ruby:2.0,ruby:1.9" ,
291+ },
292+ },
293+ "java" : {
294+ Annotations : map [string ]string {
295+ "supports" : "java,jee,wildfly" ,
296+ },
297+ },
298+ "wildfly" : {
299+ Annotations : map [string ]string {
300+ "supports" : "wildfly:8.0" ,
301+ },
302+ },
303+ },
304+ latest : "" })
226305 client := testImageStreamClient (nil , images )
227306 searcher := NewImageStreamByAnnotationSearcher (client , client , []string {"default" }).(* ImageStreamByAnnotationSearcher )
228307 tests := []struct {
@@ -279,9 +358,9 @@ func TestAnnotationMatches(t *testing.T) {
279358}
280359
281360type fakeImageStreamDesc struct {
282- name string
283- supports map [string ]string
284- latest string
361+ name string
362+ tags map [string ]imageapi. TagReference
363+ latest string
285364}
286365
287366func fakeImageStreams (descs ... * fakeImageStreamDesc ) (* imageapi.ImageStreamList , map [string ]* imageapi.ImageStreamImage ) {
@@ -290,7 +369,7 @@ func fakeImageStreams(descs ...*fakeImageStreamDesc) (*imageapi.ImageStreamList,
290369 }
291370 allImages := map [string ]* imageapi.ImageStreamImage {}
292371 for _ , desc := range descs {
293- stream , images := fakeImageStream (desc . name , desc . supports , desc . latest )
372+ stream , images := fakeImageStream (desc )
294373 streams .Items = append (streams .Items , * stream )
295374 for k , v := range images {
296375 allImages [k ] = v
@@ -299,10 +378,11 @@ func fakeImageStreams(descs ...*fakeImageStreamDesc) (*imageapi.ImageStreamList,
299378 return streams , allImages
300379}
301380
302- func fakeImageStream (name string , supports map [ string ] string , latest string ) (* imageapi.ImageStream , map [string ]* imageapi.ImageStreamImage ) {
381+ func fakeImageStream (desc * fakeImageStreamDesc ) (* imageapi.ImageStream , map [string ]* imageapi.ImageStreamImage ) {
303382 stream := & imageapi.ImageStream {
304383 ObjectMeta : kapi.ObjectMeta {
305- Name : name ,
384+ Name : desc .name ,
385+ Namespace : "namespace" ,
306386 },
307387 Spec : imageapi.ImageStreamSpec {
308388 Tags : map [string ]imageapi.TagReference {},
@@ -312,31 +392,28 @@ func fakeImageStream(name string, supports map[string]string, latest string) (*i
312392 },
313393 }
314394 images := map [string ]* imageapi.ImageStreamImage {}
315- for tag , value := range supports {
316- stream .Spec .Tags [tag ] = imageapi.TagReference {
317- Annotations : map [string ]string {
318- "supports" : value ,
319- },
320- }
395+ for tag , value := range desc .tags {
396+ stream .Spec .Tags [tag ] = value
321397 stream .Status .Tags [tag ] = imageapi.TagEventList {
322398 Items : []imageapi.TagEvent {
323399 {
324400 Image : tag + "-image" ,
325401 },
326402 },
327403 }
328- images [name + "@" + tag + "-image" ] = & imageapi.ImageStreamImage {
404+ images [desc . name + "@" + tag + "-image" ] = & imageapi.ImageStreamImage {
329405 Image : imageapi.Image {
330406 DockerImageReference : "example/" + tag ,
331407 DockerImageMetadata : imageapi.DockerImage {ID : tag },
332408 },
333409 }
334410 }
335- if len (latest ) > 0 {
411+ if len (desc . latest ) > 0 {
336412 stream .Spec .Tags ["latest" ] = imageapi.TagReference {
337413 From : & kapi.ObjectReference {
338- Kind : "ImageStreamTag" ,
339- Name : latest ,
414+ Kind : "ImageStreamTag" ,
415+ Name : desc .latest ,
416+ Namespace : "namespace" ,
340417 },
341418 }
342419 }
0 commit comments