@cryptotaxi247 / kubo / commits / b819e3e94

coreapi: adjust some tests for go-ipfs-http-api

License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>

Łukasz Magiera committed Jan 15, 2019 at 18:51 UTC b819e3e94b4439e922a93f66beb990e31dd08f02
4 files changed +29 -13
core/coreapi/interface/tests/block.go
+2 -2
@@ -159,7 +159,7 @@ func (tp *provider) TestBlockRm(t *testing.T) {
159 if err == nil {
160 t.Error("expected err to exist")
161 }
162 - if err.Error() != "blockservice: key not found" {
162 + if !strings.Contains(err.Error(), "blockservice: key not found") {
163 t.Errorf("unexpected error; %s", err.Error())
164 }
165
@@ -167,7 +167,7 @@ func (tp *provider) TestBlockRm(t *testing.T) {
167 if err == nil {
168 t.Error("expected err to exist")
169 }
170 - if err.Error() != "blockstore: block not found" {
170 + if !strings.Contains(err.Error(), "blockstore: block not found") {
171 t.Errorf("unexpected error; %s", err.Error())
172 }
173
core/coreapi/interface/tests/dht.go
+18 -2
@@ -35,12 +35,20 @@ func (tp *provider) TestDhtFindPeer(t *testing.T) {
35 t.Fatal(err)
36 }
37
38 + laddrs0, err := apis[0].Swarm().LocalAddrs(ctx)
39 + if err != nil {
40 + t.Fatal(err)
41 + }
42 + if len(laddrs0) != 1 {
43 + t.Fatal("unexpected number of local addrs")
44 + }
45 +
46 pi, err := apis[2].Dht().FindPeer(ctx, self0.ID())
47 if err != nil {
48 t.Fatal(err)
49 }
50
43 - if pi.Addrs[0].String() != "/ip4/127.0.0.1/tcp/4001" {
51 + if pi.Addrs[0].String() != laddrs0[0].String() {
52 t.Errorf("got unexpected address from FindPeer: %s", pi.Addrs[0].String())
53 }
54
@@ -54,7 +62,15 @@ func (tp *provider) TestDhtFindPeer(t *testing.T) {
62 t.Fatal(err)
63 }
64
57 - if pi.Addrs[0].String() != "/ip4/127.0.2.1/tcp/4001" {
65 + laddrs2, err := apis[2].Swarm().LocalAddrs(ctx)
66 + if err != nil {
67 + t.Fatal(err)
68 + }
69 + if len(laddrs2) != 1 {
70 + t.Fatal("unexpected number of local addrs")
71 + }
72 +
73 + if pi.Addrs[0].String() != laddrs2[0].String() {
74 t.Errorf("got unexpected address from FindPeer: %s", pi.Addrs[0].String())
75 }
76 }
core/coreapi/interface/tests/key.go
+8 -8
@@ -82,7 +82,7 @@ func (tp *provider) TestRenameSelf(t *testing.T) {
82 if err == nil {
83 t.Error("expected error to not be nil")
84 } else {
85 - if err.Error() != "cannot rename key with name 'self'" {
85 + if !strings.Contains(err.Error(), "cannot rename key with name 'self'") {
86 t.Fatalf("expected error 'cannot rename key with name 'self'', got '%s'", err.Error())
87 }
88 }
@@ -91,7 +91,7 @@ func (tp *provider) TestRenameSelf(t *testing.T) {
91 if err == nil {
92 t.Error("expected error to not be nil")
93 } else {
94 - if err.Error() != "cannot rename key with name 'self'" {
94 + if !strings.Contains(err.Error(), "cannot rename key with name 'self'") {
95 t.Fatalf("expected error 'cannot rename key with name 'self'', got '%s'", err.Error())
96 }
97 }
@@ -110,7 +110,7 @@ func (tp *provider) TestRemoveSelf(t *testing.T) {
110 if err == nil {
111 t.Error("expected error to not be nil")
112 } else {
113 - if err.Error() != "cannot remove key with name 'self'" {
113 + if !strings.Contains(err.Error(), "cannot remove key with name 'self'") {
114 t.Fatalf("expected error 'cannot remove key with name 'self'', got '%s'", err.Error())
115 }
116 }
@@ -206,7 +206,7 @@ func (tp *provider) TestGenerateExisting(t *testing.T) {
206 if err == nil {
207 t.Error("expected error to not be nil")
208 } else {
209 - if err.Error() != "key with name 'foo' already exists" {
209 + if !strings.Contains(err.Error(), "key with name 'foo' already exists") {
210 t.Fatalf("expected error 'key with name 'foo' already exists', got '%s'", err.Error())
211 }
212 }
@@ -215,7 +215,7 @@ func (tp *provider) TestGenerateExisting(t *testing.T) {
215 if err == nil {
216 t.Error("expected error to not be nil")
217 } else {
218 - if err.Error() != "cannot create key with name 'self'" {
218 + if !strings.Contains(err.Error(), "cannot create key with name 'self'") {
219 t.Fatalf("expected error 'cannot create key with name 'self'', got '%s'", err.Error())
220 }
221 }
@@ -314,7 +314,7 @@ func (tp *provider) TestRenameToSelf(t *testing.T) {
314 if err == nil {
315 t.Error("expected error to not be nil")
316 } else {
317 - if err.Error() != "cannot overwrite key with name 'self'" {
317 + if !strings.Contains(err.Error(), "cannot overwrite key with name 'self'") {
318 t.Fatalf("expected error 'cannot overwrite key with name 'self'', got '%s'", err.Error())
319 }
320 }
@@ -338,7 +338,7 @@ func (tp *provider) TestRenameToSelfForce(t *testing.T) {
338 if err == nil {
339 t.Error("expected error to not be nil")
340 } else {
341 - if err.Error() != "cannot overwrite key with name 'self'" {
341 + if !strings.Contains(err.Error(), "cannot overwrite key with name 'self'") {
342 t.Fatalf("expected error 'cannot overwrite key with name 'self'', got '%s'", err.Error())
343 }
344 }
@@ -368,7 +368,7 @@ func (tp *provider) TestRenameOverwriteNoForce(t *testing.T) {
368 if err == nil {
369 t.Error("expected error to not be nil")
370 } else {
371 - if err.Error() != "key by that name already exists, refusing to overwrite" {
371 + if !strings.Contains(err.Error(), "key by that name already exists, refusing to overwrite") {
372 t.Fatalf("expected error 'key by that name already exists, refusing to overwrite', got '%s'", err.Error())
373 }
374 }
core/coreapi/interface/tests/object.go
+1 -1
@@ -300,7 +300,7 @@ func (tp *provider) TestObjectAddLinkCreate(t *testing.T) {
300 if err == nil {
301 t.Fatal("expected an error")
302 }
303 - if err.Error() != "no link by that name" {
303 + if !strings.Contains(err.Error(), "no link by that name") {
304 t.Fatalf("unexpected error: %s", err.Error())
305 }
306