Commit 813d38e7 authored by Steven Allen's avatar Steven Allen

add a test suite runner

parent af96e515
package dstest
import (
"reflect"
"runtime"
"testing"
dstore "github.com/ipfs/go-datastore"
)
// BasicSubtests is a list of all basic tests.
var BasicSubtests = []func(t *testing.T, ds dstore.Datastore){
SubtestBasicPutGet,
SubtestNotFounds,
SubtestManyKeysAndQuery,
}
// BatchSubtests is a list of all basic batching datastore tests.
var BatchSubtests = []func(t *testing.T, ds dstore.Batching){
RunBatchTest,
RunBatchDeleteTest,
}
func getFunctionName(i interface{}) string {
return runtime.FuncForPC(reflect.ValueOf(i).Pointer()).Name()
}
// SubtestAll tests the given datastore against all the subtests.
func SubtestAll(t *testing.T, ds dstore.Datastore) {
for _, f := range BasicSubtests {
t.Run(getFunctionName(f), func(t *testing.T) {
f(t, ds)
})
}
if _, ok := ds.(dstore.Batching); ok {
for _, f := range BasicSubtests {
t.Run(getFunctionName(f), func(t *testing.T) {
f(t, ds)
})
}
}
}
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