edge/pkg/storage/driver/cache/lfu/testsuite/main.go

42 lines
895 B
Go

package testsuite
import (
"reflect"
"runtime"
"strings"
"testing"
"forge.cadoles.com/arcad/edge/pkg/storage/driver/cache/lfu"
"github.com/pkg/errors"
)
type StoreFactory func(testName string) lfu.Store[string, string]
type testCase func(t *testing.T, store lfu.Store[string, string]) error
var testCases = []testCase{
testSetGetDelete,
testEviction,
testConcurrent,
testMultipleSet,
testTTL,
}
func TestCacheWithStore(t *testing.T, factory StoreFactory) {
for _, tc := range testCases {
funcName := runtime.FuncForPC(reflect.ValueOf(tc).Pointer()).Name()
funcNameParts := strings.Split(funcName, "/")
testName := funcNameParts[len(funcNameParts)-1]
func(tc testCase) {
t.Run(testName, func(t *testing.T) {
t.Parallel()
store := factory(testName)
if err := tc(t, store); err != nil {
t.Fatalf("%+v", errors.WithStack(err))
}
})
}(tc)
}
}