Skip to content

Commit

Permalink
Add Mac OS test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
adrg committed Nov 10, 2019
1 parent 33e2c3e commit cdecb0f
Show file tree
Hide file tree
Showing 3 changed files with 221 additions and 29 deletions.
2 changes: 1 addition & 1 deletion paths_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ func initBaseDirs(home string) {
baseDirs.DataHome = xdgPath(envDataHome, filepath.Join(home, "Library", "Application Support"))
baseDirs.Data = xdgPaths(envDataDirs, "/Library/Application Support")
baseDirs.ConfigHome = xdgPath(envConfigHome, filepath.Join(home, "Library", "Preferences"))
baseDirs.Config = xdgPaths(envConfigDirs)
baseDirs.Config = xdgPaths(envConfigDirs, "/Library/Preferences")
baseDirs.CacheHome = xdgPath(envCacheHome, filepath.Join(home, "Library", "Caches"))
baseDirs.Runtime = xdgPath(envRuntimeDir, filepath.Join(home, "Library", "Application Support"))
}
Expand Down
192 changes: 192 additions & 0 deletions paths_darwin_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
// +build darwin

package xdg_test

import (
"path/filepath"
"testing"

"github.com/adrg/xdg"
)

func TestDefaultBaseDirs(t *testing.T) {
home := xdg.Home

testDirs(t,
&envSample{
name: "XDG_DATA_HOME",
expected: filepath.Join(home, "Library", "Application Support"),
actual: &xdg.DataHome,
},
&envSample{
name: "XDG_DATA_DIRS",
expected: []string{"/Library/Application Support"},
actual: &xdg.DataDirs,
},
&envSample{
name: "XDG_CONFIG_HOME",
expected: filepath.Join(home, "Library", "Preferences"),
actual: &xdg.ConfigHome,
},
&envSample{
name: "XDG_CONFIG_DIRS",
expected: []string{"/Library/Preferences"},
actual: &xdg.ConfigDirs,
},
&envSample{
name: "XDG_CACHE_HOME",
expected: filepath.Join(home, "Library", "Caches"),
actual: &xdg.CacheHome,
},
&envSample{
name: "XDG_RUNTIME_DIR",
expected: filepath.Join(home, "Library", "Application Support"),
actual: &xdg.RuntimeDir,
},
)
}

func TestCustomBaseDirs(t *testing.T) {
home := xdg.Home

testDirs(t,
&envSample{
name: "XDG_DATA_HOME",
value: "~/Library/data",
expected: filepath.Join(home, "Library/data"),
actual: &xdg.DataHome,
},
&envSample{
name: "XDG_DATA_DIRS",
value: "~/Library/data:/Library/Application Support",
expected: []string{filepath.Join(home, "Library/data"), "/Library/Application Support"},
actual: &xdg.DataDirs,
},
&envSample{
name: "XDG_CONFIG_HOME",
value: "~/Library/config",
expected: filepath.Join(home, "Library/config"),
actual: &xdg.ConfigHome,
},
&envSample{
name: "XDG_CONFIG_DIRS",
value: "~/Library/config:/Library/Preferences",
expected: []string{filepath.Join(home, "Library/config"), "/Library/Preferences"},
actual: &xdg.ConfigDirs,
},
&envSample{
name: "XDG_CACHE_HOME",
value: "~/Library/cache",
expected: filepath.Join(home, "Library/cache"),
actual: &xdg.CacheHome,
},
&envSample{
name: "XDG_RUNTIME_DIR",
value: "~/Library/runtime",
expected: filepath.Join(home, "Library/runtime"),
actual: &xdg.RuntimeDir,
},
)
}

func TestDefaultUserDirs(t *testing.T) {
home := xdg.Home

testDirs(t,
&envSample{
name: "XDG_DESKTOP_DIR",
expected: filepath.Join(home, "Desktop"),
actual: &xdg.UserDirs.Desktop,
},
&envSample{
name: "XDG_DOWNLOAD_DIR",
expected: filepath.Join(home, "Downloads"),
actual: &xdg.UserDirs.Download,
},
&envSample{
name: "XDG_DOCUMENTS_DIR",
expected: filepath.Join(home, "Documents"),
actual: &xdg.UserDirs.Documents,
},
&envSample{
name: "XDG_MUSIC_DIR",
expected: filepath.Join(home, "Music"),
actual: &xdg.UserDirs.Music,
},
&envSample{
name: "XDG_PICTURES_DIR",
expected: filepath.Join(home, "Pictures"),
actual: &xdg.UserDirs.Pictures,
},
&envSample{
name: "XDG_VIDEOS_DIR",
expected: filepath.Join(home, "Movies"),
actual: &xdg.UserDirs.Videos,
},
&envSample{
name: "XDG_TEMPLATES_DIR",
expected: filepath.Join(home, "Templates"),
actual: &xdg.UserDirs.Templates,
},
&envSample{
name: "XDG_PUBLICSHARE_DIR",
expected: filepath.Join(home, "Public"),
actual: &xdg.UserDirs.PublicShare,
},
)
}

