|
| 1 | +// |
| 2 | +// Copyright The Microcks Authors. |
| 3 | +// |
| 4 | +// Licensed under the Apache License, Version 2.0 (the "License") |
| 5 | +// you may not use this file except in compliance with the License. |
| 6 | +// You may obtain a copy of the License at |
| 7 | +// |
| 8 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +// |
| 10 | +// Unless required by applicable law or agreed to in writing, software |
| 11 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +// See the License for the specific language governing permissions and |
| 14 | +// limitations under the License. |
| 15 | +// |
| 16 | +// |
| 17 | + |
| 18 | +using Microcks.Testcontainers.Helpers; |
| 19 | + |
| 20 | +namespace Microcks.Testcontainers.Tests.DebugLogLevel; |
| 21 | + |
| 22 | +/// <summary> |
| 23 | +/// Tests for the WithDebugLogLevel feature on MicrocksContainerEnsemble. |
| 24 | +/// Verifies that debug logging environment variables are correctly set or not set |
| 25 | +/// on both Microcks (Spring) and Async Minion (Quarkus) containers. |
| 26 | +/// </summary> |
| 27 | +[Collection("DisableParallelization")] |
| 28 | +public sealed class MicrocksDebugLogLevelTests |
| 29 | +{ |
| 30 | + /// <summary> |
| 31 | + /// Verifies that when WithDebugLogLevel() is called, the appropriate debug |
| 32 | + /// environment variables are set on both Microcks and Async Minion containers. |
| 33 | + /// - Microcks (Spring): LOGGING_LEVEL_IO_GITHUB_MICROCKS=DEBUG |
| 34 | + /// - Async Minion (Quarkus): QUARKUS_LOG_CONSOLE_LEVEL=DEBUG and |
| 35 | + /// QUARKUS_LOG_CATEGORY__IO_GITHUB_MICROCKS__LEVEL=DEBUG |
| 36 | + /// </summary> |
| 37 | + [Fact] |
| 38 | + public async Task WithDebugLogLevel_ShouldSetEnvironmentVariables() |
| 39 | + { |
| 40 | + // Arrange - Create ensemble WITH WithDebugLogLevel() |
| 41 | + await using var ensemble = new MicrocksContainerEnsemble(MicrocksBuilder.MicrocksImage) |
| 42 | + .WithDebugLogLevel() |
| 43 | + .WithAsyncFeature(); |
| 44 | + |
| 45 | + await ensemble.StartAsync(TestContext.Current.CancellationToken); |
| 46 | + |
| 47 | + // Assert - Use Docker Inspect API to verify environment variables |
| 48 | + using var dockerClient = new Docker.DotNet.DockerClientConfiguration().CreateClient(); |
| 49 | + |
| 50 | + // Verify Microcks container has the debug environment variable |
| 51 | + var microcksInspect = await dockerClient.Containers.InspectContainerAsync( |
| 52 | + ensemble.MicrocksContainer.Id, |
| 53 | + TestContext.Current.CancellationToken); |
| 54 | + |
| 55 | + var expectedMicrocksEnvVar = $"{ConfigurationConstants.MicrocksLoggingLevelEnvVar}={ConfigurationConstants.DebugLogLevelEnvVar}"; |
| 56 | + Assert.Contains(expectedMicrocksEnvVar, microcksInspect.Config.Env); |
| 57 | + |
| 58 | + // Verify Async Minion container has the Quarkus debug environment variables |
| 59 | + var minionInspect = await dockerClient.Containers.InspectContainerAsync( |
| 60 | + ensemble.AsyncMinionContainer.Id, |
| 61 | + TestContext.Current.CancellationToken); |
| 62 | + |
| 63 | + var expectedConsoleLogLevel = $"{ConfigurationConstants.QuarkusConsoleLogLevelEnvVar}={ConfigurationConstants.DebugLogLevelEnvVar}"; |
| 64 | + var expectedMicrocksLogLevel = $"{ConfigurationConstants.QuarkusMicrocksCategoryLogLevelEnvVar}={ConfigurationConstants.DebugLogLevelEnvVar}"; |
| 65 | + |
| 66 | + Assert.Contains(expectedConsoleLogLevel, minionInspect.Config.Env); |
| 67 | + Assert.Contains(expectedMicrocksLogLevel, minionInspect.Config.Env); |
| 68 | + } |
| 69 | + |
| 70 | + /// <summary> |
| 71 | + /// Verifies that when WithDebugLogLevel() is NOT called, the debug environment |
| 72 | + /// variables are not present on the containers. This ensures the default behavior |
| 73 | + /// does not enable debug logging. |
| 74 | + /// </summary> |
| 75 | + [Fact] |
| 76 | + public async Task WithoutDebugLogLevel_ShouldNotSetEnvironmentVariables() |
| 77 | + { |
| 78 | + // Arrange - Create ensemble WITHOUT WithDebugLogLevel() |
| 79 | + await using var ensemble = new MicrocksContainerEnsemble(MicrocksBuilder.MicrocksImage) |
| 80 | + .WithAsyncFeature(); |
| 81 | + |
| 82 | + await ensemble.StartAsync(TestContext.Current.CancellationToken); |
| 83 | + |
| 84 | + // Assert - Use Docker Inspect API to verify environment variables are NOT set |
| 85 | + using var dockerClient = new Docker.DotNet.DockerClientConfiguration().CreateClient(); |
| 86 | + |
| 87 | + // Verify Microcks container does NOT have the debug environment variable |
| 88 | + var microcksInspect = await dockerClient.Containers.InspectContainerAsync( |
| 89 | + ensemble.MicrocksContainer.Id, |
| 90 | + TestContext.Current.CancellationToken); |
| 91 | + |
| 92 | + Assert.DoesNotContain(microcksInspect.Config.Env, |
| 93 | + env => env.StartsWith($"{ConfigurationConstants.MicrocksLoggingLevelEnvVar}=")); |
| 94 | + |
| 95 | + // Verify Async Minion container does NOT have the Quarkus debug environment variables |
| 96 | + var minionInspect = await dockerClient.Containers.InspectContainerAsync( |
| 97 | + ensemble.AsyncMinionContainer.Id, |
| 98 | + TestContext.Current.CancellationToken); |
| 99 | + |
| 100 | + Assert.DoesNotContain(minionInspect.Config.Env, |
| 101 | + env => env.StartsWith($"{ConfigurationConstants.QuarkusConsoleLogLevelEnvVar}=")); |
| 102 | + Assert.DoesNotContain(minionInspect.Config.Env, |
| 103 | + env => env.StartsWith($"{ConfigurationConstants.QuarkusMicrocksCategoryLogLevelEnvVar}=")); |
| 104 | + } |
| 105 | +} |
0 commit comments