2022-09-20 13:06:14 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
2022-10-03 10:13:48 +00:00
|
|
|
"context"
|
2022-09-20 13:06:14 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
2023-04-25 08:31:27 +00:00
|
|
|
neofscrypto "github.com/nspcc-dev/neofs-sdk-go/crypto"
|
2022-09-20 13:06:14 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
/*
|
|
|
|
File contains common functionality used for client package testing.
|
|
|
|
*/
|
|
|
|
|
|
|
|
var statusErr apistatus.ServerInternal
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
statusErr.SetMessage("test status error")
|
|
|
|
}
|
|
|
|
|
2023-04-25 09:11:42 +00:00
|
|
|
func newClient(signer neofscrypto.Signer, server neoFSAPIServer) *Client {
|
2022-09-20 13:06:14 +00:00
|
|
|
var prm PrmInit
|
2023-04-25 08:31:27 +00:00
|
|
|
prm.SetDefaultSigner(signer)
|
2022-09-20 13:06:14 +00:00
|
|
|
|
|
|
|
var c Client
|
|
|
|
c.Init(prm)
|
|
|
|
c.setNeoFSAPIServer(server)
|
|
|
|
|
|
|
|
return &c
|
|
|
|
}
|
2022-10-03 10:13:48 +00:00
|
|
|
|
|
|
|
func TestClient_DialContext(t *testing.T) {
|
|
|
|
var c Client
|
|
|
|
|
|
|
|
// try to connect to any host
|
|
|
|
var prm PrmDial
|
|
|
|
prm.SetServerURI("localhost:8080")
|
|
|
|
|
|
|
|
assert := func(ctx context.Context, errExpected error) {
|
|
|
|
// use the particular context
|
|
|
|
prm.SetContext(ctx)
|
|
|
|
|
|
|
|
// expect particular context error according to Dial docs
|
|
|
|
require.ErrorIs(t, c.Dial(prm), errExpected)
|
|
|
|
}
|
|
|
|
|
|
|
|
// create pre-abandoned context
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
cancel()
|
|
|
|
|
|
|
|
assert(ctx, context.Canceled)
|
|
|
|
|
|
|
|
// create "pre-deadlined" context
|
|
|
|
ctx, cancel = context.WithTimeout(context.Background(), 0)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
assert(ctx, context.DeadlineExceeded)
|
|
|
|
}
|