frostfs-sdk-go/client/client_test.go
Roman Khimov 2e18c3c16d client: replace client.Init() with New()
We'll need to check initialization parameters for consistency and Init doesn't
return any error, therefore it's easier to use smth.New() pattern and simplify
things a bit because uninited Client is not very useful anyway (we require
Init and there can be additional reasons for that in the future).

Refs. #164.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
2023-05-22 17:03:10 +03:00

59 lines
1.2 KiB
Go

package client
import (
"context"
"testing"
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
neofscrypto "github.com/nspcc-dev/neofs-sdk-go/crypto"
"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")
}
func newClient(t *testing.T, signer neofscrypto.Signer, server neoFSAPIServer) *Client {
var prm PrmInit
prm.SetDefaultSigner(signer)
c, err := New(prm)
require.NoError(t, err)
c.setNeoFSAPIServer(server)
return c
}
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)
}