From eb0447278d83884f2b0118926317fdf51e55c872 Mon Sep 17 00:00:00 2001 From: Aaron Bieber Date: Sat, 11 Jul 2020 08:48:52 -0600 Subject: [PATCH] Default osSuffix to runtime.GOOS instead of calling panic() - update properties_test to not require a full list of OSs. - add free, open and net BSD to the test data. --- properties.go | 4 +--- properties_test.go | 16 +++++----------- testdata/test.txt | 3 +++ 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/properties.go b/properties.go index a792102..2f330bd 100644 --- a/properties.go +++ b/properties.go @@ -94,12 +94,10 @@ var osSuffix string func init() { switch value := runtime.GOOS; value { - case "linux", "freebsd", "windows": - osSuffix = runtime.GOOS case "darwin": osSuffix = "macosx" default: - panic("Unsupported OS") + osSuffix = runtime.GOOS } } diff --git a/properties_test.go b/properties_test.go index 3225cc1..f8d6c34 100644 --- a/properties_test.go +++ b/properties_test.go @@ -58,20 +58,14 @@ func TestPropertiesTestTxt(t *testing.T) { p, err := Load(filepath.Join("testdata", "test.txt")) require.NoError(t, err) - - require.Equal(t, 4, p.Size()) require.Equal(t, "value = 1", p.Get("key")) - switch value := runtime.GOOS; value { - case "linux": - require.Equal(t, "is linux", p.Get("which.os")) - case "windows": - require.Equal(t, "is windows", p.Get("which.os")) - case "darwin": - require.Equal(t, "is macosx", p.Get("which.os")) - default: - require.FailNow(t, "unsupported OS") + runOS := runtime.GOOS + if runOS == "darwin" { + runOS = "macosx" } + + require.Equal(t, fmt.Sprintf("is %s", runOS), p.Get("which.os")) } func TestExpandPropsInStringAndMissingCheck(t *testing.T) { diff --git a/testdata/test.txt b/testdata/test.txt index af50396..ba71754 100644 --- a/testdata/test.txt +++ b/testdata/test.txt @@ -6,3 +6,6 @@ which.os=dunno which.os.linux=is linux which.os.macosx=is macosx which.os.windows=is windows +which.os.openbsd=is openbsd +which.os.freebsd=is freebsd +which.os.netbsd=is netbsd