-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
License: MIT Signed-off-by: Łukasz Magiera <[email protected]>
- Loading branch information
Showing
2 changed files
with
104 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package coreapi_test | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/ipfs/go-ipfs/core/coreapi" | ||
"github.com/ipfs/go-ipfs/path" | ||
) | ||
|
||
var ( | ||
treeExpected = map[string]struct{}{ | ||
"a": {}, | ||
"b": {}, | ||
"c": {}, | ||
"c/d": {}, | ||
"c/e": {}, | ||
} | ||
) | ||
|
||
func TestPut(t *testing.T) { | ||
ctx := context.Background() | ||
_, api, err := makeAPI(ctx) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
_, err = api.Dag().Put(ctx, strings.NewReader(`"Hello"`), "json", nil) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
} | ||
|
||
func TestPath(t *testing.T) { | ||
ctx := context.Background() | ||
_, api, err := makeAPI(ctx) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
sub, err := api.Dag().Put(ctx, strings.NewReader(`"foo"`), "json", nil) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
res, err := api.Dag().Put(ctx, strings.NewReader(`{"lnk": {"/": "`+sub[0].Cid().String()+`"}}`), "json", nil) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
p, err := coreapi.ParsePath(path.Join([]string{res[0].Cid().String(), "lnk"})) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
nd, err := api.Dag().Get(ctx, p) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
if nd.Cid().String() != sub[0].Cid().String() { | ||
t.Errorf("got unexpected cid %s, expected %s", nd.Cid().String(), sub[0].Cid().String()) | ||
} | ||
} | ||
|
||
func TestTree(t *testing.T) { | ||
ctx := context.Background() | ||
_, api, err := makeAPI(ctx) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
res, err := api.Dag().Put(ctx, strings.NewReader(`{"a": 123, "b": "foo", "c": {"d": 321, "e": 111}}`), "json", nil) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
lst := res[0].Tree("", -1) | ||
if len(lst) != len(treeExpected) { | ||
t.Errorf("tree length of %d doesn't match expected %d", len(lst), len(treeExpected)) | ||
} | ||
|
||
for _, ent := range lst { | ||
if _, ok := treeExpected[ent]; !ok { | ||
t.Errorf("unexpected tree entry %s", ent) | ||
} | ||
} | ||
} |
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