Skip to content

Commit

Permalink
fix: update current http urls as per #960 (#975)
Browse files Browse the repository at this point in the history
* redesign piece url

* remove car related code

* go.mod tidy

* implement suggestions

* remove format

* remove unused interfaces

* fix lint error

* remove methods from serverAPI
  • Loading branch information
LexLuthr authored Nov 22, 2022
1 parent 67b9a62 commit ba8936b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 356 deletions.
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

0 comments on commit ba8936b

Please sign in to comment.