forked from flyteorg/flyte
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added HOMEDIR/.flyte to search path for config.yaml (flyteorg#59)
Signed-off-by: Prafulla Mahindrakar <[email protected]>
- Loading branch information
1 parent
510d483
commit a8ebb50
Showing
4 changed files
with
78 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package filesystemutils | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
var osUserHomDirFunc = os.UserHomeDir | ||
var filePathJoinFunc = filepath.Join | ||
|
||
// UserHomeDir Returns the users home directory or on error returns the current dir | ||
func UserHomeDir() string { | ||
if homeDir, err := osUserHomDirFunc(); err == nil { | ||
return homeDir | ||
} | ||
return "." | ||
} | ||
|
||
// FilePathJoin Returns the file path obtained by joining various path elements. | ||
func FilePathJoin(elems ...string) string { | ||
return filePathJoinFunc(elems...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package filesystemutils | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
var ( | ||
homeDirVal = "/home/user" | ||
homeDirErr error | ||
) | ||
|
||
func FakeUserHomeDir() (string, error) { | ||
return homeDirVal, homeDirErr | ||
} | ||
|
||
func TestUserHomeDir(t *testing.T) { | ||
t.Run("User home dir", func(t *testing.T) { | ||
osUserHomDirFunc = FakeUserHomeDir | ||
homeDir := UserHomeDir() | ||
assert.Equal(t, homeDirVal, homeDir) | ||
}) | ||
t.Run("User home dir fail", func(t *testing.T) { | ||
homeDirErr = fmt.Errorf("failed to get users home directory") | ||
homeDirVal = "." | ||
osUserHomDirFunc = FakeUserHomeDir | ||
homeDir := UserHomeDir() | ||
assert.Equal(t, ".", homeDir) | ||
// Reset | ||
homeDirErr = nil | ||
homeDirVal = "/home/user" | ||
}) | ||
} | ||
|
||
func TestFilePathJoin(t *testing.T) { | ||
t.Run("File path join", func(t *testing.T) { | ||
homeDir := FilePathJoin("/", "home", "user") | ||
assert.Equal(t, "/home/user", homeDir) | ||
}) | ||
} |