Skip to content

Commit 3b652cb

Browse files
authored
Fix panic edge-case in report command
1 parent 039da4d commit 3b652cb

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

klog/app/cli/report.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ func (opt *Report) Run(ctx app.Context) error {
3030
if err != nil {
3131
return err
3232
}
33+
now := ctx.Now()
34+
records = opt.ApplyFilter(now, records)
3335
if len(records) == 0 {
3436
return nil
3537
}
36-
now := ctx.Now()
37-
records = opt.ApplyFilter(now, records)
3838
records, nErr := opt.ApplyNow(now, records...)
3939
if nErr != nil {
4040
return nErr

klog/app/cli/report_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cli
22

33
import (
4+
"github.com/jotaen/klog/klog"
45
"github.com/jotaen/klog/klog/app/cli/lib"
56
"github.com/stretchr/testify/assert"
67
"github.com/stretchr/testify/require"
@@ -13,6 +14,18 @@ func TestReportOfEmptyInput(t *testing.T) {
1314
assert.Equal(t, "", state.printBuffer)
1415
}
1516

17+
func TestReportOfEmptyFilteredData(t *testing.T) {
18+
state, err := NewTestingContext()._SetRecords(`
19+
2022-10-30
20+
8h
21+
`)._Run((&Report{
22+
FilterArgs: lib.FilterArgs{Date: klog.Ɀ_Date_(2022, 10, 31)},
23+
Fill: true,
24+
}).Run)
25+
require.Nil(t, err)
26+
assert.Equal(t, "", state.printBuffer)
27+
}
28+
1629
func TestDayReportOfRecords(t *testing.T) {
1730
/*
1831
Aspects tested:

0 commit comments

Comments
 (0)