Skip to content

Commit

Permalink
Address comments and add negative tests
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
  • Loading branch information
roidelapluie committed Aug 1, 2020
1 parent 88137a4 commit 0019086
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
3 changes: 1 addition & 2 deletions model/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,7 @@ func ParseDuration(durationStr string) (Duration, error) {
return 0, nil
}
matches := durationRE.FindStringSubmatch(durationStr)
fmt.Printf("%v", len(matches))
if len(matches) != 15 {
if matches == nil {
return 0, fmt.Errorf("not a valid duration string: %q", durationStr)
}
var dur time.Duration
Expand Down
21 changes: 21 additions & 0 deletions model/time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ func TestParseDuration(t *testing.T) {
in: "0",
out: 0,
expectedString: "0s",
}, {
in: "0w",
out: 0,
expectedString: "0s",
}, {
in: "0s",
out: 0,
Expand Down Expand Up @@ -151,6 +155,23 @@ func TestParseDuration(t *testing.T) {
}
}

func TestParseBadDuration(t *testing.T) {
var cases = []string{
"1",
"1y1m1d",
"-1w",
"1.5d",
}

for _, c := range cases {
_, err := ParseDuration(c)
if err == nil {
t.Errorf("Expected error on input %s", c)
}

}
}

func TestTimeJSON(t *testing.T) {
tests := []struct {
in Time
Expand Down

0 comments on commit 0019086

Please sign in to comment.