-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #93 from ipfs/feat/testing
improve testing
- Loading branch information
Showing
6 changed files
with
87 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package datastore_test | ||
|
||
import ( | ||
"testing" | ||
|
||
dstore "github.com/ipfs/go-datastore" | ||
dstest "github.com/ipfs/go-datastore/test" | ||
) | ||
|
||
func TestMapDatastore(t *testing.T) { | ||
ds := dstore.NewMapDatastore() | ||
dstest.SubtestAll(t, ds) | ||
} | ||
|
||
func TestNullDatastore(t *testing.T) { | ||
ds := dstore.NewNullDatastore() | ||
// The only test that passes. Nothing should be found. | ||
dstest.SubtestNotFounds(t, ds) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package sync | ||
|
||
import ( | ||
"testing" | ||
|
||
ds "github.com/ipfs/go-datastore" | ||
dstest "github.com/ipfs/go-datastore/test" | ||
) | ||
|
||
func TestSync(t *testing.T) { | ||
dstest.SubtestAll(t, MutexWrap(ds.NewMapDatastore())) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
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) | ||
}) | ||
} | ||
} | ||
} |