Merge pull request #6806 from filecoin-project/fix/lotus-mount-caps
capitalize lotus mount fields for deserialization
This commit is contained in:
commit
fc77705229
@ -18,8 +18,8 @@ var _ mount.Mount = (*LotusMount)(nil)
|
||||
// LotusMount is the Lotus implementation of a Sharded DAG Store Mount.
|
||||
// A Filecoin Piece is treated as a Shard by this implementation.
|
||||
type LotusMount struct {
|
||||
api LotusAccessor
|
||||
pieceCid cid.Cid
|
||||
Api LotusAccessor
|
||||
PieceCid cid.Cid
|
||||
}
|
||||
|
||||
// This method is called when registering a mount with the DAG store registry.
|
||||
@ -28,19 +28,19 @@ type LotusMount struct {
|
||||
// calls Deserialize on the cloned instance, which will have a reference to the
|
||||
// lotus mount API supplied here.
|
||||
func NewLotusMountTemplate(api LotusAccessor) *LotusMount {
|
||||
return &LotusMount{api: api}
|
||||
return &LotusMount{Api: api}
|
||||
}
|
||||
|
||||
func NewLotusMount(pieceCid cid.Cid, api LotusAccessor) (*LotusMount, error) {
|
||||
return &LotusMount{
|
||||
pieceCid: pieceCid,
|
||||
api: api,
|
||||
PieceCid: pieceCid,
|
||||
Api: api,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (l *LotusMount) Serialize() *url.URL {
|
||||
return &url.URL{
|
||||
Host: l.pieceCid.String(),
|
||||
Host: l.PieceCid.String(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -50,14 +50,14 @@ func (l *LotusMount) Deserialize(u *url.URL) error {
|
||||
return xerrors.Errorf("failed to parse PieceCid from host '%s': %w", u.Host, err)
|
||||
}
|
||||
|
||||
l.pieceCid = pieceCid
|
||||
l.PieceCid = pieceCid
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *LotusMount) Fetch(ctx context.Context) (mount.Reader, error) {
|
||||
r, err := l.api.FetchUnsealedPiece(ctx, l.pieceCid)
|
||||
r, err := l.Api.FetchUnsealedPiece(ctx, l.PieceCid)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("failed to fetch unsealed piece %s: %w", l.pieceCid, err)
|
||||
return nil, xerrors.Errorf("failed to fetch unsealed piece %s: %w", l.PieceCid, err)
|
||||
}
|
||||
return &readCloser{r}, nil
|
||||
}
|
||||
@ -76,9 +76,9 @@ func (l *LotusMount) Close() error {
|
||||
}
|
||||
|
||||
func (l *LotusMount) Stat(_ context.Context) (mount.Stat, error) {
|
||||
size, err := l.api.GetUnpaddedCARSize(l.pieceCid)
|
||||
size, err := l.Api.GetUnpaddedCARSize(l.PieceCid)
|
||||
if err != nil {
|
||||
return mount.Stat{}, xerrors.Errorf("failed to fetch piece size for piece %s: %w", l.pieceCid, err)
|
||||
return mount.Stat{}, xerrors.Errorf("failed to fetch piece size for piece %s: %w", l.PieceCid, err)
|
||||
}
|
||||
|
||||
// TODO Mark false when storage deal expires.
|
||||
|
@ -80,8 +80,8 @@ func TestLotusMountDeserialize(t *testing.T) {
|
||||
err = mnt.Deserialize(u)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, cid, mnt.pieceCid)
|
||||
require.Equal(t, api, mnt.api)
|
||||
require.Equal(t, cid, mnt.PieceCid)
|
||||
require.Equal(t, api, mnt.Api)
|
||||
|
||||
// fails if cid is not valid
|
||||
us = lotusScheme + "://" + "rand"
|
||||
@ -91,3 +91,30 @@ func TestLotusMountDeserialize(t *testing.T) {
|
||||
require.Error(t, err)
|
||||
require.Contains(t, err.Error(), "failed to parse PieceCid")
|
||||
}
|
||||
|
||||
func TestLotusMountRegistration(t *testing.T) {
|
||||
bgen := blocksutil.NewBlockGenerator()
|
||||
cid := bgen.Next().Cid()
|
||||
|
||||
// success
|
||||
us := lotusScheme + "://" + cid.String()
|
||||
u, err := url.Parse(us)
|
||||
require.NoError(t, err)
|
||||
|
||||
mockCtrl := gomock.NewController(t)
|
||||
// when test is done, assert expectations on all mock objects.
|
||||
defer mockCtrl.Finish()
|
||||
|
||||
mockLotusMountAPI := mock_dagstore.NewMockLotusMountAPI(mockCtrl)
|
||||
registry := mount.NewRegistry()
|
||||
err = registry.Register(lotusScheme, NewLotusMountTemplate(mockLotusMountAPI))
|
||||
require.NoError(t, err)
|
||||
|
||||
mnt, err := registry.Instantiate(u)
|
||||
require.NoError(t, err)
|
||||
|
||||
mockLotusMountAPI.EXPECT().GetUnpaddedCARSize(cid).Return(uint64(100), nil).Times(1)
|
||||
stat, err := mnt.Stat(context.Background())
|
||||
require.NoError(t, err)
|
||||
require.EqualValues(t, 100, stat.Size)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user