|
| 1 | +using System; |
1 | 2 | using System.Collections.Generic; |
| 3 | +using System.Net.Http; |
| 4 | +using System.Threading.Tasks; |
| 5 | +using Grpc.Core; |
| 6 | +using Grpc.Net.Client; |
| 7 | +using Xunit; |
2 | 8 |
|
3 | 9 | namespace Testcontainers.SpiceDB; |
4 | 10 |
|
@@ -30,44 +36,51 @@ public void ExpectedPortIsMapped() |
30 | 36 |
|
31 | 37 | [Fact] |
32 | 38 | [Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))] |
33 | | - public async Task ExecCommandReturnsSuccessful() |
| 39 | + public async Task VersionCommandReturnsSuccessful() |
34 | 40 | { |
35 | 41 | // Given |
36 | | - List<string> commands = ["spicedb-cli", "version"]; |
| 42 | + List<string> commands = ["spicedb", "version"]; |
37 | 43 |
|
38 | 44 | // When |
39 | 45 | var execResult = await _spicedbContainer.ExecAsync(commands, TestContext.Current.CancellationToken) |
40 | 46 | .ConfigureAwait(true); |
41 | 47 |
|
42 | 48 | // Then |
43 | 49 | Assert.True(0L.Equals(execResult.ExitCode), execResult.Stderr); |
44 | | - Assert.Contains("spicedb", execResult.Stdout); |
45 | 50 | } |
46 | 51 |
|
47 | 52 | [Fact] |
48 | 53 | [Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))] |
49 | | - public async Task PingCommandReturnsSuccessful() |
| 54 | + public void GetGrpcConnectionStringNotNull() |
50 | 55 | { |
51 | | - // Given |
52 | | - List<string> commands = ["spicedb-cli", "ping"]; |
53 | | - |
54 | | - // When |
55 | | - var execResult = await _spicedbContainer.ExecAsync(commands, TestContext.Current.CancellationToken) |
56 | | - .ConfigureAwait(true); |
| 56 | + // Given & When |
| 57 | + var connectionString = _spicedbContainer.GetGrpcConnectionString(); |
57 | 58 |
|
58 | 59 | // Then |
59 | | - Assert.True(0L.Equals(execResult.ExitCode), execResult.Stderr); |
| 60 | + Assert.NotNull(connectionString); |
60 | 61 | } |
61 | 62 |
|
62 | 63 | [Fact] |
63 | 64 | [Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))] |
64 | | - public void GetGrpcConnectionStringReturnsExpectedFormat() |
| 65 | + public async Task ShouldConnectToSpiceDB() |
65 | 66 | { |
66 | | - // Given & When |
| 67 | + // Given |
67 | 68 | var connectionString = _spicedbContainer.GetGrpcConnectionString(); |
| 69 | + var handler = new SocketsHttpHandler(); |
| 70 | + handler.SslOptions.RemoteCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true; |
| 71 | + |
| 72 | + // When |
| 73 | + using var channel = GrpcChannel.ForAddress(connectionString, new GrpcChannelOptions |
| 74 | + { |
| 75 | + HttpHandler = handler |
| 76 | + }); |
68 | 77 |
|
69 | 78 | // Then |
70 | | - // Note: This test will need to be updated once GetConnectionString() is properly implemented |
71 | 79 | Assert.NotNull(connectionString); |
| 80 | + Assert.NotNull(channel); |
| 81 | + |
| 82 | + // Test connectivity by attempting to connect |
| 83 | + await channel.ConnectAsync(); |
| 84 | + Assert.Equal(ConnectivityState.Ready, channel.State); |
72 | 85 | } |
73 | 86 | } |
0 commit comments