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

Test and Deprecate Publish HTML Report #67

Merged
merged 20 commits into from
Jan 9, 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
18 changes: 16 additions & 2 deletions src/CoveragePublisher.Tests/CoverageProcessorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using Microsoft.Azure.Pipelines.CoveragePublisher;
using Microsoft.Azure.Pipelines.CoveragePublisher.Model;
using Microsoft.Azure.Pipelines.CoveragePublisher.Parsers;
using Microsoft.Azure.Pipelines.CoveragePublisher.Publishers.DefaultPublisher;
using Microsoft.VisualStudio.Services.WebApi;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;

Expand All @@ -20,16 +22,28 @@
private PublisherConfiguration _config = new PublisherConfiguration() { ReportDirectory = "directory" };
private Mock<Parser> _mockParser;
private Mock<ITelemetryDataCollector> _mockTelemetryDataCollector = new Mock<ITelemetryDataCollector>();
private IFeatureFlagHelper _featureFlagHelper;
private ICoveragePublisher _publisher;

Check warning on line 26 in src/CoveragePublisher.Tests/CoverageProcessorTests.cs

View workflow job for this annotation

GitHub Actions / build

Field 'CoverageProcessorTests._publisher' is never assigned to, and will always have its default value null

Check warning on line 26 in src/CoveragePublisher.Tests/CoverageProcessorTests.cs

View workflow job for this annotation

GitHub Actions / build

Field 'CoverageProcessorTests._publisher' is never assigned to, and will always have its default value null
private Mock<IFeatureFlagHelper> _mockFFHelper = new Mock<IFeatureFlagHelper>();

[TestInitialize]
public void TestInitialize()
public void TestInitialize(IFeatureFlagHelper featureFlagHelper)
{
_mockParser = new Mock<Parser>(_config, _mockTelemetryDataCollector.Object);

_mockPublisher.Setup(x => x.PublishCoverageSummary(It.IsAny<CoverageSummary>(), It.IsAny<CancellationToken>())).Returns(Task.CompletedTask);
_mockPublisher.Setup(x => x.PublishNativeCoverageFiles(It.IsAny<IList<string>>(), It.IsAny<CancellationToken>())).Returns(Task.CompletedTask);
_mockPublisher.Setup(x => x.PublishFileCoverage(It.IsAny<IList<FileCoverageInfo>>(), It.IsAny<CancellationToken>())).Returns(Task.CompletedTask);
_mockPublisher.Setup(x => x.PublishHTMLReport(It.IsAny<string>(), It.IsAny<CancellationToken>())).Returns(Task.CompletedTask);
_mockPublisher.Setup(x => x.IsUploadNativeFilesToTCMSupported()).Returns(false);
_mockFFHelper.Reset();
_featureFlagHelper = featureFlagHelper;
var IsUploadNativeFilesToTCMSupported = _publisher.IsUploadNativeFilesToTCMSupported;

if (IsUploadNativeFilesToTCMSupported.Equals(false))
{
// Feature Flag for testing and deprecating PublishHTMLReport; To be cleaned up post PCCRV2 upgrade
_mockPublisher.Setup(x => x.PublishHTMLReport(It.IsAny<string>(), It.IsAny<CancellationToken>())).Returns(Task.CompletedTask);
}
}

[TestMethod]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
private Mock<IFeatureFlagHelper> _mockFFHelper = new Mock<IFeatureFlagHelper>();
private Mock<IHtmlReportPublisher> _mockHtmlPublisher = new Mock<IHtmlReportPublisher>();
private Mock<ILogStoreHelper> _mockLogStoreHelper = new Mock<ILogStoreHelper>();
private ICoveragePublisher _publisher;

Check warning on line 29 in src/CoveragePublisher.Tests/Publishers/AzurePipelines/AzurePipelinesPublisherTests.cs

View workflow job for this annotation

GitHub Actions / build

Field 'AzurePipelinesPublisherTests._publisher' is never assigned to, and will always have its default value null

