Skip to content

Commit 69cd0e6

Browse files
committed
pinning: add integration tests with go-pinning-service-http-client
Signed-off-by: Sander Pick <sanderpick@gmail.com>
1 parent 3575904 commit 69cd0e6

File tree

11 files changed

+454
-319
lines changed

11 files changed

+454
-319
lines changed

api/apitest/docker-compose.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: "3"
22
services:
33
threads:
4-
image: textile/go-threads:534a6d0
4+
image: textile/go-threads:1ef50f7
55
environment:
66
- THREADS_APIADDR=/ip4/0.0.0.0/tcp/5000
77
- THREADS_APIPROXYADDR=/ip4/0.0.0.0/tcp/5050
@@ -11,7 +11,7 @@ services:
1111
- "127.0.0.1:4002:5000"
1212
- "127.0.0.1:4052:5050"
1313
ipfs:
14-
image: ipfs/go-ipfs:v0.8.0
14+
image: textile/go-ipfs:v0.8.0-m1
1515
environment:
1616
- IPFS_PROFILE=test
1717
ports:

api/client/client.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func NewClient(addr string, opts ...grpc.DialOption) (*Client, error) {
6969
return &Client{
7070
c: pb.NewAPIServiceClient(conn),
7171
conn: conn,
72-
target: "did:key:foo", // @todo: Fix me
72+
target: "did:key:foo", // @todo: Get target from thread services
7373
}, nil
7474
}
7575

api/service.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ func (s *Service) PushPaths(server pb.APIService_PushPathsServer) error {
234234
select {
235235
case res := <-out:
236236
if err := server.Send(&pb.PushPathsResponse{
237-
Path: res.Path.String(),
237+
Path: res.Path,
238238
Cid: res.Cid.String(),
239239
Size: res.Size,
240240
Pinned: res.Pinned,

gateway/pinning.go

+38-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package gateway
22

33
import (
4+
"context"
45
"errors"
56
"net/http"
7+
"strings"
68

79
"github.com/gin-gonic/gin"
810
"github.com/textileio/go-buckets/pinning"
@@ -32,7 +34,9 @@ func (g *Gateway) listPins(c *gin.Context, key string) {
3234
return
3335
}
3436

35-
pins, err := g.ps.ListPins(thread, key, oapiQueryToQuery(query), token)
37+
ctx, cancel := context.WithTimeout(context.Background(), handlerTimeout)
38+
defer cancel()
39+
pins, err := g.ps.ListPins(ctx, thread, key, oapiQueryToQuery(query), token)
3640
if err != nil {
3741
newFailure(c, http.StatusBadRequest, err)
3842
return
@@ -45,12 +49,32 @@ func (g *Gateway) listPins(c *gin.Context, key string) {
4549
c.JSON(http.StatusOK, res)
4650
}
4751

52+
// @todo: Validate Cids
4853
func oapiQueryToQuery(q openapi.Query) queue.Query {
4954
var (
55+
status []openapi.Status
5056
before, after string
5157
limit int
5258
meta map[string]string
5359
)
60+
if len(q.Status) != 0 {
61+
for _, p := range strings.Split(q.Status, ",") {
62+
var s openapi.Status
63+
switch p {
64+
case "queued":
65+
s = openapi.QUEUED
66+
case "pinning":
67+
s = openapi.PINNING
68+
case "pinned":
69+
s = openapi.PINNED
70+
case "failed":
71+
s = openapi.FAILED
72+
default:
73+
continue
74+
}
75+
status = append(status, s)
76+
}
77+
}
5478
if q.Before != nil {
5579
before = queue.NewIDFromTime(*q.Before)
5680
}
@@ -67,7 +91,7 @@ func oapiQueryToQuery(q openapi.Query) queue.Query {
6791
Cid: q.Cid,
6892
Name: q.Name,
6993
Match: q.Match,
70-
Status: q.Status,
94+
Status: status,
7195
Before: before,
7296
After: after,
7397
Limit: limit,
@@ -97,7 +121,9 @@ func (g *Gateway) addPin(c *gin.Context, key string) {
97121
return
98122
}
99123

100-
status, err := g.ps.AddPin(thread, key, pin, token)
124+
ctx, cancel := context.WithTimeout(context.Background(), handlerTimeout)
125+
defer cancel()
126+
status, err := g.ps.AddPin(ctx, thread, key, pin, token)
101127
if err != nil {
102128
newFailure(c, http.StatusBadRequest, err)
103129
return
@@ -122,7 +148,9 @@ func (g *Gateway) getPin(c *gin.Context, key, id string) {
122148
return
123149
}
124150

125-
status, err := g.ps.GetPin(thread, key, id, token)
151+
ctx, cancel := context.WithTimeout(context.Background(), handlerTimeout)
152+
defer cancel()
153+
status, err := g.ps.GetPin(ctx, thread, key, id, token)
126154
if errors.Is(pinning.ErrPinNotFound, err) {
127155
newFailure(c, http.StatusNotFound, err)
128156
return
@@ -156,7 +184,9 @@ func (g *Gateway) replacePin(c *gin.Context, key, id string) {
156184
return
157185
}
158186

159-
status, err := g.ps.ReplacePin(thread, key, id, pin, token)
187+
ctx, cancel := context.WithTimeout(context.Background(), handlerTimeout)
188+
defer cancel()
189+
status, err := g.ps.ReplacePin(ctx, thread, key, id, pin, token)
160190
if errors.Is(pinning.ErrPinNotFound, err) {
161191
newFailure(c, http.StatusNotFound, err)
162192
return
@@ -184,7 +214,9 @@ func (g *Gateway) removePin(c *gin.Context, key, id string) {
184214
return
185215
}
186216

187-
if err := g.ps.RemovePin(thread, key, id, token); errors.Is(pinning.ErrPinNotFound, err) {
217+
ctx, cancel := context.WithTimeout(context.Background(), handlerTimeout)
218+
defer cancel()
219+
if err := g.ps.RemovePin(ctx, thread, key, id, token); errors.Is(pinning.ErrPinNotFound, err) {
188220
newFailure(c, http.StatusNotFound, err)
189221
return
190222
} else if err != nil {

0 commit comments

Comments
 (0)