mirror of
https://github.com/grafana/grafana.git
synced 2024-12-01 21:19:28 -06:00
a29cfe5d46
* Update the HandleResourceRequest function to mimic the HandleQueryRequest function * Remove CacheResourceResponse function from interface * revert additional thing I missed
43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
package caching
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
type FakeOSSCachingService struct {
|
|
calls map[string]int
|
|
ReturnHit bool
|
|
ReturnResourceResponse CachedResourceDataResponse
|
|
ReturnQueryResponse CachedQueryDataResponse
|
|
}
|
|
|
|
func (f *FakeOSSCachingService) HandleQueryRequest(ctx context.Context, req *backend.QueryDataRequest) (bool, CachedQueryDataResponse) {
|
|
f.calls["HandleQueryRequest"]++
|
|
return f.ReturnHit, f.ReturnQueryResponse
|
|
}
|
|
|
|
func (f *FakeOSSCachingService) HandleResourceRequest(ctx context.Context, req *backend.CallResourceRequest) (bool, CachedResourceDataResponse) {
|
|
f.calls["HandleResourceRequest"]++
|
|
return f.ReturnHit, f.ReturnResourceResponse
|
|
}
|
|
|
|
func (f *FakeOSSCachingService) AssertCalls(t *testing.T, fn string, times int) {
|
|
assert.Equal(t, times, f.calls[fn])
|
|
}
|
|
|
|
func (f *FakeOSSCachingService) Reset() {
|
|
*f = *NewFakeOSSCachingService()
|
|
}
|
|
|
|
func NewFakeOSSCachingService() *FakeOSSCachingService {
|
|
fake := &FakeOSSCachingService{
|
|
calls: map[string]int{},
|
|
}
|
|
|
|
return fake
|
|
}
|