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

Function TestOneShot

pkg/acquisition/modules/file/file_test.go:66–212  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

64}
65
66func TestOneShot(t *testing.T) {
67 ctx := t.Context()
68 tmpDir := t.TempDir()
69 deletedFile := filepath.Join(tmpDir, "test_delete.log")
70
71 permDeniedFile := "/etc/shadow"
72 permDeniedError := "failed opening /etc/shadow: open /etc/shadow: permission denied"
73
74 if runtime.GOOS == "windows" {
75 // Technically, this is not a permission denied error, but we just want to test what happens
76 // if we do not have access to the file
77 permDeniedFile = `C:\Windows\System32\config\SAM`
78 permDeniedError = `failed opening C:\Windows\System32\config\SAM: open C:\Windows\System32\config\SAM: The process cannot access the file because it is being used by another process.`
79 }
80
81 tests := []struct {
82 name string
83 config string
84 expectedConfigErr string
85 expectedErr string
86 expectedOutput string
87 expectedLines int
88 logLevel log.Level
89 setup func()
90 afterConfigure func()
91 teardown func()
92 }{
93 {
94 name: "permission denied",
95 config: fmt.Sprintf(`
96mode: cat
97filename: %s`, permDeniedFile),
98 expectedErr: permDeniedError,
99 logLevel: log.WarnLevel,
100 expectedLines: 0,
101 },
102 {
103 name: "ignored directory",
104 config: `
105mode: cat
106filename: /`,
107 expectedOutput: "/ is a directory, ignoring it",
108 logLevel: log.WarnLevel,
109 expectedLines: 0,
110 },
111 {
112 name: "glob syntax error",
113 config: `
114mode: cat
115filename: "[*-.log"`,
116 expectedConfigErr: "glob failure: syntax error in pattern",
117 logLevel: log.WarnLevel,
118 expectedLines: 0,
119 },
120 {
121 name: "no matching files",
122 config: `
123mode: cat

Callers

nothing calls this directly

Calls 8

ConfigureMethod · 0.95
OneShotMethod · 0.95
SetLevelMethod · 0.80
RunMethod · 0.65
CreateMethod · 0.45
CloseMethod · 0.45
LenMethod · 0.45
ResetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…