forked from TrueCloudLab/frostfs-sdk-go
client: Add tests for contextCall.err in session creation
Signed-off-by: Evgenii Baidakov <evgenii@nspcc.io>
This commit is contained in:
parent
0c7bfc2afe
commit
162a15ae4b
1 changed files with 74 additions and 0 deletions
74
client/session_test.go
Normal file
74
client/session_test.go
Normal file
|
@ -0,0 +1,74 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
v2netmap "github.com/nspcc-dev/neofs-api-go/v2/netmap"
|
||||
"github.com/nspcc-dev/neofs-api-go/v2/rpc/client"
|
||||
"github.com/nspcc-dev/neofs-api-go/v2/session"
|
||||
neofscrypto "github.com/nspcc-dev/neofs-sdk-go/crypto"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/crypto/test"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
type sessionAPIServer struct {
|
||||
signer neofscrypto.Signer
|
||||
setBody func(body *session.CreateResponseBody)
|
||||
}
|
||||
|
||||
func (m sessionAPIServer) netMapSnapshot(context.Context, v2netmap.SnapshotRequest) (*v2netmap.SnapshotResponse, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (m sessionAPIServer) createSession(*client.Client, *session.CreateRequest, ...client.CallOption) (*session.CreateResponse, error) {
|
||||
var body session.CreateResponseBody
|
||||
m.setBody(&body)
|
||||
|
||||
var resp session.CreateResponse
|
||||
resp.SetBody(&body)
|
||||
|
||||
if err := signServiceMessage(m.signer, &resp); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
func TestClient_SessionCreate(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
signer := test.RandomSignerRFC6979(t)
|
||||
|
||||
var prmInit PrmInit
|
||||
prmInit.SetDefaultSigner(signer)
|
||||
prmInit.ResolveNeoFSFailures()
|
||||
|
||||
var c Client
|
||||
c.Init(prmInit)
|
||||
|
||||
var prmSessionCreate PrmSessionCreate
|
||||
prmSessionCreate.UseSigner(signer)
|
||||
prmSessionCreate.SetExp(1)
|
||||
|
||||
t.Run("missing session id", func(t *testing.T) {
|
||||
c.setNeoFSAPIServer(&sessionAPIServer{signer: signer, setBody: func(body *session.CreateResponseBody) {
|
||||
body.SetSessionKey([]byte{1})
|
||||
}})
|
||||
|
||||
result, err := c.SessionCreate(ctx, prmSessionCreate)
|
||||
require.Nil(t, result)
|
||||
require.ErrorIs(t, err, errMissingResponseField)
|
||||
require.Equal(t, "missing session id field in the response", err.Error())
|
||||
})
|
||||
|
||||
t.Run("missing session key", func(t *testing.T) {
|
||||
c.setNeoFSAPIServer(&sessionAPIServer{signer: signer, setBody: func(body *session.CreateResponseBody) {
|
||||
body.SetID([]byte{1})
|
||||
}})
|
||||
|
||||
result, err := c.SessionCreate(ctx, prmSessionCreate)
|
||||
require.Nil(t, result)
|
||||
require.ErrorIs(t, err, errMissingResponseField)
|
||||
require.Equal(t, "missing session key field in the response", err.Error())
|
||||
})
|
||||
}
|
Loading…
Reference in a new issue