-
Notifications
You must be signed in to change notification settings - Fork 204
Add E2E tests for blob SDK type bindings #1360
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
liliankasem
merged 5 commits into
feature/sdk-type-binding
from
liliankasem/e2e/sdk-binding
Feb 22, 2023
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
There are no files selected for viewing
134 changes: 134 additions & 0 deletions
134
test/E2ETests/E2EApps/E2EApp/Blob/BlobInputBindingFunctions.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,134 @@ | ||
| // Copyright (c) .NET Foundation. All rights reserved. | ||
| // Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.IO; | ||
| using System.Net; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
| using Azure.Storage.Blobs; | ||
| using Microsoft.Azure.Functions.Worker.Http; | ||
| using Microsoft.Extensions.Logging; | ||
|
|
||
| namespace Microsoft.Azure.Functions.Worker.E2EApp.Blob | ||
| { | ||
| public class BlobInputBindingFunctions | ||
| { | ||
| private readonly ILogger<BlobInputBindingFunctions> _logger; | ||
|
|
||
| public BlobInputBindingFunctions(ILogger<BlobInputBindingFunctions> logger) | ||
| { | ||
| _logger = logger; | ||
| } | ||
|
|
||
| [Function(nameof(BlobInputClientTest))] | ||
| public async Task<HttpResponseData> BlobInputClientTest( | ||
| [HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req, | ||
| [BlobInput("test-input-dotnet-isolated/testFile.txt")] BlobClient client) | ||
| { | ||
| var downloadResult = await client.DownloadContentAsync(); | ||
| var response = req.CreateResponse(HttpStatusCode.OK); | ||
| await response.Body.WriteAsync(downloadResult.Value.Content); | ||
| return response; | ||
| } | ||
|
|
||
| [Function(nameof(BlobInputContainerClientTest))] | ||
| public async Task<HttpResponseData> BlobInputContainerClientTest( | ||
| [HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req, | ||
| [BlobInput("test-input-dotnet-isolated/testFile.txt")] BlobContainerClient client) | ||
| { | ||
| var blobClient = client.GetBlobClient("testFile.txt"); | ||
| var downloadResult = await blobClient.DownloadContentAsync(); | ||
| var response = req.CreateResponse(HttpStatusCode.OK); | ||
| await response.Body.WriteAsync(downloadResult.Value.Content); | ||
| return response; | ||
| } | ||
|
|
||
| [Function(nameof(BlobInputStreamTest))] | ||
| public async Task<HttpResponseData> BlobInputStreamTest( | ||
| [HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req, | ||
| [BlobInput("test-input-dotnet-isolated/testFile.txt")] Stream stream) | ||
| { | ||
| using var blobStreamReader = new StreamReader(stream); | ||
| var response = req.CreateResponse(HttpStatusCode.OK); | ||
| await response.WriteStringAsync(blobStreamReader.ReadToEnd()); | ||
| return response; | ||
| } | ||
|
|
||
| [Function(nameof(BlobInputByteTest))] | ||
| public async Task<HttpResponseData> BlobInputByteTest( | ||
| [HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req, | ||
| [BlobInput("test-input-dotnet-isolated/testFile.txt")] Byte[] data) | ||
| { | ||
| var response = req.CreateResponse(HttpStatusCode.OK); | ||
| await response.WriteStringAsync(Encoding.Default.GetString(data)); | ||
| return response; | ||
| } | ||
|
|
||
| [Function(nameof(BlobInputStringTest))] | ||
| public async Task<HttpResponseData> BlobInputStringTest( | ||
| [HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req, | ||
| [BlobInput("test-input-dotnet-isolated/testFile.txt")] string data) | ||
| { | ||
| var response = req.CreateResponse(HttpStatusCode.OK); | ||
| await response.WriteStringAsync(data); | ||
| return response; | ||
| } | ||
|
|
||
| [Function(nameof(BlobInputPocoTest))] | ||
| public async Task<HttpResponseData> BlobInputPocoTest( | ||
| [HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req, | ||
| [BlobInput("test-input-dotnet-isolated/testFile.txt")] Book data) | ||
| { | ||
| var response = req.CreateResponse(HttpStatusCode.OK); | ||
| await response.WriteStringAsync(data.Name); | ||
| return response; | ||
| } | ||
|
|
||
| [Function(nameof(BlobInputCollectionTest))] | ||
| public async Task<HttpResponseData> BlobInputCollectionTest( | ||
| [HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req, | ||
| [BlobInput("test-input-dotnet-isolated", IsBatched = true)] IEnumerable<BlobClient> blobs) | ||
| { | ||
| List<string> blobList = new(); | ||
|
|
||
| foreach (BlobClient blob in blobs) | ||
| { | ||
| _logger.LogInformation("Blob name: {blobName}, Container name: {containerName}", blob.Name, blob.BlobContainerName); | ||
| blobList.Add(blob.Name); | ||
| } | ||
|
|
||
| var response = req.CreateResponse(HttpStatusCode.OK); | ||
| await response.WriteStringAsync(blobList.ToString()); | ||
| return response; | ||
| } | ||
|
|
||
| [Function(nameof(BlobInputStringArrayTest))] | ||
| public async Task<HttpResponseData> BlobInputStringArrayTest( | ||
| [HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req, | ||
| [BlobInput("test-input-dotnet-isolated", IsBatched = true)] string[] blobContent) | ||
| { | ||
| var response = req.CreateResponse(HttpStatusCode.OK); | ||
| await response.WriteStringAsync(blobContent.ToString()); | ||
| return response; | ||
| } | ||
|
|
||
| [Function(nameof(BlobInputPocoArrayTest))] | ||
| public async Task<HttpResponseData> BlobInputPocoArrayTest( | ||
| [HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req, | ||
| [BlobInput("test-input-dotnet-isolated", IsBatched = true)] Book[] books) | ||
| { | ||
| List<string> bookNames = new(); | ||
|
|
||
| foreach (var item in books) | ||
| { | ||
| bookNames.Add(item.Name); | ||
| } | ||
|
|
||
| var response = req.CreateResponse(HttpStatusCode.OK); | ||
| await response.WriteStringAsync(bookNames.ToString()); | ||
| return response; | ||
| } | ||
| } | ||
| } |
This file was deleted.
Oops, something went wrong.
90 changes: 90 additions & 0 deletions
90
test/E2ETests/E2EApps/E2EApp/Blob/BlobTriggerBindingFunctions.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,90 @@ | ||
| // Copyright (c) .NET Foundation. All rights reserved. | ||
| // Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
|
||
| using System.IO; | ||
| using System.Text.Json.Serialization; | ||
| using System.Threading.Tasks; | ||
| using Azure.Storage.Blobs; | ||
| using Microsoft.Extensions.Logging; | ||
|
|
||
| namespace Microsoft.Azure.Functions.Worker.E2EApp.Blob | ||
| { | ||
| public class BlobTriggerBindingFunctions | ||
| { | ||
| private readonly ILogger<BlobTriggerBindingFunctions> _logger; | ||
|
|
||
| public BlobTriggerBindingFunctions(ILogger<BlobTriggerBindingFunctions> logger) | ||
| { | ||
| _logger = logger; | ||
| } | ||
|
|
||
| [Function(nameof(BlobTriggerToBlobTest))] | ||
| [BlobOutput("test-output-dotnet-isolated/{name}")] | ||
| public byte[] BlobTriggerToBlobTest( | ||
| [BlobTrigger("test-trigger-dotnet-isolated/{name}")] byte[] triggerBlob, string name, | ||
| [BlobInput("test-input-dotnet-isolated/{name}")] byte[] inputBlob, | ||
| FunctionContext context) | ||
| { | ||
| _logger.LogInformation("Trigger:\n Name: " + name + "\n Size: " + triggerBlob.Length + " Bytes"); | ||
| _logger.LogInformation("Input:\n Name: " + name + "\n Size: " + inputBlob.Length + " Bytes"); | ||
| return inputBlob; | ||
| } | ||
|
|
||
| [Function(nameof(BlobTriggerPocoTest))] | ||
| [BlobOutput("test-output-poco-dotnet-isolated/{name}")] | ||
| public TestBlobData BlobTriggerPocoTest( | ||
| [BlobTrigger("test-trigger-poco-dotnet-isolated/{name}")] TestBlobData triggerBlob, string name, | ||
| FunctionContext context) | ||
| { | ||
| _logger.LogInformation(".NET Blob trigger function processed a blob.\n Name: " + name + "\n Content: " + triggerBlob.BlobText); | ||
| return triggerBlob; | ||
| } | ||
|
|
||
| [Function(nameof(BlobTriggerStringTest))] | ||
| [BlobOutput("test-output-string-dotnet-isolated/{name}")] | ||
| public string BlobTriggerStringTest( | ||
| [BlobTrigger("test-trigger-string-dotnet-isolated/{name}")] string triggerBlobText, string name, | ||
| FunctionContext context) | ||
| { | ||
| _logger.LogInformation(".NET Blob trigger function processed a blob.\n Name: " + name + "\n Content: " + triggerBlobText); | ||
| return triggerBlobText; | ||
| } | ||
|
|
||
| [Function(nameof(BlobTriggerStreamTest))] | ||
| public async Task BlobTriggerStreamTest( | ||
| [BlobTrigger("test-trigger-stream-dotnet-isolated/{name}")] Stream stream, string name, | ||
| FunctionContext context) | ||
| { | ||
| using var blobStreamReader = new StreamReader(stream); | ||
| string content = await blobStreamReader.ReadToEndAsync(); | ||
| _logger.LogInformation("StreamTriggerOutput: {c}", content); | ||
| } | ||
|
|
||
| [Function(nameof(BlobTriggerBlobClientTest))] | ||
| public async Task BlobTriggerBlobClientTest( | ||
| [BlobTrigger("test-trigger-blobclient-dotnet-isolated/{name}")] BlobClient client, string name, | ||
| FunctionContext context) | ||
| { | ||
| var downloadResult = await client.DownloadContentAsync(); | ||
| string content = downloadResult.Value.Content.ToString(); | ||
| _logger.LogInformation("BlobClientTriggerOutput: {c}", content); | ||
| } | ||
|
|
||
| [Function(nameof(BlobTriggerBlobContainerClientTest))] | ||
| public async Task BlobTriggerBlobContainerClientTest( | ||
| [BlobTrigger("test-trigger-containerclient-dotnet-isolated/{name}")] BlobContainerClient client, string name, | ||
| FunctionContext context) | ||
| { | ||
| var blobClient = client.GetBlobClient(name); | ||
| var downloadResult = await blobClient.DownloadContentAsync(); | ||
| string content = downloadResult.Value.Content.ToString(); | ||
| _logger.LogInformation("BlobContainerTriggerOutput: {c}", content); | ||
| } | ||
|
|
||
| public class TestBlobData | ||
| { | ||
| [JsonPropertyName("text")] | ||
| public string BlobText { get; set; } | ||
| } | ||
| } | ||
| } |
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,11 @@ | ||
| // Copyright (c) .NET Foundation. All rights reserved. | ||
| // Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
|
||
| namespace Microsoft.Azure.Functions.Worker.E2EApp.Blob | ||
| { | ||
| public class Book | ||
| { | ||
| public string Id { get; set; } | ||
| public string Name { get; set; } | ||
| } | ||
| } |
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
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
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.