-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for AlertLifeCycleObserver
Signed-off-by: Emmanuel Lodovice <[email protected]>
- Loading branch information
1 parent
742cf42
commit 5fbcf6f
Showing
8 changed files
with
339 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright 2023 Prometheus Team | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package alertobserver | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/prometheus/alertmanager/types" | ||
) | ||
|
||
type FakeAlertLifeCycleObserver struct { | ||
ReceivedAlerts []*types.Alert | ||
RejectedAlerts []*types.Alert | ||
SentAlerts []*types.Alert | ||
FailedAlerts []*types.Alert | ||
AggrGroupAlerts []*types.Alert | ||
PipelineAlerts []*types.Alert | ||
PipelineStageAlerts map[string][]*types.Alert | ||
} | ||
|
||
func (o *FakeAlertLifeCycleObserver) Received(alerts ...*types.Alert) { | ||
o.ReceivedAlerts = append(o.ReceivedAlerts, alerts...) | ||
} | ||
|
||
func (o *FakeAlertLifeCycleObserver) Rejected(reason string, alerts ...*types.Alert) { | ||
o.RejectedAlerts = append(o.RejectedAlerts, alerts...) | ||
} | ||
|
||
func (o *FakeAlertLifeCycleObserver) AddedAggrGroup(groupKey string, alert *types.Alert) { | ||
o.AggrGroupAlerts = append(o.AggrGroupAlerts, alert) | ||
} | ||
|
||
func (o *FakeAlertLifeCycleObserver) PipelineStart(ctx context.Context, alerts ...*types.Alert) { | ||
o.PipelineAlerts = append(o.PipelineAlerts, alerts...) | ||
} | ||
|
||
func (o *FakeAlertLifeCycleObserver) Sent(ctx context.Context, integration string, alerts ...*types.Alert) { | ||
o.SentAlerts = append(o.SentAlerts, alerts...) | ||
} | ||
|
||
func (o *FakeAlertLifeCycleObserver) SendFailed( | ||
ctx context.Context, | ||
integration string, | ||
reason string, | ||
alerts ...*types.Alert, | ||
) { | ||
o.FailedAlerts = append(o.FailedAlerts, alerts...) | ||
} | ||
|
||
func (o *FakeAlertLifeCycleObserver) PipelinePassStage(ctx context.Context, stageName string, alerts ...*types.Alert) { | ||
o.PipelineStageAlerts[stageName] = append(o.PipelineStageAlerts[stageName], alerts...) | ||
} | ||
|
||
func NewFakeAlertLifeCycleObserver() *FakeAlertLifeCycleObserver { | ||
return &FakeAlertLifeCycleObserver{ | ||
PipelineStageAlerts: map[string][]*types.Alert{}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.