|
| 1 | +namespace DotNet.Testcontainers.Configurations.Modules.Databases |
| 2 | +{ |
| 3 | + using System; |
| 4 | + using System.Collections.Generic; |
| 5 | + using DotNet.Testcontainers.Builders; |
| 6 | + using JetBrains.Annotations; |
| 7 | + |
| 8 | + public class AzuriteTestcontainerConfiguration : IDisposable |
| 9 | + { |
| 10 | + /// <summary> |
| 11 | + /// Default Azurite docker image. |
| 12 | + /// </summary> |
| 13 | + public const string DefaultAzuriteImage = "mcr.microsoft.com/azure-storage/azurite:3.18.0"; |
| 14 | + |
| 15 | + /// <summary> |
| 16 | + /// Default Blob service listening port. Default is 10000. |
| 17 | + /// </summary> |
| 18 | + public const int DefaultBlobPort = 10000; |
| 19 | + |
| 20 | + /// <summary> |
| 21 | + /// Default Queue service listening port. Default is 10001. |
| 22 | + /// </summary> |
| 23 | + public const int DefaultQueuePort = 10001; |
| 24 | + |
| 25 | + /// <summary> |
| 26 | + /// Default Table service listening port. Default 10002. |
| 27 | + /// </summary> |
| 28 | + public const int DefaultTablePort = 10002; |
| 29 | + |
| 30 | + /// <summary> |
| 31 | + /// Initializes a new instance of the <see cref="AzuriteTestcontainerConfiguration" /> class with default Azurite image. |
| 32 | + /// </summary> |
| 33 | + /// <param name="image">The Docker image.</param> |
| 34 | + public AzuriteTestcontainerConfiguration() |
| 35 | + : this(DefaultAzuriteImage) |
| 36 | + { |
| 37 | + } |
| 38 | + |
| 39 | + /// <summary> |
| 40 | + /// Initializes a new instance of the <see cref="AzuriteTestcontainerConfiguration" /> class. |
| 41 | + /// </summary> |
| 42 | + /// <param name="image">The Docker image.</param> |
| 43 | + protected AzuriteTestcontainerConfiguration(string image) |
| 44 | + { |
| 45 | + this.Image = image; |
| 46 | + this.Environments = new Dictionary<string, string>(); |
| 47 | + this.OutputConsumer = Consume.DoNotConsumeStdoutAndStderr(); |
| 48 | + } |
| 49 | + |
| 50 | + /// <summary> |
| 51 | + /// Gets the Docker image. |
| 52 | + /// </summary> |
| 53 | + [PublicAPI] |
| 54 | + public string Image { get; } |
| 55 | + |
| 56 | + /// <summary> |
| 57 | + /// Gets or sets the host Blob port. |
| 58 | + /// </summary> |
| 59 | + /// <remarks> |
| 60 | + /// Corresponds to the default port of the hosted service. |
| 61 | + /// </remarks> |
| 62 | + [PublicAPI] |
| 63 | + public int BlobPort { get; set; } |
| 64 | + |
| 65 | + /// <summary> |
| 66 | + /// Gets or sets the host Queue port. |
| 67 | + /// </summary> |
| 68 | + /// <remarks> |
| 69 | + /// Corresponds to the default port of the hosted service. |
| 70 | + /// </remarks> |
| 71 | + [PublicAPI] |
| 72 | + public int QueuePort { get; set; } |
| 73 | + |
| 74 | + /// <summary> |
| 75 | + /// Gets or sets the host Table port. |
| 76 | + /// </summary> |
| 77 | + /// <remarks> |
| 78 | + /// Corresponds to the default port of the hosted service. |
| 79 | + /// </remarks> |
| 80 | + [PublicAPI] |
| 81 | + public int TablePort { get; set; } |
| 82 | + |
| 83 | + /// <summary> |
| 84 | + /// Gets the environment configuration. |
| 85 | + /// </summary> |
| 86 | + [PublicAPI] |
| 87 | + public IDictionary<string, string> Environments { get; } |
| 88 | + |
| 89 | + /// <summary> |
| 90 | + /// Gets or sets the output consumer. |
| 91 | + /// </summary> |
| 92 | + /// <remarks> |
| 93 | + /// Uses <see cref="Consume.DoNotConsumeStdoutAndStderr" /> as default value. |
| 94 | + /// </remarks> |
| 95 | + [PublicAPI] |
| 96 | + [CanBeNull] |
| 97 | + public IOutputConsumer OutputConsumer { get; set; } |
| 98 | + |
| 99 | + /// <summary> |
| 100 | + /// Gets the wait strategy. |
| 101 | + /// </summary> |
| 102 | + /// <remarks> |
| 103 | + /// Uses <see cref="Wait.ForUnixContainer" /> and waits for Azurite ports. |
| 104 | + /// </remarks> |
| 105 | + [PublicAPI] |
| 106 | + public IWaitForContainerOS WaitStrategy => Wait.ForUnixContainer() |
| 107 | + .UntilPortIsAvailable(DefaultBlobPort) |
| 108 | + .UntilPortIsAvailable(DefaultQueuePort) |
| 109 | + .UntilPortIsAvailable(DefaultTablePort); |
| 110 | + |
| 111 | + /// <inheritdoc /> |
| 112 | + public void Dispose() |
| 113 | + { |
| 114 | + this.Dispose(true); |
| 115 | + GC.SuppressFinalize(this); |
| 116 | + } |
| 117 | + |
| 118 | + /// <summary> |
| 119 | + /// Releases all resources used by the <see cref="HostedServiceConfiguration" />. |
| 120 | + /// </summary> |
| 121 | + /// <param name="disposing">True if managed resources should be disposed, otherwise false..</param> |
| 122 | + [PublicAPI] |
| 123 | + protected virtual void Dispose(bool disposing) |
| 124 | + { |
| 125 | + if (disposing) |
| 126 | + { |
| 127 | + this.OutputConsumer?.Dispose(); |
| 128 | + } |
| 129 | + } |
| 130 | + } |
| 131 | +} |
0 commit comments