@@ -169,22 +169,53 @@ func Test_NewFileDirReader_Error(t *testing.T) {
169169 t .Parallel ()
170170
171171 rootDir := t .TempDir ()
172- noPerm := os .FileMode (0000 )
173- if err := os .WriteFile (filepath .Join (rootDir , "a.txt" ), []byte ("hello world!" ), noPerm ); err != nil {
172+ rwxPerm := os .FileMode (0755 )
173+ if err := os .WriteFile (filepath .Join (rootDir , "a.txt" ), []byte ("hello world!" ), rwxPerm ); err != nil {
174+ t .Fatalf ("unexpected error while WriteFile %v" , err )
175+ }
176+ if err := os .WriteFile (filepath .Join (rootDir , "z.txt" ), []byte ("hello world!" ), rwxPerm ); err != nil {
174177 t .Fatalf ("unexpected error while WriteFile %v" , err )
175178 }
176179 path := filepath .Join (rootDir , "sub" )
180+ noPerm := os .FileMode (0000 )
177181 if err := os .Mkdir (path , noPerm ); err != nil {
178182 t .Fatalf ("unexpected error while Mkdir %v" , err )
179183 }
180- _ , err := NewFileDirReader (rootDir , false , 10 )
184+
185+ path = filepath .Join (rootDir , "sub_2" )
186+ if err := os .Mkdir (path , rwxPerm ); err != nil {
187+ t .Fatalf ("unexpected error while Mkdir %v" , err )
188+ }
189+
190+ if err := os .WriteFile (filepath .Join (path , "www.txt" ), []byte ("hello world!" ), rwxPerm ); err != nil {
191+ t .Fatalf ("unexpected error while WriteFile %v" , err )
192+ }
193+
194+ sr , err := NewFileDirReader (rootDir , false , 10 )
181195 if err != nil {
182196 t .Errorf ("unexpected error while NewFileDirReader err:%v" , err )
183197 }
184- _ , err = NewFileDirReader (rootDir , true , 10 )
198+
199+ sr , err = NewFileDirReader (rootDir , true , 10 )
185200 if ! strings .Contains (err .Error (), "permission denied" ) {
186201 t .Errorf ("unexpected error permissions denied message got:%v" , err .Error ())
187202 }
203+
204+ if diff := cmp .Diff (
205+ & StringArrayReader {
206+ strings : []string {
207+ filepath .Join (rootDir , "a.txt" ),
208+ // note we are ignoring, and not getting back sub permission denied directory
209+ filepath .Join (rootDir , "sub_2/www.txt" ),
210+ filepath .Join (rootDir , "z.txt" ),
211+ },
212+ },
213+ sr ,
214+ cmp .AllowUnexported (StringArrayReader {}),
215+ ); diff != "" {
216+ t .Errorf ("unexpected StringArrayReader mismatch (-want +got):\n %s" , diff )
217+ }
218+
188219}
189220
190221func Test_pathDepth (t * testing.T ) {
0 commit comments