grafana/pkg/services/caching/fake_caching_service.go
Michael Mandrus a29cfe5d46
Caching: Consolidate resource cache checking and updating in plugin middleware (#67002)
* Update the HandleResourceRequest function to mimic the HandleQueryRequest function

* Remove CacheResourceResponse function from interface

* revert additional thing I missed
2023-04-21 13:03:49 -04:00

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
}