3
3
// This product includes software developed at Datadog (https://www.datadoghq.com/).
4
4
// Copyright 2025-present Datadog, Inc.
5
5
6
+ //go:build test
7
+
8
+ // Package mock is the mock component for the auditor
6
9
package mock
7
10
8
11
import (
9
12
compdef "github.com/DataDog/datadog-agent/comp/def"
10
13
auditor "github.com/DataDog/datadog-agent/comp/logs/auditor/def"
11
- noneimpl "github.com/DataDog/datadog-agent/comp /logs/auditor/impl-none "
14
+ "github.com/DataDog/datadog-agent/pkg /logs/message "
12
15
"github.com/DataDog/datadog-agent/pkg/util/fxutil"
13
16
)
14
17
@@ -28,6 +31,83 @@ func AuditorMockModule() fxutil.Module {
28
31
29
32
func newMock () ProvidesMock {
30
33
return ProvidesMock {
31
- Comp : noneimpl .NewAuditor (),
34
+ Comp : NewMockAuditor (),
35
+ }
36
+ }
37
+
38
+ // NewMockAuditor returns a new mock auditor
39
+ func NewMockAuditor () * Auditor {
40
+ return & Auditor {
41
+ Registry : Registry {},
42
+ channel : make (chan * message.Payload ),
43
+ stopChannel : make (chan struct {}),
44
+ ReceivedMessages : make ([]* message.Payload , 0 ),
32
45
}
33
46
}
47
+
48
+ // Auditor is a mock auditor that does nothing
49
+ type Auditor struct {
50
+ Registry
51
+ channel chan * message.Payload
52
+ stopChannel chan struct {}
53
+ ReceivedMessages []* message.Payload
54
+ }
55
+
56
+ // Start starts the NullAuditor main loop
57
+ func (a * Auditor ) Start () {
58
+ go a .run ()
59
+ }
60
+
61
+ // Stop stops the NullAuditor main loop
62
+ func (a * Auditor ) Stop () {
63
+ a .stopChannel <- struct {}{}
64
+ }
65
+
66
+ // Channel returns the channel messages should be sent on
67
+ func (a * Auditor ) Channel () chan * message.Payload {
68
+ return a .channel
69
+ }
70
+
71
+ // run is the main run loop for the null auditor
72
+ func (a * Auditor ) run () {
73
+ for {
74
+ select {
75
+ case val := <- a .channel :
76
+ a .ReceivedMessages = append (a .ReceivedMessages , val )
77
+ case <- a .stopChannel :
78
+ close (a .channel )
79
+ return
80
+ }
81
+ }
82
+ }
83
+
84
+ // Registry does nothing
85
+ type Registry struct {
86
+ offset string
87
+ tailingMode string
88
+ }
89
+
90
+ // NewMockRegistry returns a new mock registry.
91
+ func NewMockRegistry () * Registry {
92
+ return & Registry {}
93
+ }
94
+
95
+ // GetOffset returns the offset.
96
+ func (r * Registry ) GetOffset (_ string ) string {
97
+ return r .offset
98
+ }
99
+
100
+ // SetOffset sets the offset.
101
+ func (r * Registry ) SetOffset (offset string ) {
102
+ r .offset = offset
103
+ }
104
+
105
+ // GetTailingMode returns the tailing mode.
106
+ func (r * Registry ) GetTailingMode (_ string ) string {
107
+ return r .tailingMode
108
+ }
109
+
110
+ // SetTailingMode sets the tailing mode.
111
+ func (r * Registry ) SetTailingMode (tailingMode string ) {
112
+ r .tailingMode = tailingMode
113
+ }
0 commit comments