Avoid repeating the first-run message if lzma archive is missing
If the LZMA archive is missing, the first-run message is printed every time. This commit fixes that. Split the first-run message into two pieces: - The first-run (welcome and telemetry) message is printed only once, no matter whether the cache was primed or not. - The cache-priming message is printed only if the cache is avaialble. Otherwise skip the cache introduction and the ccache priming operation.
This commit is contained in:
parent
2180d92d10
commit
34b44b999b
10 changed files with 267 additions and 16 deletions
|
@ -15,17 +15,102 @@ namespace Microsoft.DotNet.Configurer.UnitTests
|
|||
{
|
||||
private Mock<INuGetCachePrimer> _nugetCachePrimerMock;
|
||||
private Mock<INuGetCacheSentinel> _nugetCacheSentinelMock;
|
||||
private Mock<IFirstTimeUseNoticeSentinel> _firstTimeUseNoticeSentinelMock;
|
||||
private Mock<IEnvironmentProvider> _environmentProviderMock;
|
||||
private Mock<IReporter> _reporterMock;
|
||||
|
||||
public GivenADotnetFirstTimeUseConfigurer()
|
||||
{
|
||||
_nugetCachePrimerMock = new Mock<INuGetCachePrimer>();
|
||||
_nugetCacheSentinelMock = new Mock<INuGetCacheSentinel>();
|
||||
_firstTimeUseNoticeSentinelMock = new Mock<IFirstTimeUseNoticeSentinel>();
|
||||
_environmentProviderMock = new Mock<IEnvironmentProvider>();
|
||||
_reporterMock = new Mock<IReporter>();
|
||||
|
||||
_environmentProviderMock
|
||||
.Setup(e => e.GetEnvironmentVariableAsBool("DOTNET_SKIP_FIRST_TIME_EXPERIENCE", false))
|
||||
.Returns(false);
|
||||
_environmentProviderMock
|
||||
.Setup(e => e.GetEnvironmentVariableAsBool("DOTNET_PRINT_TELEMETRY_MESSAGE", true))
|
||||
.Returns(true);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_does_not_print_the_first_time_use_notice_if_the_sentinel_exists()
|
||||
{
|
||||
_firstTimeUseNoticeSentinelMock.Setup(n => n.Exists()).Returns(true);
|
||||
|
||||
var dotnetFirstTimeUseConfigurer = new DotnetFirstTimeUseConfigurer(
|
||||
_nugetCachePrimerMock.Object,
|
||||
_nugetCacheSentinelMock.Object,
|
||||
_firstTimeUseNoticeSentinelMock.Object,
|
||||
_environmentProviderMock.Object,
|
||||
_reporterMock.Object);
|
||||
|
||||
dotnetFirstTimeUseConfigurer.Configure();
|
||||
|
||||
_reporterMock.Verify(r => r.WriteLine(It.Is<string>(str => str.StartsWith("Welcome to .NET Core!"))), Times.Never);
|
||||
_reporterMock.Verify(r => r.Write(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_does_not_print_the_first_time_use_notice_when_the_user_has_set_the_DOTNET_SKIP_FIRST_TIME_EXPERIENCE_environemnt_variable()
|
||||
{
|
||||
_firstTimeUseNoticeSentinelMock.Setup(n => n.Exists()).Returns(false);
|
||||
_environmentProviderMock
|
||||
.Setup(e => e.GetEnvironmentVariableAsBool("DOTNET_SKIP_FIRST_TIME_EXPERIENCE", false))
|
||||
.Returns(true);
|
||||
|
||||
var dotnetFirstTimeUseConfigurer = new DotnetFirstTimeUseConfigurer(
|
||||
_nugetCachePrimerMock.Object,
|
||||
_nugetCacheSentinelMock.Object,
|
||||
_firstTimeUseNoticeSentinelMock.Object,
|
||||
_environmentProviderMock.Object,
|
||||
_reporterMock.Object);
|
||||
|
||||
dotnetFirstTimeUseConfigurer.Configure();
|
||||
|
||||
_reporterMock.Verify(r => r.WriteLine(It.Is<string>(str => str.StartsWith("Welcome to .NET Core!"))), Times.Never);
|
||||
_reporterMock.Verify(r => r.Write(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_does_not_print_the_first_time_use_notice_when_the_user_has_set_the_DOTNET_PRINT_TELEMETRY_MESSAGE_environemnt_variable()
|
||||
{
|
||||
_firstTimeUseNoticeSentinelMock.Setup(n => n.Exists()).Returns(false);
|
||||
_environmentProviderMock
|
||||
.Setup(e => e.GetEnvironmentVariableAsBool("DOTNET_PRINT_TELEMETRY_MESSAGE", true))
|
||||
.Returns(false);
|
||||
|
||||
var dotnetFirstTimeUseConfigurer = new DotnetFirstTimeUseConfigurer(
|
||||
_nugetCachePrimerMock.Object,
|
||||
_nugetCacheSentinelMock.Object,
|
||||
_firstTimeUseNoticeSentinelMock.Object,
|
||||
_environmentProviderMock.Object,
|
||||
_reporterMock.Object);
|
||||
|
||||
dotnetFirstTimeUseConfigurer.Configure();
|
||||
|
||||
_reporterMock.Verify(r => r.WriteLine(It.Is<string>(str => str.StartsWith("Welcome to .NET Core!"))), Times.Never);
|
||||
_reporterMock.Verify(r => r.Write(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_prints_the_telemetry_if_the_sentinel_does_not_exist()
|
||||
{
|
||||
_firstTimeUseNoticeSentinelMock.Setup(n => n.Exists()).Returns(false);
|
||||
|
||||
var dotnetFirstTimeUseConfigurer = new DotnetFirstTimeUseConfigurer(
|
||||
_nugetCachePrimerMock.Object,
|
||||
_nugetCacheSentinelMock.Object,
|
||||
_firstTimeUseNoticeSentinelMock.Object,
|
||||
_environmentProviderMock.Object,
|
||||
_reporterMock.Object);
|
||||
|
||||
dotnetFirstTimeUseConfigurer.Configure();
|
||||
|
||||
_reporterMock.Verify(r => r.WriteLine(It.Is<string>(str => str.StartsWith("Welcome to .NET Core!"))));
|
||||
_reporterMock.Verify(r => r.Write(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -36,7 +121,9 @@ namespace Microsoft.DotNet.Configurer.UnitTests
|
|||
var dotnetFirstTimeUseConfigurer = new DotnetFirstTimeUseConfigurer(
|
||||
_nugetCachePrimerMock.Object,
|
||||
_nugetCacheSentinelMock.Object,
|
||||
_environmentProviderMock.Object);
|
||||
_firstTimeUseNoticeSentinelMock.Object,
|
||||
_environmentProviderMock.Object,
|
||||
_reporterMock.Object);
|
||||
|
||||
dotnetFirstTimeUseConfigurer.Configure();
|
||||
|
||||
|
@ -51,7 +138,26 @@ namespace Microsoft.DotNet.Configurer.UnitTests
|
|||
var dotnetFirstTimeUseConfigurer = new DotnetFirstTimeUseConfigurer(
|
||||
_nugetCachePrimerMock.Object,
|
||||
_nugetCacheSentinelMock.Object,
|
||||
_environmentProviderMock.Object);
|
||||
_firstTimeUseNoticeSentinelMock.Object,
|
||||
_environmentProviderMock.Object,
|
||||
_reporterMock.Object);
|
||||
|
||||
dotnetFirstTimeUseConfigurer.Configure();
|
||||
|
||||
_nugetCachePrimerMock.Verify(r => r.PrimeCache(), Times.Never);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_does_not_prime_the_cache_if_cache_is_missing()
|
||||
{
|
||||
_nugetCachePrimerMock.Setup(n => n.SkipPrimingTheCache()).Returns(true);
|
||||
|
||||
var dotnetFirstTimeUseConfigurer = new DotnetFirstTimeUseConfigurer(
|
||||
_nugetCachePrimerMock.Object,
|
||||
_nugetCacheSentinelMock.Object,
|
||||
_firstTimeUseNoticeSentinelMock.Object,
|
||||
_environmentProviderMock.Object,
|
||||
_reporterMock.Object);
|
||||
|
||||
dotnetFirstTimeUseConfigurer.Configure();
|
||||
|
||||
|
@ -69,7 +175,9 @@ namespace Microsoft.DotNet.Configurer.UnitTests
|
|||
var dotnetFirstTimeUseConfigurer = new DotnetFirstTimeUseConfigurer(
|
||||
_nugetCachePrimerMock.Object,
|
||||
_nugetCacheSentinelMock.Object,
|
||||
_environmentProviderMock.Object);
|
||||
_firstTimeUseNoticeSentinelMock.Object,
|
||||
_environmentProviderMock.Object,
|
||||
_reporterMock.Object);
|
||||
|
||||
dotnetFirstTimeUseConfigurer.Configure();
|
||||
|
||||
|
@ -84,11 +192,34 @@ namespace Microsoft.DotNet.Configurer.UnitTests
|
|||
var dotnetFirstTimeUseConfigurer = new DotnetFirstTimeUseConfigurer(
|
||||
_nugetCachePrimerMock.Object,
|
||||
_nugetCacheSentinelMock.Object,
|
||||
_environmentProviderMock.Object);
|
||||
_firstTimeUseNoticeSentinelMock.Object,
|
||||
_environmentProviderMock.Object,
|
||||
_reporterMock.Object);
|
||||
|
||||
dotnetFirstTimeUseConfigurer.Configure();
|
||||
|
||||
_nugetCachePrimerMock.Verify(r => r.PrimeCache(), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_prints_first_use_notice_and_primes_the_cache_if_the_sentinels_do_not_exist()
|
||||
{
|
||||
_nugetCacheSentinelMock.Setup(n => n.Exists()).Returns(false);
|
||||
_firstTimeUseNoticeSentinelMock.Setup(n => n.Exists()).Returns(false);
|
||||
|
||||
var dotnetFirstTimeUseConfigurer = new DotnetFirstTimeUseConfigurer(
|
||||
_nugetCachePrimerMock.Object,
|
||||
_nugetCacheSentinelMock.Object,
|
||||
_firstTimeUseNoticeSentinelMock.Object,
|
||||
_environmentProviderMock.Object,
|
||||
_reporterMock.Object);
|
||||
|
||||
dotnetFirstTimeUseConfigurer.Configure();
|
||||
|
||||
_reporterMock.Verify(r => r.WriteLine(It.Is<string>(str => str.StartsWith("Welcome to .NET Core!"))));
|
||||
_reporterMock.Verify(r => r.WriteLine(It.Is<string>(str => str.StartsWith("Configuring"))));
|
||||
_nugetCachePrimerMock.Verify(r => r.PrimeCache(), Times.Once);
|
||||
_reporterMock.Verify(r => r.Write(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue