-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdag_store_test.go
77 lines (64 loc) · 1.21 KB
/
dag_store_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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package dagstore
import (
"context"
"fmt"
"github.com/ipfs/go-cid"
"os"
"testing"
)
func add(store *DagStore) (cid.Cid, error) {
file, err := os.OpenFile(".pdf", os.O_RDWR, 0755)
defer file.Close()
if err != nil {
return cid.Cid{}, err
}
c, err := store.Add(context.Background(), file)
if err != nil {
return cid.Cid{}, err
}
return c, nil
}
func get(store *DagStore, c cid.Cid) error {
outputFile, err := os.Create("test.pdf")
defer outputFile.Close()
if err != nil {
return err
}
writerTo, err := store.Get(context.Background(), c)
if err != nil {
return err
}
writerTo.WriteTo(outputFile)
return nil
}
func TestAdd(t *testing.T) {
store := New("./.data")
defer store.Close()
c, err := add(&store)
if err != nil {
t.Fatal(err)
}
fmt.Println(c)
}
func TestGet(t *testing.T) {
store := New("./.data")
defer store.Close()
c, err := cid.Decode("QmVDQS58P34wT9MQNBBRTaNMmeTUXiaaGoztmx3wdbk5Ac")
if err != nil {
t.Fatal(err)
}
if err := get(&store, c); err != nil {
t.Fatal(err)
}
}
func TestAddGet(t *testing.T) {
store := New("./.data")
defer store.Close()
c, err := add(&store)
if err != nil {
t.Fatal(err)
}
if err := get(&store, c); err != nil {
t.Fatal(err)
}
}