-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests(settings): adding tests for FindHome() and SetHome() (#245)
* tests(settings): adding tests for FindHome() and SetHome() * fix(tests): set homedir to tempdir in TestLoadSave * fix(tests): no longer reset home env vars.
- Loading branch information
1 parent
1b06646
commit d5c5e7b
Showing
3 changed files
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,26 @@ | ||
// +build linux darwin | ||
|
||
package settings | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/arschles/assert" | ||
) | ||
|
||
// TestFindHome ensures the correct home directory is returned by FindHome(). | ||
func TestFindHome(t *testing.T) { | ||
expectedHomeDir := "/d/e/f" | ||
os.Setenv("HOME", expectedHomeDir) | ||
|
||
assert.Equal(t, FindHome(), expectedHomeDir, "output") | ||
} | ||
|
||
// TestSetHome ensures the correct env vars are set when SetHome() is called. | ||
func TestSetHome(t *testing.T) { | ||
homeDir := "/a/b/c" | ||
SetHome(homeDir) | ||
|
||
assert.Equal(t, os.Getenv("HOME"), homeDir, "output") | ||
} |
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,29 @@ | ||
// +build windows | ||
|
||
package settings | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/arschles/assert" | ||
) | ||
|
||
// TestFindHome ensures the correct home directory is returned by FindHome(). | ||
func TestFindHome(t *testing.T) { | ||
homedrive := "C:" | ||
homepath := "/a/b/c" | ||
os.Setenv("HOMEDRIVE", homedrive) | ||
os.Setenv("HOMEPATH", homepath) | ||
assert.Equal(t, FindHome(), homedrive+homepath, "output") | ||
} | ||
|
||
// TestSetHome ensures the correct env vars are set when SetHome() is called. | ||
func TestSetHome(t *testing.T) { | ||
homeDrive := "D:" | ||
homePath := "/e/f/g" | ||
SetHome(homeDrive + homePath) | ||
|
||
assert.Equal(t, os.Getenv("HOMEDRIVE"), homeDrive, "output") | ||
assert.Equal(t, os.Getenv("HOMEPATH"), homePath, "output") | ||
} |
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