git.frostfs.info/TrueCloudLab/frostfs-sdk-go@v0.0.0-20241022124111-5361f0ecebd3/client/client_test.go (about) 1 package client 2 3 import ( 4 "context" 5 "crypto/ecdsa" 6 "crypto/elliptic" 7 "crypto/rand" 8 "testing" 9 10 apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" 11 "github.com/stretchr/testify/require" 12 ) 13 14 /* 15 File contains common functionality used for client package testing. 16 */ 17 18 var key, _ = ecdsa.GenerateKey(elliptic.P256(), rand.Reader) 19 20 var statusErr apistatus.ServerInternal 21 22 func init() { 23 statusErr.SetMessage("test status error") 24 } 25 26 func assertStatusErr(tb testing.TB, res interface{ Status() apistatus.Status }) { 27 require.IsType(tb, &statusErr, res.Status()) 28 require.Equal(tb, statusErr.Message(), res.Status().(*apistatus.ServerInternal).Message()) 29 } 30 31 func newClient(server frostFSAPIServer) *Client { 32 prm := PrmInit{ 33 Key: *key, 34 } 35 36 var c Client 37 c.Init(prm) 38 c.setFrostFSAPIServer(server) 39 40 return &c 41 } 42 43 func TestClient_DialContext(t *testing.T) { 44 var c Client 45 46 // try to connect to any host 47 prm := PrmDial{ 48 Endpoint: "localhost:8080", 49 } 50 51 assert := func(ctx context.Context, errExpected error) { 52 // expect particular context error according to Dial docs 53 require.ErrorIs(t, c.Dial(ctx, prm), errExpected) 54 } 55 56 // create pre-abandoned context 57 ctx, cancel := context.WithCancel(context.Background()) 58 cancel() 59 60 assert(ctx, context.Canceled) 61 62 // create "pre-deadlined" context 63 ctx, cancel = context.WithTimeout(context.Background(), 0) 64 defer cancel() 65 66 assert(ctx, context.DeadlineExceeded) 67 }