Skip to content

Commit

Permalink
fix: shuttle should resolve file not found in root (#210)
Browse files Browse the repository at this point in the history
Signed-off-by: Kasper J. Hermansen <[email protected]>
  • Loading branch information
kjuulh authored Jan 5, 2024
1 parent d82da95 commit 1fb5d5f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,12 @@ func shuttleFileExistsRecursive(projectPath string, existsFunc fileExistsFunc) b
return true
}

return shuttleFileExistsRecursive(path.Dir(projectPath), existsFunc)
parentProjectDir := path.Dir(projectPath)
if parentProjectDir == projectPath {
return false
}

return shuttleFileExistsRecursive(parentProjectDir, existsFunc)
}

return shuttleFileExists(projectPath, existsFunc)
Expand Down
22 changes: 22 additions & 0 deletions cmd/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,28 @@ func TestShuttleFileExistsRecursive(t *testing.T) {
assert.True(t, actual)
})

t.Run("full path, file not found", func(t *testing.T) {
actual := shuttleFileExistsRecursive("/some/long/path", func(filePath string) bool {
switch filePath {
case "/some/long/path/shuttle.yaml":
return false
case "/some/long/shuttle.yaml":
return false
case "/some/shuttle.yaml":
return false
case "/shuttle.yaml":
return false
case "/":
return false
default:
pathNotExpected(t, filePath)
return true
}
})

assert.False(t, actual)
})

t.Run("empty path, file false", func(t *testing.T) {
actual := shuttleFileExistsRecursive("", func(filePath string) bool {
switch filePath {
Expand Down

0 comments on commit 1fb5d5f

Please sign in to comment.