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
eb7ea591
Unverified
Commit
eb7ea591
authored
Aug 03, 2020
by
Zahoor Mohamed
Committed by
GitHub
Aug 03, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
return empty response when nothing is pinned (#500)
* return empty response when nothing is pinned
parent
6efcbfdf
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
0 deletions
+20
-0
pin_test.go
pkg/debugapi/pin_test.go
+7
-0
pin.go
pkg/localstore/pin.go
+10
-0
storer.go
pkg/storage/mock/storer.go
+3
-0
No files found.
pkg/debugapi/pin_test.go
View file @
eb7ea591
...
...
@@ -47,6 +47,13 @@ func TestPinChunkHandler(t *testing.T) {
})
})
// list pins without anything pinned
t
.
Run
(
"list-pins-zero-pins"
,
func
(
t
*
testing
.
T
)
{
jsonhttptest
.
ResponseDirect
(
t
,
debugTestServer
.
Client
,
http
.
MethodGet
,
"/chunks-pin"
,
nil
,
http
.
StatusOK
,
debugapi
.
ListPinnedChunksResponse
{
Chunks
:
[]
debugapi
.
PinnedChunk
{},
})
})
// pin a chunk which is not existing
t
.
Run
(
"pin-absent-chunk"
,
func
(
t
*
testing
.
T
)
{
jsonhttptest
.
ResponseDirect
(
t
,
debugTestServer
.
Client
,
http
.
MethodPost
,
"/chunks-pin/123456"
,
nil
,
http
.
StatusNotFound
,
jsonhttp
.
StatusResponse
{
...
...
pkg/localstore/pin.go
View file @
eb7ea591
...
...
@@ -30,6 +30,16 @@ func (db *DB) PinnedChunks(ctx context.Context, cursor swarm.Address) (pinnedChu
prefix
=
nil
}
c
,
err
:=
db
.
pinIndex
.
Count
()
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"list pinned chunks: %w"
,
err
)
}
// send empty response if there is nothing pinned
if
c
==
0
{
return
pinnedChunks
,
nil
}
it
,
err
:=
db
.
pinIndex
.
First
(
prefix
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"get first pin: %w"
,
err
)
...
...
pkg/storage/mock/storer.go
View file @
eb7ea591
...
...
@@ -263,6 +263,9 @@ func (m *MockStorer) SubscribePush(ctx context.Context) (c <-chan swarm.Chunk, s
func
(
m
*
MockStorer
)
PinnedChunks
(
ctx
context
.
Context
,
cursor
swarm
.
Address
)
(
pinnedChunks
[]
*
storage
.
Pinner
,
err
error
)
{
m
.
pinSetMu
.
Lock
()
defer
m
.
pinSetMu
.
Unlock
()
if
len
(
m
.
pinnedAddress
)
==
0
{
return
pinnedChunks
,
nil
}
for
i
,
addr
:=
range
m
.
pinnedAddress
{
pi
:=
&
storage
.
Pinner
{
Address
:
swarm
.
NewAddress
(
addr
.
Bytes
()),
...
...
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