diff --git a/api/webapp.go b/api/webapp.go index 64573cbff..8758e97dd 100644 --- a/api/webapp.go +++ b/api/webapp.go @@ -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() }() diff --git a/cmd/cmd_test.go b/cmd/cmd_test.go index c13be1bde..e5935cc63 100644 --- a/cmd/cmd_test.go +++ b/cmd/cmd_test.go @@ -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" ) diff --git a/cmd/stringers.go b/cmd/stringers.go index 2cb64d59c..d20ab1813 100644 --- a/cmd/stringers.go +++ b/cmd/stringers.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" "strings" + "time" "github.com/dustin/go-humanize" "github.com/fatih/color" @@ -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) } diff --git a/cmd/stringers_test.go b/cmd/stringers_test.go index ee98b4ce5..bb07ee7b9 100644 --- a/cmd/stringers_test.go +++ b/cmd/stringers_test.go @@ -1,6 +1,7 @@ package cmd import ( + "strings" "testing" "time" @@ -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") @@ -170,7 +175,7 @@ func TestJobStringer(t *testing.T) { cases := []struct { description string job *lib.Job - expect string + contains string }{ {"JobStringer - all fields", &lib.Job{ @@ -178,13 +183,13 @@ func TestJobStringer(t *testing.T) { 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) } } } diff --git a/cmd/update.go b/cmd/update.go index 3a9a0bb99..bc2e27f3f 100644 --- a/cmd/update.go +++ b/cmd/update.go @@ -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 diff --git a/cmd/update_test.go b/cmd/update_test.go index 37852def7..e61496aef 100644 --- a/cmd/update_test.go +++ b/cmd/update_test.go @@ -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()) } diff --git a/lib/update.go b/lib/update.go index 12e38999b..d5d79e330 100644 --- a/lib/update.go +++ b/lib/update.go @@ -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 }