Skip to content

Commit

Permalink
#29 Use ~/.cache/tfvm if exists, event on macOS.
Browse files Browse the repository at this point in the history
  • Loading branch information
cbuschka committed Sep 27, 2021
1 parent 9d577e7 commit a9eae97
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
12 changes: 11 additions & 1 deletion internal/inventory/dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,21 @@ func getDefaultInventoryDir(fs fs, platform platformPkg.Platform) (string, error
return oldInventoryDir, nil
}

xdgInventoryDir := getDefaultInventoryDirForXDG(homeDir)
xdgInventoryDirExists, err := fs.IsDir(xdgInventoryDir)
if err != nil {
return "", nil
}

if xdgInventoryDirExists {
return xdgInventoryDir, nil
}

if platform.IsMacOS() {
return getDefaultInventoryDirForMacOS(homeDir), nil
}

return getDefaultInventoryDirForXDG(homeDir), nil
return xdgInventoryDir, nil
}

func getDefaultInventoryDirForMacOS(homeDir string) string {
Expand Down
15 changes: 13 additions & 2 deletions internal/inventory/dir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (m *mockFs) GetHomeDir() (string, error) {
return adjustPathForRuntimeOS("/HOME"), nil
}

func TestInventoryDirOnMacOSIsDotTfvmIfExists(t *testing.T) {
func TestInventoryDirOnMacOSIsDotTfvmIfExistsAndDotTfvmNotPresent(t *testing.T) {

inventoryDir, err := getInventoryDir(fs(&mockFs{existingDirs: []string{adjustPathForRuntimeOS("/HOME/.tfvm")}}), platformPkg.Platform{Os: "darwin", Arch: "arm64"})
if err != nil {
Expand All @@ -36,7 +36,18 @@ func TestInventoryDirOnMacOSIsDotTfvmIfExists(t *testing.T) {
assert.Equal(t, adjustPathForRuntimeOS("/HOME/.tfvm"), inventoryDir)
}

func TestInventoryDirOnMacOSIsLibraryCachesTfvmIfDotTfvmNotPresent(t *testing.T) {
func TestInventoryDirOnMacOSIsDotCacheTfvmIfExists(t *testing.T) {

inventoryDir, err := getInventoryDir(fs(&mockFs{existingDirs: []string{adjustPathForRuntimeOS("/HOME/.cache/tfvm")}}), platformPkg.Platform{Os: "darwin", Arch: "arm64"})
if err != nil {
t.Fatal(err)
return
}

assert.Equal(t, adjustPathForRuntimeOS("/HOME/.cache/tfvm"), inventoryDir)
}

func TestInventoryDirOnMacOSIsLibraryCachesTfvmIfNeitherDotTfvmNorDotCacheTfvmPresent(t *testing.T) {

inventoryDir, err := getInventoryDir(fs(&mockFs{existingDirs: []string{}}), platformPkg.Platform{Os: "darwin", Arch: "arm64"})
if err != nil {
Expand Down

0 comments on commit a9eae97

Please sign in to comment.