Skip to content

Commit

Permalink
Update test cases to account for XDG_BIN_HOME directory addition
Browse files Browse the repository at this point in the history
  • Loading branch information
adrg committed Oct 11, 2024
1 parent b04f107 commit 06a69c3
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 24 deletions.
33 changes: 25 additions & 8 deletions paths_darwin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ func TestDefaultBaseDirs(t *testing.T) {
expected: homeAppSupport,
actual: &xdg.RuntimeDir,
},
&envSample{
name: "XDG_BIN_HOME",
expected: filepath.Join(home, ".local", "bin"),
actual: &xdg.BinHome,
},
&envSample{
name: "XDG_APPLICATION_DIRS",
expected: []string{
Expand Down Expand Up @@ -87,10 +92,13 @@ func TestCustomBaseDirs(t *testing.T) {
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,
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",
Expand All @@ -99,10 +107,13 @@ func TestCustomBaseDirs(t *testing.T) {
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,
name: "XDG_CONFIG_DIRS",
value: "~/Library/config:/Library/Preferences",
expected: []string{
filepath.Join(home, "Library/config"),
"/Library/Preferences",
},
actual: &xdg.ConfigDirs,
},
&envSample{
name: "XDG_STATE_HOME",
Expand All @@ -122,6 +133,12 @@ func TestCustomBaseDirs(t *testing.T) {
expected: filepath.Join(home, "Library/runtime"),
actual: &xdg.RuntimeDir,
},
&envSample{
name: "XDG_BIN_HOME",
value: "~/Library/bin",
expected: filepath.Join(home, "Library/bin"),
actual: &xdg.BinHome,
},
)
}

Expand Down
11 changes: 11 additions & 0 deletions paths_plan9_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ func TestDefaultBaseDirs(t *testing.T) {
expected: "/tmp",
actual: &xdg.RuntimeDir,
},
&envSample{
name: "XDG_BIN_HOME",
expected: filepath.Join(home, "bin"),
actual: &xdg.BinHome,
},
&envSample{
name: "XDG_APPLICATION_DIRS",
expected: []string{
Expand Down Expand Up @@ -115,6 +120,12 @@ func TestCustomBaseDirs(t *testing.T) {
expected: filepath.Join(homeLib, "runtime"),
actual: &xdg.RuntimeDir,
},
&envSample{
name: "XDG_BIN_HOME",
value: filepath.Join(homeLib, "bin"),
expected: filepath.Join(homeLib, "bin"),
actual: &xdg.BinHome,
},
)
}

Expand Down
33 changes: 25 additions & 8 deletions paths_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ func TestDefaultBaseDirs(t *testing.T) {
expected: filepath.Join("/run/user", strconv.Itoa(os.Getuid())),
actual: &xdg.RuntimeDir,
},
&envSample{
name: "XDG_BIN_HOME",
expected: filepath.Join(home, ".local", "bin"),
actual: &xdg.BinHome,
},
&envSample{
name: "XDG_APPLICATION_DIRS",
expected: []string{
Expand Down Expand Up @@ -85,10 +90,13 @@ func TestCustomBaseDirs(t *testing.T) {
actual: &xdg.DataHome,
},
&envSample{
name: "XDG_DATA_DIRS",
value: "~/.local/data:/usr/share",
expected: []string{filepath.Join(home, ".local/data"), "/usr/share"},
actual: &xdg.DataDirs,
name: "XDG_DATA_DIRS",
value: "~/.local/data:/usr/share",
expected: []string{
filepath.Join(home, ".local/data"),
"/usr/share",
},
actual: &xdg.DataDirs,
},
&envSample{
name: "XDG_CONFIG_HOME",
Expand All @@ -97,10 +105,13 @@ func TestCustomBaseDirs(t *testing.T) {
actual: &xdg.ConfigHome,
},
&envSample{
name: "XDG_CONFIG_DIRS",
value: "~/.local/config:/etc/xdg",
expected: []string{filepath.Join(home, ".local/config"), "/etc/xdg"},
actual: &xdg.ConfigDirs,
name: "XDG_CONFIG_DIRS",
value: "~/.local/config:/etc/xdg",
expected: []string{
filepath.Join(home, ".local/config"),
"/etc/xdg",
},
actual: &xdg.ConfigDirs,
},
&envSample{
name: "XDG_STATE_HOME",
Expand All @@ -120,6 +131,12 @@ func TestCustomBaseDirs(t *testing.T) {
expected: filepath.Join(home, ".local/runtime"),
actual: &xdg.RuntimeDir,
},
&envSample{
name: "XDG_BIN_HOME",
value: "~/bin",
expected: filepath.Join(home, "bin"),
actual: &xdg.BinHome,
},
)
}

Expand Down
38 changes: 30 additions & 8 deletions paths_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func TestDefaultBaseDirs(t *testing.T) {
localAppData := filepath.Join(home, "AppData", "Local")
systemRoot := filepath.Join(systemDrive, "Windows")
programData := filepath.Join(systemDrive, "ProgramData")
programFiles := filepath.Join(systemDrive, "Program Files")

envSamples := []*envSample{
{
Expand Down Expand Up @@ -56,11 +57,20 @@ func TestDefaultBaseDirs(t *testing.T) {
expected: localAppData,
actual: &xdg.RuntimeDir,
},
{
name: "XDG_BIN_HOME",
expected: filepath.Join(localAppData, "Programs"),
actual: &xdg.BinHome,
},
{
name: "XDG_APPLICATION_DIRS",
expected: []string{
filepath.Join(roamingAppData, "Microsoft", "Windows", "Start Menu", "Programs"),
filepath.Join(programData, "Microsoft", "Windows", "Start Menu", "Programs"),
programFiles,
filepath.Join(programFiles, "Common Files"),
filepath.Join(localAppData, "Programs"),
filepath.Join(localAppData, "Programs", "Common"),
},
actual: &xdg.ApplicationDirs,
},
Expand Down Expand Up @@ -105,10 +115,13 @@ func TestCustomBaseDirs(t *testing.T) {
actual: &xdg.DataHome,
},
&envSample{
name: "XDG_DATA_DIRS",
value: fmt.Sprintf("%s;%s", filepath.Join(localAppData, "Data"), filepath.Join(roamingAppData, "Data")),
expected: []string{filepath.Join(localAppData, "Data"), filepath.Join(roamingAppData, "Data")},
actual: &xdg.DataDirs,
name: "XDG_DATA_DIRS",
value: fmt.Sprintf("%s;%s", filepath.Join(localAppData, "Data"), filepath.Join(roamingAppData, "Data")),
expected: []string{
filepath.Join(localAppData, "Data"),
filepath.Join(roamingAppData, "Data"),
},
actual: &xdg.DataDirs,
},
&envSample{
name: "XDG_CONFIG_HOME",
Expand All @@ -117,10 +130,13 @@ func TestCustomBaseDirs(t *testing.T) {
actual: &xdg.ConfigHome,
},
&envSample{
name: "XDG_CONFIG_DIRS",
value: fmt.Sprintf("%s;%s", filepath.Join(localAppData, "Config"), filepath.Join(roamingAppData, "Config")),
expected: []string{filepath.Join(localAppData, "Config"), filepath.Join(roamingAppData, "Config")},
actual: &xdg.ConfigDirs,
name: "XDG_CONFIG_DIRS",
value: fmt.Sprintf("%s;%s", filepath.Join(localAppData, "Config"), filepath.Join(roamingAppData, "Config")),
expected: []string{
filepath.Join(localAppData, "Config"),
filepath.Join(roamingAppData, "Config"),
},
actual: &xdg.ConfigDirs,
},
&envSample{
name: "XDG_STATE_HOME",
Expand All @@ -140,6 +156,12 @@ func TestCustomBaseDirs(t *testing.T) {
expected: filepath.Join(programData, "Runtime"),
actual: &xdg.RuntimeDir,
},
&envSample{
name: "XDG_BIN_HOME",
value: filepath.Join(programData, "Programs"),
expected: filepath.Join(programData, "Programs"),
actual: &xdg.BinHome,
},
)

require.NoError(t, os.Setenv("APPDATA", envRoamingAppData))
Expand Down

0 comments on commit 06a69c3

Please sign in to comment.