add new os pkg on ocis-pkg
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
package os
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// MustUserConfigDir generates a default config location for a user based on their OS. This location can be used to store
|
||||
// any artefacts the app needs for its functioning. It is a pure function. Its only side effect is that results vary
|
||||
// depending on which operative system we're in.
|
||||
func MustUserConfigDir(prefix, extension string) string {
|
||||
dir, err := os.UserConfigDir()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return filepath.Join(dir, prefix, extension)
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package os
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test_mustUserConfigDir(t *testing.T) {
|
||||
configDir, _ := os.UserConfigDir()
|
||||
type args struct {
|
||||
prefix string
|
||||
extension string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "fetch the default config location for the current user",
|
||||
args: args{
|
||||
prefix: "ocis",
|
||||
extension: "testing",
|
||||
},
|
||||
want: filepath.Join(configDir, "ocis", "testing"),
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := MustUserConfigDir(tt.args.prefix, tt.args.extension); got != tt.want {
|
||||
t.Errorf("MustUserConfigDir() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user