pinsvcapi: fix several API test failures

This commit is contained in:
Hector Sanjuan 2022-03-11 16:18:08 +01:00
parent cd5f9c869d
commit fbc69ee3c6
5 changed files with 8 additions and 7 deletions

View File

@ -211,13 +211,13 @@ func TestNotFoundHandler(t *testing.T) {
var errResp api.Error
test.MakePost(t, rest, url(rest)+"/"+string(bytes), []byte{}, &errResp)
if errResp.Code != 404 {
t.Error("expected error not found")
t.Errorf("expected error not found: %+v", errResp)
}
var errResp1 api.Error
test.MakeGet(t, rest, url(rest)+"/"+string(bytes), &errResp1)
if errResp1.Code != 404 {
t.Error("expected error not found")
t.Errorf("expected error not found: %+v", errResp)
}
}

View File

@ -8,6 +8,7 @@ import (
"time"
logging "github.com/ipfs/go-log/v2"
types "github.com/ipfs/ipfs-cluster/api"
crypto "github.com/libp2p/go-libp2p-core/crypto"
peer "github.com/libp2p/go-libp2p-core/peer"
rpc "github.com/libp2p/go-libp2p-gorpc"
@ -108,7 +109,7 @@ func newTestConfig() *Config {
cfg.RequestLogger = logging.Logger("testapilog")
cfg.DefaultFunc = defaultFunc
cfg.APIErrorFunc = func(err error, status int) error {
return err
return types.Error{Code: status, Message: err.Error()}
}
return cfg
}

View File

@ -544,7 +544,7 @@ func TestAPIAllocationEndpoint(t *testing.T) {
}
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 {
t.Error("a non-pinned cid should 404")
}

View File

@ -319,7 +319,7 @@ type PinInfo struct {
Cid cid.Cid `json:"cid" codec:"c"`
Name string `json:"name" codec:"m,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"`
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.
func (e *Error) Error() string {
func (e Error) Error() string {
return fmt.Sprintf("%s (%d)", e.Message, e.Code)
}

View File

@ -156,7 +156,7 @@ func (mock *mockCluster) PinGet(ctx context.Context, in cid.Cid, out *api.Pin) e
p.ReplicationFactorMax = 1
*out = *p
default:
return errors.New("not found")
return state.ErrNotFound
}
return nil
}