-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample_test.go
46 lines (35 loc) · 1.02 KB
/
example_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
package pail
import (
"context"
"fmt"
"testing"
"github.com/ipfs/go-cid"
cidlink "github.com/ipld/go-ipld-prime/linking/cid"
"github.com/storacha/go-pail/block"
)
func TestBasicExample(t *testing.T) {
ctx := context.Background()
rootBlock, _ := New()
blocks := block.NewMapBlockstore()
_ = blocks.Put(ctx, rootBlock)
fmt.Printf("Root: %s\n", rootBlock.Link())
key := "room-guardian.jpg"
value := cidlink.Link{Cid: cid.MustParse("bafkreigh2akiscaildcqabsyg3dfr6chu3fgpregiymsck7e7aqa4s52zy")}
fmt.Printf("Putting %s: %s\n", key, value)
root, diff, _ := Put(ctx, blocks, rootBlock.Link(), key, value)
fmt.Printf("Root: %s\n", root)
fmt.Println("Added blocks:")
for _, b := range diff.Additions {
fmt.Printf("+ %s\n", b.Link())
_ = blocks.Put(ctx, b)
}
fmt.Println("Removed blocks:")
for _, b := range diff.Removals {
fmt.Printf("- %s\n", b.Link())
_ = blocks.Del(ctx, b.Link())
}
fmt.Println("Entries:")
for entry := range Entries(ctx, blocks, root) {
fmt.Printf("%s: %s\n", entry.Key, entry.Value)
}
}