Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mybee
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
mybee
Commits
dfeca7c2
Unverified
Commit
dfeca7c2
authored
Sep 07, 2020
by
Janoš Guljaš
Committed by
GitHub
Sep 07, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move chunks-pin endpoints from debugapi to api (#673)
parent
823f236d
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
136 additions
and
161 deletions
+136
-161
Swarm.yaml
openapi/Swarm.yaml
+77
-2
SwarmDebug.yaml
openapi/SwarmDebug.yaml
+0
-75
export_test.go
pkg/api/export_test.go
+6
-4
pin.go
pkg/api/pin.go
+2
-2
pin_test.go
pkg/api/pin_test.go
+33
-37
router.go
pkg/api/router.go
+9
-0
debugapi_test.go
pkg/debugapi/debugapi_test.go
+0
-22
export_test.go
pkg/debugapi/export_test.go
+9
-11
router.go
pkg/debugapi/router.go
+0
-8
No files found.
openapi/Swarm.yaml
View file @
dfeca7c2
...
@@ -450,3 +450,78 @@ paths:
...
@@ -450,3 +450,78 @@ paths:
$ref
:
'
SwarmCommon.yaml#/components/responses/500'
$ref
:
'
SwarmCommon.yaml#/components/responses/500'
default
:
default
:
description
:
Default response
description
:
Default response
'
/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
openapi/SwarmDebug.yaml
View file @
dfeca7c2
...
@@ -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
...
...
pkg/api/export_test.go
View file @
dfeca7c2
...
@@ -13,6 +13,8 @@ type (
...
@@ -13,6 +13,8 @@ type (
FileUploadResponse
=
fileUploadResponse
FileUploadResponse
=
fileUploadResponse
TagResponse
=
tagResponse
TagResponse
=
tagResponse
TagRequest
=
tagRequest
TagRequest
=
tagRequest
PinnedChunk
=
pinnedChunk
ListPinnedChunksResponse
=
listPinnedChunksResponse
)
)
var
(
var
(
...
...
pkg/
debug
api/pin.go
→
pkg/api/pin.go
View file @
dfeca7c2
...
@@ -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
debug
api
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
a
ddress: %v"
,
err
)
jsonhttp
.
BadRequest
(
w
,
"bad address"
)
jsonhttp
.
BadRequest
(
w
,
"bad address"
)
return
return
}
}
...
...
pkg/
debug
api/pin_test.go
→
pkg/api/pin_test.go
View file @
dfeca7c2
...
@@ -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
debug
api_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
(
debug
api
.
ListPinnedChunksResponse
{
jsonhttptest
.
WithExpectedJSONResponse
(
api
.
ListPinnedChunksResponse
{
Chunks
:
[]
debug
api
.
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
(
debug
api
.
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
(
debug
api
.
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
(
debug
api
.
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
(
debug
api
.
ListPinnedChunksResponse
{
jsonhttptest
.
WithExpectedJSONResponse
(
api
.
ListPinnedChunksResponse
{
Chunks
:
[]
debug
api
.
PinnedChunk
{
Chunks
:
[]
api
.
PinnedChunk
{
{
{
Address
:
swarm
.
MustParseHexAddress
(
"aabbcc"
),
Address
:
swarm
.
MustParseHexAddress
(
"aabbcc"
),
PinCounter
:
1
,
PinCounter
:
1
,
...
...
pkg/api/router.go
View file @
dfeca7c2
...
@@ -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
,
...
...
pkg/debugapi/debugapi_test.go
View file @
dfeca7c2
...
@@ -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
()
...
...
pkg/debugapi/export_test.go
View file @
dfeca7c2
...
@@ -10,8 +10,6 @@ type (
...
@@ -10,8 +10,6 @@ type (
PeerConnectResponse
=
peerConnectResponse
PeerConnectResponse
=
peerConnectResponse
PeersResponse
=
peersResponse
PeersResponse
=
peersResponse
AddressesResponse
=
addressesResponse
AddressesResponse
=
addressesResponse
PinnedChunk
=
pinnedChunk
ListPinnedChunksResponse
=
listPinnedChunksResponse
WelcomeMessageRequest
=
welcomeMessageRequest
WelcomeMessageRequest
=
welcomeMessageRequest
WelcomeMessageResponse
=
welcomeMessageResponse
WelcomeMessageResponse
=
welcomeMessageResponse
BalancesResponse
=
balancesResponse
BalancesResponse
=
balancesResponse
...
...
pkg/debugapi/router.go
View file @
dfeca7c2
...
@@ -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
),
})
})
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment