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

Function TestOneShot

pkg/acquisition/modules/journalctl/journalctl_test.go:71–127  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

69}
70
71func TestOneShot(t *testing.T) {
72 cstest.SkipOnWindows(t)
73
74 ctx := t.Context()
75
76 tests := []struct {
77 config string
78 wantErr string
79 wantLines int
80 wantLog []string
81 }{
82 {
83 config: `
84source: journalctl
85mode: cat
86journalctl_filter:
87 - "-_UID=42"`,
88 wantErr: "exit status 1",
89 wantLog: []string{
90 "Got stderr: journalctl: invalid option -- '_'",
91 },
92 wantLines: 0,
93 },
94 {
95 config: `
96source: journalctl
97mode: cat
98journalctl_filter:
99 - _SYSTEMD_UNIT=ssh.service`,
100 wantLines: 14,
101 },
102 }
103 for _, ts := range tests {
104 t.Run(ts.config, func(t *testing.T) {
105 out := make(chan pipeline.Event, 100)
106 j := Source{}
107
108 logger, hook := logtest.NewNullLogger()
109
110 err := j.Configure(ctx, []byte(ts.config), logrus.NewEntry(logger), metrics.AcquisitionMetricsLevelNone)
111 require.NoError(t, err)
112
113 err = j.OneShot(ctx, out)
114 cstest.RequireErrorContains(t, err, ts.wantErr)
115
116 for _, wantMessage := range ts.wantLog {
117 cstest.RequireLogContains(t, hook, wantMessage)
118 }
119
120 if ts.wantErr != "" {
121 return
122 }
123
124 assert.Len(t, out, ts.wantLines)
125 })
126 }
127}
128

Callers

nothing calls this directly

Calls 4

ConfigureMethod · 0.95
OneShotMethod · 0.95
RunMethod · 0.65
LenMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…