Commit dfeca7c2 authored by Janoš Guljaš's avatar Janoš Guljaš Committed by GitHub

move chunks-pin endpoints from debugapi to api (#673)

parent 823f236d
...@@ -443,10 +443,85 @@ paths: ...@@ -443,10 +443,85 @@ paths:
content: content:
application/json: application/json:
schema: schema:
$ref: 'SwarmCommon.yaml#/components/schemas/Status' $ref: 'SwarmCommon.yaml#/components/schemas/Status'
'404': '404':
$ref: 'SwarmCommon.yaml#/components/responses/404' $ref: 'SwarmCommon.yaml#/components/responses/404'
'500': '500':
$ref: 'SwarmCommon.yaml#/components/responses/500' $ref: 'SwarmCommon.yaml#/components/responses/500'
default: default:
description: Default response description: Default response
\ No newline at end of file
'/pinning/chunks/{address}':
parameters:
- in: path
name: address
schema:
$ref: 'SwarmCommon.yaml#/components/schemas/SwarmAddress'
required: true
description: Swarm address of chunk
post:
summary: Pin chunk with given address
tags:
- Chunk pinning
responses:
'200':
description: Pinning chunk with address
content:
application/json:
schema:
$ref: 'SwarmCommon.yaml#/components/schemas/Response'
'400':
$ref: 'SwarmCommon.yaml#/components/responses/400'
'404':
$ref: 'SwarmCommon.yaml#/components/responses/404'
default:
description: Default response
delete:
summary: Unpin chunk with given address
tags:
- Chunk pinning
responses:
'200':
description: Unpinning chunk with address
content:
application/json:
schema:
$ref: 'SwarmCommon.yaml#/components/schemas/Response'
'400':
$ref: 'SwarmCommon.yaml#/components/responses/400'
'404':
$ref: 'SwarmCommon.yaml#/components/responses/404'
default:
description: Default response
get:
summary: Get pinning status of chunk with given address
tags:
- Chunk pinning
responses:
'200':
description: Pinning state of chunk with address
content:
application/json:
schema:
$ref: 'SwarmCommon.yaml#/components/schemas/PinningState'
'500':
$ref: 'SwarmCommon.yaml#/components/responses/500'
default:
description: Default response
'/pinning/chunks/':
get:
summary: Get list of pinned chunks
tags:
- Chunk pinning
responses:
'200':
description: List of pinned chunks
content:
application/json:
schema:
$ref: 'SwarmCommon.yaml#/components/schemas/BzzChunksPinned'
'500':
$ref: 'SwarmCommon.yaml#/components/responses/500'
default:
description: Default response
...@@ -134,81 +134,6 @@ paths: ...@@ -134,81 +134,6 @@ paths:
default: default:
description: Default response description: Default response
'/chunks-pin/{address}':
parameters:
- in: path
name: address
schema:
$ref: 'SwarmCommon.yaml#/components/schemas/SwarmAddress'
required: true
description: Swarm address of chunk
post:
summary: Pin chunk with given address
tags:
- Chunk pinning
responses:
'200':
description: Pinning chunk with address
content:
application/json:
schema:
$ref: 'SwarmCommon.yaml#/components/schemas/Response'
'400':
$ref: 'SwarmCommon.yaml#/components/responses/400'
'404':
$ref: 'SwarmCommon.yaml#/components/responses/404'
default:
description: Default response
delete:
summary: Unpin chunk with given address
tags:
- Chunk pinning
responses:
'200':
description: Unpinning chunk with address
content:
application/json:
schema:
$ref: 'SwarmCommon.yaml#/components/schemas/Response'
'400':
$ref: 'SwarmCommon.yaml#/components/responses/400'
'404':
$ref: 'SwarmCommon.yaml#/components/responses/404'
default:
description: Default response
get:
summary: Get pinning status of chunk with given address
tags:
- Chunk pinning
responses:
'200':
description: Pinning state of chunk with address
content:
application/json:
schema:
$ref: 'SwarmCommon.yaml#/components/schemas/PinningState'
'500':
$ref: 'SwarmCommon.yaml#/components/responses/500'
default:
description: Default response
'/chunks-pin/':
get:
summary: Get list of pinned chunks
tags:
- Chunk pinning
responses:
'200':
description: List of pinned chunks
content:
application/json:
schema:
$ref: 'SwarmCommon.yaml#/components/schemas/BzzChunksPinned'
'500':
$ref: 'SwarmCommon.yaml#/components/responses/500'
default:
description: Default response
'/connect/{multiAddress}': '/connect/{multiAddress}':
post: post:
summary: Connect to address summary: Connect to address
......
...@@ -9,10 +9,12 @@ import "github.com/ethersphere/bee/pkg/swarm" ...@@ -9,10 +9,12 @@ import "github.com/ethersphere/bee/pkg/swarm"
type Server = server type Server = server
type ( type (
BytesPostResponse = bytesPostResponse BytesPostResponse = bytesPostResponse
FileUploadResponse = fileUploadResponse FileUploadResponse = fileUploadResponse
TagResponse = tagResponse TagResponse = tagResponse
TagRequest = tagRequest TagRequest = tagRequest
PinnedChunk = pinnedChunk
ListPinnedChunksResponse = listPinnedChunksResponse
) )
var ( var (
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package debugapi package api
import ( import (
"errors" "errors"
...@@ -52,7 +52,7 @@ func (s *server) pinChunk(w http.ResponseWriter, r *http.Request) { ...@@ -52,7 +52,7 @@ func (s *server) pinChunk(w http.ResponseWriter, r *http.Request) {
func (s *server) unpinChunk(w http.ResponseWriter, r *http.Request) { func (s *server) unpinChunk(w http.ResponseWriter, r *http.Request) {
addr, err := swarm.ParseHexAddress(mux.Vars(r)["address"]) addr, err := swarm.ParseHexAddress(mux.Vars(r)["address"])
if err != nil { if err != nil {
s.Logger.Debugf("debug api: pin chunk: parse chunk ddress: %v", err) s.Logger.Debugf("debug api: pin chunk: parse chunk address: %v", err)
jsonhttp.BadRequest(w, "bad address") jsonhttp.BadRequest(w, "bad address")
return return
} }
......
...@@ -2,17 +2,18 @@ ...@@ -2,17 +2,18 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package debugapi_test package api_test
import ( import (
"bytes" "bytes"
"github.com/ethersphere/bee/pkg/logging"
statestore "github.com/ethersphere/bee/pkg/statestore/mock"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"testing" "testing"
"github.com/ethersphere/bee/pkg/debugapi" "github.com/ethersphere/bee/pkg/logging"
statestore "github.com/ethersphere/bee/pkg/statestore/mock"
"github.com/ethersphere/bee/pkg/api"
"github.com/ethersphere/bee/pkg/jsonhttp" "github.com/ethersphere/bee/pkg/jsonhttp"
"github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest" "github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest"
"github.com/ethersphere/bee/pkg/storage/mock" "github.com/ethersphere/bee/pkg/storage/mock"
...@@ -36,21 +37,16 @@ func TestPinChunkHandler(t *testing.T) { ...@@ -36,21 +37,16 @@ func TestPinChunkHandler(t *testing.T) {
logger = logging.New(ioutil.Discard, 0) logger = logging.New(ioutil.Discard, 0)
tag = tags.NewTags(mockStatestore, logger) tag = tags.NewTags(mockStatestore, logger)
debugTestServer = newTestServer(t, testServerOptions{ client = newTestServer(t, testServerOptions{
Storer: mockValidatingStorer,
Tags: tag,
})
// This server is used to store chunks
bzzTestServer = newBZZTestServer(t, testServerOptions{
Storer: mockValidatingStorer, Storer: mockValidatingStorer,
Tags: tag, Tags: tag,
Logger: logger,
}) })
) )
// bad chunk address // bad chunk address
t.Run("pin-bad-address", func(t *testing.T) { t.Run("pin-bad-address", func(t *testing.T) {
jsonhttptest.Request(t, debugTestServer.Client, http.MethodPost, "/chunks-pin/abcd1100zz", http.StatusBadRequest, jsonhttptest.Request(t, client, http.MethodPost, "/pinning/chunks/abcd1100zz", http.StatusBadRequest,
jsonhttptest.WithExpectedJSONResponse(jsonhttp.StatusResponse{ jsonhttptest.WithExpectedJSONResponse(jsonhttp.StatusResponse{
Message: "bad address", Message: "bad address",
Code: http.StatusBadRequest, Code: http.StatusBadRequest,
...@@ -60,16 +56,16 @@ func TestPinChunkHandler(t *testing.T) { ...@@ -60,16 +56,16 @@ func TestPinChunkHandler(t *testing.T) {
// list pins without anything pinned // list pins without anything pinned
t.Run("list-pins-zero-pins", func(t *testing.T) { t.Run("list-pins-zero-pins", func(t *testing.T) {
jsonhttptest.Request(t, debugTestServer.Client, http.MethodGet, "/chunks-pin", http.StatusOK, jsonhttptest.Request(t, client, http.MethodGet, "/pinning/chunks", http.StatusOK,
jsonhttptest.WithExpectedJSONResponse(debugapi.ListPinnedChunksResponse{ jsonhttptest.WithExpectedJSONResponse(api.ListPinnedChunksResponse{
Chunks: []debugapi.PinnedChunk{}, Chunks: []api.PinnedChunk{},
}), }),
) )
}) })
// pin a chunk which is not existing // pin a chunk which is not existing
t.Run("pin-absent-chunk", func(t *testing.T) { t.Run("pin-absent-chunk", func(t *testing.T) {
jsonhttptest.Request(t, debugTestServer.Client, http.MethodPost, "/chunks-pin/123456", http.StatusNotFound, jsonhttptest.Request(t, client, http.MethodPost, "/pinning/chunks/123456", http.StatusNotFound,
jsonhttptest.WithExpectedJSONResponse(jsonhttp.StatusResponse{ jsonhttptest.WithExpectedJSONResponse(jsonhttp.StatusResponse{
Message: http.StatusText(http.StatusNotFound), Message: http.StatusText(http.StatusNotFound),
Code: http.StatusNotFound, Code: http.StatusNotFound,
...@@ -80,7 +76,7 @@ func TestPinChunkHandler(t *testing.T) { ...@@ -80,7 +76,7 @@ func TestPinChunkHandler(t *testing.T) {
// unpin on a chunk which is not pinned // unpin on a chunk which is not pinned
t.Run("unpin-while-not-pinned", func(t *testing.T) { t.Run("unpin-while-not-pinned", func(t *testing.T) {
// Post a chunk // Post a chunk
jsonhttptest.Request(t, bzzTestServer, http.MethodPost, resource(hash), http.StatusOK, jsonhttptest.Request(t, client, http.MethodPost, resource(hash), http.StatusOK,
jsonhttptest.WithRequestBody(bytes.NewReader(data)), jsonhttptest.WithRequestBody(bytes.NewReader(data)),
jsonhttptest.WithExpectedJSONResponse(jsonhttp.StatusResponse{ jsonhttptest.WithExpectedJSONResponse(jsonhttp.StatusResponse{
Message: http.StatusText(http.StatusOK), Message: http.StatusText(http.StatusOK),
...@@ -88,7 +84,7 @@ func TestPinChunkHandler(t *testing.T) { ...@@ -88,7 +84,7 @@ func TestPinChunkHandler(t *testing.T) {
}), }),
) )
jsonhttptest.Request(t, debugTestServer.Client, http.MethodDelete, "/chunks-pin/"+hash.String(), http.StatusBadRequest, jsonhttptest.Request(t, client, http.MethodDelete, "/pinning/chunks/"+hash.String(), http.StatusBadRequest,
jsonhttptest.WithExpectedJSONResponse(jsonhttp.StatusResponse{ jsonhttptest.WithExpectedJSONResponse(jsonhttp.StatusResponse{
Message: "chunk is not yet pinned", Message: "chunk is not yet pinned",
Code: http.StatusBadRequest, Code: http.StatusBadRequest,
...@@ -99,7 +95,7 @@ func TestPinChunkHandler(t *testing.T) { ...@@ -99,7 +95,7 @@ func TestPinChunkHandler(t *testing.T) {
// pin a existing chunk first time // pin a existing chunk first time
t.Run("pin-chunk-1", func(t *testing.T) { t.Run("pin-chunk-1", func(t *testing.T) {
// Post a chunk // Post a chunk
jsonhttptest.Request(t, bzzTestServer, http.MethodPost, resource(hash), http.StatusOK, jsonhttptest.Request(t, client, http.MethodPost, resource(hash), http.StatusOK,
jsonhttptest.WithRequestBody(bytes.NewReader(data)), jsonhttptest.WithRequestBody(bytes.NewReader(data)),
jsonhttptest.WithExpectedJSONResponse(jsonhttp.StatusResponse{ jsonhttptest.WithExpectedJSONResponse(jsonhttp.StatusResponse{
Message: http.StatusText(http.StatusOK), Message: http.StatusText(http.StatusOK),
...@@ -107,7 +103,7 @@ func TestPinChunkHandler(t *testing.T) { ...@@ -107,7 +103,7 @@ func TestPinChunkHandler(t *testing.T) {
}), }),
) )
jsonhttptest.Request(t, debugTestServer.Client, http.MethodPost, "/chunks-pin/"+hash.String(), http.StatusOK, jsonhttptest.Request(t, client, http.MethodPost, "/pinning/chunks/"+hash.String(), http.StatusOK,
jsonhttptest.WithExpectedJSONResponse(jsonhttp.StatusResponse{ jsonhttptest.WithExpectedJSONResponse(jsonhttp.StatusResponse{
Message: http.StatusText(http.StatusOK), Message: http.StatusText(http.StatusOK),
Code: http.StatusOK, Code: http.StatusOK,
...@@ -115,8 +111,8 @@ func TestPinChunkHandler(t *testing.T) { ...@@ -115,8 +111,8 @@ func TestPinChunkHandler(t *testing.T) {
) )
// Check is the chunk is pinned once // Check is the chunk is pinned once
jsonhttptest.Request(t, debugTestServer.Client, http.MethodGet, "/chunks-pin/"+hash.String(), http.StatusOK, jsonhttptest.Request(t, client, http.MethodGet, "/pinning/chunks/"+hash.String(), http.StatusOK,
jsonhttptest.WithExpectedJSONResponse(debugapi.PinnedChunk{ jsonhttptest.WithExpectedJSONResponse(api.PinnedChunk{
Address: swarm.MustParseHexAddress("aabbcc"), Address: swarm.MustParseHexAddress("aabbcc"),
PinCounter: 1, PinCounter: 1,
}), }),
...@@ -126,7 +122,7 @@ func TestPinChunkHandler(t *testing.T) { ...@@ -126,7 +122,7 @@ func TestPinChunkHandler(t *testing.T) {
// pin a existing chunk second time // pin a existing chunk second time
t.Run("pin-chunk-2", func(t *testing.T) { t.Run("pin-chunk-2", func(t *testing.T) {
jsonhttptest.Request(t, debugTestServer.Client, http.MethodPost, "/chunks-pin/"+hash.String(), http.StatusOK, jsonhttptest.Request(t, client, http.MethodPost, "/pinning/chunks/"+hash.String(), http.StatusOK,
jsonhttptest.WithExpectedJSONResponse(jsonhttp.StatusResponse{ jsonhttptest.WithExpectedJSONResponse(jsonhttp.StatusResponse{
Message: http.StatusText(http.StatusOK), Message: http.StatusText(http.StatusOK),
Code: http.StatusOK, Code: http.StatusOK,
...@@ -134,8 +130,8 @@ func TestPinChunkHandler(t *testing.T) { ...@@ -134,8 +130,8 @@ func TestPinChunkHandler(t *testing.T) {
) )
// Check is the chunk is pinned twice // Check is the chunk is pinned twice
jsonhttptest.Request(t, debugTestServer.Client, http.MethodGet, "/chunks-pin/"+hash.String(), http.StatusOK, jsonhttptest.Request(t, client, http.MethodGet, "/pinning/chunks/"+hash.String(), http.StatusOK,
jsonhttptest.WithExpectedJSONResponse(debugapi.PinnedChunk{ jsonhttptest.WithExpectedJSONResponse(api.PinnedChunk{
Address: swarm.MustParseHexAddress("aabbcc"), Address: swarm.MustParseHexAddress("aabbcc"),
PinCounter: 2, PinCounter: 2,
}), }),
...@@ -144,7 +140,7 @@ func TestPinChunkHandler(t *testing.T) { ...@@ -144,7 +140,7 @@ func TestPinChunkHandler(t *testing.T) {
// unpin a chunk first time // unpin a chunk first time
t.Run("unpin-chunk-1", func(t *testing.T) { t.Run("unpin-chunk-1", func(t *testing.T) {
jsonhttptest.Request(t, debugTestServer.Client, http.MethodDelete, "/chunks-pin/"+hash.String(), http.StatusOK, jsonhttptest.Request(t, client, http.MethodDelete, "/pinning/chunks/"+hash.String(), http.StatusOK,
jsonhttptest.WithExpectedJSONResponse(jsonhttp.StatusResponse{ jsonhttptest.WithExpectedJSONResponse(jsonhttp.StatusResponse{
Message: http.StatusText(http.StatusOK), Message: http.StatusText(http.StatusOK),
Code: http.StatusOK, Code: http.StatusOK,
...@@ -152,8 +148,8 @@ func TestPinChunkHandler(t *testing.T) { ...@@ -152,8 +148,8 @@ func TestPinChunkHandler(t *testing.T) {
) )
// Check is the chunk is pinned once // Check is the chunk is pinned once
jsonhttptest.Request(t, debugTestServer.Client, http.MethodGet, "/chunks-pin/"+hash.String(), http.StatusOK, jsonhttptest.Request(t, client, http.MethodGet, "/pinning/chunks/"+hash.String(), http.StatusOK,
jsonhttptest.WithExpectedJSONResponse(debugapi.PinnedChunk{ jsonhttptest.WithExpectedJSONResponse(api.PinnedChunk{
Address: swarm.MustParseHexAddress("aabbcc"), Address: swarm.MustParseHexAddress("aabbcc"),
PinCounter: 1, PinCounter: 1,
}), }),
...@@ -162,7 +158,7 @@ func TestPinChunkHandler(t *testing.T) { ...@@ -162,7 +158,7 @@ func TestPinChunkHandler(t *testing.T) {
// unpin a chunk second time // unpin a chunk second time
t.Run("unpin-chunk-2", func(t *testing.T) { t.Run("unpin-chunk-2", func(t *testing.T) {
jsonhttptest.Request(t, debugTestServer.Client, http.MethodDelete, "/chunks-pin/"+hash.String(), http.StatusOK, jsonhttptest.Request(t, client, http.MethodDelete, "/pinning/chunks/"+hash.String(), http.StatusOK,
jsonhttptest.WithExpectedJSONResponse(jsonhttp.StatusResponse{ jsonhttptest.WithExpectedJSONResponse(jsonhttp.StatusResponse{
Message: http.StatusText(http.StatusOK), Message: http.StatusText(http.StatusOK),
Code: http.StatusOK, Code: http.StatusOK,
...@@ -170,7 +166,7 @@ func TestPinChunkHandler(t *testing.T) { ...@@ -170,7 +166,7 @@ func TestPinChunkHandler(t *testing.T) {
) )
// Check if the chunk is removed from the pinIndex // Check if the chunk is removed from the pinIndex
jsonhttptest.Request(t, debugTestServer.Client, http.MethodGet, "/chunks-pin/"+hash.String(), http.StatusNotFound, jsonhttptest.Request(t, client, http.MethodGet, "/pinning/chunks/"+hash.String(), http.StatusNotFound,
jsonhttptest.WithExpectedJSONResponse(jsonhttp.StatusResponse{ jsonhttptest.WithExpectedJSONResponse(jsonhttp.StatusResponse{
Message: http.StatusText(http.StatusNotFound), Message: http.StatusText(http.StatusNotFound),
Code: http.StatusNotFound, Code: http.StatusNotFound,
...@@ -181,7 +177,7 @@ func TestPinChunkHandler(t *testing.T) { ...@@ -181,7 +177,7 @@ func TestPinChunkHandler(t *testing.T) {
// Add 2 chunks, pin it and check if they show up in the list // Add 2 chunks, pin it and check if they show up in the list
t.Run("list-chunks", func(t *testing.T) { t.Run("list-chunks", func(t *testing.T) {
// Post a chunk // Post a chunk
jsonhttptest.Request(t, bzzTestServer, http.MethodPost, resource(hash), http.StatusOK, jsonhttptest.Request(t, client, http.MethodPost, resource(hash), http.StatusOK,
jsonhttptest.WithRequestBody(bytes.NewReader(data)), jsonhttptest.WithRequestBody(bytes.NewReader(data)),
jsonhttptest.WithExpectedJSONResponse(jsonhttp.StatusResponse{ jsonhttptest.WithExpectedJSONResponse(jsonhttp.StatusResponse{
Message: http.StatusText(http.StatusOK), Message: http.StatusText(http.StatusOK),
...@@ -189,7 +185,7 @@ func TestPinChunkHandler(t *testing.T) { ...@@ -189,7 +185,7 @@ func TestPinChunkHandler(t *testing.T) {
}), }),
) )
jsonhttptest.Request(t, debugTestServer.Client, http.MethodPost, "/chunks-pin/"+hash.String(), http.StatusOK, jsonhttptest.Request(t, client, http.MethodPost, "/pinning/chunks/"+hash.String(), http.StatusOK,
jsonhttptest.WithExpectedJSONResponse(jsonhttp.StatusResponse{ jsonhttptest.WithExpectedJSONResponse(jsonhttp.StatusResponse{
Message: http.StatusText(http.StatusOK), Message: http.StatusText(http.StatusOK),
Code: http.StatusOK, Code: http.StatusOK,
...@@ -200,23 +196,23 @@ func TestPinChunkHandler(t *testing.T) { ...@@ -200,23 +196,23 @@ func TestPinChunkHandler(t *testing.T) {
hash2 := swarm.MustParseHexAddress("ddeeff") hash2 := swarm.MustParseHexAddress("ddeeff")
data2 := []byte("eagle") data2 := []byte("eagle")
mockValidator.AddPair(hash2, data2) mockValidator.AddPair(hash2, data2)
jsonhttptest.Request(t, bzzTestServer, http.MethodPost, resource(hash2), http.StatusOK, jsonhttptest.Request(t, client, http.MethodPost, resource(hash2), http.StatusOK,
jsonhttptest.WithRequestBody(bytes.NewReader(data2)), jsonhttptest.WithRequestBody(bytes.NewReader(data2)),
jsonhttptest.WithExpectedJSONResponse(jsonhttp.StatusResponse{ jsonhttptest.WithExpectedJSONResponse(jsonhttp.StatusResponse{
Message: http.StatusText(http.StatusOK), Message: http.StatusText(http.StatusOK),
Code: http.StatusOK, Code: http.StatusOK,
}), }),
) )
jsonhttptest.Request(t, debugTestServer.Client, http.MethodPost, "/chunks-pin/"+hash2.String(), http.StatusOK, jsonhttptest.Request(t, client, http.MethodPost, "/pinning/chunks/"+hash2.String(), http.StatusOK,
jsonhttptest.WithExpectedJSONResponse(jsonhttp.StatusResponse{ jsonhttptest.WithExpectedJSONResponse(jsonhttp.StatusResponse{
Message: http.StatusText(http.StatusOK), Message: http.StatusText(http.StatusOK),
Code: http.StatusOK, Code: http.StatusOK,
}), }),
) )
jsonhttptest.Request(t, debugTestServer.Client, http.MethodGet, "/chunks-pin", http.StatusOK, jsonhttptest.Request(t, client, http.MethodGet, "/pinning/chunks", http.StatusOK,
jsonhttptest.WithExpectedJSONResponse(debugapi.ListPinnedChunksResponse{ jsonhttptest.WithExpectedJSONResponse(api.ListPinnedChunksResponse{
Chunks: []debugapi.PinnedChunk{ Chunks: []api.PinnedChunk{
{ {
Address: swarm.MustParseHexAddress("aabbcc"), Address: swarm.MustParseHexAddress("aabbcc"),
PinCounter: 1, PinCounter: 1,
......
...@@ -81,6 +81,15 @@ func (s *server) setupRouting() { ...@@ -81,6 +81,15 @@ func (s *server) setupRouting() {
), ),
}) })
handle(router, "/pinning/chunks/{address}", jsonhttp.MethodHandler{
"GET": http.HandlerFunc(s.getPinnedChunk),
"POST": http.HandlerFunc(s.pinChunk),
"DELETE": http.HandlerFunc(s.unpinChunk),
})
handle(router, "/pinning/chunks", jsonhttp.MethodHandler{
"GET": http.HandlerFunc(s.listPinnedChunks),
})
s.Handler = web.ChainHandlers( s.Handler = web.ChainHandlers(
logging.NewHTTPAccessLogHandler(s.Logger, logrus.InfoLevel, "api access"), logging.NewHTTPAccessLogHandler(s.Logger, logrus.InfoLevel, "api access"),
handlers.CompressHandler, handlers.CompressHandler,
......
...@@ -12,13 +12,11 @@ import ( ...@@ -12,13 +12,11 @@ import (
"testing" "testing"
accountingmock "github.com/ethersphere/bee/pkg/accounting/mock" accountingmock "github.com/ethersphere/bee/pkg/accounting/mock"
"github.com/ethersphere/bee/pkg/api"
"github.com/ethersphere/bee/pkg/debugapi" "github.com/ethersphere/bee/pkg/debugapi"
"github.com/ethersphere/bee/pkg/logging" "github.com/ethersphere/bee/pkg/logging"
p2pmock "github.com/ethersphere/bee/pkg/p2p/mock" p2pmock "github.com/ethersphere/bee/pkg/p2p/mock"
"github.com/ethersphere/bee/pkg/pingpong" "github.com/ethersphere/bee/pkg/pingpong"
"github.com/ethersphere/bee/pkg/resolver" "github.com/ethersphere/bee/pkg/resolver"
resolverMock "github.com/ethersphere/bee/pkg/resolver/mock"
"github.com/ethersphere/bee/pkg/storage" "github.com/ethersphere/bee/pkg/storage"
"github.com/ethersphere/bee/pkg/swarm" "github.com/ethersphere/bee/pkg/swarm"
"github.com/ethersphere/bee/pkg/tags" "github.com/ethersphere/bee/pkg/tags"
...@@ -67,26 +65,6 @@ func newTestServer(t *testing.T, o testServerOptions) *testServer { ...@@ -67,26 +65,6 @@ func newTestServer(t *testing.T, o testServerOptions) *testServer {
} }
} }
func newBZZTestServer(t *testing.T, o testServerOptions) *http.Client {
if o.Resolver == nil {
o.Resolver = resolverMock.NewResolver()
}
s := api.New(o.Tags, o.Storer, o.Resolver, nil, logging.New(ioutil.Discard, 0), nil)
ts := httptest.NewServer(s)
t.Cleanup(ts.Close)
return &http.Client{
Transport: web.RoundTripperFunc(func(r *http.Request) (*http.Response, error) {
u, err := url.Parse(ts.URL + r.URL.String())
if err != nil {
return nil, err
}
r.URL = u
return ts.Client().Transport.RoundTrip(r)
}),
}
}
func mustMultiaddr(t *testing.T, s string) multiaddr.Multiaddr { func mustMultiaddr(t *testing.T, s string) multiaddr.Multiaddr {
t.Helper() t.Helper()
......
...@@ -5,17 +5,15 @@ ...@@ -5,17 +5,15 @@
package debugapi package debugapi
type ( type (
StatusResponse = statusResponse StatusResponse = statusResponse
PingpongResponse = pingpongResponse PingpongResponse = pingpongResponse
PeerConnectResponse = peerConnectResponse PeerConnectResponse = peerConnectResponse
PeersResponse = peersResponse PeersResponse = peersResponse
AddressesResponse = addressesResponse AddressesResponse = addressesResponse
PinnedChunk = pinnedChunk WelcomeMessageRequest = welcomeMessageRequest
ListPinnedChunksResponse = listPinnedChunksResponse WelcomeMessageResponse = welcomeMessageResponse
WelcomeMessageRequest = welcomeMessageRequest BalancesResponse = balancesResponse
WelcomeMessageResponse = welcomeMessageResponse BalanceResponse = balanceResponse
BalancesResponse = balancesResponse
BalanceResponse = balanceResponse
) )
var ( var (
......
...@@ -70,14 +70,6 @@ func (s *server) setupRouting() { ...@@ -70,14 +70,6 @@ func (s *server) setupRouting() {
"GET": http.HandlerFunc(s.hasChunkHandler), "GET": http.HandlerFunc(s.hasChunkHandler),
"DELETE": http.HandlerFunc(s.removeChunk), "DELETE": http.HandlerFunc(s.removeChunk),
}) })
router.Handle("/chunks-pin/{address}", jsonhttp.MethodHandler{
"GET": http.HandlerFunc(s.getPinnedChunk),
"POST": http.HandlerFunc(s.pinChunk),
"DELETE": http.HandlerFunc(s.unpinChunk),
})
router.Handle("/chunks-pin", jsonhttp.MethodHandler{
"GET": http.HandlerFunc(s.listPinnedChunks),
})
router.Handle("/topology", jsonhttp.MethodHandler{ router.Handle("/topology", jsonhttp.MethodHandler{
"GET": http.HandlerFunc(s.topologyHandler), "GET": http.HandlerFunc(s.topologyHandler),
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment