From 06a69c3c04adcad117b6b972be9b4948393f31e3 Mon Sep 17 00:00:00 2001 From: Adrian-George Bostan Date: Fri, 11 Oct 2024 16:23:46 +0300 Subject: [PATCH] Update test cases to account for XDG_BIN_HOME directory addition --- paths_darwin_test.go | 33 +++++++++++++++++++++++++-------- paths_plan9_test.go | 11 +++++++++++ paths_unix_test.go | 33 +++++++++++++++++++++++++-------- paths_windows_test.go | 38 ++++++++++++++++++++++++++++++-------- 4 files changed, 91 insertions(+), 24 deletions(-) diff --git a/paths_darwin_test.go b/paths_darwin_test.go index 13af1bd..95b1222 100644 --- a/paths_darwin_test.go +++ b/paths_darwin_test.go @@ -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{ @@ -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", @@ -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", @@ -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, + }, ) } diff --git a/paths_plan9_test.go b/paths_plan9_test.go index 9fff760..7ee3700 100644 --- a/paths_plan9_test.go +++ b/paths_plan9_test.go @@ -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{ @@ -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, + }, ) } diff --git a/paths_unix_test.go b/paths_unix_test.go index f0d21ad..38c44b1 100644 --- a/paths_unix_test.go +++ b/paths_unix_test.go @@ -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{ @@ -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", @@ -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", @@ -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, + }, ) } diff --git a/paths_windows_test.go b/paths_windows_test.go index 8407686..9c64455 100644 --- a/paths_windows_test.go +++ b/paths_windows_test.go @@ -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{ { @@ -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, }, @@ -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", @@ -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", @@ -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))