github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/driver_string_test.go (about) 1 package ydb 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/require" 7 8 "github.com/ydb-platform/ydb-go-sdk/v3/config" 9 "github.com/ydb-platform/ydb-go-sdk/v3/credentials" 10 "github.com/ydb-platform/ydb-go-sdk/v3/internal/xtest" 11 ) 12 13 func TestDriver_String(t *testing.T) { 14 for _, tt := range []struct { 15 name string 16 d *Driver 17 s string 18 }{ 19 { 20 name: xtest.CurrentFileLine(), 21 d: &Driver{config: config.New( 22 config.WithEndpoint("localhost"), 23 config.WithDatabase("local"), 24 config.WithSecure(false), 25 )}, 26 s: `Driver{Endpoint:"localhost",Database:"local",Secure:false,Credentials:Anonymous{From:"github.com/ydb-platform/ydb-go-sdk/v3/config.defaultConfig(defaults.go:90)"}}`, //nolint:lll 27 }, 28 { 29 name: xtest.CurrentFileLine(), 30 d: &Driver{config: config.New( 31 config.WithEndpoint("localhost"), 32 config.WithDatabase("local"), 33 config.WithSecure(true), 34 )}, 35 s: `Driver{Endpoint:"localhost",Database:"local",Secure:true,Credentials:Anonymous{From:"github.com/ydb-platform/ydb-go-sdk/v3/config.defaultConfig(defaults.go:90)"}}`, //nolint:lll 36 }, 37 { 38 name: xtest.CurrentFileLine(), 39 d: &Driver{config: config.New( 40 config.WithEndpoint("localhost"), 41 config.WithDatabase("local"), 42 config.WithSecure(false), 43 config.WithCredentials(credentials.NewAnonymousCredentials(credentials.WithSourceInfo(t.Name()))), 44 )}, 45 s: `Driver{Endpoint:"localhost",Database:"local",Secure:false,Credentials:Anonymous{From:"TestDriver_String"}}`, //nolint:lll 46 }, 47 { 48 name: xtest.CurrentFileLine(), 49 d: &Driver{config: config.New( 50 config.WithEndpoint("localhost"), 51 config.WithDatabase("local"), 52 config.WithSecure(true), 53 config.WithCredentials(credentials.NewStaticCredentials("user", "password", "")), 54 )}, 55 s: `Driver{Endpoint:"localhost",Database:"local",Secure:true,Credentials:Static{User:"user",Password:"pas***rd",Token:"****(CRC-32c: 00000000)",From:"github.com/ydb-platform/ydb-go-sdk/v3/credentials.NewStaticCredentials(credentials.go:35)"}}`, //nolint:lll 56 }, 57 { 58 name: xtest.CurrentFileLine(), 59 d: &Driver{config: config.New( 60 config.WithEndpoint("localhost"), 61 config.WithDatabase("local"), 62 config.WithSecure(true), 63 config.WithCredentials(credentials.NewAccessTokenCredentials("AUTH_TOKEN")), 64 )}, 65 s: `Driver{Endpoint:"localhost",Database:"local",Secure:true,Credentials:AccessToken{Token:"****(CRC-32c: 9F26E847)",From:"github.com/ydb-platform/ydb-go-sdk/v3/credentials.NewAccessTokenCredentials(credentials.go:20)"}}`, //nolint:lll 66 }, 67 } { 68 t.Run(tt.name, func(t *testing.T) { 69 require.Equal(t, tt.s, tt.d.String()) 70 }) 71 } 72 }