mirror of
https://github.com/ipfs/kubo.git
synced 2026-03-12 03:37:59 +08:00
Tests for OfflineRouting storage and Retrieval
License: MIT Signed-off-by: Zander Mackie <zmackie@gmail.com>
This commit is contained in:
parent
e2ba43c12d
commit
695c22a7d1
48
routing/offline/offline_test.go
Normal file
48
routing/offline/offline_test.go
Normal file
@ -0,0 +1,48 @@
|
||||
package offline
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"github.com/ipfs/go-ipfs/thirdparty/testutil"
|
||||
ds "gx/ipfs/QmRWDav6mzWseLWeYfVd5fvUKiVe9xNH29YfMF438fG364/go-datastore"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestOfflineRouterStorage(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
nds := ds.NewMapDatastore()
|
||||
privkey, _, _ := testutil.RandTestKeyPair(128)
|
||||
offline := NewOfflineRouter(nds, privkey)
|
||||
|
||||
err := offline.PutValue(ctx, "key", []byte("testing 1 2 3"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
val, err := offline.GetValue(ctx, "key")
|
||||
if !bytes.Equal([]byte("testing 1 2 3"), val) {
|
||||
t.Fatal("OfflineRouter does not properly store")
|
||||
}
|
||||
|
||||
val, err = offline.GetValue(ctx, "notHere")
|
||||
if err == nil {
|
||||
t.Fatal("Router should throw errors for unfound records")
|
||||
}
|
||||
|
||||
recVal, err := offline.GetValues(ctx, "key", 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
_, err = offline.GetValues(ctx, "notHere", 0)
|
||||
if err == nil {
|
||||
t.Fatal("Router should throw errors for unfound records")
|
||||
}
|
||||
|
||||
local := recVal[0].Val
|
||||
if !bytes.Equal([]byte("testing 1 2 3"), local) {
|
||||
t.Fatal("OfflineRouter does not properly store")
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user