Skip to content

Commit

Permalink
[Storage] [DataMovement] Added Download File Share Tests and Minor Fi…
Browse files Browse the repository at this point in the history
…xes (#39206)

* Added download tests for file shares

* Rerecorded tests

* Cleanup
  • Loading branch information
amnguye authored Oct 18, 2023
1 parent 8117e26 commit 3d85e4d
Show file tree
Hide file tree
Showing 8 changed files with 900 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "net",
"TagPrefix": "net/storage/Azure.Storage.DataMovement.Files.Shares",
"Tag": "net/storage/Azure.Storage.DataMovement.Files.Shares_b5e6d0b779"
"Tag": "net/storage/Azure.Storage.DataMovement.Files.Shares_29f88351cb"
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private static StorageResourceProperties ToStorageResourceProperties(
copyId: details.CopyId,
copyProgress: details.CopyProgress,
copySource: details.CopySource,
contentLength: details.ContentRange.Length,
contentLength: details.ContentRange?.Length ?? default,
contentType: default,
eTag: details.ETag,
contentHash: default,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public ShareFileStorageResource(
ShareFileStorageResourceOptions options = default)
{
ShareFileClient = fileClient;
_options = options;
_options = options ?? new ShareFileStorageResourceOptions();
}

/// <summary>
Expand Down Expand Up @@ -76,11 +76,11 @@ internal async Task CreateAsync(
}
await ShareFileClient.CreateAsync(
maxSize: maxSize,
httpHeaders: _options?.HttpHeaders,
metadata: _options?.FileMetadata,
smbProperties: _options?.SmbProperties,
filePermission: _options?.FilePermissions,
conditions: _options?.DestinationConditions,
httpHeaders: _options.HttpHeaders,
metadata: _options.FileMetadata,
smbProperties: _options.SmbProperties,
filePermission: _options.FilePermissions,
conditions: _options.DestinationConditions,
cancellationToken: cancellationToken).ConfigureAwait(false);
}

Expand Down Expand Up @@ -115,7 +115,7 @@ await ShareFileClient.UploadRangeFromUriAsync(
sourceUri: sourceResource.Uri,
range: range,
sourceRange: range,
options: _options?.ToShareFileUploadRangeFromUriOptions(),
options: _options.ToShareFileUploadRangeFromUriOptions(),
cancellationToken: cancellationToken).ConfigureAwait(false);
}

Expand Down Expand Up @@ -145,7 +145,7 @@ protected override async Task CopyFromStreamAsync(
await ShareFileClient.UploadRangeAsync(
new HttpRange(position, streamLength),
stream,
_options?.ToShareFileUploadRangeOptions(),
_options.ToShareFileUploadRangeOptions(),
cancellationToken).ConfigureAwait(false);
}

Expand All @@ -161,7 +161,7 @@ await ShareFileClient.UploadRangeFromUriAsync(
sourceUri: sourceResource.Uri,
range: new HttpRange(0, completeLength),
sourceRange: new HttpRange(0, completeLength),
options: _options?.ToShareFileUploadRangeFromUriOptions(),
options: _options.ToShareFileUploadRangeFromUriOptions(),
cancellationToken: cancellationToken).ConfigureAwait(false);
}

