2022-09-26 13:55:05 -05:00
|
|
|
package state
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"sync"
|
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/services/ngalert/models"
|
|
|
|
)
|
|
|
|
|
2022-10-06 01:22:58 -05:00
|
|
|
var _ InstanceStore = &FakeInstanceStore{}
|
|
|
|
|
2022-09-26 13:55:05 -05:00
|
|
|
type FakeInstanceStore struct {
|
|
|
|
mtx sync.Mutex
|
|
|
|
RecordedOps []interface{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *FakeInstanceStore) ListAlertInstances(_ context.Context, q *models.ListAlertInstancesQuery) error {
|
|
|
|
f.mtx.Lock()
|
|
|
|
defer f.mtx.Unlock()
|
|
|
|
f.RecordedOps = append(f.RecordedOps, *q)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-10-06 01:22:58 -05:00
|
|
|
func (f *FakeInstanceStore) SaveAlertInstances(_ context.Context, q ...models.AlertInstance) error {
|
2022-09-26 13:55:05 -05:00
|
|
|
f.mtx.Lock()
|
|
|
|
defer f.mtx.Unlock()
|
2022-10-06 01:22:58 -05:00
|
|
|
for _, inst := range q {
|
|
|
|
f.RecordedOps = append(f.RecordedOps, inst)
|
|
|
|
}
|
2022-09-26 13:55:05 -05:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *FakeInstanceStore) FetchOrgIds(_ context.Context) ([]int64, error) { return []int64{}, nil }
|
|
|
|
|
2022-10-06 01:22:58 -05:00
|
|
|
func (f *FakeInstanceStore) DeleteAlertInstances(_ context.Context, _ ...models.AlertInstanceKey) error {
|
2022-09-26 13:55:05 -05:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *FakeInstanceStore) DeleteAlertInstancesByRule(ctx context.Context, key models.AlertRuleKey) error {
|
|
|
|
return nil
|
|
|
|
}
|
2022-09-27 10:33:32 -05:00
|
|
|
|
|
|
|
type FakeRuleReader struct{}
|
|
|
|
|
|
|
|
func (f *FakeRuleReader) ListAlertRules(_ context.Context, q *models.ListAlertRulesQuery) error {
|
|
|
|
return nil
|
|
|
|
}
|
2022-10-05 15:32:20 -05:00
|
|
|
|
|
|
|
type FakeHistorian struct{}
|
|
|
|
|
2022-11-04 10:39:26 -05:00
|
|
|
func (f *FakeHistorian) RecordStates(ctx context.Context, rule *models.AlertRule, states []StateTransition) {
|
2022-10-05 15:32:20 -05:00
|
|
|
}
|