mirror of
https://github.com/grafana/grafana.git
synced 2024-11-25 18:30:41 -06:00
Usage Stats: Introduce an interface for usage stats service (#29882)
Adding an interface type for usage stats service allows us to not depend on the implementation outside of the package, for example when testing we can easily mock the service
This commit is contained in:
parent
56b8124afb
commit
de22374751
@ -21,6 +21,12 @@ func init() {
|
||||
registry.RegisterService(&UsageStatsService{})
|
||||
}
|
||||
|
||||
type UsageStats interface {
|
||||
GetUsageReport() (UsageReport, error)
|
||||
|
||||
RegisterMetric(name string, fn MetricFunc)
|
||||
}
|
||||
|
||||
type MetricFunc func() (interface{}, error)
|
||||
|
||||
type UsageStatsService struct {
|
||||
|
@ -25,6 +25,17 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
// This is to ensure that the interface contract is held by the implementation
|
||||
func Test_InterfaceContractValidity(t *testing.T) {
|
||||
newUsageStats := func() UsageStats {
|
||||
return &UsageStatsService{}
|
||||
}
|
||||
v, ok := newUsageStats().(*UsageStatsService)
|
||||
|
||||
assert.NotNil(t, v)
|
||||
assert.True(t, ok)
|
||||
}
|
||||
|
||||
func TestMetrics(t *testing.T) {
|
||||
t.Run("When sending usage stats", func(t *testing.T) {
|
||||
uss := &UsageStatsService{
|
||||
|
Loading…
Reference in New Issue
Block a user