Skip to content

Commit df1c650

Browse files
committed
[TESTS] tool-install/tool-update: Respect RestoreActionConfig options
1 parent f85f664 commit df1c650

File tree

4 files changed

+142
-3
lines changed

4 files changed

+142
-3
lines changed

src/Tests/dotnet.Tests/CommandTests/ToolInstallGlobalOrToolPathCommandTests.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,30 @@ public ToolInstallGlobalOrToolPathCommandTests(ITestOutputHelper log): base(log)
6363
_parseResult = Parser.Instance.Parse($"dotnet tool install -g {PackageId}");
6464
}
6565

66+
[Fact]
67+
public void WhenPassingRestoreActionConfigOptions()
68+
{
69+
var parseResult = Parser.Instance.Parse($"dotnet tool install -g {PackageId} --ignore-failed-sources");
70+
var toolInstallCommand = new ToolInstallGlobalOrToolPathCommand(parseResult);
71+
toolInstallCommand._restoreActionConfig.IgnoreFailedSources.Should().BeTrue();
72+
}
73+
74+
[Fact]
75+
public void WhenPassingIgnoreFailedSourcesItShouldNotThrow()
76+
{
77+
_fileSystem.File.WriteAllText(Path.Combine(_temporaryDirectory, "nuget.config"), _nugetConfigWithInvalidSources);
78+
79+
var toolInstallGlobalOrToolPathCommand = new ToolInstallGlobalOrToolPathCommand(
80+
_parseResult,
81+
_createToolPackageStoresAndDownloader,
82+
_createShellShimRepository,
83+
_environmentPathInstructionMock,
84+
_reporter);
85+
86+
toolInstallGlobalOrToolPathCommand.Execute().Should().Be(0);
87+
_fileSystem.File.Delete(Path.Combine(_temporaryDirectory, "nuget.config"));
88+
}
89+
6690
[Fact]
6791
public void WhenRunWithPackageIdItShouldCreateValidShim()
6892
{
@@ -630,6 +654,16 @@ public void SetPermission(string path, string chmodArgument)
630654
{
631655
}
632656
}
657+
658+
private string _nugetConfigWithInvalidSources = @"{
659+
<?xml version=""1.0"" encoding=""utf-8""?>
660+
<configuration>
661+
<packageSources>
662+
<add key=""nuget"" value=""https://api.nuget.org/v3/index.json"" />
663+
<add key=""invalid_source"" value=""https://api.nuget.org/v3/invalid.json"" />
664+
</packageSources>
665+
</configuration>
666+
}";
633667
}
634668
}
635669

src/Tests/dotnet.Tests/CommandTests/ToolInstallLocalCommandTests.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,32 @@ public ToolInstallLocalCommandTests(ITestOutputHelper log):base(log)
9696
1);
9797
}
9898

99+
[Fact]
100+
public void WhenPassingRestoreActionConfigOptions()
101+
{
102+
var parseResult = Parser.Instance.Parse($"dotnet tool install {_packageIdA.ToString()} --ignore-failed-sources");
103+
var command = new ToolInstallLocalCommand(parseResult);
104+
command._restoreActionConfig.IgnoreFailedSources.Should().BeTrue();
105+
}
106+
107+
[Fact]
108+
public void WhenPassingIgnoreFailedSourcesItShouldNotThrow()
109+
{
110+
_fileSystem.File.WriteAllText(Path.Combine(_temporaryDirectory, "nuget.config"), _nugetConfigWithInvalidSources);
111+
var parseResult = Parser.Instance.Parse($"dotnet tool install {_packageIdA.ToString()} --ignore-failed-sources");
112+
var installLocalCommand = new ToolInstallLocalCommand(
113+
parseResult,
114+
_toolPackageDownloaderMock,
115+
_toolManifestFinder,
116+
_toolManifestEditor,
117+
_localToolsResolverCache,
118+
_reporter);
119+
120+
installLocalCommand.Execute().Should().Be(0);
121+
122+
_fileSystem.File.Delete(Path.Combine(_temporaryDirectory, "nuget.config"));
123+
}
124+
99125
[Fact]
100126
public void WhenRunWithPackageIdItShouldSaveToCacheAndAddToManifestFile()
101127
{
@@ -440,6 +466,16 @@ out RestoredCommand restoredCommand
440466
""isRoot"":true,
441467
""tools"":{
442468
}
469+
}";
470+
471+
private string _nugetConfigWithInvalidSources = @"{
472+
<?xml version=""1.0"" encoding=""utf-8""?>
473+
<configuration>
474+
<packageSources>
475+
<add key=""nuget"" value=""https://api.nuget.org/v3/index.json"" />
476+
<add key=""invalid_source"" value=""https://api.nuget.org/v3/invalid.json"" />
477+
</packageSources>
478+
</configuration>
443479
}";
444480
}
445481
}

src/Tests/dotnet.Tests/CommandTests/ToolUpdateGlobalOrToolPathCommandTests.cs

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
using Microsoft.DotNet.ShellShim;
1313
using System.CommandLine;
1414
using Parser = Microsoft.DotNet.Cli.Parser;
15+
using Microsoft.DotNet.InternalAbstractions;
16+
using Microsoft.DotNet.Tools.Tool.Uninstall;
1517

