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) {
1286
1286
}
1287
1287
}
1288
1288
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
-
1322
1289
func TestIfExists_ProducesErrorPlusNoOutputForNonexistentFile (t * testing.T ) {
1323
1290
t .Parallel ()
1324
1291
want := ""
Original file line number Diff line number Diff line change 3
3
package script_test
4
4
5
5
import (
6
+ "os"
7
+ "path/filepath"
6
8
"testing"
7
9
8
10
"github.com/bitfield/script"
@@ -106,6 +108,38 @@ func TestExecPipesDataToExternalCommandAndGetsExpectedOutput(t *testing.T) {
106
108
}
107
109
}
108
110
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
+
109
143
func ExampleExec_ok () {
110
144
script .Exec ("echo Hello, world!" ).Stdout ()
111
145
// Output:
You can’t perform that action at this time.
0 commit comments