@@ -147,7 +147,7 @@ func setupTier(ctx context.Context, t *testing.T) (*DHT, *dht.IpfsDHT, *dht.Ipfs
147147 t .Fatal (err )
148148 }
149149 hlprs [0 ].allow = wan .PeerID ()
150- connect (ctx , t , wan , d .WAN )
150+ connect (ctx , t , d .WAN , wan )
151151
152152 lan , err := dht .New (
153153 ctx ,
@@ -193,7 +193,7 @@ func TestFindProviderAsync(t *testing.T) {
193193 defer wan .Close ()
194194 defer lan .Close ()
195195
196- if err := wan .Provide (ctx , wancid , true ); err != nil {
196+ if err := wan .Provide (ctx , wancid , false ); err != nil {
197197 t .Fatal (err )
198198 }
199199
@@ -221,3 +221,70 @@ func TestFindProviderAsync(t *testing.T) {
221221 t .Fatal ("find provider timeout." )
222222 }
223223}
224+
225+ func TestValueGetSet (t * testing.T ) {
226+ ctx , cancel := context .WithTimeout (context .Background (), 20 * time .Second )
227+ defer cancel ()
228+
229+ d , wan , lan := setupTier (ctx , t )
230+ defer d .Close ()
231+ defer wan .Close ()
232+ defer lan .Close ()
233+
234+ err := d .PutValue (ctx , "/v/hello" , []byte ("world" ))
235+ if err != nil {
236+ t .Fatal (err )
237+ }
238+ val , err := wan .GetValue (ctx , "/v/hello" )
239+ if err != nil {
240+ t .Fatal (err )
241+ }
242+ if string (val ) != "world" {
243+ t .Fatal ("failed to get expected string." )
244+ }
245+
246+ val , err = lan .GetValue (ctx , "/v/hello" )
247+ if err == nil {
248+ t .Fatal (err )
249+ }
250+ }
251+
252+ func TestSearchValue (t * testing.T ) {
253+ ctx , cancel := context .WithTimeout (context .Background (), 20 * time .Second )
254+ defer cancel ()
255+
256+ d , wan , lan := setupTier (ctx , t )
257+ defer d .Close ()
258+ defer wan .Close ()
259+ defer lan .Close ()
260+
261+ err := wan .PutValue (ctx , "/v/hello" , []byte ("world" ), )
262+
263+ valCh , err := d .SearchValue (ctx , "/v/hello" , dht .Quorum (0 ))
264+ if err != nil {
265+ t .Fatal (err )
266+ }
267+
268+ select {
269+ case v := <- valCh :
270+ if string (v ) != "world" {
271+ t .Errorf ("expected 'world', got '%s'" , string (v ))
272+ }
273+ case <- ctx .Done ():
274+ t .Fatal (ctx .Err ())
275+ }
276+
277+ err = lan .PutValue (ctx , "/v/hello" , []byte ("newer" ))
278+ if err != nil {
279+ t .Error (err )
280+ }
281+
282+ select {
283+ case v := <- valCh :
284+ if string (v ) != "newer" {
285+ t .Errorf ("expected 'newer', got '%s'" , string (v ))
286+ }
287+ case <- ctx .Done ():
288+ t .Fatal (ctx .Err ())
289+ }
290+ }
0 commit comments