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
|
|
|
"crypto/ecdsa"
|
|
|
|
"crypto/elliptic"
|
|
|
|
"crypto/rand"
|
|
|
|
"testing"
|
|
|
|
|
2023-03-07 11:20:03 +00:00
|
|
|
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
|
2022-09-20 13:06:14 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
/*
|
|
|
|
File contains common functionality used for client package testing.
|
|
|
|
*/
|
|
|
|
|
|
|
|
var key, _ = ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
|
|
|
|
|
|
|
|
var statusErr apistatus.ServerInternal
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
statusErr.SetMessage("test status error")
|
|
|
|
}
|
|
|
|
|
|
|
|
func assertStatusErr(tb testing.TB, res interface{ Status() apistatus.Status }) {
|
|
|
|
require.IsType(tb, &statusErr, res.Status())
|
|
|
|
require.Equal(tb, statusErr.Message(), res.Status().(*apistatus.ServerInternal).Message())
|
|
|
|
}
|
|
|
|
|
2022-12-29 10:46:18 +00:00
|
|
|
func newClient(server frostFSAPIServer) *Client {
|
2022-09-20 13:06:14 +00:00
|
|
|
var prm PrmInit
|
|
|
|
prm.SetDefaultPrivateKey(*key)
|
|
|
|
|
|
|
|
var c Client
|
|
|
|
c.Init(prm)
|
2022-12-29 10:46:18 +00:00
|
|
|
c.setFrostFSAPIServer(server)
|
2022-09-20 13:06:14 +00:00
|
|
|
|
|
|
|
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) {
|
|
|
|
// expect particular context error according to Dial docs
|
2023-04-07 05:55:12 +00:00
|
|
|
require.ErrorIs(t, c.Dial(ctx, prm), errExpected)
|
2022-10-03 10:13:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
}
|