Skip to content

Commit

Permalink
fix: InvalidOperationException when adding future volume (#817)
Browse files Browse the repository at this point in the history
  • Loading branch information
HofmeisterAn authored Mar 3, 2023
1 parent 9a5531f commit 87b7505
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Testcontainers/Configurations/Volumes/VolumeMount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ namespace DotNet.Testcontainers.Configurations
/// <inheritdoc cref="IMount" />
internal readonly struct VolumeMount : IMount
{
// Do not set the volume name immediately in the constructor. This may raise an InvalidOperationException too early.
// Depending on when the developer passes the instance to VolumeMount it may not exist yet.
private readonly IVolume volume;

/// <summary>
/// Initializes a new instance of the <see cref="VolumeMount" /> struct.
/// </summary>
Expand All @@ -13,8 +17,8 @@ namespace DotNet.Testcontainers.Configurations
/// <param name="accessMode">The Docker volume access mode.</param>
public VolumeMount(IVolume volume, string containerPath, AccessMode accessMode)
{
this.volume = volume;
this.Type = MountType.Volume;
this.Source = volume.Name;
this.Target = containerPath;
this.AccessMode = accessMode;
}
Expand All @@ -26,7 +30,7 @@ public VolumeMount(IVolume volume, string containerPath, AccessMode accessMode)
public AccessMode AccessMode { get; }

/// <inheritdoc />
public string Source { get; }
public string Source => this.volume.Name;

/// <inheritdoc />
public string Target { get; }
Expand Down

0 comments on commit 87b7505

Please sign in to comment.