@@ -8,12 +8,12 @@ import (
8
8
"testing"
9
9
"time"
10
10
11
- path "github.com/ipfs/boxo/coreiface/path"
12
-
13
- "github.com/ipfs/boxo/files"
14
-
15
11
coreiface "github.com/ipfs/boxo/coreiface"
16
12
opt "github.com/ipfs/boxo/coreiface/options"
13
+ path "github.com/ipfs/boxo/coreiface/path"
14
+ "github.com/ipfs/boxo/files"
15
+ "github.com/ipfs/boxo/ipns"
16
+ "github.com/stretchr/testify/require"
17
17
)
18
18
19
19
func (tp * TestSuite ) TestName (t * testing.T ) {
@@ -44,138 +44,68 @@ func (tp *TestSuite) TestPublishResolve(t *testing.T) {
44
44
defer cancel ()
45
45
init := func () (coreiface.CoreAPI , path.Path ) {
46
46
apis , err := tp .MakeAPISwarm (t , ctx , 5 )
47
- if err != nil {
48
- t .Fatal (err )
49
- return nil , nil
50
- }
47
+ require .NoError (t , err )
51
48
api := apis [0 ]
52
49
53
50
p , err := addTestObject (ctx , api )
54
- if err != nil {
55
- t .Fatal (err )
56
- return nil , nil
57
- }
51
+ require .NoError (t , err )
58
52
return api , p
59
53
}
60
54
run := func (t * testing.T , ropts []opt.NameResolveOption ) {
61
55
t .Run ("basic" , func (t * testing.T ) {
62
56
api , p := init ()
63
- e , err := api .Name ().Publish (ctx , p )
64
- if err != nil {
65
- t .Fatal (err )
66
- }
57
+ name , err := api .Name ().Publish (ctx , p )
58
+ require .NoError (t , err )
67
59
68
60
self , err := api .Key ().Self (ctx )
69
- if err != nil {
70
- t .Fatal (err )
71
- }
72
-
73
- if e .Name () != coreiface .FormatKeyID (self .ID ()) {
74
- t .Errorf ("expected e.Name to equal '%s', got '%s'" , coreiface .FormatKeyID (self .ID ()), e .Name ())
75
- }
76
-
77
- if e .Value ().String () != p .String () {
78
- t .Errorf ("expected paths to match, '%s'!='%s'" , e .Value ().String (), p .String ())
79
- }
80
-
81
- resPath , err := api .Name ().Resolve (ctx , e .Name (), ropts ... )
82
- if err != nil {
83
- t .Fatal (err )
84
- }
85
-
86
- if resPath .String () != p .String () {
87
- t .Errorf ("expected paths to match, '%s'!='%s'" , resPath .String (), p .String ())
88
- }
61
+ require .NoError (t , err )
62
+ require .Equal (t , name .String (), ipns .NameFromPeer (self .ID ()).String ())
63
+
64
+ resPath , err := api .Name ().Resolve (ctx , name .String (), ropts ... )
65
+ require .NoError (t , err )
66
+ require .Equal (t , p .String (), resPath .String ())
89
67
})
90
68
91
69
t .Run ("publishPath" , func (t * testing.T ) {
92
70
api , p := init ()
93
- e , err := api .Name ().Publish (ctx , appendPath (p , "/test" ))
94
- if err != nil {
95
- t .Fatal (err )
96
- }
71
+ name , err := api .Name ().Publish (ctx , appendPath (p , "/test" ))
72
+ require .NoError (t , err )
97
73
98
74
self , err := api .Key ().Self (ctx )
99
- if err != nil {
100
- t .Fatal (err )
101
- }
102
-
103
- if e .Name () != coreiface .FormatKeyID (self .ID ()) {
104
- t .Errorf ("expected e.Name to equal '%s', got '%s'" , coreiface .FormatKeyID (self .ID ()), e .Name ())
105
- }
106
-
107
- if e .Value ().String () != p .String ()+ "/test" {
108
- t .Errorf ("expected paths to match, '%s'!='%s'" , e .Value ().String (), p .String ())
109
- }
110
-
111
- resPath , err := api .Name ().Resolve (ctx , e .Name (), ropts ... )
112
- if err != nil {
113
- t .Fatal (err )
114
- }
115
-
116
- if resPath .String () != p .String ()+ "/test" {
117
- t .Errorf ("expected paths to match, '%s'!='%s'" , resPath .String (), p .String ()+ "/test" )
118
- }
75
+ require .NoError (t , err )
76
+ require .Equal (t , name .String (), ipns .NameFromPeer (self .ID ()).String ())
77
+
78
+ resPath , err := api .Name ().Resolve (ctx , name .String (), ropts ... )
79
+ require .NoError (t , err )
80
+ require .Equal (t , p .String ()+ "/test" , resPath .String ())
119
81
})
120
82
121
83
t .Run ("revolvePath" , func (t * testing.T ) {
122
84
api , p := init ()
123
- e , err := api .Name ().Publish (ctx , p )
124
- if err != nil {
125
- t .Fatal (err )
126
- }
85
+ name , err := api .Name ().Publish (ctx , p )
86
+ require .NoError (t , err )
127
87
128
88
self , err := api .Key ().Self (ctx )
129
- if err != nil {
130
- t .Fatal (err )
131
- }
132
-
133
- if e .Name () != coreiface .FormatKeyID (self .ID ()) {
134
- t .Errorf ("expected e.Name to equal '%s', got '%s'" , coreiface .FormatKeyID (self .ID ()), e .Name ())
135
- }
136
-
137
- if e .Value ().String () != p .String () {
138
- t .Errorf ("expected paths to match, '%s'!='%s'" , e .Value ().String (), p .String ())
139
- }
140
-
141
- resPath , err := api .Name ().Resolve (ctx , e .Name ()+ "/test" , ropts ... )
142
- if err != nil {
143
- t .Fatal (err )
144
- }
145
-
146
- if resPath .String () != p .String ()+ "/test" {
147
- t .Errorf ("expected paths to match, '%s'!='%s'" , resPath .String (), p .String ()+ "/test" )
148
- }
89
+ require .NoError (t , err )
90
+ require .Equal (t , name .String (), ipns .NameFromPeer (self .ID ()).String ())
91
+
92
+ resPath , err := api .Name ().Resolve (ctx , name .String ()+ "/test" , ropts ... )
93
+ require .NoError (t , err )
94
+ require .Equal (t , p .String ()+ "/test" , resPath .String ())
149
95
})
150
96
151
97
t .Run ("publishRevolvePath" , func (t * testing.T ) {
152
98
api , p := init ()
153
- e , err := api .Name ().Publish (ctx , appendPath (p , "/a" ))
154
- if err != nil {
155
- t .Fatal (err )
156
- }
99
+ name , err := api .Name ().Publish (ctx , appendPath (p , "/a" ))
100
+ require .NoError (t , err )
157
101
158
102
self , err := api .Key ().Self (ctx )
159
- if err != nil {
160
- t .Fatal (err )
161
- }
162
-
163
- if e .Name () != coreiface .FormatKeyID (self .ID ()) {
164
- t .Errorf ("expected e.Name to equal '%s', got '%s'" , coreiface .FormatKeyID (self .ID ()), e .Name ())
165
- }
166
-
167
- if e .Value ().String () != p .String ()+ "/a" {
168
- t .Errorf ("expected paths to match, '%s'!='%s'" , e .Value ().String (), p .String ())
169
- }
170
-
171
- resPath , err := api .Name ().Resolve (ctx , e .Name ()+ "/b" , ropts ... )
172
- if err != nil {
173
- t .Fatal (err )
174
- }
175
-
176
- if resPath .String () != p .String ()+ "/a/b" {
177
- t .Errorf ("expected paths to match, '%s'!='%s'" , resPath .String (), p .String ()+ "/a/b" )
178
- }
103
+ require .NoError (t , err )
104
+ require .Equal (t , name .String (), ipns .NameFromPeer (self .ID ()).String ())
105
+
106
+ resPath , err := api .Name ().Resolve (ctx , name .String ()+ "/b" , ropts ... )
107
+ require .NoError (t , err )
108
+ require .Equal (t , p .String ()+ "/a/b" , resPath .String ())
179
109
})
180
110
}
181
111
@@ -192,42 +122,22 @@ func (tp *TestSuite) TestBasicPublishResolveKey(t *testing.T) {
192
122
ctx , cancel := context .WithCancel (context .Background ())
193
123
defer cancel ()
194
124
apis , err := tp .MakeAPISwarm (t , ctx , 5 )
195
- if err != nil {
196
- t .Fatal (err )
197
- }
125
+ require .NoError (t , err )
198
126
api := apis [0 ]
199
127
200
128
k , err := api .Key ().Generate (ctx , "foo" )
201
- if err != nil {
202
- t .Fatal (err )
203
- }
129
+ require .NoError (t , err )
204
130
205
131
p , err := addTestObject (ctx , api )
206
- if err != nil {
207
- t .Fatal (err )
208
- }
209
-
210
- e , err := api .Name ().Publish (ctx , p , opt .Name .Key (k .Name ()))
211
- if err != nil {
212
- t .Fatal (err )
213
- }
214
-
215
- if e .Name () != coreiface .FormatKey (k ) {
216
- t .Errorf ("expected e.Name to equal %s, got '%s'" , e .Name (), coreiface .FormatKey (k ))
217
- }
218
-
219
- if e .Value ().String () != p .String () {
220
- t .Errorf ("expected paths to match, '%s'!='%s'" , e .Value ().String (), p .String ())
221
- }
132
+ require .NoError (t , err )
222
133
223
- resPath , err := api .Name ().Resolve (ctx , e .Name ())
224
- if err != nil {
225
- t .Fatal (err )
226
- }
134
+ name , err := api .Name ().Publish (ctx , p , opt .Name .Key (k .Name ()))
135
+ require .NoError (t , err )
136
+ require .Equal (t , name .String (), ipns .NameFromPeer (k .ID ()).String ())
227
137
228
- if resPath . String () != p .String () {
229
- t . Errorf ( "expected paths to match, '%s'!='%s'" , resPath . String (), p . String () )
230
- }
138
+ resPath , err := api . Name (). Resolve ( ctx , name .String ())
139
+ require . NoError ( t , err )
140
+ require . Equal ( t , p . String (), resPath . String ())
231
141
}
232
142
233
143
func (tp * TestSuite ) TestBasicPublishResolveTimeout (t * testing.T ) {
@@ -236,39 +146,22 @@ func (tp *TestSuite) TestBasicPublishResolveTimeout(t *testing.T) {
236
146
ctx , cancel := context .WithCancel (context .Background ())
237
147
defer cancel ()
238
148
apis , err := tp .MakeAPISwarm (t , ctx , 5 )
239
- if err != nil {
240
- t .Fatal (err )
241
- }
149
+ require .NoError (t , err )
242
150
api := apis [0 ]
243
151
p , err := addTestObject (ctx , api )
244
- if err != nil {
245
- t .Fatal (err )
246
- }
247
-
248
- e , err := api .Name ().Publish (ctx , p , opt .Name .ValidTime (time .Millisecond * 100 ))
249
- if err != nil {
250
- t .Fatal (err )
251
- }
152
+ require .NoError (t , err )
252
153
253
154
self , err := api .Key ().Self (ctx )
254
- if err != nil {
255
- t .Fatal (err )
256
- }
155
+ require .NoError (t , err )
257
156
258
- if e .Name () != coreiface .FormatKeyID (self .ID ()) {
259
- t .Errorf ("expected e.Name to equal '%s', got '%s'" , coreiface .FormatKeyID (self .ID ()), e .Name ())
260
- }
261
-
262
- if e .Value ().String () != p .String () {
263
- t .Errorf ("expected paths to match, '%s'!='%s'" , e .Value ().String (), p .String ())
264
- }
157
+ name , err := api .Name ().Publish (ctx , p , opt .Name .ValidTime (time .Millisecond * 100 ))
158
+ require .NoError (t , err )
159
+ require .Equal (t , name .String (), ipns .NameFromPeer (self .ID ()).String ())
265
160
266
161
time .Sleep (time .Second )
267
162
268
- _ , err = api .Name ().Resolve (ctx , e .Name ())
269
- if err == nil {
270
- t .Fatal ("Expected an error" )
271
- }
163
+ _ , err = api .Name ().Resolve (ctx , name .String ())
164
+ require .NoError (t , err )
272
165
}
273
166
274
167
//TODO: When swarm api is created, add multinode tests
0 commit comments