Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update current http urls as per #960 #975

Merged
merged 8 commits into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 1 addition & 59 deletions cmd/booster-http/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,8 @@ func TestHttpGzipResponse(t *testing.T) {
defer f.Close()

//Create CID
var cids []cid.Cid
cid, err := cid.Parse("bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi")
require.NoError(t, err)
cids = append(cids, cid)

// Crate pieceInfo
deal := piecestore.DealInfo{
Expand All @@ -73,12 +71,11 @@ func TestHttpGzipResponse(t *testing.T) {

mockHttpServer.EXPECT().UnsealSectorAt(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().Return(f, nil)
mockHttpServer.EXPECT().IsUnsealed(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().Return(true, nil)
mockHttpServer.EXPECT().PiecesContainingMultihash(gomock.Any(), gomock.Any()).AnyTimes().Return(cids, nil)
mockHttpServer.EXPECT().GetPieceInfo(gomock.Any()).AnyTimes().Return(&pieceInfo, nil)

//Create a client and make request with Encoding header
client := new(http.Client)
request, err := http.NewRequest("GET", "http://localhost:7777/piece?payloadCid=bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi&format=piece", nil)
request, err := http.NewRequest("GET", "http://localhost:7777/piece/bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi", nil)
require.NoError(t, err)
request.Header.Add("Accept-Encoding", "gzip")

Expand All @@ -103,61 +100,6 @@ func TestHttpGzipResponse(t *testing.T) {
require.NoError(t, err)
}

func TestHttpResponseRedirects(t *testing.T) {

// Create a new mock Http server with custom functions
ctrl := gomock.NewController(t)
mockHttpServer := mocks_booster_http.NewMockHttpServerApi(ctrl)
httpServer := NewHttpServer("", 7777, false, mockHttpServer)
httpServer.Start(context.Background())

// Create mock unsealed file for piece/car
f, _ := os.Open(testFile)
defer f.Close()

//Create CID
var cids []cid.Cid
cid, err := cid.Parse("bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi")
require.NoError(t, err)
cids = append(cids, cid)

// Crate pieceInfo
deal := piecestore.DealInfo{
DealID: 1234567,
SectorID: 0,
Offset: 1233,
Length: 123,
}
var deals []piecestore.DealInfo

pieceInfo := piecestore.PieceInfo{
PieceCID: cid,
Deals: append(deals, deal),
}

mockHttpServer.EXPECT().UnsealSectorAt(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().Return(f, nil)
mockHttpServer.EXPECT().IsUnsealed(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().Return(true, nil)
mockHttpServer.EXPECT().PiecesContainingMultihash(gomock.Any(), gomock.Any()).AnyTimes().Return(cids, nil)
mockHttpServer.EXPECT().GetPieceInfo(gomock.Any()).AnyTimes().Return(&pieceInfo, nil)

// Create a client with check against redirects
client := &http.Client{
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
},
}
request, err := http.NewRequest("GET", "http://localhost:7777/piece?payloadCid=bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi&format=piece", nil)
require.NoError(t, err)

response, err := client.Do(request)
require.NoError(t, err)
require.Equal(t, 200, response.StatusCode)

// Stop the server
err = httpServer.Stop()
require.NoError(t, err)
}

func TestHttpInfo(t *testing.T) {
var v apiVersion

Expand Down
31 changes: 0 additions & 31 deletions cmd/booster-http/mocks/mock_booster_http.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 0 additions & 9 deletions cmd/booster-http/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"github.com/filecoin-project/lotus/storage/paths"
"github.com/filecoin-project/lotus/storage/sealer"
"github.com/ipfs/go-cid"
"github.com/multiformats/go-multihash"
"github.com/urfave/cli/v2"
)

Expand Down Expand Up @@ -227,14 +226,6 @@ type serverApi struct {

var _ HttpServerApi = (*serverApi)(nil)

func (s serverApi) PiecesContainingMultihash(ctx context.Context, mh multihash.Multihash) ([]cid.Cid, error) {
return s.bapi.BoostDagstorePiecesContainingMultihash(ctx, mh)
}

func (s serverApi) GetMaxPieceOffset(pieceCid cid.Cid) (uint64, error) {
return s.bapi.PiecesGetMaxOffset(s.ctx, pieceCid)
}

func (s serverApi) GetPieceInfo(pieceCID cid.Cid) (*piecestore.PieceInfo, error) {
return s.bapi.PiecesGetPieceInfo(s.ctx, pieceCID)
}
Expand Down
Loading