Skip to content

Commit ec5d776

Browse files
committed
add test for new read-file check
1 parent edbd074 commit ec5d776

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

test/eca/features/tools/filesystem_test.clj

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,18 @@
6464
((get-in f.tools.filesystem/definitions ["eca_read_file" :handler])
6565
{"path" (h/file-path "/foo/qux")}
6666
{:db {:workspace-folders [{:uri (h/file-uri "file:///foo/bar/baz") :name "foo"}]}})))))
67+
(testing "Path is a directory"
68+
(is (match?
69+
{:error true
70+
:contents [{:type :text
71+
:text (format "%s is a directory, not a file" (h/file-path "/foo/dir"))}]}
72+
(with-redefs [fs/exists? (constantly true)
73+
fs/readable? (constantly true)
74+
fs/directory? (constantly true)
75+
f.tools.filesystem/allowed-path? (constantly true)]
76+
((get-in f.tools.filesystem/definitions ["eca_read_file" :handler])
77+
{"path" (h/file-path "/foo/dir")}
78+
{:db {:workspace-folders [{:uri (h/file-uri "file:///foo/bar/baz") :name "foo"}]}})))))
6779
(testing "Readable path"
6880
(is (match?
6981
{:error false
@@ -72,6 +84,7 @@
7284
(with-redefs [slurp (constantly "fooo")
7385
fs/exists? (constantly true)
7486
fs/readable? (constantly true)
87+
fs/directory? (constantly false)
7588
f.tools.filesystem/allowed-path? (constantly true)]
7689
((get-in f.tools.filesystem/definitions ["eca_read_file" :handler])
7790
{"path" (h/file-path "/foo/qux")}

0 commit comments

Comments
 (0)