MCPcopy
hub / github.com/crowdsecurity/crowdsec / TestListFilesAtPath

Function TestListFilesAtPath

pkg/csplugin/listfiles_test.go:14–59  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func TestListFilesAtPath(t *testing.T) {
15 dir := t.TempDir()
16
17 f, err := os.Create(filepath.Join(dir, "notification-gitter"))
18 require.NoError(t, err)
19 require.NoError(t, f.Close())
20
21 f, err = os.Create(filepath.Join(dir, "slack"))
22 require.NoError(t, err)
23 require.NoError(t, f.Close())
24
25 err = os.Mkdir(filepath.Join(dir, "somedir"), 0o755)
26 require.NoError(t, err)
27
28 f, err = os.Create(filepath.Join(dir, "somedir", "inner"))
29 require.NoError(t, err)
30 require.NoError(t, f.Close())
31
32 tests := []struct {
33 name string
34 path string
35 want []string
36 expectedErr string
37 }{
38 {
39 name: "valid directory",
40 path: dir,
41 want: []string{
42 filepath.Join(dir, "notification-gitter"),
43 filepath.Join(dir, "slack"),
44 },
45 },
46 {
47 name: "invalid directory",
48 path: "./foo/bar/",
49 expectedErr: "open ./foo/bar/: " + cstest.PathNotFoundMessage,
50 },
51 }
52 for _, tc := range tests {
53 t.Run(tc.name, func(t *testing.T) {
54 got, err := listFilesAtPath(tc.path)
55 cstest.RequireErrorContains(t, err, tc.expectedErr)
56 assert.ElementsMatch(t, tc.want, got)
57 })
58 }
59}

Callers

nothing calls this directly

Calls 4

listFilesAtPathFunction · 0.85
RunMethod · 0.65
CreateMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…