From 3b652cbc2b50e4f42043f93607903a186a8565a8 Mon Sep 17 00:00:00 2001 From: Jan Heuermann Date: Mon, 31 Oct 2022 08:45:38 +0100 Subject: [PATCH] Fix panic edge-case in report command --- klog/app/cli/report.go | 4 ++-- klog/app/cli/report_test.go | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/klog/app/cli/report.go b/klog/app/cli/report.go index e930b7d..fb3bf5a 100644 --- a/klog/app/cli/report.go +++ b/klog/app/cli/report.go @@ -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 diff --git a/klog/app/cli/report_test.go b/klog/app/cli/report_test.go index d21c46f..89f36dd 100644 --- a/klog/app/cli/report_test.go +++ b/klog/app/cli/report_test.go @@ -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" @@ -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: