-
Notifications
You must be signed in to change notification settings - Fork 281
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cleanup loading config from different locations (based on user env va…
…riables) - using afero for mocking fs
- Loading branch information
1 parent
cdb8268
commit 0eb4c9f
Showing
4 changed files
with
526 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package cli | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/spf13/afero" | ||
) | ||
|
||
func init() { | ||
|
||
AppFs = afero.NewMemMapFs() | ||
} | ||
|
||
func TestHomeConfigDir(t *testing.T) { | ||
|
||
homeDirPath := "/tmp-iofs/home/tester" | ||
AppFs.MkdirAll(homeDirPath, 0755) | ||
|
||
afero.WriteFile(AppFs, homeDirPath+"/revive.toml", []byte("\n"), 0644) | ||
os.Setenv("HOME", homeDirPath) | ||
|
||
got := buildDefaultConfigPath() | ||
want := homeDirPath + "/revive.toml" | ||
|
||
if got != want { | ||
t.Errorf("got %q, wanted %q", got, want) | ||
} | ||
|
||
} | ||
|
||
func TestXDGConfigDir(t *testing.T) { | ||
|
||
xdgDirPath := "/tmp-iofs/xdg/config" | ||
AppFs.MkdirAll(xdgDirPath, 0755) | ||
|
||
afero.WriteFile(AppFs, xdgDirPath+"/revive.toml", []byte("\n"), 0644) | ||
os.Setenv("XDG_CONFIG_HOME", xdgDirPath) | ||
|
||
got := buildDefaultConfigPath() | ||
want := xdgDirPath + "/revive.toml" | ||
|
||
if got != want { | ||
t.Errorf("got %q, wanted %q", got, want) | ||
} | ||
|
||
} | ||
|
||
func TestXDGConfigDirNoFile(t *testing.T) { | ||
|
||
xdgDirPath := "/tmp-iofs/xdg/config" | ||
os.Setenv("XDG_CONFIG_HOME", xdgDirPath) | ||
|
||
got := buildDefaultConfigPath() | ||
want := xdgDirPath + "/revive.toml" | ||
|
||
if got != want { | ||
t.Errorf("got %q, wanted %q", got, want) | ||
} | ||
} |
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
Oops, something went wrong.