@@ -466,3 +466,87 @@ func TestDeleteImageStreamTag(t *testing.T) {
466
466
}()
467
467
}
468
468
}
469
+
470
+ func TestCreateImageStreamTag (t * testing.T ) {
471
+ tests := map [string ]struct {
472
+ istag runtime.Object
473
+ expectError bool
474
+ errorTargetKind string
475
+ errorTargetID string
476
+ }{
477
+ "valid istag" : {
478
+ istag : & imageapi.ImageStreamTag {
479
+ ObjectMeta : metav1.ObjectMeta {
480
+ Namespace : "default" ,
481
+ Name : "test:tag" ,
482
+ },
483
+ Image : imageapi.Image {ObjectMeta : metav1.ObjectMeta {Name : "10" }, DockerImageReference : "foo/bar/baz" },
484
+ Tag : & imageapi.TagReference {
485
+ Name : "latest" ,
486
+ From : & kapi.ObjectReference {Kind : "DockerImage" , Name : "foo/bar/baz" },
487
+ ReferencePolicy : imageapi.TagReferencePolicy {Type : imageapi .SourceTagReferencePolicy },
488
+ },
489
+ },
490
+ },
491
+ "invalid tag" : {
492
+ istag : & imageapi.ImageStreamTag {
493
+ ObjectMeta : metav1.ObjectMeta {
494
+ Namespace : "default" ,
495
+ Name : "test:tag" ,
496
+ },
497
+ Image : imageapi.Image {ObjectMeta : metav1.ObjectMeta {Name : "10" }, DockerImageReference : "foo/bar/baz" },
498
+ Tag : & imageapi.TagReference {},
499
+ },
500
+ expectError : true ,
501
+ errorTargetKind : "ImageStreamTag" ,
502
+ errorTargetID : "test:tag" ,
503
+ },
504
+ "nil tag" : {
505
+ istag : & imageapi.ImageStreamTag {
506
+ ObjectMeta : metav1.ObjectMeta {
507
+ Namespace : "default" ,
508
+ Name : "test:tag" ,
509
+ },
510
+ Image : imageapi.Image {ObjectMeta : metav1.ObjectMeta {Name : "10" }, DockerImageReference : "foo/bar/baz" },
511
+ },
512
+ },
513
+ }
514
+
515
+ for name , tc := range tests {
516
+ func () {
517
+ client , server , storage := setup (t )
518
+ defer server .Terminate (t )
519
+
520
+ client .Put (
521
+ context .TODO (),
522
+ etcdtest .AddPrefix ("/imagestreams/default/test" ),
523
+ runtime .EncodeOrDie (kapi .Codecs .LegacyCodec (v1 .SchemeGroupVersion ),
524
+ & imageapi.ImageStream {
525
+ ObjectMeta : metav1.ObjectMeta {
526
+ CreationTimestamp : metav1 .Date (2015 , 3 , 24 , 9 , 38 , 0 , 0 , time .UTC ),
527
+ Namespace : "default" ,
528
+ Name : "test" ,
529
+ },
530
+ Spec : imageapi.ImageStreamSpec {
531
+ Tags : map [string ]imageapi.TagReference {},
532
+ },
533
+ },
534
+ ))
535
+
536
+ ctx := apirequest .WithUser (apirequest .NewDefaultContext (), & fakeUser {})
537
+ _ , err := storage .Create (ctx , tc .istag )
538
+ gotErr := err != nil
539
+ if e , a := tc .expectError , gotErr ; e != a {
540
+ t .Errorf ("%s: Expected err=%v: got %v: %v" , name , e , a , err )
541
+ return
542
+ }
543
+ if tc .expectError {
544
+ status := err .(statusError ).Status ()
545
+ if status .Details .Kind != tc .errorTargetKind || status .Details .Name != tc .errorTargetID {
546
+ t .Errorf ("%s: unexpected status: %#v" , name , status .Details )
547
+ return
548
+ }
549
+ }
550
+ }()
551
+ }
552
+ }
0 commit comments