mirror of
https://github.com/grafana/grafana.git
synced 2026-08-18 17:15:08 -05:00
Chore: Cleanup usageStatsMock duplication (#39710)
* Chore: Cleanup usageStatsMock duplication * Remove making a new slice for UsageStatsMock
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
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(_ context.Context) (Report, error) {
|
||||
all := make(map[string]interface{})
|
||||
for _, fn := range usm.metricsFuncs {
|
||||
fnMetrics, err := fn()
|
||||
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) {}
|
||||
Reference in New Issue
Block a user