Skip to content
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

fix(playwrighttesting): await upload buffer method #47056

Merged
merged 2 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,23 @@ public async Task UploadBufferAsync(string uri, string buffer, string fileRelati
_logger.Error($"Failed to upload buffer: {ex}");
}
}

public void UploadBuffer(string uri, string buffer, string fileRelativePath)
{
try
{
string cloudFilePath = GetCloudFilePath(uri, fileRelativePath);
BlobClient blobClient = new(new Uri(cloudFilePath));
byte[] bufferBytes = Encoding.UTF8.GetBytes(buffer);
blobClient.Upload(new BinaryData(bufferBytes), overwrite: true);
_logger.Info($"Uploaded buffer to {fileRelativePath}");
}
catch (Exception ex)
{
_logger.Error($"Failed to upload buffer: {ex}");
}
}

public void UploadBlobFile(string uri, string fileRelativePath, string filePath)
{
string cloudFilePath = GetCloudFilePath(uri, fileRelativePath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ internal interface IBlobService
/// <param name="fileRelativePath"></param>
/// <returns>A <see cref="Task"/> representing the result of the asynchronous operation.</returns>
Task UploadBufferAsync(string uri, string buffer, string fileRelativePath);
string GetCloudFilePath(string uri, string fileRelativePath);
void UploadBuffer(string uri, string buffer, string fileRelativePath);
string GetCloudFilePath(string uri, string fileRelativePath);
void UploadBlobFile(string uri, string fileRelativePath, string filePath);
public string? GetCloudFileName(string filePath, string testExecutionId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using Azure.Core.Pipeline;
using Azure.Developer.MicrosoftPlaywrightTesting.TestLogger.Implementation;
using Azure.Developer.MicrosoftPlaywrightTesting.TestLogger.Interface;
using Azure.Developer.MicrosoftPlaywrightTesting.TestLogger.Model;
Expand Down Expand Up @@ -174,7 +175,7 @@ public void TestRunCompleteHandler(object? sender, TestRunCompleteEventArgs e)
// Upload rawResult to blob storage using sasUri
var rawTestResultJson = JsonSerializer.Serialize(rawResult);
var filePath = $"{testResult.TestExecutionId}/rawTestResult.json";
_blobService.UploadBufferAsync(sasUri!.Uri!, rawTestResultJson, filePath);
_blobService.UploadBuffer(sasUri!.Uri!, rawTestResultJson, filePath);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ public async Task UploadBufferAsync_WithException_LogsError()
_loggerMock!.Verify(logger => logger.Error(It.IsAny<string>()), Times.Once);
}

[Test]
public void UploadBuffer_WithException_LogsError()
{
string uri = "invalid_uri";
string buffer = "Test buffer";
string fileRelativePath = "test/path";

_blobService!.UploadBuffer(uri, buffer, fileRelativePath);

_loggerMock!.Verify(logger => logger.Error(It.IsAny<string>()), Times.Once);
}

[Test]
public void GetCloudFilePath_WithValidParameters_ReturnsCorrectPath()
{
Expand Down