File tree Expand file tree Collapse file tree 2 files changed +34
-33
lines changed
Expand file tree Collapse file tree 2 files changed +34
-33
lines changed Original file line number Diff line number Diff line change @@ -1286,39 +1286,6 @@ func TestFindFiles_InNonexistentPathReturnsError(t *testing.T) {
12861286 }
12871287}
12881288
1289- func TestFindFiles_DoesNotErrorWhenSubDirectoryIsNotReadable (t * testing.T ) {
1290- t .Parallel ()
1291- tmpDir := t .TempDir ()
1292- fileAPath := filepath .Join (tmpDir , "file_a.txt" )
1293- if err := os .WriteFile (fileAPath , []byte ("hello world!" ), os .ModePerm ); err != nil {
1294- t .Fatal (err )
1295- }
1296- restrictedDirPath := filepath .Join (tmpDir , "restricted_dir" )
1297- if err := os .Mkdir (restrictedDirPath , os .ModePerm ); err != nil {
1298- t .Fatal (err )
1299- }
1300- fileBPath := filepath .Join (restrictedDirPath , "file_b.txt" )
1301- if err := os .WriteFile (fileBPath , []byte ("hello again!" ), os .ModePerm ); err != nil {
1302- t .Fatal (err )
1303- }
1304- if err := os .Chmod (restrictedDirPath , 0o000 ); err != nil {
1305- t .Fatal (err )
1306- }
1307- t .Cleanup (func () { os .Chmod (restrictedDirPath , os .ModePerm ) })
1308- p := script .FindFiles (tmpDir )
1309- if p .Error () != nil {
1310- t .Fatal (p .Error ())
1311- }
1312- want := fileAPath + "\n "
1313- got , err := p .String ()
1314- if err != nil {
1315- t .Fatal (err )
1316- }
1317- if ! cmp .Equal (want , got ) {
1318- t .Fatal (cmp .Diff (want , got ))
1319- }
1320- }
1321-
13221289func TestIfExists_ProducesErrorPlusNoOutputForNonexistentFile (t * testing.T ) {
13231290 t .Parallel ()
13241291 want := ""
Original file line number Diff line number Diff line change 33package script_test
44
55import (
6+ "os"
7+ "path/filepath"
68 "testing"
79
810 "github.com/bitfield/script"
@@ -106,6 +108,38 @@ func TestExecPipesDataToExternalCommandAndGetsExpectedOutput(t *testing.T) {
106108 }
107109}
108110
111+ func TestFindFiles_DoesNotErrorWhenSubDirectoryIsNotReadable (t * testing.T ) {
112+ t .Parallel ()
113+ tmpDir := t .TempDir ()
114+ fileAPath := filepath .Join (tmpDir , "file_a.txt" )
115+ if err := os .WriteFile (fileAPath , []byte ("hello world!" ), os .ModePerm ); err != nil {
116+ t .Fatal (err )
117+ }
118+ restrictedDirPath := filepath .Join (tmpDir , "restricted_dir" )
119+ if err := os .Mkdir (restrictedDirPath , os .ModePerm ); err != nil {
120+ t .Fatal (err )
121+ }
122+ fileBPath := filepath .Join (restrictedDirPath , "file_b.txt" )
123+ if err := os .WriteFile (fileBPath , []byte ("hello again!" ), os .ModePerm ); err != nil {
124+ t .Fatal (err )
125+ }
126+ if err := os .Chmod (restrictedDirPath , 0o000 ); err != nil {
127+ t .Fatal (err )
128+ }
129+ t .Cleanup (func () { os .Chmod (restrictedDirPath , os .ModePerm ) })
130+ got , err := script .FindFiles (tmpDir ).String ()
131+ if err != nil {
132+ t .Fatal (err )
133+ }
134+ want := fileAPath + "\n "
135+ if err != nil {
136+ t .Fatal (err )
137+ }
138+ if ! cmp .Equal (want , got ) {
139+ t .Fatal (cmp .Diff (want , got ))
140+ }
141+ }
142+
109143func ExampleExec_ok () {
110144 script .Exec ("echo Hello, world!" ).Stdout ()
111145 // Output:
You can’t perform that action at this time.
0 commit comments