Skip to content

Commit

Permalink
Fix panic edge-case in report command
Browse files Browse the repository at this point in the history
  • Loading branch information
jotaen authored Oct 31, 2022
1 parent 039da4d commit 3b652cb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions klog/app/cli/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ func (opt *Report) Run(ctx app.Context) error {
if err != nil {
return err
}
now := ctx.Now()
records = opt.ApplyFilter(now, records)
if len(records) == 0 {
return nil
}
now := ctx.Now()
records = opt.ApplyFilter(now, records)
records, nErr := opt.ApplyNow(now, records...)
if nErr != nil {
return nErr
Expand Down
13 changes: 13 additions & 0 deletions klog/app/cli/report_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cli

import (
"github.com/jotaen/klog/klog"
"github.com/jotaen/klog/klog/app/cli/lib"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand All @@ -13,6 +14,18 @@ func TestReportOfEmptyInput(t *testing.T) {
assert.Equal(t, "", state.printBuffer)
}

func TestReportOfEmptyFilteredData(t *testing.T) {
state, err := NewTestingContext()._SetRecords(`
2022-10-30
8h
`)._Run((&Report{
FilterArgs: lib.FilterArgs{Date: klog.Ɀ_Date_(2022, 10, 31)},
Fill: true,
}).Run)
require.Nil(t, err)
assert.Equal(t, "", state.printBuffer)
}

func TestDayReportOfRecords(t *testing.T) {
/*
Aspects tested:
Expand Down

0 comments on commit 3b652cb

Please sign in to comment.