Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests(settings): adding tests for FindHome() and SetHome() #245

Merged
merged 3 commits into from
Sep 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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