-
Notifications
You must be signed in to change notification settings - Fork 5.1k
[DataMovement] Adding Tests for Recorded File Upload (Add fix Creating File at Initial Start) #39037
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
[DataMovement] Adding Tests for Recorded File Upload (Add fix Creating File at Initial Start) #39037
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b157b90
Added Single Share File Upload Tests; Create before putrange
amnguye ad727d8
Merge branch 'main' into feature/storage/file-upload
amnguye 04b7ba8
WIP
amnguye a1f5223
Merge branch 'main' into feature/storage/file-upload
amnguye e8b8d71
Removed testbase for startTransfer upload test base; other pr comments
amnguye File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Added Single Share File Upload Tests; Create before putrange
- Loading branch information
commit b157b90486f4d30f277a61cd898137a68d70a0d6
There are no files selected for viewing
This file contains hidden or 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
6 changes: 6 additions & 0 deletions
6
sdk/storage/Azure.Storage.DataMovement.Files.Shares/assets.json
This file contains hidden or 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,6 @@ | ||
| { | ||
| "AssetsRepo": "Azure/azure-sdk-assets", | ||
| "AssetsRepoPrefixPath": "net", | ||
| "TagPrefix": "net/storage/Azure.Storage.DataMovement.Files.Shares", | ||
| "Tag": "net/storage/Azure.Storage.DataMovement.Files.Shares_cd21a40eed" | ||
| } |
This file contains hidden or 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 hidden or 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
42 changes: 42 additions & 0 deletions
42
sdk/storage/Azure.Storage.DataMovement.Files.Shares/tests/ClientBuilderExtensions.cs
This file contains hidden or 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,42 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Threading.Tasks; | ||
| using Azure.Storage.Files.Shares; | ||
| using Azure.Storage.Files.Shares.Tests; | ||
| using SharesClientBuilder = Azure.Storage.Test.Shared.ClientBuilder< | ||
| Azure.Storage.Files.Shares.ShareServiceClient, | ||
| Azure.Storage.Files.Shares.ShareClientOptions>; | ||
|
|
||
| namespace Azure.Storage.DataMovement.Files.Shares.Tests | ||
| { | ||
| internal static class ClientBuilderExtensions | ||
| { | ||
| public static string GetNewShareName(this SharesClientBuilder clientBuilder) | ||
| => $"test-share-{clientBuilder.Recording.Random.NewGuid()}"; | ||
| public static string GetNewDirectoryName(this SharesClientBuilder clientBuilder) | ||
| => $"test-directory-{clientBuilder.Recording.Random.NewGuid()}"; | ||
| public static string GetNewNonAsciiDirectoryName(this SharesClientBuilder clientBuilder) | ||
| => $"test-dire¢t Ø®ϒ%3A-{clientBuilder.Recording.Random.NewGuid()}"; | ||
| public static string GetNewFileName(this SharesClientBuilder clientBuilder) | ||
| => $"test-file-{clientBuilder.Recording.Random.NewGuid()}"; | ||
| public static string GetNewNonAsciiFileName(this SharesClientBuilder clientBuilder) | ||
| => $"test-ƒ¡£€‽%3A-{clientBuilder.Recording.Random.NewGuid()}"; | ||
|
|
||
| public static async Task<DisposingShare> GetTestShareAsync( | ||
| this SharesClientBuilder clientBuilder, | ||
| ShareServiceClient service = default, | ||
| string shareName = default, | ||
| IDictionary<string, string> metadata = default, | ||
| ShareClientOptions options = default) | ||
| { | ||
| service ??= clientBuilder.GetServiceClientFromSharedKeyConfig(clientBuilder.Tenants.TestConfigDefault, options); | ||
| metadata ??= new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); | ||
| shareName ??= clientBuilder.GetNewShareName(); | ||
| ShareClient share = clientBuilder.AzureCoreRecordedTestBase.InstrumentClient(service.GetShareClient(shareName)); | ||
| return await DisposingShare.CreateAsync(share, metadata); | ||
| } | ||
| } | ||
| } |
86 changes: 86 additions & 0 deletions
86
sdk/storage/Azure.Storage.DataMovement.Files.Shares/tests/DataMovementShareTestBase.cs
This file contains hidden or 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,86 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System.Threading.Tasks; | ||
| using System.Collections.Generic; | ||
| using Azure.Core.TestFramework; | ||
| using Azure.Storage.Files.Shares; | ||
| using Azure.Storage.Files.Shares.Tests; | ||
| using Azure.Storage.Test.Shared; | ||
| using SharesClientBuilder = Azure.Storage.Test.Shared.ClientBuilder< | ||
| Azure.Storage.Files.Shares.ShareServiceClient, | ||
| Azure.Storage.Files.Shares.ShareClientOptions>; | ||
| using System.IO; | ||
|
|
||
| namespace Azure.Storage.DataMovement.Files.Shares.Tests | ||
| { | ||
| [ShareClientTestFixture] | ||
| public abstract class DataMovementShareTestBase : StorageTestBase<StorageTestEnvironment> | ||
| { | ||
| protected readonly ShareClientOptions.ServiceVersion _serviceVersion; | ||
|
|
||
| /// <summary> | ||
| /// Source of clients. | ||
| /// </summary> | ||
| protected SharesClientBuilder SharesClientBuilder { get; } | ||
|
|
||
| public DataMovementShareTestBase(bool async, ShareClientOptions.ServiceVersion serviceVersion, RecordedTestMode? mode = null) | ||
| : base(async, mode /* RecordedTestMode.Record /* to re-record */) | ||
| { | ||
| _serviceVersion = serviceVersion; | ||
| SharesClientBuilder = GetNewSharesClientBuilder(Tenants, _serviceVersion); | ||
| } | ||
|
|
||
| public string GetNewShareName() => SharesClientBuilder.GetNewShareName(); | ||
| public string GetNewDirectoryName() => SharesClientBuilder.GetNewDirectoryName(); | ||
| public string GetNewNonAsciiDirectoryName() => SharesClientBuilder.GetNewNonAsciiDirectoryName(); | ||
| public string GetNewFileName() => SharesClientBuilder.GetNewFileName(); | ||
| public string GetNewNonAsciiFileName() => SharesClientBuilder.GetNewNonAsciiFileName(); | ||
|
|
||
| /// <summary> | ||
| /// Creates a new <see cref="ClientBuilder{TServiceClient, TServiceClientOptions}"/> | ||
| /// setup to generate <see cref="BlobServiceClient"/>s. | ||
| /// </summary> | ||
| /// <param name="tenants"><see cref="TenantConfigurationBuilder"/> powering this client builder.</param> | ||
| /// <param name="serviceVersion">Service version for clients to target.</param> | ||
| public SharesClientBuilder GetNewSharesClientBuilder(TenantConfigurationBuilder tenants, ShareClientOptions.ServiceVersion serviceVersion) | ||
| => new SharesClientBuilder( | ||
| ServiceEndpoint.File, | ||
| tenants, | ||
| (uri, clientOptions) => new ShareServiceClient(uri, clientOptions), | ||
| (uri, sharedKeyCredential, clientOptions) => new ShareServiceClient(uri, sharedKeyCredential, clientOptions), | ||
| (uri, tokenCredential, clientOptions) => new ShareServiceClient(uri, tokenCredential, clientOptions), | ||
| (uri, azureSasCredential, clientOptions) => new ShareServiceClient(uri, azureSasCredential, clientOptions), | ||
| () => new ShareClientOptions(serviceVersion)); | ||
|
|
||
| public async Task<DisposingShare> GetTestShareAsync( | ||
| ShareServiceClient service = default, | ||
| string containerName = default, | ||
| IDictionary<string, string> metadata = default, | ||
| ShareClientOptions options = default) | ||
| => await SharesClientBuilder.GetTestShareAsync(service, containerName, metadata, options); | ||
|
|
||
| internal async Task<ShareFileClient> CreateShareFile( | ||
| ShareDirectoryClient directoryClient, | ||
| string localSourceFile, | ||
| string fileName, | ||
| long size) | ||
| { | ||
| ShareFileClient fileClient = directoryClient.GetFileClient(fileName); | ||
|
|
||
| // create a new file and copy contents of stream into it, and then close the FileStream | ||
| // so the StagedUploadAsync call is not prevented from reading using its FileStream. | ||
| using Stream originalStream = await CreateLimitedMemoryStream(size); | ||
| using (FileStream fileStream = File.Create(localSourceFile)) | ||
| { | ||
| // Copy source to a file, so we can verify the source against downloaded blob later | ||
| await originalStream.CopyToAsync(fileStream); | ||
| // Upload blob to storage account | ||
| originalStream.Position = 0; | ||
| await fileClient.CreateAsync(size); | ||
| await fileClient.UploadAsync(originalStream); | ||
| } | ||
| return fileClient; | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.