-
Notifications
You must be signed in to change notification settings - Fork 3
/
feedstore_test.go
57 lines (42 loc) · 914 Bytes
/
feedstore_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package orbitdb
import (
"fmt"
"github.com/keks/go-ipfs-colog"
"io"
"time"
)
func ExampleFeedStore() {
s1, err := NewOrbitDB(topic)
assert(err == nil, err)
time.Sleep(10 * time.Millisecond)
s2, err := NewOrbitDB(topic)
assert(err == nil, err)
fs1 := NewFeedStore(s1)
fs2 := NewFeedStore(s2)
fmt.Println("fs1: add foo")
fooEntry, err := fs1.Add("foo")
assert(err == nil, err)
time.Sleep(10 * time.Millisecond)
fmt.Println("fs2: add bar")
_, err = fs2.Add("bar")
assert(err == nil, err)
time.Sleep(10 * time.Millisecond)
fmt.Println("fs2: del foo")
_, err = fs2.Delete(fooEntry.Hash)
assert(err == nil, err)
time.Sleep(10 * time.Millisecond)
res := fs1.Query(colog.Query{})
var (
p Event
)
for err == nil {
p, err = res()
assert(err == nil || err == io.EOF, err)
fmt.Println(p.GetString())
}
// Output:
// fs1: add foo
// fs2: add bar
// fs2: del foo
// bar
}