Skip to content

Commit

Permalink
feat(update): cleanup CLI output
Browse files Browse the repository at this point in the history
  • Loading branch information
b5 committed Jun 4, 2019
1 parent 93cb843 commit fa2ebad
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 12 deletions.
2 changes: 1 addition & 1 deletion api/webapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (s Server) ServeWebapp(ctx context.Context) {

go func() {
<-ctx.Done()
log.Info("clsing webapp server")
log.Info("closing webapp server")
webappserver.Close()
}()

Expand Down
1 change: 0 additions & 1 deletion cmd/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/qri-io/qri/repo/gen"
regmock "github.com/qri-io/registry/regserver/mock"
"github.com/spf13/cobra"

golog "github.com/ipfs/go-log"
)

Expand Down
6 changes: 4 additions & 2 deletions cmd/stringers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"strings"
"time"

"github.com/dustin/go-humanize"
"github.com/fatih/color"
Expand Down Expand Up @@ -116,8 +117,9 @@ type jobStringer cron.Job
func (j jobStringer) String() string {
w := &bytes.Buffer{}
name := color.New(color.Bold).SprintFunc()
time := j.Periodicity.After(j.LastRunStart)
fmt.Fprintf(w, "%s\n%s | %s\n", name(j.Name), j.Type, time)
t := j.Periodicity.After(j.LastRunStart)
relTime := humanize.RelTime(time.Now().In(time.UTC), t, "", "")
fmt.Fprintf(w, "%s\nin %sat %s | %s\n", name(j.Name), relTime, t.In(time.Now().Location()).Format(time.Kitchen), j.Type)
if j.RepoPath != "" {
fmt.Fprintf(w, "\nrepo: %s\n", j.RepoPath)
}
Expand Down
13 changes: 9 additions & 4 deletions cmd/stringers_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"strings"
"testing"
"time"

Expand Down Expand Up @@ -160,6 +161,10 @@ func TestLogStringer(t *testing.T) {
}

func TestJobStringer(t *testing.T) {
// NB: JobStringer is tough to write tests for at the moment
// thanks to printing in local timezones
// TODO (b5) - look into setting local timezone for this test

setNoColor(false)
time := time.Date(2001, 01, 01, 01, 01, 01, 01, time.UTC)
p, err := iso8601.ParseRepeatingInterval("R/P1D")
Expand All @@ -170,21 +175,21 @@ func TestJobStringer(t *testing.T) {
cases := []struct {
description string
job *lib.Job
expect string
contains string
}{
{"JobStringer - all fields",
&lib.Job{
Name: "Job",
Type: "dataset",
Periodicity: p,
LastRunStart: time,
}, "\u001b[1mJob\u001b[0m\ndataset | 2001-01-02 01:01:01.000000001 +0000 UTC\n\n",
}, "\u001b[1mJob\u001b[0m\n",
},
}
for _, c := range cases {
jobStr := jobStringer(*c.job).String()
if c.expect != jobStr {
t.Errorf("case '%s', expected: '%s', got'%s'", c.description, c.expect, jobStr)
if !strings.Contains(jobStr, c.contains) {
t.Errorf("case '%s', expected '%s' to contain string: '%s'", c.description, jobStr, c.contains)
}
}
}
9 changes: 7 additions & 2 deletions cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,13 @@ func (o *UpdateOptions) List() (err error) {
}

items := make([]fmt.Stringer, len(res))
for i, r := range res {
items[i] = jobStringer(*r)
// iterate in reverse to show upcoming items first
// TODO (b5) - this will have wierd interaction with pagination,
// should use a more proper fix
j := 0
for i := len(res) - 1; i >= 0; i-- {
items[j] = jobStringer(*res[i])
j++
}
printItems(o.Out, items, page.Offset())
return
Expand Down
4 changes: 3 additions & 1 deletion cmd/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ func TestUpdateMethods(t *testing.T) {
if err := o.List(); err != nil {
t.Error(err)
}
listStdOutContains := "shell | 0001-01-01 00:00:01 +0000 UTC"

// TODO (b5) - wee note on TestJobStringer, we should be testing times by setting local timezones
listStdOutContains := "| shell"
if !strings.Contains(out.String(), listStdOutContains) {
t.Errorf("list response mismatch. stdOut doesn't contain:\n%s\ngot:\n%s", listStdOutContains, out.String())
}
Expand Down
1 change: 0 additions & 1 deletion lib/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ func (m *UpdateMethods) Schedule(in *ScheduleParams, out *cron.Job) (err error)

err = m.inst.cron.Schedule(ctx, job)
*out = *job
log.Errorf("%#v", job)
return err
}

Expand Down

0 comments on commit fa2ebad

Please sign in to comment.