Skip to content

Commit

Permalink
tests(settings): adding tests for FindHome() and SetHome() (#245)
Browse files Browse the repository at this point in the history
* 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
ultimateboy committed Sep 15, 2016
1 parent 1b06646 commit d5c5e7b
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
26 changes: 26 additions & 0 deletions settings/home_unix_test.go
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")
}
29 changes: 29 additions & 0 deletions settings/home_windows_test.go
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")
}
8 changes: 8 additions & 0 deletions settings/settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ func TestLoadSave(t *testing.T) {

s.Client.ControllerURL = u

// Create a tempdir and set as HOME.
dir, err := ioutil.TempDir("", "deishome")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(dir)
SetHome(dir)

if _, err = s.Save(file); err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit d5c5e7b

Please sign in to comment.