ipfs-cluster/ipld-importer/import_test.go

84 lines
2.0 KiB
Go
Raw Normal View History

package importer
import (
"context"
"fmt"
"os"
"path"
"testing"
"github.com/ipfs/go-ipfs-cmdkit/files"
ipld "github.com/ipfs/go-ipld-format"
)
const testDir = "testingData"
func getTestingDir() (files.File, error) {
fpath := testDir
stat, err := os.Lstat(fpath)
if err != nil {
return nil, err
}
if !stat.IsDir() {
return nil, fmt.Errorf("testDir should be seen as directory")
}
return files.NewSerialFile(path.Base(fpath), fpath, false, stat)
}
// simply import and ensure no errors occur
func TestToPrint(t *testing.T) {
file, err := getTestingDir()
if err != nil {
t.Fatal(err)
}
err = ToPrint(file)
if err != nil {
t.Fatal(err)
}
}
var orderedCids = [18]string{"QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn",
"Qmbp4C4KkyjVzTpZ327Ub555FEHizhJS4M17f2zCCrQMAz",
"QmYz38urZ99eVCxSccM63bGtDv54UWtBDWJdTxGch23khA",
"QmUwG2mfhhfBEzVtvyEvva1kc8kU4CrXphdMCdAiFNWdxy",
"QmRgkP4x7tXW9PyiPPxe3aqALQEs22nifkwzrm7wickdfr",
"QmNpCHs9zrzP4aArBzRQgjNSbMC5hYqJa1ksmbyorSu44b",
"QmQbg4sHm4zVHnqCS14YzNnQFVMqjZpu5XjkF7vtbzqkFW",
"QmcUBApwNSDg2Q2J4NXzks1HewVGFohNpPyEud7bZfo5tE",
"QmaKaB735eydQwnaJNuYbXRU1gVb4MJdzHp1rpUZJN67G6",
"QmQ6n82dRtEJVHMDLW5BSrJ6bRDXkFXj2i7Vjxy4B2PH82",
"QmbDaWrwxk93RfWSBL8ajTproNKbE2EghBLSk8199EBm1m",
"QmXDmRPxV9KWYLhN7bqGn143GgiNxhy9Hqc3ZPJW63xgok",
"QmPZLJ3CZYgxH4K1w5jdbAdxJynXn5TCB4kHy7u8uHC3fy",
"QmUqmcdJJodX7mPoUv9u71HoNAiegBCiCqdUZd5ZrCyLbs",
"QmaytnNarHzDp1ipGyC7zd7Hw2AePmtSpLLaygQ2e9Yvqe",
"QmZwab9h6ADw3tv8pzXVF2yndgJpTWKrrMjJQqRkgYmCRH",
"QmaNfMZDZjfqjHrFCc6tZwmkqbXs1fnY9AXZ81WUztFeXm",
"QmY4qt6WG12qYwWeeTNhggqaNMJWp2NouuTSf79ukoobw8"}
// import and receive all blocks
func TestToChannel(t *testing.T) {
file, err := getTestingDir()
if err != nil {
t.Fatal(err)
}
outChan := make(chan *ipld.Node)
go func() {
i := 0
for node := range outChan {
cid := (*node).String()
if cid != orderedCids[i] {
t.Error("unexpected cid: %s instead of %s", cid, orderedCids[i])
}
i += 1
}
}()
err = ToChannel(file, outChan, context.Background())
if err != nil {
t.Fatal(err)
}
}