From 9a74999263672ba2dc0ec9a0c3edae1910e73123 Mon Sep 17 00:00:00 2001 From: Markus Linnala Date: Tue, 22 Feb 2022 14:52:00 +0200 Subject: [PATCH 1/2] TestMustGetParsedDuration: drop version tests Fails: % go version go version go1.18beta2 linux/amd64 As per: https://go.dev/doc/devel/release#policy Supported versions are today 1.16 and 1.17, so we can drop this brittle check. --- properties_test.go | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/properties_test.go b/properties_test.go index 7fc2e94..adde065 100644 --- a/properties_test.go +++ b/properties_test.go @@ -11,8 +11,6 @@ import ( "os" "reflect" "regexp" - "runtime" - "strconv" "strings" "testing" "time" @@ -560,24 +558,7 @@ func TestMustGetParsedDuration(t *testing.T) { input := "key = 123ms\nkey2 = ghi" p := mustParse(t, input) assert.Equal(t, p.MustGetParsedDuration("key"), 123*time.Millisecond) - - // 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 devel || major == 1 && minor >= 15: - // go1.15 ... gotip - assert.Panic(t, func() { p.MustGetParsedDuration("key2") }, `time: invalid duration "ghi"`) - default: - // go1.x..go1.14 - assert.Panic(t, func() { p.MustGetParsedDuration("key2") }, `time: invalid duration ghi`) - } + assert.Panic(t, func() { p.MustGetParsedDuration("key2") }, `time: invalid duration "ghi"`) assert.Panic(t, func() { p.MustGetParsedDuration("invalid") }, "unknown property: invalid") } From 419d6506e87240a97816a93bc4fc39eb25f1f738 Mon Sep 17 00:00:00 2001 From: Frank Schroeder Date: Tue, 22 Feb 2022 15:10:28 +0100 Subject: [PATCH 2/2] retain go1.3 backwards compatibility --- properties_go1.15_test.go | 25 +++++++++++++++++++++++++ properties_pre_go1.15_test.go | 25 +++++++++++++++++++++++++ properties_test.go | 8 -------- 3 files changed, 50 insertions(+), 8 deletions(-) create mode 100644 properties_go1.15_test.go create mode 100644 properties_pre_go1.15_test.go diff --git a/properties_go1.15_test.go b/properties_go1.15_test.go new file mode 100644 index 0000000..909b4a4 --- /dev/null +++ b/properties_go1.15_test.go @@ -0,0 +1,25 @@ +//go:build go1.15 +// +build go1.15 + +package properties + +import ( + "testing" + "time" + + "github.com/magiconair/properties/assert" +) + +// TestMustGetParsedDuration works with go1.15 and beyond where the panic +// message was changed slightly. We keep this test (!) here to demonstrate the +// backwards compatibility and to keep the author happy as long as it does not +// affect any real users. Thank you! Frank :) +// +// See https://github.com/magiconair/properties/pull/63 +func TestMustGetParsedDuration(t *testing.T) { + input := "key = 123ms\nkey2 = ghi" + p := mustParse(t, input) + assert.Equal(t, p.MustGetParsedDuration("key"), 123*time.Millisecond) + assert.Panic(t, func() { p.MustGetParsedDuration("key2") }, `time: invalid duration "ghi"`) + assert.Panic(t, func() { p.MustGetParsedDuration("invalid") }, "unknown property: invalid") +} diff --git a/properties_pre_go1.15_test.go b/properties_pre_go1.15_test.go new file mode 100644 index 0000000..2a7f7c6 --- /dev/null +++ b/properties_pre_go1.15_test.go @@ -0,0 +1,25 @@ +//go:build !go1.15 +// +build !go1.15 + +package properties + +import ( + "testing" + "time" + + "github.com/magiconair/properties/assert" +) + +// TestMustGetParsedDuration works with go before go1.15 where the panic +// message was changed slightly. We keep this test (!) here to demonstrate the +// backwards compatibility and to keep the author happy as long as it does not +// affect any real users. Thank you! Frank :) +// +// See https://github.com/magiconair/properties/pull/63 +func TestMustGetParsedDuration(t *testing.T) { + input := "key = 123ms\nkey2 = ghi" + p := mustParse(t, input) + assert.Equal(t, p.MustGetParsedDuration("key"), 123*time.Millisecond) + assert.Panic(t, func() { p.MustGetParsedDuration("key2") }, `time: invalid duration ghi`) + assert.Panic(t, func() { p.MustGetParsedDuration("invalid") }, "unknown property: invalid") +} diff --git a/properties_test.go b/properties_test.go index adde065..33f516c 100644 --- a/properties_test.go +++ b/properties_test.go @@ -554,14 +554,6 @@ func TestGetParsedDuration(t *testing.T) { } } -func TestMustGetParsedDuration(t *testing.T) { - input := "key = 123ms\nkey2 = ghi" - p := mustParse(t, input) - assert.Equal(t, p.MustGetParsedDuration("key"), 123*time.Millisecond) - assert.Panic(t, func() { p.MustGetParsedDuration("key2") }, `time: invalid duration "ghi"`) - assert.Panic(t, func() { p.MustGetParsedDuration("invalid") }, "unknown property: invalid") -} - func TestGetFloat64(t *testing.T) { for _, test := range floatTests { p := mustParse(t, test.input)