Skip to content

Commit abf81b5

Browse files
fix linter + added tests
1 parent 06b0e42 commit abf81b5

File tree

2 files changed

+37
-21
lines changed

2 files changed

+37
-21
lines changed

src/Ydb.Sdk/src/IDriver.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ public interface IBidirectionalStream<in TRequest, out TResponse> : IDisposable
4848
public abstract class BaseDriver : IDriver
4949
{
5050
private readonly ICredentialsProvider? _credentialsProvider;
51-
51+
5252
protected readonly DriverConfig Config;
5353
protected readonly ILogger Logger;
54-
54+
5555
internal readonly GrpcChannelFactory GrpcChannelFactory;
5656
internal readonly ChannelPool<GrpcChannel> ChannelPool;
5757

@@ -66,10 +66,10 @@ ILogger logger
6666
Config = config;
6767
Logger = logger;
6868
LoggerFactory = loggerFactory;
69-
69+
7070
GrpcChannelFactory = new GrpcChannelFactory(LoggerFactory, Config);
7171
ChannelPool = new ChannelPool<GrpcChannel>(LoggerFactory, GrpcChannelFactory);
72-
72+
7373
_credentialsProvider = Config.User != null
7474
? new CachedCredentialsProvider(
7575
new StaticCredentialsAuthClient(Config, GrpcChannelFactory, LoggerFactory),

src/Ydb.Sdk/tests/Ado/YdbAdoUserPasswordTests.cs

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,20 @@ namespace Ydb.Sdk.Tests.Ado;
77

88
public class YdbAdoUserPasswordTests : YdbAdoNetFixture
99
{
10+
private readonly string _user = "kurdyukovkirya" + Random.Shared.Next();
11+
1012
public YdbAdoUserPasswordTests(YdbFactoryFixture fixture) : base(fixture)
1113
{
1214
}
1315

1416
[Fact]
1517
public async Task Authentication_WhenUserAndPassword_ReturnValidConnection()
1618
{
17-
await using var connection = await CreateOpenConnectionAsync();
18-
var ydbCommand = connection.CreateCommand();
19-
var kurdyukovkirya = "kurdyukovkirya" + Random.Shared.Next();
20-
ydbCommand.CommandText = $"CREATE USER {kurdyukovkirya} PASSWORD 'password'";
21-
await ydbCommand.ExecuteNonQueryAsync();
22-
await connection.CloseAsync();
23-
24-
await using var userPasswordConnection =
25-
new YdbConnection($"{ConnectionString};User={kurdyukovkirya};Password=password;");
19+
await using var userPasswordConnection = new YdbConnection(
20+
$"{ConnectionString};User={_user};Password=password;");
2621
await userPasswordConnection.OpenAsync();
27-
ydbCommand = userPasswordConnection.CreateCommand();
28-
ydbCommand.CommandText = "SELECT 1 + 2";
29-
Assert.Equal(3, await ydbCommand.ExecuteScalarAsync());
30-
31-
await using var newConnection = await CreateOpenConnectionAsync();
32-
ydbCommand = newConnection.CreateCommand();
33-
ydbCommand.CommandText = $"DROP USER {kurdyukovkirya};";
34-
await ydbCommand.ExecuteNonQueryAsync();
22+
Assert.Equal(3, await new YdbCommand(userPasswordConnection)
23+
{ CommandText = "SELECT 1 + 2" }.ExecuteScalarAsync());
3524
}
3625

3726
[Fact]
@@ -45,4 +34,31 @@ public async Task ExecuteNonQueryAsync_WhenCreateUser_ReturnEmptyResultSet()
4534
dbCommand.CommandText = $"DROP USER {user};";
4635
await dbCommand.ExecuteNonQueryAsync();
4736
}
37+
38+
[Fact]
39+
public async Task DisableDiscovery_WhenUserIsCreatedAndPropertyIsTrue_SimpleWorking()
40+
{
41+
await using var userPasswordConnection = new YdbConnection(
42+
$"{ConnectionString};User={_user};Password=password;DisableDiscovery=true");
43+
await userPasswordConnection.OpenAsync();
44+
var ydbCommand = userPasswordConnection.CreateCommand();
45+
ydbCommand.CommandText = "SELECT 1 + 2";
46+
Assert.Equal(3, await ydbCommand.ExecuteScalarAsync());
47+
}
48+
49+
protected override async Task OnInitializeAsync()
50+
{
51+
await using var connection = await CreateOpenConnectionAsync();
52+
var ydbCommand = connection.CreateCommand();
53+
ydbCommand.CommandText = $"CREATE USER {_user} PASSWORD 'password'";
54+
await ydbCommand.ExecuteNonQueryAsync();
55+
}
56+
57+
protected override async Task OnDisposeAsync()
58+
{
59+
await using var ydbConnection = await CreateOpenConnectionAsync();
60+
var ydbCommand = ydbConnection.CreateCommand();
61+
ydbCommand.CommandText = $"DROP USER {_user};";
62+
await ydbCommand.ExecuteNonQueryAsync();
63+
}
4864
}

0 commit comments

Comments
 (0)