Skip to content

Commit

Permalink
Add parse duration range tests
Browse files Browse the repository at this point in the history
  • Loading branch information
triole committed Jul 29, 2024
1 parent d27ad3c commit 21d8f0a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/conf/range.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
str2duration "github.com/xhit/go-str2duration/v2"
)

func parseRangeArg(s string, lg logseal.Logseal) (minAge, maxAge time.Duration) {
func parseDurationRangeArg(s string, lg logseal.Logseal) (minAge, maxAge time.Duration) {
var err error
arr := strings.Split(s, ",")
minAge, err = str2duration.ParseDuration(arr[0])
Expand Down
33 changes: 28 additions & 5 deletions src/conf/range_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,33 @@
package conf

import "testing"
import (
"testing"
"time"

func TestParseRangeArg(t *testing.T) {
// TODO: write tests
if true == false {
t.Errorf("An error occured.")
"github.com/triole/logseal"
)

func TestParseDurationRangeArg(t *testing.T) {
lg := logseal.Init()
validateParseDurationRangeArg("10s", time.Second*10, time.Second*0, lg, t)
validateParseDurationRangeArg("10s,0", time.Second*10, time.Second*0, lg, t)
validateParseDurationRangeArg("120s,1h", time.Second*120, time.Second*3600, lg, t)
validateParseDurationRangeArg("0,30m", time.Second*0, time.Second*1800, lg, t)
validateParseDurationRangeArg("0", time.Second*0, time.Second*0, lg, t)
}

func validateParseDurationRangeArg(s string, expMin, expMax time.Duration, lg logseal.Logseal, t *testing.T) {
min, max := parseDurationRangeArg(s, lg)
if min != expMin {
t.Errorf(
"failed test parseDurationRangeArg, min != expMin: %s != %s",
min, expMin,
)
}
if max != expMax {
t.Errorf(
"failed test parseDurationRangeArg, max != expMax: %s != %s",
max, expMax,
)
}
}

0 comments on commit 21d8f0a

Please sign in to comment.