mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
feat(alerting): requests looks to be working again
This commit is contained in:
39
pkg/tsdb/fake_test.go
Normal file
39
pkg/tsdb/fake_test.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package tsdb
|
||||
|
||||
type FakeExecutor struct {
|
||||
results map[string]*QueryResult
|
||||
resultsFn map[string]ResultsFn
|
||||
}
|
||||
|
||||
type ResultsFn func(context *QueryContext) *QueryResult
|
||||
|
||||
func NewFakeExecutor(dsInfo *DataSourceInfo) *FakeExecutor {
|
||||
return &FakeExecutor{
|
||||
results: make(map[string]*QueryResult),
|
||||
resultsFn: make(map[string]ResultsFn),
|
||||
}
|
||||
}
|
||||
|
||||
func (e *FakeExecutor) Execute(queries QuerySlice, context *QueryContext) *BatchResult {
|
||||
result := &BatchResult{QueryResults: make(map[string]*QueryResult)}
|
||||
for _, query := range queries {
|
||||
if results, has := e.results[query.RefId]; has {
|
||||
result.QueryResults[query.RefId] = results
|
||||
}
|
||||
if testFunc, has := e.resultsFn[query.RefId]; has {
|
||||
result.QueryResults[query.RefId] = testFunc(context)
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func (e *FakeExecutor) Return(refId string, series TimeSeriesSlice) {
|
||||
e.results[refId] = &QueryResult{
|
||||
RefId: refId, Series: series,
|
||||
}
|
||||
}
|
||||
|
||||
func (e *FakeExecutor) HandleQuery(refId string, fn ResultsFn) {
|
||||
e.resultsFn[refId] = fn
|
||||
}
|
||||
Reference in New Issue
Block a user