coreapi: cleanup coredag references in interface
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com> This commit was moved from ipfs/interface-go-ipfs-core@c3fa814784e5a96d5baeb5722bc51da7750a09ce This commit was moved from ipfs/boxo@d15daa504fd1884c0e2a9c57ae3ae42343ec482e
Łukasz Magiera committed
Feb 8, 2019 at 17:58 UTC
23d84ed3ef15cb86a8c41d0db2db1007d650414f
3 files changed
+56
-51
core/coreiface/tests/dag.go
+27
-26
@@ -8,8 +8,9 @@ import (
8
"testing"
9
10
coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
11
- coredag "github.com/ipfs/go-ipfs/core/coredag"
11
12
+ ipld "gx/ipfs/QmRL22E4paat7ky7vx9MLpR97JHHbFPrg3ytFQw6qp1y1s/go-ipld-format"
13
+ ipldcbor "gx/ipfs/QmRZxJ7oybgnnwriuRub9JXp5YdFM9wiGSyRq38QC7swpS/go-ipld-cbor"
14
mh "gx/ipfs/QmerPMzPk1mJVowm8KgmoknWa4yCYvvugMPsgWmDNUvDLW/go-multihash"
15
)
16
@@ -46,18 +47,18 @@ func (tp *provider) TestPut(t *testing.T) {
47
t.Error(err)
48
}
49
49
- nds, err := coredag.ParseInputs("json", "dag-cbor", strings.NewReader(`"Hello"`), math.MaxUint64, -1)
50
+ nd, err := ipldcbor.FromJSON(strings.NewReader(`"Hello"`), math.MaxUint64, -1)
51
if err != nil {
52
t.Error(err)
53
}
54
54
- err = api.Dag().Add(ctx, nds[0])
55
+ err = api.Dag().Add(ctx, nd)
56
if err != nil {
57
t.Fatal(err)
58
}
59
59
- if nds[0].Cid().String() != "zdpuAqckYF3ToF3gcJNxPZXmnmGuXd3gxHCXhq81HGxBejEvv" {
60
- t.Errorf("got wrong cid: %s", nds[0].Cid().String())
60
+ if nd.Cid().String() != "zdpuAqckYF3ToF3gcJNxPZXmnmGuXd3gxHCXhq81HGxBejEvv" {
61
+ t.Errorf("got wrong cid: %s", nd.Cid().String())
62
}
63
}
64
@@ -69,18 +70,18 @@ func (tp *provider) TestPutWithHash(t *testing.T) {
70
t.Error(err)
71
}
72
72
- nds, err := coredag.ParseInputs("json", "dag-cbor", strings.NewReader(`"Hello"`), mh.ID, -1)
73
+ nd, err := ipldcbor.FromJSON(strings.NewReader(`"Hello"`), mh.ID, -1)
74
if err != nil {
75
t.Error(err)
76
}
77
77
- err = api.Dag().Add(ctx, nds[0])
78
+ err = api.Dag().Add(ctx, nd)
79
if err != nil {
80
t.Fatal(err)
81
}
82
82
- if nds[0].Cid().String() != "z5hRLNd2sv4z1c" {
83
- t.Errorf("got wrong cid: %s", nds[0].Cid().String())
83
+ if nd.Cid().String() != "z5hRLNd2sv4z1c" {
84
+ t.Errorf("got wrong cid: %s", nd.Cid().String())
85
}
86
}
87
@@ -92,27 +93,27 @@ func (tp *provider) TestDagPath(t *testing.T) {
93
t.Error(err)
94
}
95
95
- snds, err := coredag.ParseInputs("json", "dag-cbor", strings.NewReader(`"foo"`), math.MaxUint64, -1)
96
+ snd, err := ipldcbor.FromJSON(strings.NewReader(`"foo"`), math.MaxUint64, -1)
97
if err != nil {
98
t.Error(err)
99
}
100
100
- err = api.Dag().Add(ctx, snds[0])
101
+ err = api.Dag().Add(ctx, snd)
102
if err != nil {
103
t.Fatal(err)
104
}
105
105
- nds, err := coredag.ParseInputs("json", "dag-cbor", strings.NewReader(`{"lnk": {"/": "`+snds[0].Cid().String()+`"}}`), math.MaxUint64, -1)
106
+ nd, err := ipldcbor.FromJSON(strings.NewReader(`{"lnk": {"/": "`+snd.Cid().String()+`"}}`), math.MaxUint64, -1)
107
if err != nil {
108
t.Error(err)
109
}
110
110
- err = api.Dag().Add(ctx, nds[0])
111
+ err = api.Dag().Add(ctx, nd)
112
if err != nil {
113
t.Fatal(err)
114
}
115
115
- p, err := coreiface.ParsePath(path.Join(nds[0].Cid().String(), "lnk"))
116
+ p, err := coreiface.ParsePath(path.Join(nd.Cid().String(), "lnk"))
117
if err != nil {
118
t.Error(err)
119
}
@@ -122,13 +123,13 @@ func (tp *provider) TestDagPath(t *testing.T) {
123
t.Error(err)
124
}
125
125
- nd, err := api.Dag().Get(ctx, rp.Cid())
126
+ ndd, err := api.Dag().Get(ctx, rp.Cid())
127
if err != nil {
128
t.Error(err)
129
}
130
130
- if nd.Cid().String() != snds[0].Cid().String() {
131
- t.Errorf("got unexpected cid %s, expected %s", nd.Cid().String(), snds[0].Cid().String())
131
+ if nd.Cid().String() != snd.Cid().String() {
132
+ t.Errorf("got unexpected cid %s, expected %s", ndd.Cid().String(), snd.Cid().String())
133
}
134
}
135
@@ -140,17 +141,17 @@ func (tp *provider) TestTree(t *testing.T) {
141
t.Error(err)
142
}
143
143
- nds, err := coredag.ParseInputs("json", "dag-cbor", strings.NewReader(`{"a": 123, "b": "foo", "c": {"d": 321, "e": 111}}`), math.MaxUint64, -1)
144
+ nd, err := ipldcbor.FromJSON(strings.NewReader(`{"a": 123, "b": "foo", "c": {"d": 321, "e": 111}}`), math.MaxUint64, -1)
145
if err != nil {
146
t.Error(err)
147
}
148
148
- err = api.Dag().Add(ctx, nds[0])
149
+ err = api.Dag().Add(ctx, nd)
150
if err != nil {
151
t.Fatal(err)
152
}
153
153
- res, err := api.Dag().Get(ctx, nds[0].Cid())
154
+ res, err := api.Dag().Get(ctx, nd.Cid())
155
if err != nil {
156
t.Error(err)
157
}
@@ -175,25 +176,25 @@ func (tp *provider) TestBatch(t *testing.T) {
176
t.Error(err)
177
}
178
178
- nds, err := coredag.ParseInputs("json", "dag-cbor", strings.NewReader(`"Hello"`), math.MaxUint64, -1)
179
+ nd, err := ipldcbor.FromJSON(strings.NewReader(`"Hello"`), math.MaxUint64, -1)
180
if err != nil {
181
t.Error(err)
182
}
183
183
- if nds[0].Cid().String() != "zdpuAqckYF3ToF3gcJNxPZXmnmGuXd3gxHCXhq81HGxBejEvv" {
184
- t.Errorf("got wrong cid: %s", nds[0].Cid().String())
184
+ if nd.Cid().String() != "zdpuAqckYF3ToF3gcJNxPZXmnmGuXd3gxHCXhq81HGxBejEvv" {
185
+ t.Errorf("got wrong cid: %s", nd.Cid().String())
186
}
187
187
- _, err = api.Dag().Get(ctx, nds[0].Cid())
188
+ _, err = api.Dag().Get(ctx, nd.Cid())
189
if err == nil || !strings.Contains(err.Error(), "not found") {
190
t.Error(err)
191
}
192
192
- if err := api.Dag().AddMany(ctx, nds); err != nil {
193
+ if err := api.Dag().AddMany(ctx, []ipld.Node{nd}); err != nil {
194
t.Error(err)
195
}
196
196
- _, err = api.Dag().Get(ctx, nds[0].Cid())
197
+ _, err = api.Dag().Get(ctx, nd.Cid())
198
if err != nil {
199
t.Error(err)
200
}
core/coreiface/tests/path.go
+17
-15
@@ -8,7 +8,8 @@ import (
8
9
coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
10
"github.com/ipfs/go-ipfs/core/coreapi/interface/options"
11
- "github.com/ipfs/go-ipfs/core/coredag"
11
+
12
+ ipldcbor "gx/ipfs/QmRZxJ7oybgnnwriuRub9JXp5YdFM9wiGSyRq38QC7swpS/go-ipld-cbor"
13
)
14
15
func (tp *provider) TestPath(t *testing.T) {
@@ -37,7 +38,8 @@ func (tp *provider) TestMutablePath(t *testing.T) {
38
t.Error("expected /ipld path to be immutable")
39
}
40
40
- // get self /ipns path
41
+ // get self /ipns path ipldcbor "gx/ipfs/QmRZxJ7oybgnnwriuRub9JXp5YdFM9wiGSyRq38QC7swpS/go-ipld-cbor"
42
+
43
if api.Key() == nil {
44
t.Fatal(".Key not implemented")
45
}
@@ -64,16 +66,16 @@ func (tp *provider) TestPathRemainder(t *testing.T) {
66
t.Fatal(".Dag not implemented")
67
}
68
67
- nds, err := coredag.ParseInputs("json", "dag-cbor", strings.NewReader(`{"foo": {"bar": "baz"}}`), math.MaxUint64, -1)
69
+ nd, err := ipldcbor.FromJSON(strings.NewReader(`{"foo": {"bar": "baz"}}`), math.MaxUint64, -1)
70
if err != nil {
71
t.Error(err)
72
}
73
72
- if err := api.Dag().AddMany(ctx, nds); err != nil {
74
+ if err := api.Dag().Add(ctx, nd); err != nil {
75
t.Fatal(err)
76
}
77
76
- p1, err := coreiface.ParsePath(nds[0].String() + "/foo/bar")
78
+ p1, err := coreiface.ParsePath(nd.String() + "/foo/bar")
79
if err != nil {
80
t.Error(err)
81
}
@@ -100,16 +102,16 @@ func (tp *provider) TestEmptyPathRemainder(t *testing.T) {
102
t.Fatal(".Dag not implemented")
103
}
104
103
- nds, err := coredag.ParseInputs("json", "dag-cbor", strings.NewReader(`{"foo": {"bar": "baz"}}`), math.MaxUint64, -1)
105
+ nd, err := ipldcbor.FromJSON(strings.NewReader(`{"foo": {"bar": "baz"}}`), math.MaxUint64, -1)
106
if err != nil {
107
t.Error(err)
108
}
109
108
- if err := api.Dag().AddMany(ctx, nds); err != nil {
110
+ if err := api.Dag().Add(ctx, nd); err != nil {
111
t.Fatal(err)
112
}
113
112
- p1, err := coreiface.ParsePath(nds[0].Cid().String())
114
+ p1, err := coreiface.ParsePath(nd.Cid().String())
115
if err != nil {
116
t.Error(err)
117
}
@@ -136,16 +138,16 @@ func (tp *provider) TestInvalidPathRemainder(t *testing.T) {
138
t.Fatal(".Dag not implemented")
139
}
140
139
- nds, err := coredag.ParseInputs("json", "dag-cbor", strings.NewReader(`{"foo": {"bar": "baz"}}`), math.MaxUint64, -1)
141
+ nd, err := ipldcbor.FromJSON(strings.NewReader(`{"foo": {"bar": "baz"}}`), math.MaxUint64, -1)
142
if err != nil {
143
t.Error(err)
144
}
145
144
- if err := api.Dag().AddMany(ctx, nds); err != nil {
146
+ if err := api.Dag().Add(ctx, nd); err != nil {
147
t.Fatal(err)
148
}
149
148
- p1, err := coreiface.ParsePath("/ipld/" + nds[0].Cid().String() + "/bar/baz")
150
+ p1, err := coreiface.ParsePath("/ipld/" + nd.Cid().String() + "/bar/baz")
151
if err != nil {
152
t.Error(err)
153
}
@@ -177,16 +179,16 @@ func (tp *provider) TestPathRoot(t *testing.T) {
179
t.Fatal(".Dag not implemented")
180
}
181
180
- nds, err := coredag.ParseInputs("json", "dag-cbor", strings.NewReader(`{"foo": {"/": "`+blk.Path().Cid().String()+`"}}`), math.MaxUint64, -1)
182
+ nd, err := ipldcbor.FromJSON(strings.NewReader(`{"foo": {"/": "`+blk.Path().Cid().String()+`"}}`), math.MaxUint64, -1)
183
if err != nil {
184
t.Error(err)
185
}
186
185
- if err := api.Dag().AddMany(ctx, nds); err != nil {
187
+ if err := api.Dag().Add(ctx, nd); err != nil {
188
t.Fatal(err)
189
}
190
189
- p1, err := coreiface.ParsePath("/ipld/" + nds[0].Cid().String() + "/foo")
191
+ p1, err := coreiface.ParsePath("/ipld/" + nd.Cid().String() + "/foo")
192
if err != nil {
193
t.Error(err)
194
}
@@ -196,7 +198,7 @@ func (tp *provider) TestPathRoot(t *testing.T) {
198
t.Fatal(err)
199
}
200
199
- if rp.Root().String() != nds[0].Cid().String() {
201
+ if rp.Root().String() != nd.Cid().String() {
202
t.Error("unexpected path root")
203
}
204
core/coreiface/tests/pin.go
+12
-10
@@ -8,7 +8,9 @@ import (
8
9
"github.com/ipfs/go-ipfs/core/coreapi/interface"
10
opt "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
11
- "github.com/ipfs/go-ipfs/core/coredag"
11
+
12
+ ipld "gx/ipfs/QmRL22E4paat7ky7vx9MLpR97JHHbFPrg3ytFQw6qp1y1s/go-ipld-format"
13
+ ipldcbor "gx/ipfs/QmRZxJ7oybgnnwriuRub9JXp5YdFM9wiGSyRq38QC7swpS/go-ipld-cbor"
14
)
15
16
func (tp *provider) TestPin(t *testing.T) {
@@ -111,26 +113,26 @@ func (tp *provider) TestPinRecursive(t *testing.T) {
113
t.Error(err)
114
}
115
114
- nd2, err := coredag.ParseInputs("json", "dag-cbor", strings.NewReader(`{"lnk": {"/": "`+p0.Cid().String()+`"}}`), math.MaxUint64, -1)
116
+ nd2, err := ipldcbor.FromJSON(strings.NewReader(`{"lnk": {"/": "`+p0.Cid().String()+`"}}`), math.MaxUint64, -1)
117
if err != nil {
118
t.Error(err)
119
}
120
119
- nd3, err := coredag.ParseInputs("json", "dag-cbor", strings.NewReader(`{"lnk": {"/": "`+p1.Cid().String()+`"}}`), math.MaxUint64, -1)
121
+ nd3, err := ipldcbor.FromJSON(strings.NewReader(`{"lnk": {"/": "`+p1.Cid().String()+`"}}`), math.MaxUint64, -1)
122
if err != nil {
123
t.Error(err)
124
}
125
124
- if err := api.Dag().AddMany(ctx, append(nd2, nd3...)); err != nil {
126
+ if err := api.Dag().AddMany(ctx, []ipld.Node{nd2, nd3}); err != nil {
127
t.Fatal(err)
128
}
129
128
- err = api.Pin().Add(ctx, iface.IpldPath(nd2[0].Cid()))
130
+ err = api.Pin().Add(ctx, iface.IpldPath(nd2.Cid()))
131
if err != nil {
132
t.Error(err)
133
}
134
133
- err = api.Pin().Add(ctx, iface.IpldPath(nd3[0].Cid()), opt.Pin.Recursive(false))
135
+ err = api.Pin().Add(ctx, iface.IpldPath(nd3.Cid()), opt.Pin.Recursive(false))
136
if err != nil {
137
t.Error(err)
138
}
@@ -153,8 +155,8 @@ func (tp *provider) TestPinRecursive(t *testing.T) {
155
t.Errorf("unexpected pin list len: %d", len(list))
156
}
157
156
- if list[0].Path().String() != iface.IpldPath(nd3[0].Cid()).String() {
157
- t.Errorf("unexpected path, %s != %s", list[0].Path().String(), iface.IpfsPath(nd2[0].Cid()).String())
158
+ if list[0].Path().String() != iface.IpldPath(nd3.Cid()).String() {
159
+ t.Errorf("unexpected path, %s != %s", list[0].Path().String(), iface.IpfsPath(nd2.Cid()).String())
160
}
161
162
list, err = api.Pin().Ls(ctx, opt.Pin.Type.Recursive())
@@ -166,8 +168,8 @@ func (tp *provider) TestPinRecursive(t *testing.T) {
168
t.Errorf("unexpected pin list len: %d", len(list))
169
}
170
169
- if list[0].Path().String() != iface.IpldPath(nd2[0].Cid()).String() {
170
- t.Errorf("unexpected path, %s != %s", list[0].Path().String(), iface.IpldPath(nd3[0].Cid()).String())
171
+ if list[0].Path().String() != iface.IpldPath(nd2.Cid()).String() {
172
+ t.Errorf("unexpected path, %s != %s", list[0].Path().String(), iface.IpldPath(nd3.Cid()).String())
173
}
174
175
list, err = api.Pin().Ls(ctx, opt.Pin.Type.Indirect())