func TestCustomUserDirs(t *testing.T) {
home := xdg.Home

testDirs(t,
&envSample{
name: "XDG_DESKTOP_DIR",
value: "$HOME/Library/Desktop",
expected: filepath.Join(home, "Library/Desktop"),
actual: &xdg.UserDirs.Desktop,
},
&envSample{
name: "XDG_DOWNLOAD_DIR",
value: "$HOME/Library/Downloads",
expected: filepath.Join(home, "Library/Downloads"),
actual: &xdg.UserDirs.Download,
},
&envSample{
name: "XDG_DOCUMENTS_DIR",
value: "$HOME/Library/Documents",
expected: filepath.Join(home, "Library/Documents"),
actual: &xdg.UserDirs.Documents,
},
&envSample{
name: "XDG_MUSIC_DIR",
value: "$HOME/Library/Music",
expected: filepath.Join(home, "Library/Music"),
actual: &xdg.UserDirs.Music,
},
&envSample{
name: "XDG_PICTURES_DIR",
value: "$HOME/Library/Pictures",
expected: filepath.Join(home, "Library/Pictures"),
actual: &xdg.UserDirs.Pictures,
},
&envSample{
name: "XDG_VIDEOS_DIR",
value: "$HOME/Library/Movies",
expected: filepath.Join(home, "Library/Movies"),
actual: &xdg.UserDirs.Videos,
},
&envSample{
name: "XDG_TEMPLATES_DIR",
value: "$HOME/Library/Templates",
expected: filepath.Join(home, "Library/Templates"),
actual: &xdg.UserDirs.Templates,
},
&envSample{
name: "XDG_PUBLICSHARE_DIR",
value: "$HOME/Library/Public",
expected: filepath.Join(home, "Library/Public"),
actual: &xdg.UserDirs.PublicShare,
},
)
}
56 changes: 28 additions & 28 deletions paths_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,38 +54,38 @@ func TestCustomBaseDirs(t *testing.T) {
testDirs(t,
&envSample{
name: "XDG_DATA_HOME",
value: "~/.data/home",
expected: filepath.Join(home, ".data/home"),
value: "~/.local/data",
expected: filepath.Join(home, ".local/data"),
actual: &xdg.DataHome,
},
&envSample{
name: "XDG_DATA_DIRS",
value: "~/.data/dirs:/usr/share",
expected: []string{filepath.Join(home, ".data/dirs"), "/usr/share"},
value: "~/.local/data:/usr/share",
expected: []string{filepath.Join(home, ".local/data"), "/usr/share"},
actual: &xdg.DataDirs,
},
&envSample{
name: "XDG_CONFIG_HOME",
value: "~/.config/home",
expected: filepath.Join(home, ".config/home"),
value: "~/.local/config",
expected: filepath.Join(home, ".local/config"),
actual: &xdg.ConfigHome,
},
&envSample{
name: "XDG_CONFIG_DIRS",
value: "~/.config/dirs:/etc/xdg",
expected: []string{filepath.Join(home, ".config/dirs"), "/etc/xdg"},
value: "~/.local/config:/etc/xdg",
expected: []string{filepath.Join(home, ".local/config"), "/etc/xdg"},
actual: &xdg.ConfigDirs,
},
&envSample{
name: "XDG_CACHE_HOME",
value: "~/.cache/home",
expected: filepath.Join(home, ".cache/home"),
value: "~/.local/cache",
expected: filepath.Join(home, ".local/cache"),
actual: &xdg.CacheHome,
},
&envSample{
name: "XDG_RUNTIME_DIR",
value: filepath.Join(os.TempDir(), "runtime"),
expected: filepath.Join(os.TempDir(), "runtime"),
value: "~/.local/runtime",
expected: filepath.Join(home, ".local/runtime"),
actual: &xdg.RuntimeDir,
},
)
Expand Down Expand Up @@ -144,50 +144,50 @@ func TestCustomUserDirs(t *testing.T) {
testDirs(t,
&envSample{
name: "XDG_DESKTOP_DIR",
value: "$HOME/files/desktop",
expected: filepath.Join(home, "files/desktop"),
value: "$HOME/.local/Desktop",
expected: filepath.Join(home, ".local/Desktop"),
actual: &xdg.UserDirs.Desktop,
},
&envSample{
name: "XDG_DOWNLOAD_DIR",
value: "$HOME/files/downloads",
expected: filepath.Join(home, "files/downloads"),
value: "$HOME/.local/Downloads",
expected: filepath.Join(home, ".local/Downloads"),
actual: &xdg.UserDirs.Download,
},
&envSample{
name: "XDG_DOCUMENTS_DIR",
value: "$HOME/files/documents",
expected: filepath.Join(home, "files/documents"),
value: "$HOME/.local/Documents",
expected: filepath.Join(home, ".local/Documents"),
actual: &xdg.UserDirs.Documents,
},
&envSample{
name: "XDG_MUSIC_DIR",
value: "$HOME/files/music",
expected: filepath.Join(home, "files/music"),
value: "$HOME/.local/Music",
expected: filepath.Join(home, ".local/Music"),
actual: &xdg.UserDirs.Music,
},
&envSample{
name: "XDG_PICTURES_DIR",
value: "$HOME/files/pictures",
expected: filepath.Join(home, "files/pictures"),
value: "$HOME/.local/Pictures",
expected: filepath.Join(home, ".local/Pictures"),
actual: &xdg.UserDirs.Pictures,
},
&envSample{
name: "XDG_VIDEOS_DIR",
value: "$HOME/files/videos",
expected: filepath.Join(home, "files/videos"),
value: "$HOME/.local/Videos",
expected: filepath.Join(home, ".local/Videos"),
actual: &xdg.UserDirs.Videos,
},
&envSample{
name: "XDG_TEMPLATES_DIR",
value: "$HOME/files/templates",
expected: filepath.Join(home, "files/templates"),
value: "$HOME/.local/Templates",
expected: filepath.Join(home, ".local/Templates"),
actual: &xdg.UserDirs.Templates,
},
&envSample{
name: "XDG_PUBLICSHARE_DIR",
value: "$HOME/files/public",
expected: filepath.Join(home, "files/public"),
value: "$HOME/.local/Public",
expected: filepath.Join(home, ".local/Public"),
actual: &xdg.UserDirs.PublicShare,
},
)
Expand Down

0 comments on commit cdecb0f

Please sign in to comment.