unbreak itests
This commit is contained in:
parent
e8c44babcf
commit
0c34699f23
@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@ -143,36 +144,44 @@ func TestDMLevelPartialRetrieval(t *testing.T) {
|
||||
}
|
||||
|
||||
func testDMExportAsFile(ctx context.Context, client *kit.TestFullNode, expDirective api.ExportRef, tempDir string) error {
|
||||
out, err := ioutil.TempFile(tempDir, "exp-test")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer out.Close() //nolint:errcheck
|
||||
out := tempDir + string(os.PathSeparator) + "exp-test" + expDirective.Root.String()
|
||||
|
||||
fileDest := api.FileRef{
|
||||
Path: out.Name(),
|
||||
Path: out,
|
||||
}
|
||||
err = client.ClientExport(ctx, expDirective, fileDest)
|
||||
err := client.ClientExport(ctx, expDirective, fileDest)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return validateDMUnixFile(out)
|
||||
|
||||
f, err := os.Open(out)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer f.Close() //nolint:errcheck
|
||||
|
||||
return validateDMUnixFile(f)
|
||||
}
|
||||
func testV0RetrievalAsFile(ctx context.Context, client *kit.TestFullNode, retOrder api0.RetrievalOrder, tempDir string) error {
|
||||
out, err := ioutil.TempFile(tempDir, "exp-test")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer out.Close() //nolint:errcheck
|
||||
out := tempDir + string(os.PathSeparator) + "exp-test" + retOrder.Root.String()
|
||||
|
||||
cv0 := &api0.WrapperV1Full{client.FullNode} //nolint:govet
|
||||
err = cv0.ClientRetrieve(ctx, retOrder, &api.FileRef{
|
||||
Path: out.Name(),
|
||||
err := cv0.ClientRetrieve(ctx, retOrder, &api.FileRef{
|
||||
Path: out,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return validateDMUnixFile(out)
|
||||
|
||||
f, err := os.Open(out)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer f.Close() //nolint:errcheck
|
||||
|
||||
return validateDMUnixFile(f)
|
||||
}
|
||||
func validateDMUnixFile(r io.Reader) error {
|
||||
data, err := io.ReadAll(r)
|
||||
|
@ -5,7 +5,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
@ -109,9 +108,7 @@ func TestPartialRetrieval(t *testing.T) {
|
||||
|
||||
// test retrieval of either data or constructing a partial selective-car
|
||||
for _, retrieveAsCar := range []bool{false, true} {
|
||||
outFile, err := ioutil.TempFile(t.TempDir(), "ret-file")
|
||||
require.NoError(t, err)
|
||||
defer outFile.Close() //nolint:errcheck
|
||||
outFile := t.TempDir() + string(os.PathSeparator) + "ret-file" + retOrder.Root.String()
|
||||
|
||||
require.NoError(t, testGenesisRetrieval(
|
||||
ctx,
|
||||
@ -119,10 +116,9 @@ func TestPartialRetrieval(t *testing.T) {
|
||||
retOrder,
|
||||
eref,
|
||||
&api.FileRef{
|
||||
Path: outFile.Name(),
|
||||
Path: outFile,
|
||||
IsCAR: retrieveAsCar,
|
||||
},
|
||||
outFile,
|
||||
))
|
||||
|
||||
// UGH if I do not sleep here, I get things like:
|
||||
@ -152,7 +148,6 @@ func TestPartialRetrieval(t *testing.T) {
|
||||
DAGs: []api.DagSpec{{DataSelector: &textSelectorNonexistent}},
|
||||
},
|
||||
&api.FileRef{},
|
||||
nil,
|
||||
),
|
||||
fmt.Sprintf("parsing dag spec: path selection does not match a node within %s", carRoot),
|
||||
)
|
||||
@ -173,13 +168,12 @@ func TestPartialRetrieval(t *testing.T) {
|
||||
DAGs: []api.DagSpec{{DataSelector: &textSelectorNonLink}},
|
||||
},
|
||||
&api.FileRef{},
|
||||
nil,
|
||||
),
|
||||
fmt.Sprintf("parsing dag spec: error while locating partial retrieval sub-root: unsupported selection path '%s' does not correspond to a block boundary (a.k.a. CID link)", textSelectorNonLink),
|
||||
)
|
||||
}
|
||||
|
||||
func testGenesisRetrieval(ctx context.Context, client *kit.TestFullNode, retOrder api.RetrievalOrder, eref api.ExportRef, retRef *api.FileRef, outFile *os.File) error {
|
||||
func testGenesisRetrieval(ctx context.Context, client *kit.TestFullNode, retOrder api.RetrievalOrder, eref api.ExportRef, retRef *api.FileRef) error {
|
||||
|
||||
if retOrder.Total.Nil() {
|
||||
retOrder.Total = big.Zero()
|
||||
@ -205,6 +199,13 @@ func testGenesisRetrieval(ctx context.Context, client *kit.TestFullNode, retOrde
|
||||
return err
|
||||
}
|
||||
|
||||
outFile, err := os.Open(retRef.Path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer outFile.Close() //nolint:errcheck
|
||||
|
||||
var data []byte
|
||||
if !retRef.IsCAR {
|
||||
|
||||
|
@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
@ -323,10 +322,7 @@ func (dh *DealHarness) PerformRetrieval(ctx context.Context, deal *cid.Cid, root
|
||||
offer = offers[0]
|
||||
}
|
||||
|
||||
carFile, err := ioutil.TempFile(dh.t.TempDir(), "ret-car")
|
||||
require.NoError(dh.t, err)
|
||||
|
||||
defer carFile.Close() //nolint:errcheck
|
||||
carFile := dh.t.TempDir() + string(os.PathSeparator) + "ret-car-" + root.String()
|
||||
|
||||
caddr, err := dh.client.WalletDefaultAddress(ctx)
|
||||
require.NoError(dh.t, err)
|
||||
@ -367,16 +363,16 @@ consumeEvents:
|
||||
DealID: retrievalRes.DealID,
|
||||
},
|
||||
api.FileRef{
|
||||
Path: carFile.Name(),
|
||||
Path: carFile,
|
||||
IsCAR: carExport,
|
||||
}))
|
||||
|
||||
ret := carFile.Name()
|
||||
ret := carFile
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
func (dh *DealHarness) ExtractFileFromCAR(ctx context.Context, file *os.File) (out *os.File) {
|
||||
func (dh *DealHarness) ExtractFileFromCAR(ctx context.Context, file *os.File) string {
|
||||
bserv := dstest.Bserv()
|
||||
ch, err := car.LoadCar(ctx, bserv.Blockstore(), file)
|
||||
require.NoError(dh.t, err)
|
||||
@ -391,12 +387,9 @@ func (dh *DealHarness) ExtractFileFromCAR(ctx context.Context, file *os.File) (o
|
||||
fil, err := unixfile.NewUnixfsFile(ctx, dserv, nd)
|
||||
require.NoError(dh.t, err)
|
||||
|
||||
tmpfile, err := ioutil.TempFile(dh.t.TempDir(), "file-in-car")
|
||||
require.NoError(dh.t, err)
|
||||
tmpfile := dh.t.TempDir() + string(os.PathSeparator) + "file-in-car" + b.Cid().String()
|
||||
|
||||
defer tmpfile.Close() //nolint:errcheck
|
||||
|
||||
err = files.WriteTo(fil, tmpfile.Name())
|
||||
err = files.WriteTo(fil, tmpfile)
|
||||
require.NoError(dh.t, err)
|
||||
|
||||
return tmpfile
|
||||
@ -452,7 +445,7 @@ func (dh *DealHarness) RunConcurrentDeals(opts RunConcurrentDealsOpts) {
|
||||
actualFile := dh.ExtractFileFromCAR(ctx, f)
|
||||
require.NoError(dh.t, f.Close())
|
||||
|
||||
AssertFilesEqual(dh.t, inPath, actualFile.Name())
|
||||
AssertFilesEqual(dh.t, inPath, actualFile)
|
||||
} else {
|
||||
AssertFilesEqual(dh.t, inPath, outPath)
|
||||
}
|
||||
|
@ -113,11 +113,9 @@ func TestRoundtripUnixFS_Filestore(t *testing.T) {
|
||||
require.Equal(t, inputContents, bz2)
|
||||
}
|
||||
|
||||
// creates a new tempdir each time, guaranteeing uniqueness
|
||||
func newTmpFile(t *testing.T) string {
|
||||
f, err := os.CreateTemp("", "")
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.Close())
|
||||
return f.Name()
|
||||
return t.TempDir() + string(os.PathSeparator) + "tmp"
|
||||
}
|
||||
|
||||
func genInputFile(t *testing.T) (filepath string, contents []byte) {
|
||||
|
Loading…
Reference in New Issue
Block a user