Skip to content

Commit

Permalink
Improve non-existent runtime directory test case
Browse files Browse the repository at this point in the history
  • Loading branch information
adrg committed Oct 31, 2024
1 parent 800775a commit d9f76be
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions xdg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ func TestInvalidPaths(t *testing.T) {

func TestNonExistentRuntimeDir(t *testing.T) {
var (
runtimeFiles = []string{"app.pid", "appname/app.pid"}
envRuntimeDirVar = "XDG_RUNTIME_DIR"
originalRuntimeDir = xdg.RuntimeDir
nonExistentRuntimeDir = filepath.Join(xdg.Home, "runtime")
Expand All @@ -212,7 +213,18 @@ func TestNonExistentRuntimeDir(t *testing.T) {
xdg.Reload()
require.Equal(t, nonExistentRuntimeDir, xdg.RuntimeDir)

p, err := xdg.RuntimeFile("app.pid")
require.NoError(t, err)
require.Equal(t, filepath.Clean(os.TempDir()), filepath.Dir(p))
for _, runtimeFile := range runtimeFiles {
suggestedPath, err := xdg.RuntimeFile(runtimeFile)
require.NoError(t, err)
require.Equal(t, true, strings.HasPrefix(suggestedPath, os.TempDir()))

f, err := os.Create(suggestedPath)
require.NoError(t, err)
require.NoError(t, f.Close())
defer os.Remove(suggestedPath)

foundPath, err := xdg.SearchRuntimeFile(runtimeFile)
require.NoError(t, err)
require.Equal(t, suggestedPath, foundPath)
}
}

0 comments on commit d9f76be

Please sign in to comment.