Skip to content

Commit

Permalink
Sort istags alphabetically during schema conversion
Browse files Browse the repository at this point in the history
Signed-off-by: Michal Minář <[email protected]>
  • Loading branch information
Michal Minář committed Nov 23, 2017
1 parent 21f535d commit 0f6440d
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
45 changes: 45 additions & 0 deletions pkg/image/apis/image/test/conversion_test.go
Original file line number Diff line number Diff line change
@@ -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))
}
}
2 changes: 1 addition & 1 deletion pkg/image/apis/image/v1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
3 changes: 2 additions & 1 deletion test/cmd/images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 0f6440d

Please sign in to comment.