-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
52 lines (41 loc) · 1016 Bytes
/
main_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
package main
import (
"testing"
"fmt"
"github.com/ipfs/go-datastore"
"github.com/ipfs/go-ipfs-blockstore"
)
func createSmorServ() *SmorServ {
db := datastore.NewMapDatastore()
ss := &SmorServ{db: db, bs: blockstore.NewBlockstore(db)}
return ss
}
func TestFeed(t *testing.T) {
ss := createSmorServ()
var posts []*Smor
postLimit := 11
for i := 1; i <= postLimit; i++ {
posts = append(posts, getRandomSmor(uint64(i)))
}
user := &User{
CreatedAt: 0,
Username: "alice",
}
if err := ss.saveUser(user); err != nil {
t.Fatal("Save user failed")
}
usr, err := ss.getUser(user.Username)
if err != nil {
t.Fatal("getUser failed")
}
fmt.Println("User obj retrieved", usr)
if err := ss.postFeedItems(user.Username, posts); err != nil {
t.Fatal("Failed postFeedItems")
}
fmt.Print("Posted items")
retrievedPosts, err := ss.getFeed(user.Username)
if err != nil {
t.Fatal("Failed getFeed")
}
fmt.Println("Out posts", retrievedPosts)
}