mirror of
https://github.com/grafana/grafana.git
synced 2024-12-02 13:39:19 -06:00
9340430723
* Add context for alert * Remove context.TODO * Remove xorm * Remove context.TODO * Fix UsageStatsQuerier interface
37 lines
776 B
Go
37 lines
776 B
Go
package usagestats
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
type UsageStatsMock struct {
|
|
T testing.TB
|
|
metricsFuncs []MetricsFunc
|
|
}
|
|
|
|
func (usm *UsageStatsMock) RegisterMetricsFunc(fn MetricsFunc) {
|
|
usm.metricsFuncs = append(usm.metricsFuncs, fn)
|
|
}
|
|
|
|
func (usm *UsageStatsMock) GetUsageReport(ctx context.Context) (Report, error) {
|
|
all := make(map[string]interface{})
|
|
for _, fn := range usm.metricsFuncs {
|
|
fnMetrics, err := fn(ctx)
|
|
require.NoError(usm.T, err)
|
|
|
|
for name, value := range fnMetrics {
|
|
all[name] = value
|
|
}
|
|
}
|
|
return Report{Metrics: all}, nil
|
|
}
|
|
|
|
func (usm *UsageStatsMock) ShouldBeReported(_ string) bool {
|
|
return true
|
|
}
|
|
|
|
func (usm *UsageStatsMock) RegisterSendReportCallback(_ SendReportCallbackFunc) {}
|