use mockgen
This commit is contained in:
parent
77b5e8d045
commit
0d88800eb9
133
extern/sector-storage/stores/http_handler_test.go
vendored
133
extern/sector-storage/stores/http_handler_test.go
vendored
@ -15,7 +15,7 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/extern/sector-storage/stores/mocks"
|
"github.com/filecoin-project/lotus/extern/sector-storage/stores/mocks"
|
||||||
"github.com/filecoin-project/lotus/extern/sector-storage/storiface"
|
"github.com/filecoin-project/lotus/extern/sector-storage/storiface"
|
||||||
"github.com/filecoin-project/specs-storage/storage"
|
"github.com/filecoin-project/specs-storage/storage"
|
||||||
"github.com/stretchr/testify/mock"
|
"github.com/golang/mock/gomock"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
)
|
)
|
||||||
@ -62,8 +62,8 @@ func TestRemoteGetAllocated(t *testing.T) {
|
|||||||
|
|
||||||
tcs := map[string]struct {
|
tcs := map[string]struct {
|
||||||
piFnc func(pi *pieceInfo)
|
piFnc func(pi *pieceInfo)
|
||||||
storeFnc func(s *mocks.Store)
|
storeFnc func(s *mocks.MockStore)
|
||||||
pfFunc func(s *mocks.PartialFileHandler)
|
pfFunc func(s *mocks.MockpartialFileHandler)
|
||||||
|
|
||||||
// expectation
|
// expectation
|
||||||
expectedStatusCode int
|
expectedStatusCode int
|
||||||
@ -100,97 +100,101 @@ func TestRemoteGetAllocated(t *testing.T) {
|
|||||||
},
|
},
|
||||||
"fails when errors out during acquiring unsealed sector file": {
|
"fails when errors out during acquiring unsealed sector file": {
|
||||||
expectedStatusCode: http.StatusInternalServerError,
|
expectedStatusCode: http.StatusInternalServerError,
|
||||||
storeFnc: func(l *mocks.Store) {
|
storeFnc: func(l *mocks.MockStore) {
|
||||||
l.On("AcquireSector", mock.Anything, expectedSectorRef, storiface.FTUnsealed,
|
|
||||||
|
l.EXPECT().AcquireSector(gomock.Any(), expectedSectorRef, storiface.FTUnsealed,
|
||||||
storiface.FTNone, storiface.PathStorage, storiface.AcquireMove).Return(storiface.SectorPaths{
|
storiface.FTNone, storiface.PathStorage, storiface.AcquireMove).Return(storiface.SectorPaths{
|
||||||
Unsealed: "path",
|
Unsealed: "path",
|
||||||
},
|
},
|
||||||
storiface.SectorPaths{}, xerrors.New("some error"))
|
storiface.SectorPaths{}, xerrors.New("some error")).Times(1)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"fails when unsealed sector file is not found locally": {
|
"fails when unsealed sector file is not found locally": {
|
||||||
expectedStatusCode: http.StatusInternalServerError,
|
expectedStatusCode: http.StatusInternalServerError,
|
||||||
storeFnc: func(l *mocks.Store) {
|
storeFnc: func(l *mocks.MockStore) {
|
||||||
|
|
||||||
l.On("AcquireSector", mock.Anything, expectedSectorRef, storiface.FTUnsealed,
|
l.EXPECT().AcquireSector(gomock.Any(), expectedSectorRef, storiface.FTUnsealed,
|
||||||
storiface.FTNone, storiface.PathStorage, storiface.AcquireMove).Return(storiface.SectorPaths{},
|
storiface.FTNone, storiface.PathStorage, storiface.AcquireMove).Return(storiface.SectorPaths{},
|
||||||
storiface.SectorPaths{}, nil)
|
storiface.SectorPaths{}, nil).Times(1)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"fails when partial file is not found locally": {
|
"fails when partial file is not found locally": {
|
||||||
expectedStatusCode: http.StatusInternalServerError,
|
expectedStatusCode: http.StatusInternalServerError,
|
||||||
storeFnc: func(l *mocks.Store) {
|
storeFnc: func(l *mocks.MockStore) {
|
||||||
// will return emppty paths
|
// will return emppty paths
|
||||||
|
|
||||||
l.On("AcquireSector", mock.Anything, expectedSectorRef, storiface.FTUnsealed,
|
l.EXPECT().AcquireSector(gomock.Any(), expectedSectorRef, storiface.FTUnsealed,
|
||||||
storiface.FTNone, storiface.PathStorage, storiface.AcquireMove).Return(storiface.SectorPaths{
|
storiface.FTNone, storiface.PathStorage, storiface.AcquireMove).Return(storiface.SectorPaths{
|
||||||
Unsealed: pfPath,
|
Unsealed: pfPath,
|
||||||
},
|
},
|
||||||
storiface.SectorPaths{}, nil)
|
storiface.SectorPaths{}, nil).Times(1)
|
||||||
},
|
},
|
||||||
|
|
||||||
pfFunc: func(pf *mocks.PartialFileHandler) {
|
pfFunc: func(pf *mocks.MockpartialFileHandler) {
|
||||||
//OpenPartialFile(maxPieceSize abi.PaddedPieceSize, path string)
|
//OpenPartialFile(maxPieceSize abi.PaddedPieceSize, path string)
|
||||||
pf.On("OpenPartialFile", abi.PaddedPieceSize(sectorSize), pfPath).Return(&partialfile.PartialFile{},
|
pf.EXPECT().OpenPartialFile(abi.PaddedPieceSize(sectorSize), pfPath).Return(&partialfile.PartialFile{},
|
||||||
xerrors.New("some error"))
|
xerrors.New("some error")).Times(1)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
"fails when determining partial file allocation returns an error": {
|
"fails when determining partial file allocation returns an error": {
|
||||||
expectedStatusCode: http.StatusInternalServerError,
|
expectedStatusCode: http.StatusInternalServerError,
|
||||||
storeFnc: func(l *mocks.Store) {
|
storeFnc: func(l *mocks.MockStore) {
|
||||||
// will return emppty paths
|
// will return emppty paths
|
||||||
|
|
||||||
l.On("AcquireSector", mock.Anything, expectedSectorRef, storiface.FTUnsealed,
|
l.EXPECT().AcquireSector(gomock.Any(), expectedSectorRef, storiface.FTUnsealed,
|
||||||
storiface.FTNone, storiface.PathStorage, storiface.AcquireMove).Return(storiface.SectorPaths{
|
storiface.FTNone, storiface.PathStorage, storiface.AcquireMove).Return(storiface.SectorPaths{
|
||||||
Unsealed: pfPath,
|
Unsealed: pfPath,
|
||||||
},
|
},
|
||||||
storiface.SectorPaths{}, nil)
|
storiface.SectorPaths{}, nil).Times(1)
|
||||||
},
|
},
|
||||||
|
|
||||||
pfFunc: func(pf *mocks.PartialFileHandler) {
|
pfFunc: func(pf *mocks.MockpartialFileHandler) {
|
||||||
pf.On("OpenPartialFile", abi.PaddedPieceSize(sectorSize), pfPath).Return(emptyPartialFile,
|
pf.EXPECT().OpenPartialFile(abi.PaddedPieceSize(sectorSize), pfPath).Return(emptyPartialFile,
|
||||||
nil)
|
nil).Times(1)
|
||||||
pf.On("HasAllocated", emptyPartialFile, storiface.UnpaddedByteIndex(validOffsetInt),
|
|
||||||
abi.UnpaddedPieceSize(validSizeInt)).Return(true, xerrors.New("some error"))
|
pf.EXPECT().HasAllocated(emptyPartialFile, storiface.UnpaddedByteIndex(validOffsetInt),
|
||||||
|
abi.UnpaddedPieceSize(validSizeInt)).Return(true, xerrors.New("some error")).Times(1)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"StatusRequestedRangeNotSatisfiable when piece is NOT allocated in partial file": {
|
"StatusRequestedRangeNotSatisfiable when piece is NOT allocated in partial file": {
|
||||||
expectedStatusCode: http.StatusRequestedRangeNotSatisfiable,
|
expectedStatusCode: http.StatusRequestedRangeNotSatisfiable,
|
||||||
storeFnc: func(l *mocks.Store) {
|
storeFnc: func(l *mocks.MockStore) {
|
||||||
// will return emppty paths
|
// will return emppty paths
|
||||||
|
|
||||||
l.On("AcquireSector", mock.Anything, expectedSectorRef, storiface.FTUnsealed,
|
l.EXPECT().AcquireSector(gomock.Any(), expectedSectorRef, storiface.FTUnsealed,
|
||||||
storiface.FTNone, storiface.PathStorage, storiface.AcquireMove).Return(storiface.SectorPaths{
|
storiface.FTNone, storiface.PathStorage, storiface.AcquireMove).Return(storiface.SectorPaths{
|
||||||
Unsealed: pfPath,
|
Unsealed: pfPath,
|
||||||
},
|
},
|
||||||
storiface.SectorPaths{}, nil)
|
storiface.SectorPaths{}, nil).Times(1)
|
||||||
},
|
},
|
||||||
|
|
||||||
pfFunc: func(pf *mocks.PartialFileHandler) {
|
pfFunc: func(pf *mocks.MockpartialFileHandler) {
|
||||||
pf.On("OpenPartialFile", abi.PaddedPieceSize(sectorSize), pfPath).Return(emptyPartialFile,
|
pf.EXPECT().OpenPartialFile(abi.PaddedPieceSize(sectorSize), pfPath).Return(emptyPartialFile,
|
||||||
nil)
|
nil).Times(1)
|
||||||
pf.On("HasAllocated", emptyPartialFile, storiface.UnpaddedByteIndex(validOffsetInt),
|
|
||||||
abi.UnpaddedPieceSize(validSizeInt)).Return(false, nil)
|
pf.EXPECT().HasAllocated(emptyPartialFile, storiface.UnpaddedByteIndex(validOffsetInt),
|
||||||
|
abi.UnpaddedPieceSize(validSizeInt)).Return(false, nil).Times(1)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"OK when piece is allocated in partial file": {
|
"OK when piece is allocated in partial file": {
|
||||||
expectedStatusCode: http.StatusOK,
|
expectedStatusCode: http.StatusOK,
|
||||||
storeFnc: func(l *mocks.Store) {
|
storeFnc: func(l *mocks.MockStore) {
|
||||||
// will return emppty paths
|
// will return emppty paths
|
||||||
|
|
||||||
l.On("AcquireSector", mock.Anything, expectedSectorRef, storiface.FTUnsealed,
|
l.EXPECT().AcquireSector(gomock.Any(), expectedSectorRef, storiface.FTUnsealed,
|
||||||
storiface.FTNone, storiface.PathStorage, storiface.AcquireMove).Return(storiface.SectorPaths{
|
storiface.FTNone, storiface.PathStorage, storiface.AcquireMove).Return(storiface.SectorPaths{
|
||||||
Unsealed: pfPath,
|
Unsealed: pfPath,
|
||||||
},
|
},
|
||||||
storiface.SectorPaths{}, nil)
|
storiface.SectorPaths{}, nil).Times(1)
|
||||||
},
|
},
|
||||||
|
|
||||||
pfFunc: func(pf *mocks.PartialFileHandler) {
|
pfFunc: func(pf *mocks.MockpartialFileHandler) {
|
||||||
pf.On("OpenPartialFile", abi.PaddedPieceSize(sectorSize), pfPath).Return(emptyPartialFile,
|
pf.EXPECT().OpenPartialFile(abi.PaddedPieceSize(sectorSize), pfPath).Return(emptyPartialFile,
|
||||||
nil)
|
nil).Times(1)
|
||||||
pf.On("HasAllocated", emptyPartialFile, storiface.UnpaddedByteIndex(validOffsetInt),
|
|
||||||
abi.UnpaddedPieceSize(validSizeInt)).Return(true, nil)
|
pf.EXPECT().HasAllocated(emptyPartialFile, storiface.UnpaddedByteIndex(validOffsetInt),
|
||||||
|
abi.UnpaddedPieceSize(validSizeInt)).Return(true, nil).Times(1)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -198,8 +202,13 @@ func TestRemoteGetAllocated(t *testing.T) {
|
|||||||
for name, tc := range tcs {
|
for name, tc := range tcs {
|
||||||
tc := tc
|
tc := tc
|
||||||
t.Run(name, func(t *testing.T) {
|
t.Run(name, func(t *testing.T) {
|
||||||
lstore := &mocks.Store{}
|
// create go mock controller here
|
||||||
pfhandler := &mocks.PartialFileHandler{}
|
mockCtrl := gomock.NewController(t)
|
||||||
|
// when test is done, assert expectations on all mock objects.
|
||||||
|
defer mockCtrl.Finish()
|
||||||
|
|
||||||
|
lstore := mocks.NewMockStore(mockCtrl)
|
||||||
|
pfhandler := mocks.NewMockpartialFileHandler(mockCtrl)
|
||||||
|
|
||||||
handler := &stores.FetchHandler{
|
handler := &stores.FetchHandler{
|
||||||
lstore,
|
lstore,
|
||||||
@ -239,9 +248,6 @@ func TestRemoteGetAllocated(t *testing.T) {
|
|||||||
|
|
||||||
// assert expected status code
|
// assert expected status code
|
||||||
require.Equal(t, tc.expectedStatusCode, resp.StatusCode)
|
require.Equal(t, tc.expectedStatusCode, resp.StatusCode)
|
||||||
|
|
||||||
// assert expectations on the mocks
|
|
||||||
lstore.AssertExpectations(t)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -271,7 +277,7 @@ func TestRemoteGetSector(t *testing.T) {
|
|||||||
|
|
||||||
tcs := map[string]struct {
|
tcs := map[string]struct {
|
||||||
siFnc func(pi *sectorInfo)
|
siFnc func(pi *sectorInfo)
|
||||||
storeFnc func(s *mocks.Store, path string)
|
storeFnc func(s *mocks.MockStore, path string)
|
||||||
|
|
||||||
// reading a file or a dir
|
// reading a file or a dir
|
||||||
isDir bool
|
isDir bool
|
||||||
@ -297,31 +303,32 @@ func TestRemoteGetSector(t *testing.T) {
|
|||||||
noResponseBytes: true,
|
noResponseBytes: true,
|
||||||
},
|
},
|
||||||
"fails when error while acquiring sector file": {
|
"fails when error while acquiring sector file": {
|
||||||
storeFnc: func(l *mocks.Store, _ string) {
|
storeFnc: func(l *mocks.MockStore, _ string) {
|
||||||
l.On("AcquireSector", mock.Anything, expectedSectorRef, storiface.FTUnsealed,
|
|
||||||
|
l.EXPECT().AcquireSector(gomock.Any(), expectedSectorRef, storiface.FTUnsealed,
|
||||||
storiface.FTNone, storiface.PathStorage, storiface.AcquireMove).Return(storiface.SectorPaths{
|
storiface.FTNone, storiface.PathStorage, storiface.AcquireMove).Return(storiface.SectorPaths{
|
||||||
Unsealed: "path",
|
Unsealed: "path",
|
||||||
},
|
},
|
||||||
storiface.SectorPaths{}, xerrors.New("some error"))
|
storiface.SectorPaths{}, xerrors.New("some error")).Times(1)
|
||||||
},
|
},
|
||||||
expectedStatusCode: http.StatusInternalServerError,
|
expectedStatusCode: http.StatusInternalServerError,
|
||||||
noResponseBytes: true,
|
noResponseBytes: true,
|
||||||
},
|
},
|
||||||
"fails when acquired sector file path is empty": {
|
"fails when acquired sector file path is empty": {
|
||||||
expectedStatusCode: http.StatusInternalServerError,
|
expectedStatusCode: http.StatusInternalServerError,
|
||||||
storeFnc: func(l *mocks.Store, _ string) {
|
storeFnc: func(l *mocks.MockStore, _ string) {
|
||||||
|
|
||||||
l.On("AcquireSector", mock.Anything, expectedSectorRef, storiface.FTUnsealed,
|
l.EXPECT().AcquireSector(gomock.Any(), expectedSectorRef, storiface.FTUnsealed,
|
||||||
storiface.FTNone, storiface.PathStorage, storiface.AcquireMove).Return(storiface.SectorPaths{},
|
storiface.FTNone, storiface.PathStorage, storiface.AcquireMove).Return(storiface.SectorPaths{},
|
||||||
storiface.SectorPaths{}, nil)
|
storiface.SectorPaths{}, nil).Times(1)
|
||||||
},
|
},
|
||||||
noResponseBytes: true,
|
noResponseBytes: true,
|
||||||
},
|
},
|
||||||
"fails when acquired file does not exist": {
|
"fails when acquired file does not exist": {
|
||||||
expectedStatusCode: http.StatusInternalServerError,
|
expectedStatusCode: http.StatusInternalServerError,
|
||||||
storeFnc: func(l *mocks.Store, _ string) {
|
storeFnc: func(l *mocks.MockStore, _ string) {
|
||||||
|
|
||||||
l.On("AcquireSector", mock.Anything, expectedSectorRef, storiface.FTUnsealed,
|
l.EXPECT().AcquireSector(gomock.Any(), expectedSectorRef, storiface.FTUnsealed,
|
||||||
storiface.FTNone, storiface.PathStorage, storiface.AcquireMove).Return(storiface.SectorPaths{
|
storiface.FTNone, storiface.PathStorage, storiface.AcquireMove).Return(storiface.SectorPaths{
|
||||||
Unsealed: "path",
|
Unsealed: "path",
|
||||||
},
|
},
|
||||||
@ -330,9 +337,9 @@ func TestRemoteGetSector(t *testing.T) {
|
|||||||
noResponseBytes: true,
|
noResponseBytes: true,
|
||||||
},
|
},
|
||||||
"successfully read a sector file": {
|
"successfully read a sector file": {
|
||||||
storeFnc: func(l *mocks.Store, path string) {
|
storeFnc: func(l *mocks.MockStore, path string) {
|
||||||
|
|
||||||
l.On("AcquireSector", mock.Anything, expectedSectorRef, storiface.FTUnsealed,
|
l.EXPECT().AcquireSector(gomock.Any(), expectedSectorRef, storiface.FTUnsealed,
|
||||||
storiface.FTNone, storiface.PathStorage, storiface.AcquireMove).Return(storiface.SectorPaths{
|
storiface.FTNone, storiface.PathStorage, storiface.AcquireMove).Return(storiface.SectorPaths{
|
||||||
Unsealed: path,
|
Unsealed: path,
|
||||||
},
|
},
|
||||||
@ -345,9 +352,9 @@ func TestRemoteGetSector(t *testing.T) {
|
|||||||
expectedResponseBytes: fileBytes,
|
expectedResponseBytes: fileBytes,
|
||||||
},
|
},
|
||||||
"successfully read a sector dir": {
|
"successfully read a sector dir": {
|
||||||
storeFnc: func(l *mocks.Store, path string) {
|
storeFnc: func(l *mocks.MockStore, path string) {
|
||||||
|
|
||||||
l.On("AcquireSector", mock.Anything, expectedSectorRef, storiface.FTUnsealed,
|
l.EXPECT().AcquireSector(gomock.Any(), expectedSectorRef, storiface.FTUnsealed,
|
||||||
storiface.FTNone, storiface.PathStorage, storiface.AcquireMove).Return(storiface.SectorPaths{
|
storiface.FTNone, storiface.PathStorage, storiface.AcquireMove).Return(storiface.SectorPaths{
|
||||||
Unsealed: path,
|
Unsealed: path,
|
||||||
},
|
},
|
||||||
@ -365,6 +372,12 @@ func TestRemoteGetSector(t *testing.T) {
|
|||||||
for name, tc := range tcs {
|
for name, tc := range tcs {
|
||||||
tc := tc
|
tc := tc
|
||||||
t.Run(name, func(t *testing.T) {
|
t.Run(name, func(t *testing.T) {
|
||||||
|
mockCtrl := gomock.NewController(t)
|
||||||
|
// when test is done, assert expectations on all mock objects.
|
||||||
|
defer mockCtrl.Finish()
|
||||||
|
lstore := mocks.NewMockStore(mockCtrl)
|
||||||
|
pfhandler := mocks.NewMockpartialFileHandler(mockCtrl)
|
||||||
|
|
||||||
var path string
|
var path string
|
||||||
|
|
||||||
if !tc.isDir {
|
if !tc.isDir {
|
||||||
@ -401,9 +414,6 @@ func TestRemoteGetSector(t *testing.T) {
|
|||||||
path = tempDir
|
path = tempDir
|
||||||
}
|
}
|
||||||
|
|
||||||
lstore := &mocks.Store{}
|
|
||||||
pfhandler := &mocks.PartialFileHandler{}
|
|
||||||
|
|
||||||
handler := &stores.FetchHandler{
|
handler := &stores.FetchHandler{
|
||||||
lstore,
|
lstore,
|
||||||
pfhandler,
|
pfhandler,
|
||||||
@ -447,9 +457,6 @@ func TestRemoteGetSector(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
require.Equal(t, tc.expectedContentType, resp.Header.Get("Content-Type"))
|
require.Equal(t, tc.expectedContentType, resp.Header.Get("Content-Type"))
|
||||||
|
|
||||||
// assert expectations on the mocks
|
|
||||||
lstore.AssertExpectations(t)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
2
extern/sector-storage/stores/interface.go
vendored
2
extern/sector-storage/stores/interface.go
vendored
@ -35,4 +35,6 @@ type Store interface {
|
|||||||
MoveStorage(ctx context.Context, s storage.SectorRef, types storiface.SectorFileType) error
|
MoveStorage(ctx context.Context, s storage.SectorRef, types storiface.SectorFileType) error
|
||||||
|
|
||||||
FsStat(ctx context.Context, id ID) (fsutil.FsStat, error)
|
FsStat(ctx context.Context, id ID) (fsutil.FsStat, error)
|
||||||
|
|
||||||
|
Reserve(ctx context.Context, sid storage.SectorRef, ft storiface.SectorFileType, storageIDs storiface.SectorPaths, overheadTab map[storiface.SectorFileType]int) (func(), error)
|
||||||
}
|
}
|
||||||
|
@ -1,61 +0,0 @@
|
|||||||
// Code generated by mockery 2.7.5. DO NOT EDIT.
|
|
||||||
|
|
||||||
package mocks
|
|
||||||
|
|
||||||
import (
|
|
||||||
abi "github.com/filecoin-project/go-state-types/abi"
|
|
||||||
mock "github.com/stretchr/testify/mock"
|
|
||||||
|
|
||||||
partialfile "github.com/filecoin-project/lotus/extern/sector-storage/partialfile"
|
|
||||||
|
|
||||||
storiface "github.com/filecoin-project/lotus/extern/sector-storage/storiface"
|
|
||||||
)
|
|
||||||
|
|
||||||
// PartialFileHandler is an autogenerated mock type for the PartialFileHandler type
|
|
||||||
type PartialFileHandler struct {
|
|
||||||
mock.Mock
|
|
||||||
}
|
|
||||||
|
|
||||||
// HasAllocated provides a mock function with given fields: pf, offset, size
|
|
||||||
func (_m *PartialFileHandler) HasAllocated(pf *partialfile.PartialFile, offset storiface.UnpaddedByteIndex, size abi.UnpaddedPieceSize) (bool, error) {
|
|
||||||
ret := _m.Called(pf, offset, size)
|
|
||||||
|
|
||||||
var r0 bool
|
|
||||||
if rf, ok := ret.Get(0).(func(*partialfile.PartialFile, storiface.UnpaddedByteIndex, abi.UnpaddedPieceSize) bool); ok {
|
|
||||||
r0 = rf(pf, offset, size)
|
|
||||||
} else {
|
|
||||||
r0 = ret.Get(0).(bool)
|
|
||||||
}
|
|
||||||
|
|
||||||
var r1 error
|
|
||||||
if rf, ok := ret.Get(1).(func(*partialfile.PartialFile, storiface.UnpaddedByteIndex, abi.UnpaddedPieceSize) error); ok {
|
|
||||||
r1 = rf(pf, offset, size)
|
|
||||||
} else {
|
|
||||||
r1 = ret.Error(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
return r0, r1
|
|
||||||
}
|
|
||||||
|
|
||||||
// OpenPartialFile provides a mock function with given fields: maxPieceSize, path
|
|
||||||
func (_m *PartialFileHandler) OpenPartialFile(maxPieceSize abi.PaddedPieceSize, path string) (*partialfile.PartialFile, error) {
|
|
||||||
ret := _m.Called(maxPieceSize, path)
|
|
||||||
|
|
||||||
var r0 *partialfile.PartialFile
|
|
||||||
if rf, ok := ret.Get(0).(func(abi.PaddedPieceSize, string) *partialfile.PartialFile); ok {
|
|
||||||
r0 = rf(maxPieceSize, path)
|
|
||||||
} else {
|
|
||||||
if ret.Get(0) != nil {
|
|
||||||
r0 = ret.Get(0).(*partialfile.PartialFile)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var r1 error
|
|
||||||
if rf, ok := ret.Get(1).(func(abi.PaddedPieceSize, string) error); ok {
|
|
||||||
r1 = rf(maxPieceSize, path)
|
|
||||||
} else {
|
|
||||||
r1 = ret.Error(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
return r0, r1
|
|
||||||
}
|
|
182
extern/sector-storage/stores/mocks/stores.go
vendored
Normal file
182
extern/sector-storage/stores/mocks/stores.go
vendored
Normal file
@ -0,0 +1,182 @@
|
|||||||
|
// Code generated by MockGen. DO NOT EDIT.
|
||||||
|
// Source: interface.go
|
||||||
|
|
||||||
|
// Package mock_stores is a generated GoMock package.
|
||||||
|
package mocks
|
||||||
|
|
||||||
|
import (
|
||||||
|
context "context"
|
||||||
|
reflect "reflect"
|
||||||
|
|
||||||
|
abi "github.com/filecoin-project/go-state-types/abi"
|
||||||
|
fsutil "github.com/filecoin-project/lotus/extern/sector-storage/fsutil"
|
||||||
|
partialfile "github.com/filecoin-project/lotus/extern/sector-storage/partialfile"
|
||||||
|
stores "github.com/filecoin-project/lotus/extern/sector-storage/stores"
|
||||||
|
storiface "github.com/filecoin-project/lotus/extern/sector-storage/storiface"
|
||||||
|
storage "github.com/filecoin-project/specs-storage/storage"
|
||||||
|
gomock "github.com/golang/mock/gomock"
|
||||||
|
)
|
||||||
|
|
||||||
|
// MockpartialFileHandler is a mock of partialFileHandler interface.
|
||||||
|
type MockpartialFileHandler struct {
|
||||||
|
ctrl *gomock.Controller
|
||||||
|
recorder *MockpartialFileHandlerMockRecorder
|
||||||
|
}
|
||||||
|
|
||||||
|
// MockpartialFileHandlerMockRecorder is the mock recorder for MockpartialFileHandler.
|
||||||
|
type MockpartialFileHandlerMockRecorder struct {
|
||||||
|
mock *MockpartialFileHandler
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewMockpartialFileHandler creates a new mock instance.
|
||||||
|
func NewMockpartialFileHandler(ctrl *gomock.Controller) *MockpartialFileHandler {
|
||||||
|
mock := &MockpartialFileHandler{ctrl: ctrl}
|
||||||
|
mock.recorder = &MockpartialFileHandlerMockRecorder{mock}
|
||||||
|
return mock
|
||||||
|
}
|
||||||
|
|
||||||
|
// EXPECT returns an object that allows the caller to indicate expected use.
|
||||||
|
func (m *MockpartialFileHandler) EXPECT() *MockpartialFileHandlerMockRecorder {
|
||||||
|
return m.recorder
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasAllocated mocks base method.
|
||||||
|
func (m *MockpartialFileHandler) HasAllocated(pf *partialfile.PartialFile, offset storiface.UnpaddedByteIndex, size abi.UnpaddedPieceSize) (bool, error) {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "HasAllocated", pf, offset, size)
|
||||||
|
ret0, _ := ret[0].(bool)
|
||||||
|
ret1, _ := ret[1].(error)
|
||||||
|
return ret0, ret1
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasAllocated indicates an expected call of HasAllocated.
|
||||||
|
func (mr *MockpartialFileHandlerMockRecorder) HasAllocated(pf, offset, size interface{}) *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HasAllocated", reflect.TypeOf((*MockpartialFileHandler)(nil).HasAllocated), pf, offset, size)
|
||||||
|
}
|
||||||
|
|
||||||
|
// OpenPartialFile mocks base method.
|
||||||
|
func (m *MockpartialFileHandler) OpenPartialFile(maxPieceSize abi.PaddedPieceSize, path string) (*partialfile.PartialFile, error) {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "OpenPartialFile", maxPieceSize, path)
|
||||||
|
ret0, _ := ret[0].(*partialfile.PartialFile)
|
||||||
|
ret1, _ := ret[1].(error)
|
||||||
|
return ret0, ret1
|
||||||
|
}
|
||||||
|
|
||||||
|
// OpenPartialFile indicates an expected call of OpenPartialFile.
|
||||||
|
func (mr *MockpartialFileHandlerMockRecorder) OpenPartialFile(maxPieceSize, path interface{}) *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "OpenPartialFile", reflect.TypeOf((*MockpartialFileHandler)(nil).OpenPartialFile), maxPieceSize, path)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MockStore is a mock of Store interface.
|
||||||
|
type MockStore struct {
|
||||||
|
ctrl *gomock.Controller
|
||||||
|
recorder *MockStoreMockRecorder
|
||||||
|
}
|
||||||
|
|
||||||
|
// MockStoreMockRecorder is the mock recorder for MockStore.
|
||||||
|
type MockStoreMockRecorder struct {
|
||||||
|
mock *MockStore
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewMockStore creates a new mock instance.
|
||||||
|
func NewMockStore(ctrl *gomock.Controller) *MockStore {
|
||||||
|
mock := &MockStore{ctrl: ctrl}
|
||||||
|
mock.recorder = &MockStoreMockRecorder{mock}
|
||||||
|
return mock
|
||||||
|
}
|
||||||
|
|
||||||
|
// EXPECT returns an object that allows the caller to indicate expected use.
|
||||||
|
func (m *MockStore) EXPECT() *MockStoreMockRecorder {
|
||||||
|
return m.recorder
|
||||||
|
}
|
||||||
|
|
||||||
|
// AcquireSector mocks base method.
|
||||||
|
func (m *MockStore) AcquireSector(ctx context.Context, s storage.SectorRef, existing, allocate storiface.SectorFileType, sealing storiface.PathType, op storiface.AcquireMode) (storiface.SectorPaths, storiface.SectorPaths, error) {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "AcquireSector", ctx, s, existing, allocate, sealing, op)
|
||||||
|
ret0, _ := ret[0].(storiface.SectorPaths)
|
||||||
|
ret1, _ := ret[1].(storiface.SectorPaths)
|
||||||
|
ret2, _ := ret[2].(error)
|
||||||
|
return ret0, ret1, ret2
|
||||||
|
}
|
||||||
|
|
||||||
|
// AcquireSector indicates an expected call of AcquireSector.
|
||||||
|
func (mr *MockStoreMockRecorder) AcquireSector(ctx, s, existing, allocate, sealing, op interface{}) *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AcquireSector", reflect.TypeOf((*MockStore)(nil).AcquireSector), ctx, s, existing, allocate, sealing, op)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FsStat mocks base method.
|
||||||
|
func (m *MockStore) FsStat(ctx context.Context, id stores.ID) (fsutil.FsStat, error) {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "FsStat", ctx, id)
|
||||||
|
ret0, _ := ret[0].(fsutil.FsStat)
|
||||||
|
ret1, _ := ret[1].(error)
|
||||||
|
return ret0, ret1
|
||||||
|
}
|
||||||
|
|
||||||
|
// FsStat indicates an expected call of FsStat.
|
||||||
|
func (mr *MockStoreMockRecorder) FsStat(ctx, id interface{}) *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FsStat", reflect.TypeOf((*MockStore)(nil).FsStat), ctx, id)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MoveStorage mocks base method.
|
||||||
|
func (m *MockStore) MoveStorage(ctx context.Context, s storage.SectorRef, types storiface.SectorFileType) error {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "MoveStorage", ctx, s, types)
|
||||||
|
ret0, _ := ret[0].(error)
|
||||||
|
return ret0
|
||||||
|
}
|
||||||
|
|
||||||
|
// MoveStorage indicates an expected call of MoveStorage.
|
||||||
|
func (mr *MockStoreMockRecorder) MoveStorage(ctx, s, types interface{}) *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "MoveStorage", reflect.TypeOf((*MockStore)(nil).MoveStorage), ctx, s, types)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove mocks base method.
|
||||||
|
func (m *MockStore) Remove(ctx context.Context, s abi.SectorID, types storiface.SectorFileType, force bool) error {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "Remove", ctx, s, types, force)
|
||||||
|
ret0, _ := ret[0].(error)
|
||||||
|
return ret0
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove indicates an expected call of Remove.
|
||||||
|
func (mr *MockStoreMockRecorder) Remove(ctx, s, types, force interface{}) *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Remove", reflect.TypeOf((*MockStore)(nil).Remove), ctx, s, types, force)
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveCopies mocks base method.
|
||||||
|
func (m *MockStore) RemoveCopies(ctx context.Context, s abi.SectorID, types storiface.SectorFileType) error {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "RemoveCopies", ctx, s, types)
|
||||||
|
ret0, _ := ret[0].(error)
|
||||||
|
return ret0
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveCopies indicates an expected call of RemoveCopies.
|
||||||
|
func (mr *MockStoreMockRecorder) RemoveCopies(ctx, s, types interface{}) *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RemoveCopies", reflect.TypeOf((*MockStore)(nil).RemoveCopies), ctx, s, types)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reserve mocks base method.
|
||||||
|
func (m *MockStore) Reserve(ctx context.Context, sid storage.SectorRef, ft storiface.SectorFileType, storageIDs storiface.SectorPaths, overheadTab map[storiface.SectorFileType]int) (func(), error) {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "Reserve", ctx, sid, ft, storageIDs, overheadTab)
|
||||||
|
ret0, _ := ret[0].(func())
|
||||||
|
ret1, _ := ret[1].(error)
|
||||||
|
return ret0, ret1
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reserve indicates an expected call of Reserve.
|
||||||
|
func (mr *MockStoreMockRecorder) Reserve(ctx, sid, ft, storageIDs, overheadTab interface{}) *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Reserve", reflect.TypeOf((*MockStore)(nil).Reserve), ctx, sid, ft, storageIDs, overheadTab)
|
||||||
|
}
|
4
extern/sector-storage/stores/remote.go
vendored
4
extern/sector-storage/stores/remote.go
vendored
@ -581,4 +581,8 @@ func (r *Remote) Reader(ctx context.Context, s storage.SectorRef, offset, size a
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *Remote) Reserve(ctx context.Context, sid storage.SectorRef, ft storiface.SectorFileType, storageIDs storiface.SectorPaths, overheadTab map[storiface.SectorFileType]int) (func(), error) {
|
||||||
|
panic("not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
var _ Store = &Remote{}
|
var _ Store = &Remote{}
|
||||||
|
2
go.mod
2
go.mod
@ -55,7 +55,7 @@ require (
|
|||||||
github.com/gdamore/tcell/v2 v2.2.0
|
github.com/gdamore/tcell/v2 v2.2.0
|
||||||
github.com/go-kit/kit v0.10.0
|
github.com/go-kit/kit v0.10.0
|
||||||
github.com/go-ole/go-ole v1.2.4 // indirect
|
github.com/go-ole/go-ole v1.2.4 // indirect
|
||||||
github.com/golang/mock v1.4.4
|
github.com/golang/mock v1.5.0
|
||||||
github.com/google/uuid v1.1.2
|
github.com/google/uuid v1.1.2
|
||||||
github.com/gorilla/mux v1.7.4
|
github.com/gorilla/mux v1.7.4
|
||||||
github.com/gorilla/websocket v1.4.2
|
github.com/gorilla/websocket v1.4.2
|
||||||
|
2
go.sum
2
go.sum
@ -418,6 +418,8 @@ github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt
|
|||||||
github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
|
github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
|
||||||
github.com/golang/mock v1.4.4 h1:l75CXGRSwbaYNpl/Z2X1XIIAMSCquvXgpVZDhwEIJsc=
|
github.com/golang/mock v1.4.4 h1:l75CXGRSwbaYNpl/Z2X1XIIAMSCquvXgpVZDhwEIJsc=
|
||||||
github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4=
|
github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4=
|
||||||
|
github.com/golang/mock v1.5.0 h1:jlYHihg//f7RRwuPfptm04yp4s7O6Kw8EZiVYIGcH0g=
|
||||||
|
github.com/golang/mock v1.5.0/go.mod h1:CWnOUgYIOo4TcNZ0wHX3YZCqsaM1I1Jvs6v3mP3KVu8=
|
||||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||||
github.com/golang/protobuf v1.3.0/go.mod h1:Qd/q+1AKNOZr9uGQzbzCmRO6sUih6GTPZv6a1/R87v0=
|
github.com/golang/protobuf v1.3.0/go.mod h1:Qd/q+1AKNOZr9uGQzbzCmRO6sUih6GTPZv6a1/R87v0=
|
||||||
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||||
|
Loading…
Reference in New Issue
Block a user