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 #24 from ipfs/test/use-fatal
Browse files Browse the repository at this point in the history
fix a bunch of small test "bugs"
  • Loading branch information
Stebalien committed Mar 27, 2019
2 parents c35356b + 5d6a474 commit ccf9dac
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 99 deletions.
28 changes: 14 additions & 14 deletions tests/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (tp *provider) TestBlockPutFormat(t *testing.T) {
defer cancel()
api, err := tp.makeAPI(ctx)
if err != nil {
t.Error(err)
t.Fatal(err)
}

res, err := api.Block().Put(ctx, strings.NewReader(`Hello`), opt.Block.Format("cbor"))
Expand All @@ -70,7 +70,7 @@ func (tp *provider) TestBlockPutHash(t *testing.T) {
defer cancel()
api, err := tp.makeAPI(ctx)
if err != nil {
t.Error(err)
t.Fatal(err)
}

res, err := api.Block().Put(ctx, strings.NewReader(`Hello`), opt.Block.Hash(mh.KECCAK_512, -1))
Expand All @@ -88,7 +88,7 @@ func (tp *provider) TestBlockGet(t *testing.T) {
defer cancel()
api, err := tp.makeAPI(ctx)
if err != nil {
t.Error(err)
t.Fatal(err)
}

res, err := api.Block().Put(ctx, strings.NewReader(`Hello`), opt.Block.Hash(mh.KECCAK_512, -1))
Expand All @@ -98,12 +98,12 @@ func (tp *provider) TestBlockGet(t *testing.T) {

r, err := api.Block().Get(ctx, res.Path())
if err != nil {
t.Error(err)
t.Fatal(err)
}

d, err := ioutil.ReadAll(r)
if err != nil {
t.Error(err)
t.Fatal(err)
}

if string(d) != "Hello" {
Expand All @@ -112,7 +112,7 @@ func (tp *provider) TestBlockGet(t *testing.T) {

p, err := coreiface.ParsePath("/ipfs/" + res.Path().Cid().String())
if err != nil {
t.Error(err)
t.Fatal(err)
}

rp, err := api.ResolvePath(ctx, p)
Expand All @@ -129,7 +129,7 @@ func (tp *provider) TestBlockRm(t *testing.T) {
defer cancel()
api, err := tp.makeAPI(ctx)
if err != nil {
t.Error(err)
t.Fatal(err)
}

res, err := api.Block().Put(ctx, strings.NewReader(`Hello`))
Expand All @@ -139,12 +139,12 @@ func (tp *provider) TestBlockRm(t *testing.T) {

r, err := api.Block().Get(ctx, res.Path())
if err != nil {
t.Error(err)
t.Fatal(err)
}

d, err := ioutil.ReadAll(r)
if err != nil {
t.Error(err)
t.Fatal(err)
}

if string(d) != "Hello" {
Expand All @@ -153,7 +153,7 @@ func (tp *provider) TestBlockRm(t *testing.T) {

err = api.Block().Rm(ctx, res.Path())
if err != nil {
t.Error(err)
t.Fatal(err)
}

_, err = api.Block().Get(ctx, res.Path())
Expand All @@ -174,7 +174,7 @@ func (tp *provider) TestBlockRm(t *testing.T) {

err = api.Block().Rm(ctx, res.Path(), opt.Block.Force(true))
if err != nil {
t.Error(err)
t.Fatal(err)
}
}

Expand All @@ -183,7 +183,7 @@ func (tp *provider) TestBlockStat(t *testing.T) {
defer cancel()
api, err := tp.makeAPI(ctx)
if err != nil {
t.Error(err)
t.Fatal(err)
}

res, err := api.Block().Put(ctx, strings.NewReader(`Hello`))
Expand All @@ -193,7 +193,7 @@ func (tp *provider) TestBlockStat(t *testing.T) {

stat, err := api.Block().Stat(ctx, res.Path())
if err != nil {
t.Error(err)
t.Fatal(err)
}

if stat.Path().String() != res.Path().String() {
Expand All @@ -210,7 +210,7 @@ func (tp *provider) TestBlockPin(t *testing.T) {
defer cancel()
api, err := tp.makeAPI(ctx)
if err != nil {
t.Error(err)
t.Fatal(err)
}

_, err = api.Block().Put(ctx, strings.NewReader(`Hello`))
Expand Down
36 changes: 18 additions & 18 deletions tests/dag.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ func (tp *provider) TestPut(t *testing.T) {
defer cancel()
api, err := tp.makeAPI(ctx)
if err != nil {
t.Error(err)
t.Fatal(err)
}

nd, err := ipldcbor.FromJSON(strings.NewReader(`"Hello"`), math.MaxUint64, -1)
if err != nil {
t.Error(err)
t.Fatal(err)
}

err = api.Dag().Add(ctx, nd)
Expand All @@ -67,12 +67,12 @@ func (tp *provider) TestPutWithHash(t *testing.T) {
defer cancel()
api, err := tp.makeAPI(ctx)
if err != nil {
t.Error(err)
t.Fatal(err)
}

nd, err := ipldcbor.FromJSON(strings.NewReader(`"Hello"`), mh.ID, -1)
if err != nil {
t.Error(err)
t.Fatal(err)
}

err = api.Dag().Add(ctx, nd)
Expand All @@ -90,12 +90,12 @@ func (tp *provider) TestDagPath(t *testing.T) {
defer cancel()
api, err := tp.makeAPI(ctx)
if err != nil {
t.Error(err)
t.Fatal(err)
}

snd, err := ipldcbor.FromJSON(strings.NewReader(`"foo"`), math.MaxUint64, -1)
if err != nil {
t.Error(err)
t.Fatal(err)
}

err = api.Dag().Add(ctx, snd)
Expand All @@ -105,7 +105,7 @@ func (tp *provider) TestDagPath(t *testing.T) {

nd, err := ipldcbor.FromJSON(strings.NewReader(`{"lnk": {"/": "`+snd.Cid().String()+`"}}`), math.MaxUint64, -1)
if err != nil {
t.Error(err)
t.Fatal(err)
}

err = api.Dag().Add(ctx, nd)
Expand All @@ -115,17 +115,17 @@ func (tp *provider) TestDagPath(t *testing.T) {

p, err := coreiface.ParsePath(path.Join(nd.Cid().String(), "lnk"))
if err != nil {
t.Error(err)
t.Fatal(err)
}

rp, err := api.ResolvePath(ctx, p)
if err != nil {
t.Error(err)
t.Fatal(err)
}

ndd, err := api.Dag().Get(ctx, rp.Cid())
if err != nil {
t.Error(err)
t.Fatal(err)
}

if ndd.Cid().String() != snd.Cid().String() {
Expand All @@ -138,12 +138,12 @@ func (tp *provider) TestTree(t *testing.T) {
defer cancel()
api, err := tp.makeAPI(ctx)
if err != nil {
t.Error(err)
t.Fatal(err)
}

nd, err := ipldcbor.FromJSON(strings.NewReader(`{"a": 123, "b": "foo", "c": {"d": 321, "e": 111}}`), math.MaxUint64, -1)
if err != nil {
t.Error(err)
t.Fatal(err)
}

err = api.Dag().Add(ctx, nd)
Expand All @@ -153,7 +153,7 @@ func (tp *provider) TestTree(t *testing.T) {

res, err := api.Dag().Get(ctx, nd.Cid())
if err != nil {
t.Error(err)
t.Fatal(err)
}

lst := res.Tree("", -1)
Expand All @@ -173,12 +173,12 @@ func (tp *provider) TestBatch(t *testing.T) {
defer cancel()
api, err := tp.makeAPI(ctx)
if err != nil {
t.Error(err)
t.Fatal(err)
}

nd, err := ipldcbor.FromJSON(strings.NewReader(`"Hello"`), math.MaxUint64, -1)
if err != nil {
t.Error(err)
t.Fatal(err)
}

if nd.Cid().String() != "zdpuAqckYF3ToF3gcJNxPZXmnmGuXd3gxHCXhq81HGxBejEvv" {
Expand All @@ -187,15 +187,15 @@ func (tp *provider) TestBatch(t *testing.T) {

_, err = api.Dag().Get(ctx, nd.Cid())
if err == nil || !strings.Contains(err.Error(), "not found") {
t.Error(err)
t.Fatal(err)
}

if err := api.Dag().AddMany(ctx, []ipld.Node{nd}); err != nil {
t.Error(err)
t.Fatal(err)
}

_, err = api.Dag().Get(ctx, nd.Cid())
if err != nil {
t.Error(err)
t.Fatal(err)
}
}
26 changes: 13 additions & 13 deletions tests/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (tp *provider) TestGenerate(t *testing.T) {
defer cancel()
api, err := tp.makeAPI(ctx)
if err != nil {
t.Error(err)
t.Fatal(err)
}

k, err := api.Key().Generate(ctx, "foo")
Expand All @@ -144,7 +144,7 @@ func (tp *provider) TestGenerateSize(t *testing.T) {
defer cancel()
api, err := tp.makeAPI(ctx)
if err != nil {
t.Error(err)
t.Fatal(err)
}

k, err := api.Key().Generate(ctx, "foo", opt.Key.Size(1024))
Expand All @@ -169,7 +169,7 @@ func (tp *provider) TestGenerateType(t *testing.T) {

api, err := tp.makeAPI(ctx)
if err != nil {
t.Error(err)
t.Fatal(err)
}

k, err := api.Key().Generate(ctx, "bar", opt.Key.Type(opt.Ed25519Key))
Expand All @@ -193,7 +193,7 @@ func (tp *provider) TestGenerateExisting(t *testing.T) {
defer cancel()
api, err := tp.makeAPI(ctx)
if err != nil {
t.Error(err)
t.Fatal(err)
}

_, err = api.Key().Generate(ctx, "foo")
Expand Down Expand Up @@ -226,7 +226,7 @@ func (tp *provider) TestList(t *testing.T) {
defer cancel()
api, err := tp.makeAPI(ctx)
if err != nil {
t.Error(err)
t.Fatal(err)
}

_, err = api.Key().Generate(ctx, "foo")
Expand Down Expand Up @@ -272,7 +272,7 @@ func (tp *provider) TestRename(t *testing.T) {
defer cancel()
api, err := tp.makeAPI(ctx)
if err != nil {
t.Error(err)
t.Fatal(err)
}

_, err = api.Key().Generate(ctx, "foo")
Expand Down Expand Up @@ -301,7 +301,7 @@ func (tp *provider) TestRenameToSelf(t *testing.T) {
defer cancel()
api, err := tp.makeAPI(ctx)
if err != nil {
t.Error(err)
t.Fatal(err)
}

_, err = api.Key().Generate(ctx, "foo")
Expand All @@ -325,7 +325,7 @@ func (tp *provider) TestRenameToSelfForce(t *testing.T) {
defer cancel()
api, err := tp.makeAPI(ctx)
if err != nil {
t.Error(err)
t.Fatal(err)
}

_, err = api.Key().Generate(ctx, "foo")
Expand All @@ -349,7 +349,7 @@ func (tp *provider) TestRenameOverwriteNoForce(t *testing.T) {
defer cancel()
api, err := tp.makeAPI(ctx)
if err != nil {
t.Error(err)
t.Fatal(err)
}

_, err = api.Key().Generate(ctx, "foo")
Expand Down Expand Up @@ -379,7 +379,7 @@ func (tp *provider) TestRenameOverwrite(t *testing.T) {
defer cancel()
api, err := tp.makeAPI(ctx)
if err != nil {
t.Error(err)
t.Fatal(err)
}

kfoo, err := api.Key().Generate(ctx, "foo")
Expand Down Expand Up @@ -418,7 +418,7 @@ func (tp *provider) TestRenameSameNameNoForce(t *testing.T) {
defer cancel()
api, err := tp.makeAPI(ctx)
if err != nil {
t.Error(err)
t.Fatal(err)
}

_, err = api.Key().Generate(ctx, "foo")
Expand Down Expand Up @@ -447,7 +447,7 @@ func (tp *provider) TestRenameSameName(t *testing.T) {
defer cancel()
api, err := tp.makeAPI(ctx)
if err != nil {
t.Error(err)
t.Fatal(err)
}

_, err = api.Key().Generate(ctx, "foo")
Expand Down Expand Up @@ -476,7 +476,7 @@ func (tp *provider) TestRemove(t *testing.T) {
defer cancel()
api, err := tp.makeAPI(ctx)
if err != nil {
t.Error(err)
t.Fatal(err)
}

k, err := api.Key().Generate(ctx, "foo")
Expand Down
Loading

0 comments on commit ccf9dac

Please sign in to comment.