pinsvcapi: fix several API test failures
This commit is contained in:
parent
cd5f9c869d
commit
fbc69ee3c6
|
@ -211,13 +211,13 @@ func TestNotFoundHandler(t *testing.T) {
|
||||||
var errResp api.Error
|
var errResp api.Error
|
||||||
test.MakePost(t, rest, url(rest)+"/"+string(bytes), []byte{}, &errResp)
|
test.MakePost(t, rest, url(rest)+"/"+string(bytes), []byte{}, &errResp)
|
||||||
if errResp.Code != 404 {
|
if errResp.Code != 404 {
|
||||||
t.Error("expected error not found")
|
t.Errorf("expected error not found: %+v", errResp)
|
||||||
}
|
}
|
||||||
|
|
||||||
var errResp1 api.Error
|
var errResp1 api.Error
|
||||||
test.MakeGet(t, rest, url(rest)+"/"+string(bytes), &errResp1)
|
test.MakeGet(t, rest, url(rest)+"/"+string(bytes), &errResp1)
|
||||||
if errResp1.Code != 404 {
|
if errResp1.Code != 404 {
|
||||||
t.Error("expected error not found")
|
t.Errorf("expected error not found: %+v", errResp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
logging "github.com/ipfs/go-log/v2"
|
logging "github.com/ipfs/go-log/v2"
|
||||||
|
types "github.com/ipfs/ipfs-cluster/api"
|
||||||
crypto "github.com/libp2p/go-libp2p-core/crypto"
|
crypto "github.com/libp2p/go-libp2p-core/crypto"
|
||||||
peer "github.com/libp2p/go-libp2p-core/peer"
|
peer "github.com/libp2p/go-libp2p-core/peer"
|
||||||
rpc "github.com/libp2p/go-libp2p-gorpc"
|
rpc "github.com/libp2p/go-libp2p-gorpc"
|
||||||
|
@ -108,7 +109,7 @@ func newTestConfig() *Config {
|
||||||
cfg.RequestLogger = logging.Logger("testapilog")
|
cfg.RequestLogger = logging.Logger("testapilog")
|
||||||
cfg.DefaultFunc = defaultFunc
|
cfg.DefaultFunc = defaultFunc
|
||||||
cfg.APIErrorFunc = func(err error, status int) error {
|
cfg.APIErrorFunc = func(err error, status int) error {
|
||||||
return err
|
return types.Error{Code: status, Message: err.Error()}
|
||||||
}
|
}
|
||||||
return cfg
|
return cfg
|
||||||
}
|
}
|
||||||
|
|
|
@ -544,7 +544,7 @@ func TestAPIAllocationEndpoint(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
errResp := api.Error{}
|
errResp := api.Error{}
|
||||||
test.MakeGet(t, rest, url(rest)+"/allocations/"+clustertest.ErrorCid.String(), &errResp)
|
test.MakeGet(t, rest, url(rest)+"/allocations/"+clustertest.Cid4.String(), &errResp)
|
||||||
if errResp.Code != 404 {
|
if errResp.Code != 404 {
|
||||||
t.Error("a non-pinned cid should 404")
|
t.Error("a non-pinned cid should 404")
|
||||||
}
|
}
|
||||||
|
|
|
@ -319,7 +319,7 @@ type PinInfo struct {
|
||||||
Cid cid.Cid `json:"cid" codec:"c"`
|
Cid cid.Cid `json:"cid" codec:"c"`
|
||||||
Name string `json:"name" codec:"m,omitempty"`
|
Name string `json:"name" codec:"m,omitempty"`
|
||||||
Peer peer.ID `json:"peer" codec:"p,omitempty"`
|
Peer peer.ID `json:"peer" codec:"p,omitempty"`
|
||||||
Allocations []peer.ID `json:"allocations" codec:"a,omitempty"`
|
Allocations []peer.ID `json:"allocations" codec:"o,omitempty"`
|
||||||
Origins []Multiaddr `json:"origins" codec:"g,omitempty"`
|
Origins []Multiaddr `json:"origins" codec:"g,omitempty"`
|
||||||
Metadata map[string]string `json:"metadata" codec:"md,omitempty"`
|
Metadata map[string]string `json:"metadata" codec:"md,omitempty"`
|
||||||
|
|
||||||
|
@ -1225,7 +1225,7 @@ type Error struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Error implements the error interface and returns the error's message.
|
// Error implements the error interface and returns the error's message.
|
||||||
func (e *Error) Error() string {
|
func (e Error) Error() string {
|
||||||
return fmt.Sprintf("%s (%d)", e.Message, e.Code)
|
return fmt.Sprintf("%s (%d)", e.Message, e.Code)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -156,7 +156,7 @@ func (mock *mockCluster) PinGet(ctx context.Context, in cid.Cid, out *api.Pin) e
|
||||||
p.ReplicationFactorMax = 1
|
p.ReplicationFactorMax = 1
|
||||||
*out = *p
|
*out = *p
|
||||||
default:
|
default:
|
||||||
return errors.New("not found")
|
return state.ErrNotFound
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user