2017-11-27 18:45:43 +00:00
|
|
|
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
|
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using FluentAssertions;
|
2018-03-23 19:40:58 +00:00
|
|
|
using Microsoft.DotNet.Cli.Utils;
|
2017-12-04 22:13:24 +00:00
|
|
|
using Microsoft.DotNet.Configurer;
|
2018-01-13 17:40:48 +00:00
|
|
|
using Microsoft.DotNet.Tools;
|
2017-11-27 18:45:43 +00:00
|
|
|
using Microsoft.DotNet.Tools.Test.Utilities;
|
|
|
|
using Microsoft.Extensions.DependencyModel.Tests;
|
2018-03-23 19:40:58 +00:00
|
|
|
using Moq;
|
2017-11-27 18:45:43 +00:00
|
|
|
using Xunit;
|
|
|
|
|
2017-12-04 22:13:24 +00:00
|
|
|
namespace Microsoft.DotNet.ShellShim.Tests
|
2017-11-27 18:45:43 +00:00
|
|
|
{
|
|
|
|
public class LinuxEnvironmentPathTests
|
|
|
|
{
|
|
|
|
[Fact]
|
2018-03-23 19:40:58 +00:00
|
|
|
public void GivenPathNotSetItPrintsManualInstructions()
|
2017-11-27 18:45:43 +00:00
|
|
|
{
|
2018-01-18 03:26:52 +00:00
|
|
|
var reporter = new BufferedReporter();
|
2018-03-23 19:40:58 +00:00
|
|
|
var toolsPath = new BashPathUnderHomeDirectory("/home/user", ".dotnet/tools");
|
|
|
|
var pathValue = @"/usr/bin";
|
|
|
|
var provider = new Mock<IEnvironmentProvider>(MockBehavior.Strict);
|
|
|
|
|
|
|
|
provider
|
|
|
|
.Setup(p => p.GetEnvironmentVariable("PATH"))
|
|
|
|
.Returns(pathValue);
|
|
|
|
|
|
|
|
var environmentPath = new LinuxEnvironmentPath(
|
|
|
|
toolsPath,
|
2018-01-18 03:26:52 +00:00
|
|
|
reporter,
|
2018-03-23 19:40:58 +00:00
|
|
|
provider.Object,
|
|
|
|
FileSystemMockBuilder.Empty.File);
|
2017-11-27 18:45:43 +00:00
|
|
|
|
2018-03-23 19:40:58 +00:00
|
|
|
environmentPath.PrintAddPathInstructionIfPathDoesNotExist();
|
2017-11-27 18:45:43 +00:00
|
|
|
|
2018-01-18 03:26:52 +00:00
|
|
|
reporter.Lines.Should().Equal(
|
2018-01-13 17:40:48 +00:00
|
|
|
string.Format(
|
2018-01-28 21:35:04 +00:00
|
|
|
CommonLocalizableStrings.EnvironmentPathLinuxManualInstructions,
|
2018-03-23 19:40:58 +00:00
|
|
|
toolsPath.Path));
|
2017-11-27 18:45:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
2018-03-23 19:40:58 +00:00
|
|
|
public void GivenPathNotSetAndProfileExistsItPrintsLogoutMessage()
|
|
|
|
{
|
|
|
|
var reporter = new BufferedReporter();
|
|
|
|
var toolsPath = new BashPathUnderHomeDirectory("/home/user", ".dotnet/tools");
|
|
|
|
var pathValue = @"/usr/bin";
|
|
|
|
var provider = new Mock<IEnvironmentProvider>(MockBehavior.Strict);
|
|
|
|
|
|
|
|
provider
|
|
|
|
.Setup(p => p.GetEnvironmentVariable("PATH"))
|
|
|
|
.Returns(pathValue);
|
|
|
|
|
|
|
|
var environmentPath = new LinuxEnvironmentPath(
|
|
|
|
toolsPath,
|
|
|
|
reporter,
|
|
|
|
provider.Object,
|
|
|
|
new FileSystemMockBuilder()
|
|
|
|
.AddFile(LinuxEnvironmentPath.DotnetCliToolsProfilePath, "")
|
|
|
|
.Build()
|
|
|
|
.File);
|
|
|
|
|
|
|
|
environmentPath.PrintAddPathInstructionIfPathDoesNotExist();
|
|
|
|
|
|
|
|
reporter.Lines.Should().Equal(CommonLocalizableStrings.EnvironmentPathLinuxNeedLogout);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Theory]
|
|
|
|
[InlineData("/home/user/.dotnet/tools")]
|
|
|
|
[InlineData("~/.dotnet/tools")]
|
|
|
|
public void GivenPathSetItPrintsNothing(string toolsDiretoryOnPath)
|
2017-11-27 18:45:43 +00:00
|
|
|
{
|
2018-01-18 03:26:52 +00:00
|
|
|
var reporter = new BufferedReporter();
|
2018-03-23 19:40:58 +00:00
|
|
|
var toolsPath = new BashPathUnderHomeDirectory("/home/user", ".dotnet/tools");
|
|
|
|
var pathValue = @"/usr/bin";
|
|
|
|
var provider = new Mock<IEnvironmentProvider>(MockBehavior.Strict);
|
|
|
|
|
|
|
|
provider
|
|
|
|
.Setup(p => p.GetEnvironmentVariable("PATH"))
|
|
|
|
.Returns(pathValue + ":" + toolsDiretoryOnPath);
|
|
|
|
|
|
|
|
var environmentPath = new LinuxEnvironmentPath(
|
|
|
|
toolsPath,
|
2018-01-18 03:26:52 +00:00
|
|
|
reporter,
|
2018-03-23 19:40:58 +00:00
|
|
|
provider.Object,
|
|
|
|
FileSystemMockBuilder.Empty.File);
|
2017-11-27 18:45:43 +00:00
|
|
|
|
2018-03-23 19:40:58 +00:00
|
|
|
environmentPath.PrintAddPathInstructionIfPathDoesNotExist();
|
2017-11-27 18:45:43 +00:00
|
|
|
|
2018-01-18 03:26:52 +00:00
|
|
|
reporter.Lines.Should().BeEmpty();
|
2017-11-27 18:45:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
2018-03-23 19:40:58 +00:00
|
|
|
public void GivenPathSetItDoesNotAddPathToEnvironment()
|
2017-11-27 18:45:43 +00:00
|
|
|
{
|
2018-01-18 03:26:52 +00:00
|
|
|
var reporter = new BufferedReporter();
|
2018-03-23 19:40:58 +00:00
|
|
|
var toolsPath = new BashPathUnderHomeDirectory("/home/user", ".dotnet/tools");
|
|
|
|
var pathValue = @"/usr/bin";
|
|
|
|
var provider = new Mock<IEnvironmentProvider>(MockBehavior.Strict);
|
|
|
|
var fileSystem = new FileSystemMockBuilder().Build().File;
|
|
|
|
|
|
|
|
provider
|
|
|
|
.Setup(p => p.GetEnvironmentVariable("PATH"))
|
|
|
|
.Returns(pathValue + ":" + toolsPath.Path);
|
|
|
|
|
|
|
|
var environmentPath = new LinuxEnvironmentPath(
|
|
|
|
toolsPath,
|
2018-01-18 03:26:52 +00:00
|
|
|
reporter,
|
2018-03-23 19:40:58 +00:00
|
|
|
provider.Object,
|
|
|
|
fileSystem);
|
|
|
|
|
|
|
|
environmentPath.AddPackageExecutablePathToUserPath();
|
|
|
|
|
|
|
|
reporter.Lines.Should().BeEmpty();
|
|
|
|
|
|
|
|
fileSystem
|
|
|
|
.Exists(LinuxEnvironmentPath.DotnetCliToolsProfilePath)
|
|
|
|
.Should()
|
|
|
|
.Be(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void GivenPathNotSetItAddsToEnvironment()
|
|
|
|
{
|
|
|
|
var reporter = new BufferedReporter();
|
|
|
|
var toolsPath = new BashPathUnderHomeDirectory("/home/user", ".dotnet/tools");
|
|
|
|
var pathValue = @"/usr/bin";
|
|
|
|
var provider = new Mock<IEnvironmentProvider>(MockBehavior.Strict);
|
|
|
|
var fileSystem = new FileSystemMockBuilder().Build().File;
|
|
|
|
|
|
|
|
provider
|
|
|
|
.Setup(p => p.GetEnvironmentVariable("PATH"))
|
|
|
|
.Returns(pathValue);
|
|
|
|
|
|
|
|
var environmentPath = new LinuxEnvironmentPath(
|
|
|
|
toolsPath,
|
|
|
|
reporter,
|
|
|
|
provider.Object,
|
|
|
|
fileSystem);
|
|
|
|
|
|
|
|
environmentPath.AddPackageExecutablePathToUserPath();
|
|
|
|
|
|
|
|
reporter.Lines.Should().BeEmpty();
|
|
|
|
|
|
|
|
fileSystem
|
|
|
|
.ReadAllText(LinuxEnvironmentPath.DotnetCliToolsProfilePath)
|
|
|
|
.Should()
|
|
|
|
.Be($"export PATH=\"$PATH:{toolsPath.PathWithDollar}\"");
|
2017-11-27 18:45:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|