Skip to content

Commit

Permalink
Generating cc attachments with correct uri (#2750) (#2754)
Browse files Browse the repository at this point in the history
* Generating cc attachments with correct uri

* Remove constructor

Co-authored-by: Jakub Chocholowicz <jachocho@microsoft.com>

Co-authored-by: Jakub Chocholowicz <jachocho@microsoft.com>
  • Loading branch information
jakubch1 and Jakub Chocholowicz authored Feb 16, 2021
1 parent bae1c7e commit 27786c2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -328,11 +328,9 @@ private void AddNewFileTransfer(FileTransferInformation fileTransferInfo, AsyncC
{
if (t.Exception == null)
{
// Uri doesn't recognize file paths in unix. See https://github.com/dotnet/corefx/issues/1745
var attachmentUri = new UriBuilder() { Scheme = "file", Host = "", Path = localFilePath }.Uri;
lock (attachmentTaskLock)
{
this.AttachmentSets[fileTransferInfo.Context][uri].Attachments.Add(new UriDataAttachment(attachmentUri, fileTransferInfo.Description));
this.AttachmentSets[fileTransferInfo.Context][uri].Attachments.Add(UriDataAttachment.CreateFrom(localFilePath, fileTransferInfo.Description));
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/Microsoft.TestPlatform.ObjectModel/AttachmentSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,11 @@ public override string ToString()
{
return $"{nameof(Uri)}: {Uri.AbsoluteUri}, {nameof(Description)}: {Description}";
}

public static UriDataAttachment CreateFrom(string localFilePath, string description)
{
var uri = new UriBuilder() { Scheme = "file", Host = "", Path = localFilePath }.Uri;
return new UriDataAttachment(uri, description);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ public async Task<ICollection<AttachmentSet>> ProcessAttachmentSetsAsync(ICollec
if (!string.IsNullOrEmpty(mergedCoverageReportFilePath))
{
var resultAttachmentSet = new AttachmentSet(CodeCoverageDataCollectorUri, CoverageFriendlyName);
resultAttachmentSet.Attachments.Add(new UriDataAttachment(new Uri(mergedCoverageReportFilePath), CoverageFriendlyName));
resultAttachmentSet.Attachments.Add(UriDataAttachment.CreateFrom(mergedCoverageReportFilePath, CoverageFriendlyName));

foreach (var coverageOtherFilePath in coverageOtherFilePaths)
{
resultAttachmentSet.Attachments.Add(new UriDataAttachment(new Uri(coverageOtherFilePath), string.Empty));
resultAttachmentSet.Attachments.Add(UriDataAttachment.CreateFrom(coverageOtherFilePath, string.Empty));
}

return new Collection<AttachmentSet> { resultAttachmentSet };
Expand Down

0 comments on commit 27786c2

Please sign in to comment.