Fix sorting from 2 bugs
This commit is contained in:
@@ -24,9 +24,35 @@ import (
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
)
|
||||
|
||||
func encodeOrDie(obj runtime.Object) []byte {
|
||||
data, err := api.Codec.Encode(obj)
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
func TestSortingPrinter(t *testing.T) {
|
||||
intPtr := func(val int) *int { return &val }
|
||||
|
||||
a := &api.Pod{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "a",
|
||||
},
|
||||
}
|
||||
|
||||
b := &api.Pod{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "b",
|
||||
},
|
||||
}
|
||||
|
||||
c := &api.Pod{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "c",
|
||||
},
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
obj runtime.Object
|
||||
sort runtime.Object
|
||||
@@ -159,6 +185,42 @@ func TestSortingPrinter(t *testing.T) {
|
||||
},
|
||||
field: "{.spec.replicas}",
|
||||
},
|
||||
{
|
||||
name: "v1.List in order",
|
||||
obj: &api.List{
|
||||
Items: []runtime.RawExtension{
|
||||
{RawJSON: encodeOrDie(a)},
|
||||
{RawJSON: encodeOrDie(b)},
|
||||
{RawJSON: encodeOrDie(c)},
|
||||
},
|
||||
},
|
||||
sort: &api.List{
|
||||
Items: []runtime.RawExtension{
|
||||
{RawJSON: encodeOrDie(a)},
|
||||
{RawJSON: encodeOrDie(b)},
|
||||
{RawJSON: encodeOrDie(c)},
|
||||
},
|
||||
},
|
||||
field: "{.metadata.name}",
|
||||
},
|
||||
{
|
||||
name: "v1.List in reverse",
|
||||
obj: &api.List{
|
||||
Items: []runtime.RawExtension{
|
||||
{RawJSON: encodeOrDie(c)},
|
||||
{RawJSON: encodeOrDie(b)},
|
||||
{RawJSON: encodeOrDie(a)},
|
||||
},
|
||||
},
|
||||
sort: &api.List{
|
||||
Items: []runtime.RawExtension{
|
||||
{RawJSON: encodeOrDie(a)},
|
||||
{RawJSON: encodeOrDie(b)},
|
||||
{RawJSON: encodeOrDie(c)},
|
||||
},
|
||||
},
|
||||
field: "{.metadata.name}",
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
sort := &SortingPrinter{SortField: test.field}
|
||||
|
||||
Reference in New Issue
Block a user