File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -72,15 +72,15 @@ func (*FS) Getwd() (string, error) {
7272// FileExists returns true if the file at the given path exists and is readable.
7373// Returns false if the given file is a directory.
7474func (f * FS ) FileExists (name string ) bool {
75- if stats , err := f .Stat (path . Join ( f . dir , name ) ); err == nil {
75+ if stats , err := f .Stat (name ); err == nil {
7676 return ! stats .IsDir ()
7777 }
7878 return false
7979}
8080
8181// IsDirectory returns true if the file at the given path exists, is a directory and is readable.
8282func (f * FS ) IsDirectory (name string ) bool {
83- if stats , err := f .Stat (path . Join ( f . dir , name ) ); err == nil {
83+ if stats , err := f .Stat (name ); err == nil {
8484 return stats .IsDir ()
8585 }
8686 return false
Original file line number Diff line number Diff line change @@ -99,13 +99,27 @@ func TestOSFS(t *testing.T) {
9999 assert .False (t , fs .FileExists ("resources/notafile.txt" ))
100100 })
101101
102+ t .Run ("FileExistsWithBaseDir" , func (t * testing.T ) {
103+ fs := New ("resources" )
104+ assert .True (t , fs .FileExists ("test_file.txt" ))
105+ assert .False (t , fs .FileExists ("lang" ))
106+ assert .False (t , fs .FileExists ("notafile.txt" ))
107+ })
108+
102109 t .Run ("IsDirectory" , func (t * testing.T ) {
103110 fs := & FS {}
104111 assert .False (t , fs .IsDirectory ("resources/test_file.txt" ))
105112 assert .True (t , fs .IsDirectory ("resources" ))
106113 assert .False (t , fs .IsDirectory ("resources/notadir" ))
107114 })
108115
116+ t .Run ("IsDirectoryWithBaseDir" , func (t * testing.T ) {
117+ fs := New ("resources" )
118+ assert .False (t , fs .IsDirectory ("test_file.txt" ))
119+ assert .True (t , fs .IsDirectory ("lang" ))
120+ assert .False (t , fs .IsDirectory ("notadir" ))
121+ })
122+
109123 t .Run ("Mkdir" , func (t * testing.T ) {
110124 fs := & FS {}
111125 path := "resources/testdir"
You can’t perform that action at this time.
0 commit comments