1618
namespace Microsoft.DotNet.Tests.Commands.Tool
1719
{
@@ -28,14 +30,15 @@ public class ToolUpdateGlobalOrToolPathCommandTests
2830
private const string HigherPreviewPackageVersion = "1.0.5-preview3";
2931
private readonly string _shimsDirectory;
3032
private readonly string _toolsDirectory;
33+
private readonly string _tempDirectory;
3134

3235
public ToolUpdateGlobalOrToolPathCommandTests()
3336
{
3437
_reporter = new BufferedReporter();
3538
_fileSystem = new FileSystemMockBuilder().UseCurrentSystemTemporaryDirectory().Build();
36-
var tempDirectory = _fileSystem.Directory.CreateTemporaryDirectory().DirectoryPath;
37-
_shimsDirectory = Path.Combine(tempDirectory, "shims");
38-
_toolsDirectory = Path.Combine(tempDirectory, "tools");
39+
_tempDirectory = _fileSystem.Directory.CreateTemporaryDirectory().DirectoryPath;
40+
_shimsDirectory = Path.Combine(_tempDirectory, "shims");
41+
_toolsDirectory = Path.Combine(_tempDirectory, "tools");
3942
_environmentPathInstructionMock = new EnvironmentPathInstructionMock(_reporter, _shimsDirectory);
4043
_store = new ToolPackageStoreMock(new DirectoryPath(_toolsDirectory), _fileSystem);
4144
_mockFeeds = new List<MockFeed>
@@ -68,6 +71,25 @@ public ToolUpdateGlobalOrToolPathCommandTests()
6871
};
6972
}
7073

74+
[Fact]
75+
public void WhenPassingRestoreActionConfigOptions()
76+
{
77+
var parseResult = Parser.Instance.Parse($"dotnet tool update -g {_packageId} --ignore-failed-sources");
78+
var toolUpdateCommand = new ToolUpdateGlobalOrToolPathCommand(parseResult);
79+
toolUpdateCommand._restoreActionConfig.IgnoreFailedSources.Should().BeTrue();
80+
}
81+
82+
[Fact]
83+
public void WhenPassingIgnoreFailedSourcesItShouldNotThrow()
84+
{
85+
_fileSystem.File.WriteAllText(Path.Combine(_tempDirectory, "nuget.config"), _nugetConfigWithInvalidSources);
86+
87+
var command = CreateUpdateCommand($"-g {_packageId} --ignore-failed-sources");
88+
89+
command.Execute().Should().Be(0);
90+
_fileSystem.File.Delete(Path.Combine(_tempDirectory, "nuget.config"));
91+
}
92+
7193
[Fact]
7294
public void GivenANonFeedExistentPackageItErrors()
7395
{
@@ -373,6 +395,16 @@ private ShellShimRepository GetMockedShellShimRepository()
373395
appHostShellShimMaker: new AppHostShellShimMakerMock(_fileSystem),
374396
filePermissionSetter: new ToolInstallGlobalOrToolPathCommandTests.NoOpFilePermissionSetter());
375397
}
398+
399+
private string _nugetConfigWithInvalidSources = @"{
400+
<?xml version=""1.0"" encoding=""utf-8""?>
401+
<configuration>
402+
<packageSources>
403+
<add key=""nuget"" value=""https://api.nuget.org/v3/index.json"" />
404+
<add key=""invalid_source"" value=""https://api.nuget.org/v3/invalid.json"" />
405+
</packageSources>
406+
</configuration>
407+
}";
376408
}
377409
}
378410

src/Tests/dotnet.Tests/CommandTests/ToolUpdateLocalCommandTests.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Microsoft.DotNet.ToolManifest;
88
using Microsoft.DotNet.ToolPackage;
99
using Microsoft.DotNet.Tools.Tests.ComponentMocks;
10+
using Microsoft.DotNet.Tools.Tool.Install;
1011
using Microsoft.DotNet.Tools.Tool.Restore;
1112
using Microsoft.DotNet.Tools.Tool.Update;
1213
using Microsoft.Extensions.DependencyModel.Tests;
@@ -112,6 +113,32 @@ public ToolUpdateLocalCommandTests()
112113
_reporter);
113114
}
114115

116+
[Fact]
117+
public void WhenPassingRestoreActionConfigOptions()
118+
{
119+
var parseResult = Parser.Instance.Parse($"dotnet tool update {_packageIdA.ToString()} --ignore-failed-sources");
120+
var command = new ToolUpdateLocalCommand(parseResult);
121+
command._restoreActionConfig.IgnoreFailedSources.Should().BeTrue();
122+
}
123+
124+
[Fact]
125+
public void WhenPassingIgnoreFailedSourcesItShouldNotThrow()
126+
{
127+
_fileSystem.File.WriteAllText(Path.Combine(_temporaryDirectory, "nuget.config"), _nugetConfigWithInvalidSources);
128+
var parseResult = Parser.Instance.Parse($"dotnet tool update {_packageIdA.ToString()} --ignore-failed-sources");
129+
var updateLocalCommand = new ToolUpdateLocalCommand(
130+
parseResult,
131+
_toolPackageDownloaderMock,
132+
_toolManifestFinder,
133+
_toolManifestEditor,
134+
_localToolsResolverCache,
135+
_reporter);
136+
137+
updateLocalCommand.Execute().Should().Be(0);
138+
139+
_fileSystem.File.Delete(Path.Combine(_temporaryDirectory, "nuget.config"));
140+
}
141+
115142
[Fact]
116143
public void WhenRunWithPackageIdItShouldUpdateFromManifestFile()
117144
{
@@ -349,6 +376,16 @@ out RestoredCommand restoredCommand
349376
""version"": 1,
350377
""isRoot"": false,
351378
""tools"": {}
379+
}";
380+
381+
private string _nugetConfigWithInvalidSources = @"{
382+
<?xml version=""1.0"" encoding=""utf-8""?>
383+
<configuration>
384+
<packageSources>
385+
<add key=""nuget"" value=""https://api.nuget.org/v3/index.json"" />
386+
<add key=""invalid_source"" value=""https://api.nuget.org/v3/invalid.json"" />
387+
</packageSources>
388+
</configuration>
352389
}";
353390
}
354391
}

0 commit comments

Comments
 (0)