Commit de223747 by Vardan Torosyan Committed by GitHub

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
parent 56b8124a
......@@ -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{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment