From 526c4f430a771b07e2e47d702f4dc24307b405bd Mon Sep 17 00:00:00 2001 From: Seth Hoenig Date: Thu, 29 Feb 2024 16:42:10 +0000 Subject: [PATCH] test: fix FileExists assertion where relative paths did not work --- must/must.go | 5 +++-- test.go | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/must/must.go b/must/must.go index ca976d6..4488e96 100644 --- a/must/must.go +++ b/must/must.go @@ -510,8 +510,9 @@ func FileExistsFS(t T, system fs.FS, file string, settings ...Setting) { // FileExists asserts file exists on the OS filesystem. func FileExists(t T, file string, settings ...Setting) { t.Helper() - file = strings.TrimPrefix(file, "/") - invoke(t, assertions.FileExistsFS(os.DirFS(brokenfs.Root), file), settings...) + dir := filepath.Dir(file) + file = filepath.Base(file) + invoke(t, assertions.FileExistsFS(os.DirFS(dir), file), settings...) } // FileNotExistsFS asserts file does not exist on the fs.FS filesystem. diff --git a/test.go b/test.go index 2723cd2..94b0481 100644 --- a/test.go +++ b/test.go @@ -508,8 +508,9 @@ func FileExistsFS(t T, system fs.FS, file string, settings ...Setting) { // FileExists asserts file exists on the OS filesystem. func FileExists(t T, file string, settings ...Setting) { t.Helper() - file = strings.TrimPrefix(file, "/") - invoke(t, assertions.FileExistsFS(os.DirFS(brokenfs.Root), file), settings...) + dir := filepath.Dir(file) + file = filepath.Base(file) + invoke(t, assertions.FileExistsFS(os.DirFS(dir), file), settings...) } // FileNotExistsFS asserts file does not exist on the fs.FS filesystem.