diff --git a/src/core/tests/Deal.Tests.Unit/Support/TelegramIngressTestHost.cs b/src/core/tests/Deal.Tests.Unit/Support/TelegramIngressTestHost.cs index 6548585..84075ae 100644 --- a/src/core/tests/Deal.Tests.Unit/Support/TelegramIngressTestHost.cs +++ b/src/core/tests/Deal.Tests.Unit/Support/TelegramIngressTestHost.cs @@ -18,6 +18,7 @@ using Grpc.Net.Client; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Diagnostics.HealthChecks; @@ -57,15 +58,17 @@ internal static class TelegramIngressTestHost Func scenario, RateLimitOptions? rateLimitOptions = null) { - string? originalToken = Environment.GetEnvironmentVariable(ServiceTokenEnvKey); - Environment.SetEnvironmentVariable(ServiceTokenEnvKey, serviceToken); - WebApplication? app = null; GrpcChannel? channel = null; try { int port = TestPort.Allocate(); WebApplicationBuilder builder = WebApplication.CreateBuilder(); + // Токен ингресса задаётся конфигурацией хоста (в приоритете над env) — без мутации процесса. + builder.Configuration.AddInMemoryCollection(new Dictionary + { + [ServiceTokenEnvKey] = serviceToken, + }); builder.WebHost.ConfigureKestrel(kestrel => kestrel.Listen(IPAddress.Loopback, port, listen => listen.Protocols = HttpProtocols.Http2)); @@ -131,8 +134,6 @@ internal static class TelegramIngressTestHost await app.StopAsync(); await app.DisposeAsync(); } - - Environment.SetEnvironmentVariable(ServiceTokenEnvKey, originalToken); } }