Skip to content

Commit

Permalink
Merge branch 'main' into consent-cli
Browse files Browse the repository at this point in the history
  • Loading branch information
hk21702 committed Feb 3, 2025
2 parents 4599876 + bb2413e commit c9f8079
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
9 changes: 4 additions & 5 deletions internal/report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,15 @@ func GetPeriodStart(period int, t time.Time) (int64, error) {
//
// For example, given reports 1 and 7, with time 2 and period 7, the function will return the path for report 1.
func GetForPeriod(dir string, t time.Time, period int) (Report, error) {
if period <= 0 {
return Report{}, ErrInvalidPeriod
periodStart, err := GetPeriodStart(period, t)
if err != nil {
return Report{}, err
}

periodStart := t.Unix() - (t.Unix() % int64(period))
periodEnd := periodStart + int64(period)

// Reports names are utc timestamps. Get the most recent report within the period window.
var report Report
err := filepath.WalkDir(dir, func(path string, d os.DirEntry, err error) error {
err = filepath.WalkDir(dir, func(path string, d os.DirEntry, err error) error {
if err != nil {
return fmt.Errorf("failed to access path: %v", err)
}
Expand Down
5 changes: 3 additions & 2 deletions internal/report/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ func TestGetPeriodStart(t *testing.T) {

wantErr error
}{
"Valid Period": {period: 500, time: 100000},
"Negative Time:": {period: 500, time: -100000},
"Valid Period": {period: 500, time: 100000},
"Negative Time:": {period: 500, time: -100000},
"Non-Multiple Time": {period: 500, time: 1051},

"Invalid Negative Period": {period: -500, wantErr: report.ErrInvalidPeriod},
"Invalid Zero Period": {period: 0, wantErr: report.ErrInvalidPeriod},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1000

0 comments on commit c9f8079

Please sign in to comment.