@@ -7,31 +7,25 @@ import (
77 "context"
88 "crypto/tls"
99 "fmt"
10- "net/url"
1110 "os"
1211 "testing"
1312 "time"
1413
1514 "github.com/ydb-platform/ydb-go-genproto/Ydb_Discovery_V1"
1615 "github.com/ydb-platform/ydb-go-genproto/Ydb_Export_V1"
17- "github.com/ydb-platform/ydb-go-genproto/Ydb_Monitoring_V1"
1816 "github.com/ydb-platform/ydb-go-genproto/Ydb_Scripting_V1"
1917 "github.com/ydb-platform/ydb-go-genproto/protos/Ydb"
2018 "github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Discovery"
2119 "github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Export"
22- "github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Monitoring"
2320 "github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Operations"
2421 "github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Scripting"
2522 "google.golang.org/grpc"
26- grpcCredentials "google.golang.org/grpc/credentials"
27- "google.golang.org/grpc/credentials/insecure"
2823 "google.golang.org/grpc/metadata"
2924 "google.golang.org/protobuf/proto"
3025 "google.golang.org/protobuf/types/known/durationpb"
3126
3227 "github.com/ydb-platform/ydb-go-sdk/v3"
3328 "github.com/ydb-platform/ydb-go-sdk/v3/config"
34- "github.com/ydb-platform/ydb-go-sdk/v3/credentials"
3529 "github.com/ydb-platform/ydb-go-sdk/v3/internal/meta"
3630 "github.com/ydb-platform/ydb-go-sdk/v3/log"
3731 "github.com/ydb-platform/ydb-go-sdk/v3/retry"
@@ -320,107 +314,3 @@ func TestConnection(t *testing.T) {
320314 }
321315 })
322316}
323-
324- func TestStaticCredentials (t * testing.T ) {
325- t .Skip ("wait for newest cr.yandex/yc/yandex-docker-local-ydb:latest was published" )
326-
327- ctx , cancel := context .WithTimeout (context .Background (), time .Second * 10 )
328- defer cancel ()
329-
330- var dsn string
331- if v , has := os .LookupEnv ("YDB_CONNECTION_STRING" ); ! has {
332- t .Fatal ("env YDB_CONNECTION_STRING required" )
333- } else {
334- dsn = v
335- }
336-
337- url , err := url .Parse (dsn )
338- if err != nil {
339- t .Fatal (err )
340- }
341-
342- staticCredentials := credentials .NewStaticCredentials ("root" , "" , url .Host , func () grpc.DialOption {
343- if url .Scheme == "grpcs" {
344- transportCredentials , transportCredentialsErr := grpcCredentials .NewClientTLSFromFile (
345- os .Getenv ("YDB_SSL_ROOT_CERTIFICATES_FILE" ), url .Hostname (),
346- )
347- if err != nil {
348- t .Fatalf ("cannot create transport credentials: %v" , transportCredentialsErr )
349- }
350- return grpc .WithTransportCredentials (transportCredentials )
351- }
352- return grpc .WithTransportCredentials (insecure .NewCredentials ())
353- }())
354-
355- token , err := staticCredentials .Token (ctx )
356- if err != nil {
357- t .Fatalf ("get token failed: %v" , err )
358- } else {
359- fmt .Printf ("token: %s\n " , token )
360- }
361-
362- db , err := ydb .Open (
363- ctx ,
364- "" , // corner case for check replacement of endpoint+database+secure
365- ydb .WithConnectionString (os .Getenv ("YDB_CONNECTION_STRING" )),
366- ydb .WithCredentials (staticCredentials ),
367- )
368- if err != nil {
369- t .Fatal (err )
370- }
371- defer func () {
372- // cleanup connection
373- if e := db .Close (ctx ); e != nil {
374- t .Fatalf ("close failed: %+v" , e )
375- }
376- }()
377- _ , err = db .Discovery ().WhoAmI (ctx )
378- if err != nil {
379- t .Fatal (err )
380- }
381- }
382-
383- func TestMonitoring (t * testing.T ) {
384- t .Skip ("wait for newest cr.yandex/yc/yandex-docker-local-ydb:latest was published" )
385-
386- ctx , cancel := context .WithTimeout (context .Background (), time .Second * 10 )
387- defer cancel ()
388-
389- db , err := ydb .Open (
390- ctx ,
391- "" , // corner case for check replacement of endpoint+database+secure
392- ydb .WithConnectionString (os .Getenv ("YDB_CONNECTION_STRING" )),
393- )
394- if err != nil {
395- t .Fatal (err )
396- }
397- defer func () {
398- // cleanup connection
399- if e := db .Close (ctx ); e != nil {
400- t .Fatalf ("close failed: %+v" , e )
401- }
402- }()
403- t .Run ("monitoring.SelfCheck" , func (t * testing.T ) {
404- if err = retry .Retry (ctx , func (ctx context.Context ) (err error ) {
405- client := Ydb_Monitoring_V1 .NewMonitoringServiceClient (ydb .GRPCConn (db ))
406- response , err := client .SelfCheck (ctx , & Ydb_Monitoring.SelfCheckRequest {
407- OperationParams : nil ,
408- ReturnVerboseStatus : false ,
409- MinimumStatus : 0 ,
410- MaximumLevel : 0 ,
411- })
412- if err != nil {
413- return err
414- }
415- var result Ydb_Monitoring.SelfCheckResult
416- err = response .Operation .Result .UnmarshalTo (& result )
417- if err != nil {
418- return err
419- }
420- fmt .Printf ("%+v\n " , & result )
421- return nil
422- }, retry .WithIdempotent (true )); err != nil {
423- t .Fatalf ("Execute failed: %v" , err )
424- }
425- })
426- }
0 commit comments