MCPcopy Create free account
hub / github.com/VirusTotal/vt-cli / Test_NewFileDirReader_Error

Function Test_NewFileDirReader_Error

utils/file_utils_test.go:168–219  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

166}
167
168func Test_NewFileDirReader_Error(t *testing.T) {
169 t.Parallel()
170
171 rootDir := t.TempDir()
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 {
177 t.Fatalf("unexpected error while WriteFile %v", err)
178 }
179 path := filepath.Join(rootDir, "sub")
180 noPerm := os.FileMode(0000)
181 if err := os.Mkdir(path, noPerm); err != nil {
182 t.Fatalf("unexpected error while Mkdir %v", err)
183 }
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)
195 if err != nil {
196 t.Errorf("unexpected error while NewFileDirReader err:%v", err)
197 }
198
199 sr, err = NewFileDirReader(rootDir, true, 10)
200 if !strings.Contains(err.Error(), "permission denied") {
201 t.Errorf("unexpected error permissions denied message got:%v", err.Error())
202 }
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
219}
220
221func Test_pathDepth(t *testing.T) {
222 t.Parallel()

Callers

nothing calls this directly

Calls 1

NewFileDirReaderFunction · 0.85

Tested by

no test coverage detected