437dcc875c
* Integrate mt querier with query caching * typo * let the caller set cache status response header * fix TestQueryAPI * make gen-go * handle CachingServiceClient being nil and make gen-go * include namespace in cache key * set signed in user namespace in query_test.go * fix test * remove commented out code * undo services/query/query.go changes * make gen-go * remove namespace requirement * fix tests * fix test * remove namespace from SignedInUser in tests * make gen-go
45 lines
1.2 KiB
Go
45 lines
1.2 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
|
|
ReturnStatus CacheStatus
|
|
ReturnHit bool
|
|
ReturnResourceResponse CachedResourceDataResponse
|
|
ReturnQueryResponse CachedQueryDataResponse
|
|
}
|
|
|
|
func (f *FakeOSSCachingService) HandleQueryRequest(ctx context.Context, req *backend.QueryDataRequest) (bool, CachedQueryDataResponse, CacheStatus) {
|
|
f.calls["HandleQueryRequest"]++
|
|
return f.ReturnHit, f.ReturnQueryResponse, f.ReturnStatus
|
|
}
|
|
|
|
func (f *FakeOSSCachingService) HandleResourceRequest(ctx context.Context, req *backend.CallResourceRequest) (bool, CachedResourceDataResponse, CacheStatus) {
|
|
f.calls["HandleResourceRequest"]++
|
|
return f.ReturnHit, f.ReturnResourceResponse, f.ReturnStatus
|
|
}
|
|
|
|
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{},
|
|
ReturnStatus: "unset",
|
|
}
|
|
|
|
return fake
|
|
}
|