Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coreiface: add a testing.T argument to the provider #321

Merged
merged 1 commit into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions coreiface/tests/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ var errAPINotImplemented = errors.New("api not implemented")

type Provider interface {
// Make creates n nodes. fullIdentity set to false can be ignored
MakeAPISwarm(ctx context.Context, fullIdentity bool, online bool, n int) ([]coreiface.CoreAPI, error)
MakeAPISwarm(t *testing.T, ctx context.Context, fullIdentity bool, online bool, n int) ([]coreiface.CoreAPI, error)
}

func (tp *TestSuite) makeAPISwarm(ctx context.Context, fullIdentity bool, online bool, n int) ([]coreiface.CoreAPI, error) {
func (tp *TestSuite) makeAPISwarm(t *testing.T, ctx context.Context, fullIdentity bool, online bool, n int) ([]coreiface.CoreAPI, error) {
if tp.apis != nil {
tp.apis <- 1
go func() {
Expand All @@ -25,29 +25,29 @@ func (tp *TestSuite) makeAPISwarm(ctx context.Context, fullIdentity bool, online
}()
}

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

func (tp *TestSuite) makeAPI(ctx context.Context) (coreiface.CoreAPI, error) {
api, err := tp.makeAPISwarm(ctx, false, false, 1)
func (tp *TestSuite) makeAPI(t *testing.T, ctx context.Context) (coreiface.CoreAPI, error) {
api, err := tp.makeAPISwarm(t, ctx, false, false, 1)
if err != nil {
return nil, err
}

return api[0], nil
}

func (tp *TestSuite) makeAPIWithIdentityAndOffline(ctx context.Context) (coreiface.CoreAPI, error) {
api, err := tp.makeAPISwarm(ctx, true, false, 1)
func (tp *TestSuite) makeAPIWithIdentityAndOffline(t *testing.T, ctx context.Context) (coreiface.CoreAPI, error) {
api, err := tp.makeAPISwarm(t, ctx, true, false, 1)
if err != nil {
return nil, err
}

return api[0], nil
}

func (tp *TestSuite) MakeAPISwarm(ctx context.Context, n int) ([]coreiface.CoreAPI, error) {
return tp.makeAPISwarm(ctx, true, true, n)
func (tp *TestSuite) MakeAPISwarm(t *testing.T, ctx context.Context, n int) ([]coreiface.CoreAPI, error) {
return tp.makeAPISwarm(t, ctx, true, true, n)
}

type TestSuite struct {
Expand Down Expand Up @@ -99,7 +99,7 @@ func TestApi(p Provider) func(t *testing.T) {
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)
api, err := tp.makeAPI(t, ctx)
if err != nil {
t.Fatal(err)
}
Expand Down
22 changes: 11 additions & 11 deletions coreiface/tests/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (tp *TestSuite) TestBlock(t *testing.T) {
func (tp *TestSuite) TestBlockPut(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
api, err := tp.makeAPI(t, ctx)
if err != nil {
t.Fatal(err)
}
Expand All @@ -78,7 +78,7 @@ func (tp *TestSuite) TestBlockPut(t *testing.T) {
func (tp *TestSuite) TestBlockPutFormatDagCbor(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
api, err := tp.makeAPI(t, ctx)
if err != nil {
t.Fatal(err)
}
Expand All @@ -98,7 +98,7 @@ func (tp *TestSuite) TestBlockPutFormatDagCbor(t *testing.T) {
func (tp *TestSuite) TestBlockPutFormatDagPb(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
api, err := tp.makeAPI(t, ctx)
if err != nil {
t.Fatal(err)
}
Expand All @@ -118,7 +118,7 @@ func (tp *TestSuite) TestBlockPutFormatDagPb(t *testing.T) {
func (tp *TestSuite) TestBlockPutFormatV0(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
api, err := tp.makeAPI(t, ctx)
if err != nil {
t.Fatal(err)
}
Expand All @@ -136,7 +136,7 @@ func (tp *TestSuite) TestBlockPutFormatV0(t *testing.T) {
func (tp *TestSuite) TestBlockPutCidCodecDagCbor(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
api, err := tp.makeAPI(t, ctx)
if err != nil {
t.Fatal(err)
}
Expand All @@ -154,7 +154,7 @@ func (tp *TestSuite) TestBlockPutCidCodecDagCbor(t *testing.T) {
func (tp *TestSuite) TestBlockPutCidCodecDagPb(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
api, err := tp.makeAPI(t, ctx)
if err != nil {
t.Fatal(err)
}
Expand All @@ -172,7 +172,7 @@ func (tp *TestSuite) TestBlockPutCidCodecDagPb(t *testing.T) {
func (tp *TestSuite) TestBlockPutHash(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
api, err := tp.makeAPI(t, ctx)
if err != nil {
t.Fatal(err)
}
Expand All @@ -195,7 +195,7 @@ func (tp *TestSuite) TestBlockPutHash(t *testing.T) {
func (tp *TestSuite) TestBlockGet(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
api, err := tp.makeAPI(t, ctx)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -233,7 +233,7 @@ func (tp *TestSuite) TestBlockGet(t *testing.T) {
func (tp *TestSuite) TestBlockRm(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
api, err := tp.makeAPI(t, ctx)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -287,7 +287,7 @@ func (tp *TestSuite) TestBlockRm(t *testing.T) {
func (tp *TestSuite) TestBlockStat(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
api, err := tp.makeAPI(t, ctx)
if err != nil {
t.Fatal(err)
}
Expand All @@ -314,7 +314,7 @@ func (tp *TestSuite) TestBlockStat(t *testing.T) {
func (tp *TestSuite) TestBlockPin(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
api, err := tp.makeAPI(t, ctx)
if err != nil {
t.Fatal(err)
}
Expand Down
10 changes: 5 additions & 5 deletions coreiface/tests/dag.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ var (
func (tp *TestSuite) TestPut(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
api, err := tp.makeAPI(t, ctx)
if err != nil {
t.Fatal(err)
}
Expand All @@ -67,7 +67,7 @@ func (tp *TestSuite) TestPut(t *testing.T) {
func (tp *TestSuite) TestPutWithHash(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
api, err := tp.makeAPI(t, ctx)
if err != nil {
t.Fatal(err)
}
Expand All @@ -90,7 +90,7 @@ func (tp *TestSuite) TestPutWithHash(t *testing.T) {
func (tp *TestSuite) TestDagPath(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
api, err := tp.makeAPI(t, ctx)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -135,7 +135,7 @@ func (tp *TestSuite) TestDagPath(t *testing.T) {
func (tp *TestSuite) TestTree(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
api, err := tp.makeAPI(t, ctx)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -170,7 +170,7 @@ func (tp *TestSuite) TestTree(t *testing.T) {
func (tp *TestSuite) TestBatch(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
api, err := tp.makeAPI(t, ctx)
if err != nil {
t.Fatal(err)
}
Expand Down
6 changes: 3 additions & 3 deletions coreiface/tests/dht.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (tp *TestSuite) TestDht(t *testing.T) {
func (tp *TestSuite) TestDhtFindPeer(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
apis, err := tp.MakeAPISwarm(ctx, 5)
apis, err := tp.MakeAPISwarm(t, ctx, 5)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -81,7 +81,7 @@ func (tp *TestSuite) TestDhtFindPeer(t *testing.T) {
func (tp *TestSuite) TestDhtFindProviders(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
apis, err := tp.MakeAPISwarm(ctx, 5)
apis, err := tp.MakeAPISwarm(t, ctx, 5)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -113,7 +113,7 @@ func (tp *TestSuite) TestDhtFindProviders(t *testing.T) {
func (tp *TestSuite) TestDhtProvide(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
apis, err := tp.MakeAPISwarm(ctx, 5)
apis, err := tp.MakeAPISwarm(t, ctx, 5)
if err != nil {
t.Fatal(err)
}
Expand Down
32 changes: 16 additions & 16 deletions coreiface/tests/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (tp *TestSuite) TestKey(t *testing.T) {
func (tp *TestSuite) TestListSelf(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
api, err := tp.makeAPI(t, ctx)
if err != nil {
t.Fatal(err)
return
Expand Down Expand Up @@ -74,7 +74,7 @@ func (tp *TestSuite) TestListSelf(t *testing.T) {
func (tp *TestSuite) TestRenameSelf(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
api, err := tp.makeAPI(t, ctx)
if err != nil {
t.Fatal(err)
return
Expand Down Expand Up @@ -102,7 +102,7 @@ func (tp *TestSuite) TestRenameSelf(t *testing.T) {
func (tp *TestSuite) TestRemoveSelf(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
api, err := tp.makeAPI(t, ctx)
if err != nil {
t.Fatal(err)
return
Expand All @@ -121,7 +121,7 @@ func (tp *TestSuite) TestRemoveSelf(t *testing.T) {
func (tp *TestSuite) TestGenerate(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
api, err := tp.makeAPI(t, ctx)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -165,7 +165,7 @@ func verifyIPNSPath(t *testing.T, p string) bool {
func (tp *TestSuite) TestGenerateSize(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
api, err := tp.makeAPI(t, ctx)
if err != nil {
t.Fatal(err)
}
Expand All @@ -189,7 +189,7 @@ func (tp *TestSuite) TestGenerateType(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

api, err := tp.makeAPI(ctx)
api, err := tp.makeAPI(t, ctx)
if err != nil {
t.Fatal(err)
}
Expand All @@ -213,7 +213,7 @@ func (tp *TestSuite) TestGenerateType(t *testing.T) {
func (tp *TestSuite) TestGenerateExisting(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
api, err := tp.makeAPI(t, ctx)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -246,7 +246,7 @@ func (tp *TestSuite) TestGenerateExisting(t *testing.T) {
func (tp *TestSuite) TestList(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
api, err := tp.makeAPI(t, ctx)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -285,7 +285,7 @@ func (tp *TestSuite) TestList(t *testing.T) {
func (tp *TestSuite) TestRename(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
api, err := tp.makeAPI(t, ctx)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -314,7 +314,7 @@ func (tp *TestSuite) TestRename(t *testing.T) {
func (tp *TestSuite) TestRenameToSelf(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
api, err := tp.makeAPI(t, ctx)
if err != nil {
t.Fatal(err)
}
Expand All @@ -338,7 +338,7 @@ func (tp *TestSuite) TestRenameToSelf(t *testing.T) {
func (tp *TestSuite) TestRenameToSelfForce(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
api, err := tp.makeAPI(t, ctx)
if err != nil {
t.Fatal(err)
}
Expand All @@ -362,7 +362,7 @@ func (tp *TestSuite) TestRenameToSelfForce(t *testing.T) {
func (tp *TestSuite) TestRenameOverwriteNoForce(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
api, err := tp.makeAPI(t, ctx)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -392,7 +392,7 @@ func (tp *TestSuite) TestRenameOverwriteNoForce(t *testing.T) {
func (tp *TestSuite) TestRenameOverwrite(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
api, err := tp.makeAPI(t, ctx)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -431,7 +431,7 @@ func (tp *TestSuite) TestRenameOverwrite(t *testing.T) {
func (tp *TestSuite) TestRenameSameNameNoForce(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
api, err := tp.makeAPI(t, ctx)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -460,7 +460,7 @@ func (tp *TestSuite) TestRenameSameNameNoForce(t *testing.T) {
func (tp *TestSuite) TestRenameSameName(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
api, err := tp.makeAPI(t, ctx)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -489,7 +489,7 @@ func (tp *TestSuite) TestRenameSameName(t *testing.T) {
func (tp *TestSuite) TestRemove(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
api, err := tp.makeAPI(ctx)
api, err := tp.makeAPI(t, ctx)
if err != nil {
t.Fatal(err)
}
Expand Down
Loading