Skip to content

Commit

Permalink
fix time test for older versions
Browse files Browse the repository at this point in the history
  • Loading branch information
magiconair committed Mar 24, 2021
1 parent f70a7db commit 291b826
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions properties_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"reflect"
"regexp"
"runtime"
"strconv"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -563,11 +564,17 @@ func TestMustGetParsedDuration(t *testing.T) {
p := mustParse(t, input)
assert.Equal(t, p.MustGetParsedDuration("key"), 123*time.Millisecond)

// runtime.Version is go1.x.y or devel or <gitsha>
// ver[0] == major version, ver[1] == minor version
// parse runtime.Version into major and minor version
var major, minor int
ver := strings.Split(runtime.Version(), ".")
devel := !strings.HasPrefix(ver[0], "go")
major, _ = strconv.Atoi(strings.TrimPrefix(ver[0], "go"))
if len(ver) > 1 {
minor, _ = strconv.Atoi(ver[1])
}

switch {
case strings.HasPrefix(ver[0], "go") && ver[1] >= "15":
case devel || major == 1 && minor >= 15:
// go1.15 ... gotip
assert.Panic(t, func() { p.MustGetParsedDuration("key2") }, `time: invalid duration "ghi"`)
default:
Expand Down

0 comments on commit 291b826

Please sign in to comment.