-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
63 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package config | ||
|
||
import ( | ||
"os" | ||
"runtime" | ||
"testing" | ||
) | ||
|
||
func getUserHomeDir() string { | ||
if runtime.GOOS == "windows" { | ||
home := os.Getenv("HOMEDRIVE") + os.Getenv("HOMEPATH") | ||
if home == "" { | ||
home = os.Getenv("USERPROFILE") | ||
} | ||
return home | ||
} | ||
return os.Getenv("HOME") | ||
} | ||
|
||
func TestExpandPathWithTilde(t *testing.T) { | ||
test_path := "~/.config/pet" | ||
expectedPath := getUserHomeDir() + "/.config/pet" | ||
|
||
result, err := ExpandPath(test_path) | ||
|
||
if err != nil { | ||
t.Errorf("Expected no error, but %v was raised", err) | ||
} | ||
|
||
if result != expectedPath { | ||
t.Errorf("Expected result to be %s, but got %s", expectedPath, result) | ||
} | ||
} | ||
|
||
func TestExpandAbsolutePath(t *testing.T) { | ||
test_path := "/var/tmp/" | ||
expectedPath := "/var/tmp/" | ||
|
||
result, err := ExpandPath(test_path) | ||
|
||
if err != nil { | ||
t.Errorf("Expected no error, but %v was raised", err) | ||
} | ||
|
||
if result != expectedPath { | ||
t.Errorf("Expected result to be %s, but got %s", expectedPath, result) | ||
} | ||
} | ||
|
||
func TestExpandPathWithEmptyInput(t *testing.T) { | ||
test_path := "" | ||
expectedPath := "" | ||
|
||
result, err := ExpandPath(test_path) | ||
|
||
if err == nil { | ||
t.Errorf("Expected error to be raised, but got nil") | ||
} | ||
|
||
if result != expectedPath { | ||
t.Errorf("Expected result to be empty, but got %s", result) | ||
} | ||
} |