mirror of https://github.com/knative/client.git
list services sorted by alphabetical order (#330)
This commit is contained in:
parent
3594b39659
commit
8c362f0363
|
|
@ -34,6 +34,10 @@
|
|||
| `kn service describe`
|
||||
| https://github.com/knative/client/pull/252[#252]
|
||||
|
||||
| 🐛
|
||||
| `kn service list` lists services sorted by alphabetical order
|
||||
| https://github.com/knative/client/pull/330[#330]
|
||||
|
||||
|===
|
||||
|
||||
## v0.2.0 (2019-07-10)
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ package service
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"github.com/knative/client/pkg/kn/commands"
|
||||
v1alpha12 "github.com/knative/client/pkg/serving/v1alpha1"
|
||||
|
|
@ -61,6 +62,11 @@ func NewServiceListCommand(p *commands.KnParams) *cobra.Command {
|
|||
return err
|
||||
}
|
||||
|
||||
// Sort serviceList by name
|
||||
sort.SliceStable(serviceList.Items, func(i, j int) bool {
|
||||
return serviceList.Items[i].ObjectMeta.Name < serviceList.Items[j].ObjectMeta.Name
|
||||
})
|
||||
|
||||
err = printer.PrintObj(serviceList, cmd.OutOrStdout())
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -76,9 +76,10 @@ func TestGetEmpty(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestServiceListDefaultOutput(t *testing.T) {
|
||||
service1 := createMockServiceWithParams("foo", "http://foo.default.example.com", 1)
|
||||
service2 := createMockServiceWithParams("bar", "http://bar.default.example.com", 2)
|
||||
serviceList := &v1alpha1.ServiceList{Items: []v1alpha1.Service{*service1, *service2}}
|
||||
service1 := createMockServiceWithParams("foo", "http://foo.default.example.com", 2)
|
||||
service3 := createMockServiceWithParams("sss", "http://sss.default.example.com", 3)
|
||||
service2 := createMockServiceWithParams("bar", "http://bar.default.example.com", 1)
|
||||
serviceList := &v1alpha1.ServiceList{Items: []v1alpha1.Service{*service1, *service2, *service3}}
|
||||
action, output, err := fakeServiceList([]string{"service", "list"}, serviceList)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
|
@ -88,9 +89,11 @@ func TestServiceListDefaultOutput(t *testing.T) {
|
|||
} else if !action.Matches("list", "services") {
|
||||
t.Errorf("Bad action %v", action)
|
||||
}
|
||||
// Outputs in alphabetical order
|
||||
assert.Check(t, util.ContainsAll(output[0], "NAME", "URL", "GENERATION", "AGE", "CONDITIONS", "READY", "REASON"))
|
||||
assert.Check(t, util.ContainsAll(output[1], "foo", "foo.default.example.com", "1"))
|
||||
assert.Check(t, util.ContainsAll(output[2], "bar", "bar.default.example.com", "2"))
|
||||
assert.Check(t, util.ContainsAll(output[1], "bar", "bar.default.example.com", "1"))
|
||||
assert.Check(t, util.ContainsAll(output[2], "foo", "foo.default.example.com", "2"))
|
||||
assert.Check(t, util.ContainsAll(output[3], "sss", "sss.default.example.com", "3"))
|
||||
}
|
||||
|
||||
func TestServiceGetOneOutput(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue