-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Datamovement tests ShareUploadDirectory (#39718)
* initial testbase implementation * hook up shares to testbase, some failures * fixes * fix a test * get root vs nonroot tests working together * fix build * cleanup * testproxy * rerecord * rerecord * rerecord (exceeding file path limits) * change path generation, hopefully fix linux tests * recorded test attr * disable bad test * use system path separator * bugfix
- Loading branch information
1 parent
bb20017
commit 19c5fd2
Showing
8 changed files
with
638 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
...e/Azure.Storage.DataMovement.Files.Shares/tests/ShareDirectoryStartTransferUploadTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading; | ||
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(true)] | ||
[ShareClientTestFixture(false)] | ||
internal class ShareDirectoryStartTransferUploadTests : StartTransferUploadDirectoryTestBase< | ||
ShareServiceClient, | ||
ShareDirectoryClient, | ||
ShareFileClient, | ||
ShareClientOptions, | ||
StorageTestEnvironment> | ||
{ | ||
/// <summary> | ||
/// A <see cref="DisposingShare"/> but exposes a directory client within that share. | ||
/// Still cleans up the whole share. Helpful for parameterizing tests to use a root | ||
/// directory vs a subdir. | ||
/// </summary> | ||
private class DisposingShareDirectory : IDisposingContainer<ShareDirectoryClient> | ||
{ | ||
private readonly DisposingShare _disposingShare; | ||
public ShareDirectoryClient Container { get; } | ||
|
||
public DisposingShareDirectory(DisposingShare disposingShare, ShareDirectoryClient dirClient) | ||
{ | ||
_disposingShare = disposingShare; | ||
Container = dirClient; | ||
} | ||
|
||
public async ValueTask DisposeAsync() | ||
{ | ||
if (_disposingShare != default) | ||
{ | ||
await _disposingShare.DisposeAsync(); | ||
} | ||
} | ||
} | ||
|
||
public bool UseNonRootDirectory { get; } | ||
|
||
public ShareDirectoryStartTransferUploadTests(bool async, ShareClientOptions.ServiceVersion serviceVersion, bool useNonRootDirectory) | ||
: base(async, null /* RecordedTestMode.Record /* to re-record */) | ||
{ | ||
ClientBuilder = ClientBuilderExtensions.GetNewShareClientBuilder(Tenants, serviceVersion); | ||
UseNonRootDirectory = useNonRootDirectory; | ||
} | ||
|
||
protected override async Task<IDisposingContainer<ShareDirectoryClient>> GetDisposingContainerAsync(ShareServiceClient service = null, string containerName = null) | ||
{ | ||
DisposingShare disposingShare = await ClientBuilder.GetTestShareAsync(service, containerName); | ||
ShareDirectoryClient directoryClient = disposingShare.Container.GetRootDirectoryClient(); | ||
if (UseNonRootDirectory) | ||
{ | ||
foreach (var _ in Enumerable.Range(0, 2)) | ||
{ | ||
directoryClient = directoryClient.GetSubdirectoryClient(GetNewObjectName()); | ||
await directoryClient.CreateAsync(); | ||
} | ||
} | ||
return new DisposingShareDirectory(disposingShare, directoryClient); | ||
} | ||
|
||
protected override StorageResourceContainer GetStorageResourceContainer(ShareDirectoryClient containerClient) | ||
{ | ||
return new ShareDirectoryStorageResourceContainer(containerClient, null); | ||
} | ||
|
||
protected override TransferValidator.ListFilesAsync GetStorageResourceLister(ShareDirectoryClient containerClient) | ||
{ | ||
return TransferValidator.GetShareFileLister(containerClient); | ||
} | ||
|
||
protected override async Task InitializeDestinationDataAsync(ShareDirectoryClient containerClient, List<(string FilePath, long Size)> fileSizes, CancellationToken cancellationToken) | ||
{ | ||
foreach ((string filePath, long size) in fileSizes) | ||
{ | ||
ShareDirectoryClient directory = containerClient; | ||
|
||
string[] pathSegments = filePath.Split('/'); | ||
foreach (string pathSegment in pathSegments.Take(pathSegments.Length - 1)) | ||
{ | ||
directory = directory.GetSubdirectoryClient(pathSegment); | ||
await directory.CreateIfNotExistsAsync(cancellationToken: cancellationToken); | ||
} | ||
ShareFileClient file = directory.GetFileClient(pathSegments.Last()); | ||
await file.CreateAsync(size, cancellationToken: cancellationToken); | ||
await file.UploadAsync(await CreateLimitedMemoryStream(size), cancellationToken: cancellationToken); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.