Skip to content

Commit

Permalink
Fix lint and add another test case
Browse files Browse the repository at this point in the history
  • Loading branch information
bergundy committed Sep 13, 2024
1 parent 66e899e commit 2439122
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion nexus/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ func validateLinkType(value string) error {
return nil
}

var durationRegexp = regexp.MustCompile("^(\\d+(?:\\.\\d+)?)(ms|s|m)$")
var durationRegexp = regexp.MustCompile(`^(\d+(?:\.\d+)?)(ms|s|m)$`)

func parseDuration(value string) (time.Duration, error) {
m := durationRegexp.FindStringSubmatch(value)
Expand Down
7 changes: 5 additions & 2 deletions nexus/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,9 +511,12 @@ func TestDecodeLink(t *testing.T) {
}

func TestParseDuration(t *testing.T) {
d, err := parseDuration("invalid")
_, err := parseDuration("invalid")
require.ErrorContains(t, err, "invalid duration:")
d, err = parseDuration("10ms")
d, err := parseDuration("10ms")
require.NoError(t, err)
require.Equal(t, 10*time.Millisecond, d)
d, err = parseDuration("10.1ms")
require.NoError(t, err)
require.Equal(t, 10*time.Millisecond, d)
d, err = parseDuration("1s")
Expand Down

0 comments on commit 2439122

Please sign in to comment.