1
1
package integration
2
2
3
3
import (
4
+ "encoding/json"
4
5
"os"
5
6
"reflect"
6
7
"testing"
@@ -11,6 +12,7 @@ import (
11
12
12
13
deployapi "github.com/openshift/origin/pkg/deploy/api"
13
14
stratsupport "github.com/openshift/origin/pkg/deploy/strategy/support"
15
+ imagetest "github.com/openshift/origin/pkg/image/admission/testutil"
14
16
imageapi "github.com/openshift/origin/pkg/image/api"
15
17
testutil "github.com/openshift/origin/test/util"
16
18
testserver "github.com/openshift/origin/test/util/server"
@@ -282,6 +284,104 @@ func TestImageStreamMappingCreate(t *testing.T) {
282
284
}
283
285
}
284
286
287
+ func TestImageStreamWithoutDockerImageConfig (t * testing.T ) {
288
+ testutil .RequireEtcd (t )
289
+ defer testutil .DumpEtcdOnFailure (t )
290
+ _ , clusterAdminKubeConfig , err := testserver .StartTestMasterAPI ()
291
+ if err != nil {
292
+ t .Fatalf ("unexpected error: %v" , err )
293
+ }
294
+
295
+ clusterAdminClient , err := testutil .GetClusterAdminClient (clusterAdminKubeConfig )
296
+ if err != nil {
297
+ t .Errorf ("unexpected error: %v" , err )
298
+ }
299
+ err = testutil .CreateNamespace (clusterAdminKubeConfig , testutil .Namespace ())
300
+ if err != nil {
301
+ t .Errorf ("unexpected error: %v" , err )
302
+ }
303
+
304
+ stream := mockImageStream ()
305
+
306
+ expected , err := clusterAdminClient .ImageStreams (testutil .Namespace ()).Create (stream )
307
+ if err != nil {
308
+ t .Fatalf ("Unexpected error: %v" , err )
309
+ }
310
+ if expected .Name == "" {
311
+ t .Errorf ("Unexpected empty image Name %v" , expected )
312
+ }
313
+
314
+ imageConfig := imageapi.DockerConfig {
315
+ Hostname : "example.com" ,
316
+ Env : []string {"A=B" },
317
+ }
318
+
319
+ imageConfigBytes , err := json .Marshal (imageConfig )
320
+ if err != nil {
321
+ t .Fatalf ("error marshaling image config: %s" , err )
322
+ }
323
+
324
+ image := imageapi.Image {
325
+ ObjectMeta : kapi.ObjectMeta {
326
+ Name : imagetest .BaseImageWith1LayerDigest ,
327
+ },
328
+ DockerImageMetadata : imageapi.DockerImage {
329
+ Config : & imageapi.DockerConfig {
330
+ Hostname : "example.com" ,
331
+ Env : []string {"A=B" },
332
+ },
333
+ },
334
+ DockerImageConfig : string (imageConfigBytes ),
335
+ DockerImageReference : "some/namespace/name" ,
336
+ }
337
+
338
+ // create a mapping to an image that doesn't exist
339
+ mapping := & imageapi.ImageStreamMapping {
340
+ ObjectMeta : kapi.ObjectMeta {
341
+ Name : stream .Name ,
342
+ },
343
+ Tag : "newer" ,
344
+ Image : image ,
345
+ }
346
+ if err := clusterAdminClient .ImageStreamMappings (testutil .Namespace ()).Create (mapping ); err != nil {
347
+ t .Fatalf ("unexpected error: %v" , err )
348
+ }
349
+
350
+ img , err := clusterAdminClient .Images ().Get (image .Name )
351
+ if err != nil {
352
+ t .Fatalf ("unexpected error: %v" , err )
353
+ }
354
+ if img .Name != image .Name {
355
+ t .Fatalf ("unexpected image: %#v" , img )
356
+ }
357
+ if len (img .DockerImageConfig ) == 0 {
358
+ t .Fatalf ("image has an empty config: %#v" , img )
359
+ }
360
+
361
+ ist , err := clusterAdminClient .ImageStreamTags (testutil .Namespace ()).Get (stream .Name , "newer" )
362
+ if err != nil {
363
+ t .Fatalf ("Unexpected error: %v" , err )
364
+ }
365
+ if ist .Image .Name != image .Name {
366
+ t .Fatalf ("unexpected image: %#v" , img )
367
+ }
368
+ if len (ist .Image .DockerImageConfig ) != 0 {
369
+ t .Errorf ("image has a not empty config: %#v" , ist )
370
+ }
371
+
372
+ isi , err := clusterAdminClient .ImageStreamImages (testutil .Namespace ()).Get (stream .Name , imagetest .BaseImageWith1LayerDigest )
373
+ if err != nil {
374
+ t .Fatalf ("Unexpected error: %v" , err )
375
+ }
376
+ if isi .Image .Name != image .Name {
377
+ t .Fatalf ("unexpected image: %#v" , img )
378
+ }
379
+ if len (isi .Image .DockerImageConfig ) != 0 {
380
+ t .Errorf ("image has a not empty config: %#v" , isi )
381
+ }
382
+
383
+ }
384
+
285
385
func TestImageStreamTagLifecycleHook (t * testing.T ) {
286
386
testutil .RequireEtcd (t )
287
387
defer testutil .DumpEtcdOnFailure (t )
0 commit comments