Skip to content
This repository has been archived by the owner on Jun 19, 2023. It is now read-only.

Commit

Permalink
Merge pull request #34 from ipfs/feat/expose-tests
Browse files Browse the repository at this point in the history
tests: expose TestSuite
  • Loading branch information
magik6k committed May 20, 2019
2 parents 5d8d216 + 6fe8577 commit 103b645
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 88 deletions.
22 changes: 12 additions & 10 deletions tests/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

var apiNotImplemented = errors.New("api not implemented")

func (tp *provider) makeAPI(ctx context.Context) (coreiface.CoreAPI, error) {
func (tp *TestSuite) makeAPI(ctx context.Context) (coreiface.CoreAPI, error) {
api, err := tp.MakeAPISwarm(ctx, false, 1)
if err != nil {
return nil, err
Expand All @@ -25,17 +25,19 @@ type Provider interface {
MakeAPISwarm(ctx context.Context, fullIdentity bool, n int) ([]coreiface.CoreAPI, error)
}

func (tp *provider) MakeAPISwarm(ctx context.Context, fullIdentity bool, n int) ([]coreiface.CoreAPI, error) {
tp.apis <- 1
go func() {
<-ctx.Done()
tp.apis <- -1
}()
func (tp *TestSuite) MakeAPISwarm(ctx context.Context, fullIdentity bool, n int) ([]coreiface.CoreAPI, error) {
if tp.apis != nil {
tp.apis <- 1
go func() {
<-ctx.Done()
tp.apis <- -1
}()
}

return tp.Provider.MakeAPISwarm(ctx, fullIdentity, n)
}

type provider struct {
type TestSuite struct {
Provider

apis chan int
Expand All @@ -55,7 +57,7 @@ func TestApi(p Provider) func(t *testing.T) {
}
}()

tp := &provider{Provider: p, apis: apis}
tp := &TestSuite{Provider: p, apis: apis}

return func(t *testing.T) {
t.Run("Block", tp.TestBlock)
Expand All @@ -80,7 +82,7 @@ func TestApi(p Provider) func(t *testing.T) {
}
}

func (tp *provider) hasApi(t *testing.T, tf func(coreiface.CoreAPI) error) {
func (tp *TestSuite) hasApi(t *testing.T, tf func(coreiface.CoreAPI) error) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
Expand Down
16 changes: 8 additions & 8 deletions tests/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
mh "github.com/multiformats/go-multihash"
)

func (tp *provider) TestBlock(t *testing.T) {
func (tp *TestSuite) TestBlock(t *testing.T) {
tp.hasApi(t, func(api coreiface.CoreAPI) error {
if api.Block() == nil {
return apiNotImplemented
Expand All @@ -30,7 +30,7 @@ func (tp *provider) TestBlock(t *testing.T) {
t.Run("TestBlockPin", tp.TestBlockPin)
}

func (tp *provider) TestBlockPut(t *testing.T) {
func (tp *TestSuite) TestBlockPut(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
Expand All @@ -48,7 +48,7 @@ func (tp *provider) TestBlockPut(t *testing.T) {
}
}

func (tp *provider) TestBlockPutFormat(t *testing.T) {
func (tp *TestSuite) TestBlockPutFormat(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
Expand All @@ -66,7 +66,7 @@ func (tp *provider) TestBlockPutFormat(t *testing.T) {
}
}

func (tp *provider) TestBlockPutHash(t *testing.T) {
func (tp *TestSuite) TestBlockPutHash(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
Expand All @@ -84,7 +84,7 @@ func (tp *provider) TestBlockPutHash(t *testing.T) {
}
}

func (tp *provider) TestBlockGet(t *testing.T) {
func (tp *TestSuite) TestBlockGet(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
Expand Down Expand Up @@ -122,7 +122,7 @@ func (tp *provider) TestBlockGet(t *testing.T) {
}
}

func (tp *provider) TestBlockRm(t *testing.T) {
func (tp *TestSuite) TestBlockRm(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
Expand Down Expand Up @@ -176,7 +176,7 @@ func (tp *provider) TestBlockRm(t *testing.T) {
}
}

func (tp *provider) TestBlockStat(t *testing.T) {
func (tp *TestSuite) TestBlockStat(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
Expand All @@ -203,7 +203,7 @@ func (tp *provider) TestBlockStat(t *testing.T) {
}
}

func (tp *provider) TestBlockPin(t *testing.T) {
func (tp *TestSuite) TestBlockPin(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
Expand Down
12 changes: 6 additions & 6 deletions tests/dag.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
mh "github.com/multiformats/go-multihash"
)

func (tp *provider) TestDag(t *testing.T) {
func (tp *TestSuite) TestDag(t *testing.T) {
tp.hasApi(t, func(api coreiface.CoreAPI) error {
if api.Dag() == nil {
return apiNotImplemented
Expand All @@ -40,7 +40,7 @@ var (
}
)

func (tp *provider) TestPut(t *testing.T) {
func (tp *TestSuite) TestPut(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
Expand All @@ -63,7 +63,7 @@ func (tp *provider) TestPut(t *testing.T) {
}
}

func (tp *provider) TestPutWithHash(t *testing.T) {
func (tp *TestSuite) TestPutWithHash(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
Expand All @@ -86,7 +86,7 @@ func (tp *provider) TestPutWithHash(t *testing.T) {
}
}

func (tp *provider) TestDagPath(t *testing.T) {
func (tp *TestSuite) TestDagPath(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
Expand Down Expand Up @@ -131,7 +131,7 @@ func (tp *provider) TestDagPath(t *testing.T) {
}
}

func (tp *provider) TestTree(t *testing.T) {
func (tp *TestSuite) TestTree(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
Expand Down Expand Up @@ -166,7 +166,7 @@ func (tp *provider) TestTree(t *testing.T) {
}
}

func (tp *provider) TestBatch(t *testing.T) {
func (tp *TestSuite) TestBatch(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
Expand Down
8 changes: 4 additions & 4 deletions tests/dht.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/ipfs/interface-go-ipfs-core/options"
)

func (tp *provider) TestDht(t *testing.T) {
func (tp *TestSuite) TestDht(t *testing.T) {
tp.hasApi(t, func(api iface.CoreAPI) error {
if api.Dht() == nil {
return apiNotImplemented
Expand All @@ -22,7 +22,7 @@ func (tp *provider) TestDht(t *testing.T) {
t.Run("TestDhtProvide", tp.TestDhtProvide)
}

func (tp *provider) TestDhtFindPeer(t *testing.T) {
func (tp *TestSuite) TestDhtFindPeer(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
apis, err := tp.MakeAPISwarm(ctx, true, 5)
Expand Down Expand Up @@ -75,7 +75,7 @@ func (tp *provider) TestDhtFindPeer(t *testing.T) {
}
}

func (tp *provider) TestDhtFindProviders(t *testing.T) {
func (tp *TestSuite) TestDhtFindProviders(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
apis, err := tp.MakeAPISwarm(ctx, true, 5)
Expand Down Expand Up @@ -105,7 +105,7 @@ func (tp *provider) TestDhtFindProviders(t *testing.T) {
}
}

func (tp *provider) TestDhtProvide(t *testing.T) {
func (tp *TestSuite) TestDhtProvide(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
apis, err := tp.MakeAPISwarm(ctx, true, 5)
Expand Down
34 changes: 17 additions & 17 deletions tests/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
opt "github.com/ipfs/interface-go-ipfs-core/options"
)

func (tp *provider) TestKey(t *testing.T) {
func (tp *TestSuite) TestKey(t *testing.T) {
tp.hasApi(t, func(api iface.CoreAPI) error {
if api.Key() == nil {
return apiNotImplemented
Expand All @@ -35,7 +35,7 @@ func (tp *provider) TestKey(t *testing.T) {
t.Run("TestRemove", tp.TestRemove)
}

func (tp *provider) TestListSelf(t *testing.T) {
func (tp *TestSuite) TestListSelf(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
Expand Down Expand Up @@ -69,7 +69,7 @@ func (tp *provider) TestListSelf(t *testing.T) {
}
}

func (tp *provider) TestRenameSelf(t *testing.T) {
func (tp *TestSuite) TestRenameSelf(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
Expand Down Expand Up @@ -97,7 +97,7 @@ func (tp *provider) TestRenameSelf(t *testing.T) {
}
}

func (tp *provider) TestRemoveSelf(t *testing.T) {
func (tp *TestSuite) TestRemoveSelf(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
Expand All @@ -116,7 +116,7 @@ func (tp *provider) TestRemoveSelf(t *testing.T) {
}
}

func (tp *provider) TestGenerate(t *testing.T) {
func (tp *TestSuite) TestGenerate(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
Expand All @@ -139,7 +139,7 @@ func (tp *provider) TestGenerate(t *testing.T) {
}
}

func (tp *provider) TestGenerateSize(t *testing.T) {
func (tp *TestSuite) TestGenerateSize(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
Expand All @@ -162,7 +162,7 @@ func (tp *provider) TestGenerateSize(t *testing.T) {
}
}

func (tp *provider) TestGenerateType(t *testing.T) {
func (tp *TestSuite) TestGenerateType(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
t.Skip("disabled until libp2p/specs#111 is fixed")
Expand All @@ -188,7 +188,7 @@ func (tp *provider) TestGenerateType(t *testing.T) {
}
}

func (tp *provider) TestGenerateExisting(t *testing.T) {
func (tp *TestSuite) TestGenerateExisting(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
Expand Down Expand Up @@ -221,7 +221,7 @@ func (tp *provider) TestGenerateExisting(t *testing.T) {
}
}

func (tp *provider) TestList(t *testing.T) {
func (tp *TestSuite) TestList(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
Expand Down Expand Up @@ -267,7 +267,7 @@ func (tp *provider) TestList(t *testing.T) {
}
}

func (tp *provider) TestRename(t *testing.T) {
func (tp *TestSuite) TestRename(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
Expand Down Expand Up @@ -296,7 +296,7 @@ func (tp *provider) TestRename(t *testing.T) {
}
}

func (tp *provider) TestRenameToSelf(t *testing.T) {
func (tp *TestSuite) TestRenameToSelf(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
Expand All @@ -320,7 +320,7 @@ func (tp *provider) TestRenameToSelf(t *testing.T) {
}
}

func (tp *provider) TestRenameToSelfForce(t *testing.T) {
func (tp *TestSuite) TestRenameToSelfForce(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
Expand All @@ -344,7 +344,7 @@ func (tp *provider) TestRenameToSelfForce(t *testing.T) {
}
}

func (tp *provider) TestRenameOverwriteNoForce(t *testing.T) {
func (tp *TestSuite) TestRenameOverwriteNoForce(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
Expand Down Expand Up @@ -374,7 +374,7 @@ func (tp *provider) TestRenameOverwriteNoForce(t *testing.T) {
}
}

func (tp *provider) TestRenameOverwrite(t *testing.T) {
func (tp *TestSuite) TestRenameOverwrite(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
Expand Down Expand Up @@ -413,7 +413,7 @@ func (tp *provider) TestRenameOverwrite(t *testing.T) {
}
}

func (tp *provider) TestRenameSameNameNoForce(t *testing.T) {
func (tp *TestSuite) TestRenameSameNameNoForce(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
Expand Down Expand Up @@ -442,7 +442,7 @@ func (tp *provider) TestRenameSameNameNoForce(t *testing.T) {
}
}

func (tp *provider) TestRenameSameName(t *testing.T) {
func (tp *TestSuite) TestRenameSameName(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
Expand Down Expand Up @@ -471,7 +471,7 @@ func (tp *provider) TestRenameSameName(t *testing.T) {
}
}

func (tp *provider) TestRemove(t *testing.T) {
func (tp *TestSuite) TestRemove(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
Expand Down

0 comments on commit 103b645

Please sign in to comment.