-
Notifications
You must be signed in to change notification settings - Fork 390
/
mocknotifier.go
48 lines (40 loc) · 1.1 KB
/
mocknotifier.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
// Copyright (C) 2022 Storj Labs, Inc.
// See LICENSE for copying information.
package nodeevents
import (
"context"
"strings"
"go.uber.org/zap"
"storj.io/common/storj"
)
// MockNotifier implements the Notifier interface.
type MockNotifier struct {
log *zap.Logger
}
// NewMockNotifier is a constructor for MockNotifier.
func NewMockNotifier(log *zap.Logger) *MockNotifier {
return &MockNotifier{
log: log,
}
}
// Notify stores the events in the Notifications field so they can be checked.
func (m *MockNotifier) Notify(ctx context.Context, satellite string, events []NodeEvent) (err error) {
var nodeIDs string
if len(events) == 0 {
return nil
}
seen := make(map[storj.NodeID]struct{})
for _, e := range events {
if _, ok := seen[e.NodeID]; !ok {
seen[e.NodeID] = struct{}{}
nodeIDs = nodeIDs + e.NodeID.String() + ","
}
}
nodeIDs = strings.TrimSuffix(nodeIDs, ",")
name, err := events[0].Event.Name()
if err != nil {
return err
}
m.log.Info("node operator notified", zap.String("email", events[0].Email), zap.String("event", name), zap.String("node IDs", nodeIDs))
return nil
}