Check warning on line 29 in src/CoveragePublisher.Tests/Publishers/AzurePipelines/AzurePipelinesPublisherTests.cs

View workflow job for this annotation

GitHub Actions / build

Field 'AzurePipelinesPublisherTests._publisher' is never assigned to, and will always have its default value null

[TestInitialize]
public void TestInitialize()
public void TestInitialize(IFeatureFlagHelper featureFlagHelper)
{
_context = new TestPipelinesExecutionContext(_logger);
_logger.Log = "";
Expand Down Expand Up @@ -99,16 +100,22 @@
[TestMethod]
public void WillPublishHtmlReport()
{
var publisher = new AzurePipelinesPublisher(_context, _mockClientFactory.Object, _mockFFHelper.Object, _mockHtmlPublisher.Object, _mockLogStoreHelper.Object, true);
var token = new CancellationToken();
var IsUploadNativeFilesToTCMSupported = _publisher.IsUploadNativeFilesToTCMSupported;

// Feature Flag for testing and deprecating PublishHTMLReport; To be cleaned up post PCCRV2 upgrade
if (IsUploadNativeFilesToTCMSupported.Equals(false))
{
var publisher = new AzurePipelinesPublisher(_context, _mockClientFactory.Object, _mockFFHelper.Object, _mockHtmlPublisher.Object, _mockLogStoreHelper.Object, true);
var token = new CancellationToken();

_mockHtmlPublisher.Setup(x => x.PublishHTMLReportAsync(It.IsAny<string>(), It.IsAny<CancellationToken>())).Returns(Task.CompletedTask);
_mockHtmlPublisher.Setup(x => x.PublishHTMLReportAsync(It.IsAny<string>(), It.IsAny<CancellationToken>())).Returns(Task.CompletedTask);

publisher.PublishHTMLReport("directory", token).Wait();
publisher.PublishHTMLReport("directory", token).Wait();

_mockHtmlPublisher.Verify(x => x.PublishHTMLReportAsync(
It.Is<string>(a => a == "directory"),
It.Is<CancellationToken>(b => b == token)));
_mockHtmlPublisher.Verify(x => x.PublishHTMLReportAsync(
It.Is<string>(a => a == "directory"),
It.Is<CancellationToken>(b => b == token)));
}
}

[TestMethod]
Expand Down
22 changes: 12 additions & 10 deletions src/CoveragePublisher/CoverageProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Microsoft.Azure.Pipelines.CoveragePublisher.Model;
using Microsoft.Azure.Pipelines.CoveragePublisher.Parsers;
using Microsoft.Azure.Pipelines.CoveragePublisher.Utils;
using Microsoft.Azure.Pipelines.CoveragePublisher.Publishers.DefaultPublisher;
using Microsoft.VisualStudio.Services.WebApi;

namespace Microsoft.Azure.Pipelines.CoveragePublisher
Expand Down Expand Up @@ -108,20 +109,21 @@ public async Task ParseAndPublishCoverage(PublisherConfiguration config, Cancell
}
}

if (config.GenerateHTMLReport)
{
if (!Directory.Exists(config.ReportDirectory))
{
TraceLogger.Warning(Resources.NoReportDirectoryGenerated);
}
else
//Feature Flag for testing and deprecating PublishHTMLReport; To be cleaned up post PCCRV2 upgrade
if (!uploadNativeCoverageFilesToLogStore && config.GenerateHTMLReport)
{
using (new SimpleTimer("CoverageProcesser", "PublishHTMLReport", _telemetry))
if (!Directory.Exists(config.ReportDirectory))
{
await _publisher.PublishHTMLReport(config.ReportDirectory, token);
TraceLogger.Warning(Resources.NoReportDirectoryGenerated);
}
else
{
using (new SimpleTimer("CoverageProcesser", "PublishHTMLReport", _telemetry))
{
await _publisher.PublishHTMLReport(config.ReportDirectory, token);
}
}
}
}
}
// Only catastrophic failures should trickle down to these catch blocks
catch(ParsingException ex)
Expand Down
Loading