Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
chore(): move to upload buffer sync
  • Loading branch information
Sid200026 committed Nov 11, 2024
commit 4ac702ea9288b8c09373758ae6b631acff97c3f6
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