-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathimporter_test.go
95 lines (86 loc) · 1.66 KB
/
importer_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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package car
import (
"context"
"fmt"
"testing"
"github.com/photon-storage/go-common/testing/require"
)
func TestImport(t *testing.T) {
ctx := context.Background()
pi := NewDataImporter()
// CID v0
cid, err := pi.Import(
ctx,
"./data",
ImportOpts.CIDv0(),
)
require.NoError(t, err)
require.Equal(t,
"QmVyN4KhsSEgQ21WhnrNVQondEBAXYSEVSNJpTqRsyMKkg",
cid.String(),
)
// CID v1
cid, err = pi.Import(
ctx,
"./data",
ImportOpts.CIDv1(),
)
require.NoError(t, err)
require.Equal(t,
"bafybeid4ij3cn74tlwbnnwscmsjxz2h5n6j7xtafbp77xkekik6e42xjk4",
cid.String(),
)
// CID v0, inline
cid, err = pi.Import(
ctx,
"./data",
ImportOpts.CIDv0(),
ImportOpts.InlineBlock(),
)
require.NoError(t, err)
require.Equal(t,
"QmfFmGQrgrn2HiW44dfJLuV1aNGnjfEFY9qJ8SWCbVDZzw",
cid.String(),
)
// CID v1, inline
cid, err = pi.Import(
ctx,
"./data",
ImportOpts.CIDv1(),
ImportOpts.InlineBlock(),
)
require.NoError(t, err)
require.Equal(t,
"bafybeihtxqlpsentx42rarm44fz4d7brmzsq5yozk3cpzmtsomo4embx6m",
cid.String(),
)
// CID v1, inline, exclude bob.txt
cid, err = pi.Import(
ctx,
"./data",
ImportOpts.CIDv1(),
ImportOpts.InlineBlock(),
ImportOpts.Ignores("bob.txt"),
)
require.NoError(t, err)
require.Equal(t,
"bafybeigszi3podzseg3m64vvosm4sgyfrk7reukhifpuf627iwjkebochu",
cid.String(),
)
// CID v0, with events
ch := make(chan *ImportEvent, 8)
cid, err = pi.Import(
ctx,
"./data",
ImportOpts.CIDv0(),
ImportOpts.Events(ch),
)
require.NoError(t, err)
require.Equal(t,
"QmVyN4KhsSEgQ21WhnrNVQondEBAXYSEVSNJpTqRsyMKkg",
cid.String(),
)
for ev := range ch {
fmt.Printf("%v %v\n", ev.Name, ev.CID.String())
}
}