diff --git a/pkg/image/apis/image/test/conversion_test.go b/pkg/image/apis/image/test/conversion_test.go new file mode 100644 index 000000000000..8bc873bceff9 --- /dev/null +++ b/pkg/image/apis/image/test/conversion_test.go @@ -0,0 +1,45 @@ +package v1 + +import ( + "reflect" + "testing" + + "k8s.io/apimachinery/pkg/util/diff" + kapi "k8s.io/kubernetes/pkg/api" + + newer "github.com/openshift/origin/pkg/image/apis/image" + "github.com/openshift/origin/pkg/image/apis/image/v1" + + _ "github.com/openshift/origin/pkg/image/apis/image/install" +) + +func TestImageStreamStatusConversionPreservesTags(t *testing.T) { + in := &newer.ImageStreamStatus{ + Tags: map[string]newer.TagEventList{ + "v3.5.0": {}, + "3.5.0": {}, + }, + } + expOutVersioned := &v1.ImageStreamStatus{ + Tags: []v1.NamedTagEventList{{Tag: "3.5.0"}, {Tag: "v3.5.0"}}, + } + + outVersioned := v1.ImageStreamStatus{Tags: []v1.NamedTagEventList{}} + err := kapi.Scheme.Convert(in, &outVersioned, nil) + if err != nil { + t.Fatalf("got unexpected error: %v", err) + } + if a, e := &outVersioned, expOutVersioned; !reflect.DeepEqual(a, e) { + t.Fatalf("got unexpected output: %s", diff.ObjectDiff(&a, e)) + } + + // convert back from v1 to internal scheme + out := newer.ImageStreamStatus{} + err = kapi.Scheme.Convert(&outVersioned, &out, nil) + if err != nil { + t.Fatalf("got unexpected error: %v", err) + } + if a, e := &out, in; !reflect.DeepEqual(a, e) { + t.Fatalf("got unexpected output: %s", diff.ObjectDiff(&a, e)) + } +} diff --git a/pkg/image/apis/image/v1/conversion.go b/pkg/image/apis/image/v1/conversion.go index a5863a72754c..cef81a667f4d 100644 --- a/pkg/image/apis/image/v1/conversion.go +++ b/pkg/image/apis/image/v1/conversion.go @@ -231,7 +231,7 @@ func Convert_image_TagEventListArray_to_v1_NamedTagEventListArray(in *map[string for key := range *in { allKeys = append(allKeys, key) } - newer.PrioritizeTags(allKeys) + sort.Strings(allKeys) for _, key := range allKeys { newTagEventList := (*in)[key] diff --git a/test/cmd/images.sh b/test/cmd/images.sh index bd15283a9984..cf0e9a1f3975 100755 --- a/test/cmd/images.sh +++ b/test/cmd/images.sh @@ -283,7 +283,8 @@ os::test::junit::declare_suite_end os::test::junit::declare_suite_start "cmd/images${IMAGES_TESTS_POSTFIX:-}/delete-istag" # test deleting a tag using oc delete os::cmd::expect_success_and_text "oc get is perl --template '{{(index .spec.tags 0).name}}'" '5.16' -os::cmd::expect_success_and_text "oc get is perl --template '{{(index .status.tags 0).tag}}'" 'latest' +os::cmd::expect_success_and_text "oc get is perl --template '{{(index .status.tags 0).tag}}'" '5.16' +os::cmd::expect_success_and_text "oc describe is perl | sed -n -e '0,/^Tags:/d' -e '/^\s\+/d' -e '/./p' | head -n 1" 'latest' os::cmd::expect_success "oc delete istag/perl:5.16 --context='${cluster_admin_context}'" os::cmd::expect_success_and_not_text 'oc get is/perl --template={{.spec.tags}}' 'version:5.16' os::cmd::expect_success_and_not_text 'oc get is/perl --template={{.status.tags}}' 'version:5.16'