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

Fix localappdata folder for Linux and Mac #2765

Merged
merged 3 commits into from
Apr 25, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ internal interface IEnvironment

IDictionary GetEnvironmentVariables();

string GetFolderPath(Environment.SpecialFolder folder, Environment.SpecialFolderOption option);

void FailFast(string? message, Exception? exception);

void FailFast(string? message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ internal sealed class SystemEnvironment : IEnvironment

public IDictionary GetEnvironmentVariables() => Environment.GetEnvironmentVariables();

public string GetFolderPath(Environment.SpecialFolder folder, Environment.SpecialFolderOption option) => Environment.GetFolderPath(folder, option);

public void FailFast(string? message, Exception? exception) => Environment.FailFast(message, exception);

public void FailFast(string? message) => Environment.FailFast(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ public async Task<ITelemetryCollector> BuildAsync(ServiceProvider serviceProvide
if (!isTelemetryOptedOut && !doNotShowLogo)
{
ITestApplicationModuleInfo testApplicationModuleInfo = serviceProvider.GetTestApplicationModuleInfo();
string? directory = environment.GetEnvironmentVariable("LOCALAPPDATA") ?? environment.GetEnvironmentVariable("HOME");
#pragma warning disable RS0030 // Do not use banned APIs - There is no easy way to disable it for all members
string? directory = environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.Create);
#pragma warning restore RS0030 // Do not use banned APIs
if (directory is not null)
{
directory = Path.Combine(directory, "Microsoft", "TestingPlatform");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,7 @@ public async Task TelemetryManager_UsingTelemetryOptOutShouldDisableTelemetry(st
}
}

[Arguments("LOCALAPPDATA")]
[Arguments("HOME")]
public async Task TelemetryManager_SentinelIsWrittenPerUserAndAvoidsShowingNoticeOnSubsequentRuns(string variable)
public async Task TelemetryManager_SentinelIsWrittenPerUserAndAvoidsShowingNoticeOnSubsequentRuns()
{
// Arrange
var options = new TestApplicationOptions();
Expand All @@ -143,7 +141,8 @@ public async Task TelemetryManager_SentinelIsWrittenPerUserAndAvoidsShowingNotic
var fileSystemMock = new Mock<IFileSystem>();
var environmentMock = new Mock<IEnvironment>();
var commandLineOptions = new Mock<ICommandLineOptions>();
environmentMock.Setup(s => s.GetEnvironmentVariable(variable)).Returns("sentinelDir");
environmentMock.Setup(s => s.GetFolderPath(Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.Create))
.Returns("sentinelDir");
var outputDevice = new Mock<IOutputDevice>();

var testApplicationModuleInfoMock = new Mock<ITestApplicationModuleInfo>();
Expand Down Expand Up @@ -194,9 +193,7 @@ public async Task TelemetryManager_SentinelIsWrittenPerUserAndAvoidsShowingNotic
fileSystemMock.Verify(f => f.NewFileStream(path, It.IsAny<FileMode>(), It.IsAny<FileAccess>()), Times.Never);
}

[Arguments("LOCALAPPDATA")]
[Arguments("HOME")]
public async Task TelemetryManager_SentinelIsWrittenOnlyWhenUserWouldSeeTheMessage(string variable)
public async Task TelemetryManager_SentinelIsWrittenOnlyWhenUserWouldSeeTheMessage()
{
// Arrange
var options = new TestApplicationOptions();
Expand All @@ -205,7 +202,8 @@ public async Task TelemetryManager_SentinelIsWrittenOnlyWhenUserWouldSeeTheMessa
var fileSystemMock = new Mock<IFileSystem>();
var environmentMock = new Mock<IEnvironment>();
var commandLineOptions = new Mock<ICommandLineOptions>();
environmentMock.Setup(s => s.GetEnvironmentVariable(variable)).Returns("sentinelDir");
environmentMock.Setup(s => s.GetFolderPath(Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.Create))
.Returns("sentinelDir");
var outputDevice = new Mock<IOutputDevice>();

var testApplicationModuleInfoMock = new Mock<ITestApplicationModuleInfo>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,8 @@ Microsoft.Testing.Platform.UnitTests.Microsoft.Testing.Platform.UnitTests.TaskEx
Microsoft.Testing.Platform.UnitTests.Microsoft.Testing.Platform.UnitTests.TaskExtensionsTests.TimeoutAfterAsync_CancellationToken_Succeeds()
Microsoft.Testing.Platform.UnitTests.Microsoft.Testing.Platform.UnitTests.TaskExtensionsTests.TimeoutAfterAsync_CancellationTokenNone_Succeeds()
Microsoft.Testing.Platform.UnitTests.Microsoft.Testing.Platform.UnitTests.TaskExtensionsTests.TimeoutAfterAsync_Succeeds()
Microsoft.Testing.Platform.UnitTests.Microsoft.Testing.Platform.UnitTests.TelemetryManagerTests.TelemetryManager_SentinelIsWrittenOnlyWhenUserWouldSeeTheMessage(string) (variable: "HOME")
Microsoft.Testing.Platform.UnitTests.Microsoft.Testing.Platform.UnitTests.TelemetryManagerTests.TelemetryManager_SentinelIsWrittenOnlyWhenUserWouldSeeTheMessage(string) (variable: "LOCALAPPDATA")
Microsoft.Testing.Platform.UnitTests.Microsoft.Testing.Platform.UnitTests.TelemetryManagerTests.TelemetryManager_SentinelIsWrittenPerUserAndAvoidsShowingNoticeOnSubsequentRuns(string) (variable: "HOME")
Microsoft.Testing.Platform.UnitTests.Microsoft.Testing.Platform.UnitTests.TelemetryManagerTests.TelemetryManager_SentinelIsWrittenPerUserAndAvoidsShowingNoticeOnSubsequentRuns(string) (variable: "LOCALAPPDATA")
Microsoft.Testing.Platform.UnitTests.Microsoft.Testing.Platform.UnitTests.TelemetryManagerTests.TelemetryManager_SentinelIsWrittenOnlyWhenUserWouldSeeTheMessage()
Microsoft.Testing.Platform.UnitTests.Microsoft.Testing.Platform.UnitTests.TelemetryManagerTests.TelemetryManager_SentinelIsWrittenPerUserAndAvoidsShowingNoticeOnSubsequentRuns()
Microsoft.Testing.Platform.UnitTests.Microsoft.Testing.Platform.UnitTests.TelemetryManagerTests.TelemetryManager_UsingNoBannerCommandLine_ShouldSuppressTelemetryMessage()
Microsoft.Testing.Platform.UnitTests.Microsoft.Testing.Platform.UnitTests.TelemetryManagerTests.TelemetryManager_UsingNoLogoShouldSuppressTelemetryMessage(string, string) (variable: "DOTNET_NOLOGO", value: "0")
Microsoft.Testing.Platform.UnitTests.Microsoft.Testing.Platform.UnitTests.TelemetryManagerTests.TelemetryManager_UsingNoLogoShouldSuppressTelemetryMessage(string, string) (variable: "DOTNET_NOLOGO", value: "1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,8 @@ Microsoft.Testing.Platform.UnitTests.Microsoft.Testing.Platform.UnitTests.TaskEx
Microsoft.Testing.Platform.UnitTests.Microsoft.Testing.Platform.UnitTests.TaskExtensionsTests.TimeoutAfterAsync_CancellationToken_Succeeds()
Microsoft.Testing.Platform.UnitTests.Microsoft.Testing.Platform.UnitTests.TaskExtensionsTests.TimeoutAfterAsync_CancellationTokenNone_Succeeds()
Microsoft.Testing.Platform.UnitTests.Microsoft.Testing.Platform.UnitTests.TaskExtensionsTests.TimeoutAfterAsync_Succeeds()
Microsoft.Testing.Platform.UnitTests.Microsoft.Testing.Platform.UnitTests.TelemetryManagerTests.TelemetryManager_SentinelIsWrittenOnlyWhenUserWouldSeeTheMessage(string) (variable: "HOME")
Microsoft.Testing.Platform.UnitTests.Microsoft.Testing.Platform.UnitTests.TelemetryManagerTests.TelemetryManager_SentinelIsWrittenOnlyWhenUserWouldSeeTheMessage(string) (variable: "LOCALAPPDATA")
Microsoft.Testing.Platform.UnitTests.Microsoft.Testing.Platform.UnitTests.TelemetryManagerTests.TelemetryManager_SentinelIsWrittenPerUserAndAvoidsShowingNoticeOnSubsequentRuns(string) (variable: "HOME")
Microsoft.Testing.Platform.UnitTests.Microsoft.Testing.Platform.UnitTests.TelemetryManagerTests.TelemetryManager_SentinelIsWrittenPerUserAndAvoidsShowingNoticeOnSubsequentRuns(string) (variable: "LOCALAPPDATA")
Microsoft.Testing.Platform.UnitTests.Microsoft.Testing.Platform.UnitTests.TelemetryManagerTests.TelemetryManager_SentinelIsWrittenOnlyWhenUserWouldSeeTheMessage()
Microsoft.Testing.Platform.UnitTests.Microsoft.Testing.Platform.UnitTests.TelemetryManagerTests.TelemetryManager_SentinelIsWrittenPerUserAndAvoidsShowingNoticeOnSubsequentRuns()
Microsoft.Testing.Platform.UnitTests.Microsoft.Testing.Platform.UnitTests.TelemetryManagerTests.TelemetryManager_UsingNoBannerCommandLine_ShouldSuppressTelemetryMessage()
Microsoft.Testing.Platform.UnitTests.Microsoft.Testing.Platform.UnitTests.TelemetryManagerTests.TelemetryManager_UsingNoLogoShouldSuppressTelemetryMessage(string, string) (variable: "DOTNET_NOLOGO", value: "0")
Microsoft.Testing.Platform.UnitTests.Microsoft.Testing.Platform.UnitTests.TelemetryManagerTests.TelemetryManager_UsingNoLogoShouldSuppressTelemetryMessage(string, string) (variable: "DOTNET_NOLOGO", value: "1")
Expand Down