-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
mock.go
70 lines (57 loc) · 1.65 KB
/
mock.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2020-present Datadog, Inc.
package statusimpl
import (
"sync"
"go.uber.org/fx"
"github.com/DataDog/datadog-agent/comp/snmptraps/status"
"github.com/DataDog/datadog-agent/pkg/util/fxutil"
)
// MockModule defines a fake Component
func MockModule() fxutil.Module {
return fxutil.Component(
fx.Provide(newMock),
)
}
// newMock returns a Component that uses plain internal values instead of expvars
func newMock() status.Component {
return &mockManager{}
}
// mockManager mocks a manager using plain values (not expvars)
type mockManager struct {
trapsPackets, trapsPacketsUnknownCommunityString int64
lock sync.Mutex
err error
}
func (s *mockManager) AddTrapsPackets(i int64) {
s.lock.Lock()
defer s.lock.Unlock()
s.trapsPackets += i
}
func (s *mockManager) AddTrapsPacketsUnknownCommunityString(i int64) {
s.lock.Lock()
defer s.lock.Unlock()
s.trapsPacketsUnknownCommunityString += i
}
func (s *mockManager) GetTrapsPackets() int64 {
s.lock.Lock()
defer s.lock.Unlock()
return s.trapsPackets
}
func (s *mockManager) GetTrapsPacketsUnknownCommunityString() int64 {
s.lock.Lock()
defer s.lock.Unlock()
return s.trapsPacketsUnknownCommunityString
}
func (s *mockManager) SetStartError(err error) {
s.lock.Lock()
defer s.lock.Unlock()
s.err = err
}
func (s *mockManager) GetStartError() error {
s.lock.Lock()
defer s.lock.Unlock()
return s.err
}