2022-11-07 19:08:53 +00:00
|
|
|
// Copyright (C) 2022 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package nodeevents
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|
2023-02-03 22:11:31 +00:00
|
|
|
idsMap := make(map[string]struct{})
|
2022-11-07 19:08:53 +00:00
|
|
|
for _, e := range events {
|
2023-02-03 22:11:31 +00:00
|
|
|
idStr := e.NodeID.String()
|
|
|
|
if _, ok := idsMap[idStr]; !ok {
|
|
|
|
idsMap[idStr] = struct{}{}
|
|
|
|
nodeIDs = nodeIDs + idStr + ","
|
|
|
|
}
|
2022-11-07 19:08:53 +00:00
|
|
|
}
|
|
|
|
nodeIDs = strings.TrimSuffix(nodeIDs, ",")
|
|
|
|
|
2022-11-16 22:36:24 +00:00
|
|
|
name, err := events[0].Event.Name()
|
2022-11-07 19:08:53 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-11-16 22:36:24 +00:00
|
|
|
m.log.Info("node operator notified", zap.String("email", events[0].Email), zap.String("event", name), zap.String("node IDs", nodeIDs))
|
2022-11-07 19:08:53 +00:00
|
|
|
return nil
|
|
|
|
}
|