@@ -58,110 +58,145 @@ func testData() []*imageapi.ImageStream {
58
58
},
59
59
},
60
60
},
61
+ {
62
+ ObjectMeta : api.ObjectMeta {Name : "django" , Namespace : "yourproject" , ResourceVersion : "11" , CreationTimestamp : unversioned .Now ()},
63
+ Spec : imageapi.ImageStreamSpec {
64
+ DockerImageRepository : "" ,
65
+ Tags : map [string ]imageapi.TagReference {
66
+ "tip" : {
67
+ From : & api.ObjectReference {
68
+ Name : "python" ,
69
+ Namespace : "openshift" ,
70
+ Kind : "ImageStreamTag" ,
71
+ },
72
+ },
73
+ },
74
+ },
75
+ },
61
76
}
62
77
}
63
78
64
- func TestRunTag_AddAccrossNamespaces (t * testing.T ) {
79
+ func TestTag (t * testing.T ) {
65
80
streams := testData ()
66
- client := testclient .NewSimpleFake (streams [2 ], streams [0 ])
67
- client .PrependReactor ("create" , "imagestreamtags" , func (action core.Action ) (handled bool , ret runtime.Object , err error ) {
68
- return true , nil , kapierrors .NewMethodNotSupported (imageapi .Resource ("imagestreamtags" ), "create" )
69
- })
70
- client .PrependReactor ("update" , "imagestreamtags" , func (action core.Action ) (handled bool , ret runtime.Object , err error ) {
71
- return true , nil , kapierrors .NewMethodNotSupported (imageapi .Resource ("imagestreamtags" ), "update" )
72
- })
73
81
74
- test := struct {
82
+ testCases := map [string ]struct {
83
+ data []runtime.Object
75
84
opts * TagOptions
76
85
expectedActions []testAction
77
- expectedErr error
86
+ validateErr string
87
+ runErr string
78
88
}{
79
- opts : & TagOptions {
80
- out : os .Stdout ,
81
- osClient : client ,
82
- ref : imageapi.DockerImageReference {
83
- Namespace : "openshift" ,
84
- Name : "ruby" ,
85
- Tag : "latest" ,
89
+ "tag across namespaces" : {
90
+ data : []runtime.Object {streams [2 ], streams [0 ]},
91
+ opts : & TagOptions {
92
+ ref : imageapi.DockerImageReference {
93
+ Namespace : "openshift" ,
94
+ Name : "ruby" ,
95
+ Tag : "latest" ,
96
+ },
97
+ referencePolicy : sourceReferencePolicy ,
98
+ namespace : "myproject2" ,
99
+ sourceKind : "ImageStreamTag" ,
100
+ destNamespace : []string {"yourproject" },
101
+ destNameAndTag : []string {"rails:tip" },
102
+ },
103
+ expectedActions : []testAction {
104
+ {verb : "update" , resource : "imagestreamtags" },
105
+ {verb : "create" , resource : "imagestreamtags" },
106
+ {verb : "get" , resource : "imagestreams" },
107
+ {verb : "update" , resource : "imagestreams" },
86
108
},
87
- namespace : "myproject2" ,
88
- sourceKind : "ImageStreamTag" ,
89
- destNamespace : []string {"yourproject" },
90
- destNameAndTag : []string {"rails:tip" },
91
109
},
92
- expectedActions : []testAction {
93
- {verb : "update" , resource : "imagestreamtags" },
94
- {verb : "create" , resource : "imagestreamtags" },
95
- {verb : "get" , resource : "imagestreams" },
96
- {verb : "update" , resource : "imagestreams" },
110
+ "alias tag across namespaces" : {
111
+ data : []runtime.Object {streams [2 ], streams [0 ]},
112
+ opts : & TagOptions {
113
+ ref : imageapi.DockerImageReference {
114
+ Namespace : "openshift" ,
115
+ Name : "ruby" ,
116
+ Tag : "latest" ,
117
+ },
118
+ aliasTag : true ,
119
+ referencePolicy : sourceReferencePolicy ,
120
+ namespace : "myproject2" ,
121
+ sourceKind : "ImageStreamTag" ,
122
+ destNamespace : []string {"yourproject" },
123
+ destNameAndTag : []string {"rails:tip" },
124
+ },
125
+ validateErr : "cannot set alias across different Image Streams" ,
97
126
},
98
- expectedErr : nil ,
99
- }
100
-
101
- if err := test .opts .RunTag (); err != test .expectedErr {
102
- t .Fatalf ("error mismatch: expected %v, got %v" , test .expectedErr , err )
103
- }
104
-
105
- got := client .Actions ()
106
- if len (test .expectedActions ) != len (got ) {
107
- t .Fatalf ("action length mismatch: expectedc %d, got %d" , len (test .expectedActions ), len (got ))
108
- }
109
-
110
- for i , action := range test .expectedActions {
111
- if ! got [i ].Matches (action .verb , action .resource ) {
112
- t .Errorf ("action mismatch: expected %s %s, got %s %s" , action .verb , action .resource , got [i ].GetVerb (), got [i ].GetResource ())
113
- }
114
- }
115
- }
116
-
117
- func TestRunTag_AddOld (t * testing.T ) {
118
- streams := testData ()
119
- client := testclient .NewSimpleFake (streams [0 ])
120
- client .PrependReactor ("create" , "imagestreamtags" , func (action core.Action ) (handled bool , ret runtime.Object , err error ) {
121
- return true , nil , kapierrors .NewMethodNotSupported (imageapi .Resource ("imagestreamtags" ), "create" )
122
- })
123
- client .PrependReactor ("update" , "imagestreamtags" , func (action core.Action ) (handled bool , ret runtime.Object , err error ) {
124
- return true , nil , kapierrors .NewMethodNotSupported (imageapi .Resource ("imagestreamtags" ), "update" )
125
- })
126
-
127
- test := struct {
128
- opts * TagOptions
129
- expectedActions []testAction
130
- expectedErr error
131
- }{
132
- opts : & TagOptions {
133
- out : os .Stdout ,
134
- osClient : client ,
135
- ref : imageapi.DockerImageReference {
136
- Namespace : "openshift" ,
137
- Name : "ruby" ,
138
- Tag : "2.0" ,
127
+ "alias tag across image streams" : {
128
+ data : []runtime.Object {streams [3 ], streams [0 ]},
129
+ opts : & TagOptions {
130
+ ref : imageapi.DockerImageReference {
131
+ Namespace : "yourproject" ,
132
+ Name : "rails" ,
133
+ Tag : "latest" ,
134
+ },
135
+ aliasTag : true ,
136
+ referencePolicy : sourceReferencePolicy ,
137
+ namespace : "myproject2" ,
138
+ sourceKind : "ImageStreamTag" ,
139
+ destNamespace : []string {"yourproject" },
140
+ destNameAndTag : []string {"python:alias" },
139
141
},
140
- sourceKind : "ImageStreamTag" ,
141
- destNamespace : []string {"yourproject" },
142
- destNameAndTag : []string {"rails:tip" },
142
+ validateErr : "cannot set alias across different Image Streams" ,
143
143
},
144
- expectedActions : []testAction {
145
- {verb : "update" , resource : "imagestreamtags" },
146
- {verb : "create" , resource : "imagestreamtags" },
147
- {verb : "get" , resource : "imagestreams" },
148
- {verb : "update" , resource : "imagestreams" },
144
+ "add old" : {
145
+ data : []runtime.Object {streams [0 ]},
146
+ opts : & TagOptions {
147
+ ref : imageapi.DockerImageReference {
148
+ Namespace : "openshift" ,
149
+ Name : "ruby" ,
150
+ Tag : "2.0" ,
151
+ },
152
+ referencePolicy : sourceReferencePolicy ,
153
+ sourceKind : "ImageStreamTag" ,
154
+ destNamespace : []string {"yourproject" },
155
+ destNameAndTag : []string {"rails:tip" },
156
+ },
157
+ expectedActions : []testAction {
158
+ {verb : "update" , resource : "imagestreamtags" },
159
+ {verb : "create" , resource : "imagestreamtags" },
160
+ {verb : "get" , resource : "imagestreams" },
161
+ {verb : "update" , resource : "imagestreams" },
162
+ },
149
163
},
150
- expectedErr : nil ,
151
164
}
152
165
153
- if err := test .opts .RunTag (); err != test .expectedErr {
154
- t .Fatalf ("error mismatch: expected %v, got %v" , test .expectedErr , err )
155
- }
166
+ for name , test := range testCases {
167
+ client := testclient .NewSimpleFake (test .data ... )
168
+ client .PrependReactor ("create" , "imagestreamtags" , func (action core.Action ) (handled bool , ret runtime.Object , err error ) {
169
+ return true , nil , kapierrors .NewMethodNotSupported (imageapi .Resource ("imagestreamtags" ), "create" )
170
+ })
171
+ client .PrependReactor ("update" , "imagestreamtags" , func (action core.Action ) (handled bool , ret runtime.Object , err error ) {
172
+ return true , nil , kapierrors .NewMethodNotSupported (imageapi .Resource ("imagestreamtags" ), "update" )
173
+ })
174
+
175
+ test .opts .out = os .Stdout
176
+ test .opts .osClient = client
177
+
178
+ err := test .opts .Validate ()
179
+ if (err == nil && len (test .validateErr ) != 0 ) || (err != nil && err .Error () != test .validateErr ) {
180
+ t .Errorf ("%s: validation error mismatch: expected %v, got %v" , name , test .validateErr , err )
181
+ }
182
+ if err != nil {
183
+ continue
184
+ }
156
185
157
- got := client . Actions ()
158
- if len (test .expectedActions ) != len ( got ) {
159
- t . Fatalf ( "action length mismatch: expectedc %d , got %d " , len ( test .expectedActions ), len ( got ) )
160
- }
186
+ err = test . opts . Run ()
187
+ if ( err == nil && len (test .runErr ) != 0 ) || ( err != nil && err . Error () != test . runErr ) {
188
+ t . Errorf ( "%s: run error mismatch: expected %v , got %v " , name , test .runErr , err )
189
+ }
161
190
162
- for i , action := range test .expectedActions {
163
- if ! got [i ].Matches (action .verb , action .resource ) {
164
- t .Errorf ("action mismatch: expected %s %s, got %s %s" , action .verb , action .resource , got [i ].GetVerb (), got [i ].GetResource ())
191
+ got := client .Actions ()
192
+ if len (test .expectedActions ) != len (got ) {
193
+ t .Fatalf ("%s: action length mismatch: expected %d, got %d" , name , len (test .expectedActions ), len (got ))
194
+ }
195
+ for i , action := range test .expectedActions {
196
+ if ! got [i ].Matches (action .verb , action .resource ) {
197
+ t .Errorf ("%s: [%o] action mismatch: expected %s %s, got %s %s" ,
198
+ name , i , action .verb , action .resource , got [i ].GetVerb (), got [i ].GetResource ())
199
+ }
165
200
}
166
201
}
167
202
}
@@ -199,7 +234,7 @@ func TestRunTag_DeleteOld(t *testing.T) {
199
234
expectedErr : nil ,
200
235
}
201
236
202
- if err := test .opts .RunTag (); err != test .expectedErr {
237
+ if err := test .opts .Run (); err != test .expectedErr {
203
238
t .Fatalf ("error mismatch: expected %v, got %v" , test .expectedErr , err )
204
239
}
205
240
@@ -245,7 +280,7 @@ func TestRunTag_AddNew(t *testing.T) {
245
280
expectedErr : nil ,
246
281
}
247
282
248
- if err := test .opts .RunTag (); err != test .expectedErr {
283
+ if err := test .opts .Run (); err != test .expectedErr {
249
284
t .Fatalf ("error mismatch: expected %v, got %v" , test .expectedErr , err )
250
285
}
251
286
@@ -294,7 +329,7 @@ func TestRunTag_AddRestricted(t *testing.T) {
294
329
expectedErr : nil ,
295
330
}
296
331
297
- if err := test .opts .RunTag (); err != test .expectedErr {
332
+ if err := test .opts .Run (); err != test .expectedErr {
298
333
t .Fatalf ("error mismatch: expected %v, got %v" , test .expectedErr , err )
299
334
}
300
335
@@ -334,7 +369,7 @@ func TestRunTag_DeleteNew(t *testing.T) {
334
369
expectedErr : nil ,
335
370
}
336
371
337
- if err := test .opts .RunTag (); err != test .expectedErr {
372
+ if err := test .opts .Run (); err != test .expectedErr {
338
373
t .Fatalf ("error mismatch: expected %v, got %v" , test .expectedErr , err )
339
374
}
340
375
0 commit comments