Skip to content

Default osSuffix to runtime.GOOS instead of calling panic() #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
16 changes: 5 additions & 11 deletions properties_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions testdata/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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