Skip to content

Commit

Permalink
Merge remote-tracking branch 'gojek/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
jensoncs committed Feb 12, 2019
2 parents 8f48217 + a7ba579 commit 95f39d3
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
3 changes: 2 additions & 1 deletion cmd/list/lister.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/gojektech/proctor/daemon"
"github.com/gojektech/proctor/io"
"github.com/spf13/cobra"
"github.com/gojektech/proctor/utility/sort"
)

func NewCmd(printer io.Printer, proctorDClient daemon.Client) *cobra.Command {
Expand All @@ -21,8 +22,8 @@ func NewCmd(printer io.Printer, proctorDClient daemon.Client) *cobra.Command {
printer.Println(err.Error(), color.FgRed)
return
}

printer.Println("List of Procs:\n", color.FgGreen)
sort.Procs(procList)

for _, proc := range procList {
printer.Println(fmt.Sprintf("%-40s %-100s", proc.Name, proc.Description), color.Reset)
Expand Down
1 change: 0 additions & 1 deletion cmd/list/lister_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ func (s *ListCmdTestSuite) TestListCmdRun() {
s.mockPrinter.On("Println", fmt.Sprintf("%-40s %-100s", procOne.Name, procOne.Description), color.Reset).Once()
s.mockPrinter.On("Println", fmt.Sprintf("%-40s %-100s", procTwo.Name, procTwo.Description), color.Reset).Once()
s.mockPrinter.On("Println", "\nFor detailed information of any proc, run:\nproctor describe <proc_name>", color.FgGreen).Once()

s.testListCmd.Run(&cobra.Command{}, []string{})

s.mockProctorDClient.AssertExpectations(s.T())
Expand Down
12 changes: 12 additions & 0 deletions utility/sort/sort.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package sort

import (
"github.com/gojektech/proctor/proctord/jobs/metadata"
"sort"
)

func Procs(procList []metadata.Metadata) {
sort.Slice(procList, func(i, j int) bool {
return procList[i].Name < procList[j].Name
})
}
19 changes: 19 additions & 0 deletions utility/sort/sort_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package sort

import (
"github.com/gojektech/proctor/proctord/jobs/metadata"
"github.com/stretchr/testify/assert"
"testing"
)

func TestSorting(t *testing.T) {
procOne := metadata.Metadata{Name: "one"}
procTwo := metadata.Metadata{Name: "two"}
procThree := metadata.Metadata{Name: "three"}
procList := []metadata.Metadata{procThree, procTwo, procOne}
expectedProcList := []metadata.Metadata{procOne, procThree, procTwo}

Procs(procList)

assert.Equal(t, expectedProcList, procList)
}

0 comments on commit 95f39d3

Please sign in to comment.