Skip to content

Commit

Permalink
Revert "Fix: Blob OpenWrite methods do not set metadata"
Browse files Browse the repository at this point in the history
This reverts commit fa4277b.
  • Loading branch information
tomas-pajurek committed Aug 16, 2024
1 parent fa4277b commit 8d3b27d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public async Task<Stream> OpenWriteAsync(bool overwrite, BlobOpenWriteOptions? o

using var blob = AcquireBlob(cancellationToken);

if (!blob.Value.TryOpenWrite(options?.OpenConditions, options?.BufferSize, options?.Metadata, out var stream, out var error))
if (!blob.Value.TryOpenWrite(options?.OpenConditions, options?.BufferSize, out var stream, out var error))
{
throw error.GetClientException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public bool TryGetBlockList(
return true;
}

public bool TryOpenWrite(RequestConditions? conditions, long? bufferSize, IDictionary<string, string>? metadata, [NotNullWhen(true)] out Stream? stream, [NotNullWhen(false)] out OpenWriteError? error)
public bool TryOpenWrite(RequestConditions? conditions, long? bufferSize, [NotNullWhen(true)] out Stream? stream, [NotNullWhen(false)] out OpenWriteError? error)
{
if (!ConditionChecker.CheckConditions(_properties?.ETag, conditions?.IfMatch, conditions?.IfNoneMatch, out var conditionError))
{
Expand All @@ -263,7 +263,7 @@ public bool TryOpenWrite(RequestConditions? conditions, long? bufferSize, IDicti
return false;
}

SetCommitedState(null, metadata, []);
SetCommitedState(null, null, []);

var client = InMemoryBlockBlobClient.FromAccount(Container.Service.Account, ContainerName, Name);

Expand Down
64 changes: 6 additions & 58 deletions tests/Tests/Storage/Blobs/BlobClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,31 +143,6 @@ public void OpenWrite_And_Dispose_Should_Create_Blob(BlobClientType clientType)
}


[TestMethod]
[TestCategory(TestCategory.AzureInfra)]
[DataRow(BlobClientType.Generic)]
[DataRow(BlobClientType.Block)]
public void OpenWrite_Should_Set_Blob_Metadata(BlobClientType clientType)
{
var containerClient = ImplementationProvider.GetBlobContainerClient();

containerClient.CreateIfNotExists();

var blobName = Guid.NewGuid().ToString();

var blobClient = containerClient.GetBlobBaseClient(blobName, clientType);

blobClient.Exists().Value.Should().BeFalse();

var metadata = new Dictionary<string, string> { { "test-key", "test-value" } };

using var stream = OpenWrite(blobClient, true, metadata);

stream.Dispose();

blobClient.GetProperties().Value.Metadata.Should().Contain("test-key", "test-value");
}

[TestMethod]
[TestCategory(TestCategory.AzureInfra)]
[DataRow(BlobClientType.Generic)]
Expand All @@ -190,7 +165,6 @@ public void OpenWrite_Without_Overwrite_Option_Should_Be_Unsupported(BlobClientT

}


[TestMethod]
[TestCategory(TestCategory.AzureInfra)]
[DataRow(BlobClientType.Generic)]
Expand Down Expand Up @@ -444,40 +418,14 @@ private static void Upload(BlobBaseClient blobClient, byte[] content, BlobUpload
}
}

private static Stream OpenWrite(BlobBaseClient blobClient, bool overwrite, IDictionary<string, string>? metadata = null)
private static Stream OpenWrite(BlobBaseClient blobClient, bool overwrite)
{
if (blobClient is BlobClient genericClient)
{
BlobOpenWriteOptions? options = null;

if (metadata is not null)
{
options = new()
{
Metadata = metadata
};
}

return genericClient.OpenWrite(overwrite, options);
}

if (blobClient is BlockBlobClient blockClient)
return blobClient switch
{
BlockBlobOpenWriteOptions? options = null;

if (metadata is not null)
{
options = new()
{
Metadata = metadata
};
}

return blockClient.OpenWrite(overwrite, options);
}

throw new InvalidOperationException("Unexpected client type.");

BlobClient genericClient => genericClient.OpenWrite(overwrite),
BlockBlobClient blockClient => blockClient.OpenWrite(overwrite),
_ => throw new InvalidOperationException()
};
}


Expand Down

0 comments on commit 8d3b27d

Please sign in to comment.