@cryptotaxi247 / kubo / commits / 09cc62ebd

Additional provider tests

License: MIT Signed-off-by: Erik Ingenito <erik@carbonfive.com>

Erik Ingenito committed Mar 16, 2019 at 09:52 UTC 09cc62ebdfe9b1c6277e4a8f142cd10819cd93b9
2 files changed +61 -11
provider/provider_test.go
+9 -10
@@ -19,6 +19,15 @@ type mockRouting struct {
19 provided chan cid.Cid
20 }
21
22 +func (r *mockRouting) Provide(ctx context.Context, cid cid.Cid, recursive bool) error {
23 + r.provided <- cid
24 + return nil
25 +}
26 +
27 +func (r *mockRouting) FindProvidersAsync(ctx context.Context, cid cid.Cid, timeout int) <-chan pstore.PeerInfo {
28 + return nil
29 +}
30 +
31 func mockContentRouting() *mockRouting {
32 r := mockRouting{}
33 r.provided = make(chan cid.Cid)
@@ -68,13 +77,3 @@ func TestAnnouncement(t *testing.T) {
77 }
78 }
79 }
71 -
72 -func (r *mockRouting) Provide(ctx context.Context, cid cid.Cid, recursive bool) error {
73 - r.provided <- cid
74 - return nil
75 -}
76 -
77 -// Search for peers who are able to provide a given key
78 -func (r *mockRouting) FindProvidersAsync(ctx context.Context, cid cid.Cid, timeout int) <-chan pstore.PeerInfo {
79 - return nil
80 -}
provider/queue_test.go
+52 -1
@@ -52,7 +52,37 @@ func TestBasicOperation(t *testing.T) {
52 assertOrdered(cids, queue, t)
53 }
54
55 -func TestInitialization(t *testing.T) {
55 +func TestSparseDatastore(t *testing.T) {
56 + ctx := context.Background()
57 + defer ctx.Done()
58 +
59 + ds := sync.MutexWrap(datastore.NewMapDatastore())
60 + queue, err := NewQueue(ctx, "test", ds)
61 + if err != nil {
62 + t.Fatal(err)
63 + }
64 +
65 + cids := makeCids(10)
66 + for _, c := range cids {
67 + queue.Enqueue(c)
68 + }
69 +
70 + // remove entries in the middle
71 + err = queue.ds.Delete(queue.queueKey(5))
72 + if err != nil {
73 + t.Fatal(err)
74 + }
75 +
76 + err = queue.ds.Delete(queue.queueKey(6))
77 + if err != nil {
78 + t.Fatal(err)
79 + }
80 +
81 + expected := append(cids[:5], cids[7:]...)
82 + assertOrdered(expected, queue, t)
83 +}
84 +
85 +func TestMangledData(t *testing.T) {
86 ctx := context.Background()
87 defer ctx.Done()
88
@@ -63,7 +93,28 @@ func TestInitialization(t *testing.T) {
93 }
94
95 cids := makeCids(10)
96 + for _, c := range cids {
97 + queue.Enqueue(c)
98 + }
99 +
100 + // remove entries in the middle
101 + err = queue.ds.Put(queue.queueKey(5), []byte("borked"))
102
103 + expected := append(cids[:5], cids[6:]...)
104 + assertOrdered(expected, queue, t)
105 +}
106 +
107 +func TestInitialization(t *testing.T) {
108 + ctx := context.Background()
109 + defer ctx.Done()
110 +
111 + ds := sync.MutexWrap(datastore.NewMapDatastore())
112 + queue, err := NewQueue(ctx, "test", ds)
113 + if err != nil {
114 + t.Fatal(err)
115 + }
116 +
117 + cids := makeCids(10)
118 for _, c := range cids {
119 queue.Enqueue(c)
120 }