Skip to content

Commit

Permalink
Add IsPathAccessible API
Browse files Browse the repository at this point in the history
  • Loading branch information
eyalbe4 committed Aug 16, 2024
1 parent 724b4ee commit 40a9aff
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions utils/io/fileutils/files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,16 @@ import (
)

func TestIsPathExistsAndIsPathAccessible(t *testing.T) {
var symlinkPath string
symlinkCreated := false

// Create a temporary file
tempFile, err := os.CreateTemp("", "testfile")
assert.NoError(t, err)
defer func() {
if symlinkCreated {
assert.NoError(t, os.Remove(symlinkPath))
}
assert.NoError(t, os.Remove(tempFile.Name()))
}()

Expand All @@ -45,12 +51,10 @@ func TestIsPathExistsAndIsPathAccessible(t *testing.T) {
assert.False(t, IsPathAccessible(tempDir+"_nonexistent"))

// Create a symlink and test with preserveSymLink true and false
symlinkPath := tempFile.Name() + "_symlink"
symlinkPath = tempFile.Name() + "_symlink"
err = os.Symlink(tempFile.Name(), symlinkPath)
assert.NoError(t, err)
defer func() {
assert.NoError(t, os.Remove(symlinkPath))
}()
symlinkCreated = true

assert.True(t, IsPathExists(symlinkPath, true))
assert.True(t, IsPathExists(symlinkPath, false))
Expand Down

0 comments on commit 40a9aff

Please sign in to comment.