Skip to content

Commit

Permalink
chore(): move to upload buffer sync
Browse files Browse the repository at this point in the history
  • Loading branch information
Siddharth Singha Roy committed Nov 11, 2024
1 parent a2a564a commit 4ac702e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
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,9 +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";
#pragma warning disable AZC0102 // Do not use GetAwaiter().GetResult().
_blobService.UploadBufferAsync(sasUri!.Uri!, rawTestResultJson, filePath).GetAwaiter().GetResult();
#pragma warning restore AZC0102 // Do not use GetAwaiter().GetResult().
_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

0 comments on commit 4ac702e

Please sign in to comment.