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