Expand All @@ -182,7 +182,7 @@ protected override async Task<StorageResourceProperties> GetPropertiesAsync(Canc
{
CancellationHelper.ThrowIfCancellationRequested(cancellationToken);
Response<ShareFileProperties> response = await ShareFileClient.GetPropertiesAsync(
conditions: _options?.SourceConditions,
conditions: _options.SourceConditions,
cancellationToken: cancellationToken).ConfigureAwait(false);
// TODO: should we be grabbing the ETag here even though we can't apply it to the download.
//GrabEtag(response.GetRawResponse());
Expand All @@ -196,7 +196,7 @@ protected override async Task<StorageResourceReadStreamResult> ReadStreamAsync(
{
CancellationHelper.ThrowIfCancellationRequested(cancellationToken);
Response<ShareFileDownloadInfo> response = await ShareFileClient.DownloadAsync(
_options?.ToShareFileDownloadOptions(new HttpRange(position, length)),
_options.ToShareFileDownloadOptions(new HttpRange(position, length)),
cancellationToken).ConfigureAwait(false);
return response.Value.ToStorageResourceReadStreamResult();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<Compile Include="$(AzureStorageDataMovementTestSharedSources)TestEventsRaised.cs" LinkBase="Shared\DataMovement" />
<Compile Include="$(AzureStorageDataMovementTestSharedSources)DisposingLocalDirectory.cs" LinkBase="Shared\DataMovement" />
<Compile Include="$(AzureStorageDataMovementTestSharedSources)StartTransferUploadTestBase.cs" LinkBase="Shared\DataMovement" />
<Compile Include="$(AzureStorageDataMovementTestSharedSources)StartTransferDownloadTestBase.cs" LinkBase="Shared\DataMovement" />
</ItemGroup>
<ItemGroup>
<Content Include="Resources\**">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Azure.Storage.DataMovement.Tests;
using Azure.Storage.Files.Shares;
using Azure.Storage.Files.Shares.Tests;
using Azure.Storage.Test.Shared;

namespace Azure.Storage.DataMovement.Files.Shares.Tests
{
[ShareClientTestFixture]
public class ShareFileStartTransferDownloadTests : StartTransferDownloadTestBase<
ShareServiceClient,
ShareClient,
ShareFileClient,
ShareClientOptions,
StorageTestEnvironment>
{
private const string _fileResourcePrefix = "test-file-";
private const string _expectedOverwriteExceptionMessage = "Cannot overwrite file.";

public ShareFileStartTransferDownloadTests(
bool async,
ShareClientOptions.ServiceVersion serviceVersion)
: base(async, _expectedOverwriteExceptionMessage, _fileResourcePrefix, null /* RecordedTestMode.Record /* to re-record */)
{
ClientBuilder = ClientBuilderExtensions.GetNewShareClientBuilder(Tenants, serviceVersion);
}

protected override async Task<IDisposingContainer<ShareClient>> GetDisposingContainerAsync(ShareServiceClient service = null, string containerName = null)
=> await ClientBuilder.GetTestShareAsync(service, containerName);

protected override async Task<ShareFileClient> GetObjectClientAsync(
ShareClient container,
long? objectLength,
string objectName,
bool createObject = false,
ShareClientOptions options = null,
Stream contents = null)
{
objectName ??= GetNewObjectName();
if (createObject)
{
if (!objectLength.HasValue)
{
throw new InvalidOperationException($"Cannot create share file without size specified.");
}
ShareFileClient fileClient = container.GetRootDirectoryClient().GetFileClient(objectName);
await fileClient.CreateAsync(objectLength.Value);

if (contents != default && contents.Length > 0)
{
await fileClient.UploadAsync(contents);
}

return fileClient;
}
return container.GetRootDirectoryClient().GetFileClient(objectName);
}

protected override StorageResourceItem GetStorageResourceItem(ShareFileClient objectClient)
=> new ShareFileStorageResource(objectClient);

protected override Task<Stream> OpenReadAsync(ShareFileClient objectClient)
=> objectClient.OpenReadAsync();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ protected override async Task<ShareFileClient> GetObjectClientAsync(
ShareClient container,
long? resourceLength = null,
bool createResource = false,
string resourceName = null,
string objectName = null,
ShareClientOptions options = null,
Stream contents = default)
{
resourceName ??= GetNewObjectName();
objectName ??= GetNewObjectName();
if (createResource)
{
if (!resourceLength.HasValue)
{
throw new InvalidOperationException($"Cannot create share file without size specified. Either set {nameof(createResource)} to false or specify a {nameof(resourceLength)}.");
}
ShareFileClient fileClient = container.GetRootDirectoryClient().GetFileClient(resourceName);
ShareFileClient fileClient = container.GetRootDirectoryClient().GetFileClient(objectName);
await fileClient.CreateAsync(resourceLength.Value);

if (contents != default)
Expand All @@ -59,11 +59,11 @@ protected override async Task<ShareFileClient> GetObjectClientAsync(

return fileClient;
}
return container.GetRootDirectoryClient().GetFileClient(resourceName);
return container.GetRootDirectoryClient().GetFileClient(objectName);
}

protected override StorageResourceItem GetStorageResourceItem(ShareFileClient resourceClient)
=> new ShareFileStorageResource(resourceClient);
protected override StorageResourceItem GetStorageResourceItem(ShareFileClient objectClient)
=> new ShareFileStorageResource(objectClient);

protected override Task<Stream> OpenReadAsync(ShareFileClient objectClient)
=> objectClient.OpenReadAsync();
Expand Down
Loading

0 comments on commit 3d85e4d

Please sign in to comment.