Change --source to --source-feed and make it additional (#8833)
Other than change source to source-feed and make it additional instead of exclusive. I changed source to be multiple. Because restore support multiple source https://github.com/Microsoft/dotnet/issues/361 As for mock. The offline feed and source feed is considered the same, so remove the category of “source”. I renamed source to “AdditionalFeed” because that is more accurate on implementation level. Note: NuGet feed don’t have order. Whichever responses the fastest, is the first. No change on restore. scripts/cli-test-env.sh change is due to mac 10.13 is finally added to RID graph. And it is “considered” one of the CLI supported RID
This commit is contained in:
parent
67c4562f43
commit
9cc2b7cd2f
44 changed files with 433 additions and 362 deletions
|
@ -46,7 +46,7 @@ namespace Microsoft.DotNet.ToolPackage.Tests
|
|||
[Theory]
|
||||
[InlineData(false)]
|
||||
[InlineData(true)]
|
||||
public void GivenOfflineFeedInstallSuceeds(bool testMockBehaviorIsInSync)
|
||||
public void GivenOfflineFeedInstallSucceeds(bool testMockBehaviorIsInSync)
|
||||
{
|
||||
var (store, installer, reporter, fileSystem) = Setup(
|
||||
useMock: testMockBehaviorIsInSync,
|
||||
|
@ -63,6 +63,30 @@ namespace Microsoft.DotNet.ToolPackage.Tests
|
|||
package.Uninstall();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(false)]
|
||||
[InlineData(true)]
|
||||
public void GivenAEmptySourceAndOfflineFeedInstallSucceeds(bool testMockBehaviorIsInSync)
|
||||
{
|
||||
var emptySource = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
|
||||
Directory.CreateDirectory(emptySource);
|
||||
|
||||
var (store, installer, reporter, fileSystem) = Setup(
|
||||
useMock: testMockBehaviorIsInSync,
|
||||
offlineFeed: new DirectoryPath(GetTestLocalFeedPath()),
|
||||
feeds: GetOfflineMockFeed());
|
||||
|
||||
var package = installer.InstallPackage(
|
||||
packageId: TestPackageId,
|
||||
versionRange: VersionRange.Parse(TestPackageVersion),
|
||||
targetFramework: _testTargetframework,
|
||||
additionalFeeds: new[] {emptySource});
|
||||
|
||||
AssertPackageInstall(reporter, fileSystem, package, store);
|
||||
|
||||
package.Uninstall();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(false)]
|
||||
[InlineData(true)]
|
||||
|
@ -228,7 +252,31 @@ namespace Microsoft.DotNet.ToolPackage.Tests
|
|||
packageId: TestPackageId,
|
||||
versionRange: VersionRange.Parse(TestPackageVersion),
|
||||
targetFramework: _testTargetframework,
|
||||
source: source);
|
||||
additionalFeeds: new[] {source});
|
||||
|
||||
AssertPackageInstall(reporter, fileSystem, package, store);
|
||||
|
||||
package.Uninstall();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(false)]
|
||||
[InlineData(true)]
|
||||
public void GivenAEmptySourceAndNugetConfigInstallSucceeds(bool testMockBehaviorIsInSync)
|
||||
{
|
||||
var nugetConfigPath = WriteNugetConfigFileToPointToTheFeed();
|
||||
var emptySource = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
|
||||
Directory.CreateDirectory(emptySource);
|
||||
|
||||
var (store, installer, reporter, fileSystem) = Setup(
|
||||
useMock: testMockBehaviorIsInSync,
|
||||
feeds: GetMockFeedsForSource(emptySource));
|
||||
|
||||
var package = installer.InstallPackage(
|
||||
packageId: TestPackageId,
|
||||
versionRange: VersionRange.Parse(TestPackageVersion),
|
||||
targetFramework: _testTargetframework,
|
||||
nugetConfig: nugetConfigPath, additionalFeeds: new[] {emptySource});
|
||||
|
||||
AssertPackageInstall(reporter, fileSystem, package, store);
|
||||
|
||||
|
@ -281,7 +329,7 @@ namespace Microsoft.DotNet.ToolPackage.Tests
|
|||
packageId: TestPackageId,
|
||||
versionRange: VersionRange.Parse(TestPackageVersion),
|
||||
targetFramework: _testTargetframework,
|
||||
source: source);
|
||||
additionalFeeds: new[] {source});
|
||||
|
||||
FailedStepAfterSuccessRestore();
|
||||
t.Complete();
|
||||
|
@ -313,7 +361,7 @@ namespace Microsoft.DotNet.ToolPackage.Tests
|
|||
packageId: TestPackageId,
|
||||
versionRange: VersionRange.Parse(TestPackageVersion),
|
||||
targetFramework: _testTargetframework,
|
||||
source: source);
|
||||
additionalFeeds: new[] {source});
|
||||
|
||||
first.ShouldNotThrow();
|
||||
|
||||
|
@ -321,7 +369,7 @@ namespace Microsoft.DotNet.ToolPackage.Tests
|
|||
packageId: TestPackageId,
|
||||
versionRange: VersionRange.Parse(TestPackageVersion),
|
||||
targetFramework: _testTargetframework,
|
||||
source: source);
|
||||
additionalFeeds: new[] {source});
|
||||
|
||||
t.Complete();
|
||||
}
|
||||
|
@ -352,7 +400,7 @@ namespace Microsoft.DotNet.ToolPackage.Tests
|
|||
packageId: TestPackageId,
|
||||
versionRange: VersionRange.Parse(TestPackageVersion),
|
||||
targetFramework: _testTargetframework,
|
||||
source: source);
|
||||
additionalFeeds: new[] {source});
|
||||
|
||||
AssertPackageInstall(reporter, fileSystem, package, store);
|
||||
|
||||
|
@ -360,7 +408,7 @@ namespace Microsoft.DotNet.ToolPackage.Tests
|
|||
packageId: TestPackageId,
|
||||
versionRange: VersionRange.Parse(TestPackageVersion),
|
||||
targetFramework: _testTargetframework,
|
||||
source: source);
|
||||
additionalFeeds: new[] {source});
|
||||
|
||||
reporter.Lines.Should().BeEmpty();
|
||||
|
||||
|
@ -401,7 +449,7 @@ namespace Microsoft.DotNet.ToolPackage.Tests
|
|||
packageId: TestPackageId,
|
||||
versionRange: VersionRange.Parse(TestPackageVersion),
|
||||
targetFramework: _testTargetframework,
|
||||
source: source);
|
||||
additionalFeeds: new[] {source});
|
||||
|
||||
AssertPackageInstall(reporter, fileSystem, package, store);
|
||||
|
||||
|
@ -425,7 +473,7 @@ namespace Microsoft.DotNet.ToolPackage.Tests
|
|||
packageId: TestPackageId,
|
||||
versionRange: VersionRange.Parse(TestPackageVersion),
|
||||
targetFramework: _testTargetframework,
|
||||
source: source);
|
||||
additionalFeeds: new[] {source});
|
||||
|
||||
AssertPackageInstall(reporter, fileSystem, package, store);
|
||||
|
||||
|
@ -458,7 +506,7 @@ namespace Microsoft.DotNet.ToolPackage.Tests
|
|||
packageId: TestPackageId,
|
||||
versionRange: VersionRange.Parse(TestPackageVersion),
|
||||
targetFramework: _testTargetframework,
|
||||
source: source);
|
||||
additionalFeeds: new[] {source});
|
||||
|
||||
AssertPackageInstall(reporter, fileSystem, package, store);
|
||||
|
||||
|
@ -597,7 +645,7 @@ namespace Microsoft.DotNet.ToolPackage.Tests
|
|||
{
|
||||
new MockFeed
|
||||
{
|
||||
Type = MockFeedType.Source,
|
||||
Type = MockFeedType.ImplicitAdditionalFeed,
|
||||
Uri = source,
|
||||
Packages = new List<MockFeedPackage>
|
||||
{
|
||||
|
@ -617,7 +665,7 @@ namespace Microsoft.DotNet.ToolPackage.Tests
|
|||
{
|
||||
new MockFeed
|
||||
{
|
||||
Type = MockFeedType.OfflineFeed,
|
||||
Type = MockFeedType.ImplicitAdditionalFeed,
|
||||
Uri = GetTestLocalFeedPath(),
|
||||
Packages = new List<MockFeedPackage>
|
||||
{
|
||||
|
|
|
@ -7,7 +7,6 @@ namespace Microsoft.DotNet.Tools.Tests.ComponentMocks
|
|||
{
|
||||
FeedFromLookUpNugetConfig,
|
||||
ExplicitNugetConfig,
|
||||
Source,
|
||||
OfflineFeed
|
||||
ImplicitAdditionalFeed
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,17 +56,14 @@ namespace Microsoft.DotNet.Tools.Tests.ComponentMocks
|
|||
}
|
||||
}
|
||||
|
||||
public void Restore(
|
||||
FilePath project,
|
||||
public void Restore(FilePath project,
|
||||
DirectoryPath assetJsonOutput,
|
||||
FilePath? nugetConfig = null,
|
||||
string source = null,
|
||||
string verbosity = null)
|
||||
{
|
||||
string packageId;
|
||||
VersionRange versionRange;
|
||||
string targetFramework;
|
||||
|
||||
try
|
||||
{
|
||||
// The mock installer wrote a mock project file containing id:version:framework
|
||||
|
@ -94,8 +91,7 @@ namespace Microsoft.DotNet.Tools.Tests.ComponentMocks
|
|||
var feedPackage = GetPackage(
|
||||
packageId,
|
||||
versionRange,
|
||||
nugetConfig,
|
||||
source);
|
||||
nugetConfig);
|
||||
|
||||
var packageVersion = feedPackage.Version;
|
||||
targetFramework = string.IsNullOrEmpty(targetFramework) ? "targetFramework" : targetFramework;
|
||||
|
@ -118,49 +114,38 @@ namespace Microsoft.DotNet.Tools.Tests.ComponentMocks
|
|||
private MockFeedPackage GetPackage(
|
||||
string packageId,
|
||||
VersionRange versionRange = null,
|
||||
FilePath? nugetConfig = null,
|
||||
string source = null)
|
||||
FilePath? nugetConfig = null)
|
||||
{
|
||||
var allPackages = _feeds
|
||||
.Where(f => {
|
||||
var allPackages = _feeds
|
||||
.Where(f =>
|
||||
{
|
||||
if (nugetConfig != null)
|
||||
{
|
||||
return f.Type == MockFeedType.ExplicitNugetConfig && f.Uri == nugetConfig.Value.Value;
|
||||
}
|
||||
if (source != null)
|
||||
{
|
||||
return f.Type == MockFeedType.Source && f.Uri == source;
|
||||
return ExcludeOtherFeeds(nugetConfig, f);
|
||||
}
|
||||
|
||||
return true;
|
||||
})
|
||||
.SelectMany(f => f.Packages)
|
||||
.Where(f => f.PackageId == packageId);
|
||||
|
||||
var bestVersion = versionRange.FindBestMatch(allPackages.Select(p => NuGetVersion.Parse(p.Version)));
|
||||
var bestVersion = versionRange.FindBestMatch(allPackages.Select(p => NuGetVersion.Parse(p.Version)));
|
||||
|
||||
var package = allPackages.Where(p => NuGetVersion.Parse(p.Version).Equals(bestVersion)).FirstOrDefault();
|
||||
|
||||
if (package == null)
|
||||
{
|
||||
if (_reporter != null)
|
||||
{
|
||||
_reporter.WriteLine($"Error: failed to restore package {packageId}.");
|
||||
}
|
||||
_reporter?.WriteLine($"Error: failed to restore package {packageId}.");
|
||||
throw new ToolPackageException(LocalizableStrings.ToolInstallationRestoreFailed);
|
||||
}
|
||||
|
||||
return package;
|
||||
}
|
||||
|
||||
private static bool MatchPackage(MockFeedPackage p, string packageId, VersionRange versionRange)
|
||||
private static bool ExcludeOtherFeeds(FilePath? nugetConfig, MockFeed f)
|
||||
{
|
||||
if (string.Compare(p.PackageId, packageId, StringComparison.CurrentCultureIgnoreCase) != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return versionRange == null ||
|
||||
versionRange.FindBestMatch(new[] { NuGetVersion.Parse(p.Version) }) != null;
|
||||
return f.Type == MockFeedType.ImplicitAdditionalFeed
|
||||
|| (f.Type == MockFeedType.ExplicitNugetConfig && f.Uri == nugetConfig.Value.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,13 +35,12 @@ namespace Microsoft.DotNet.Tools.Tests.ComponentMocks
|
|||
_installCallback = installCallback;
|
||||
}
|
||||
|
||||
public IToolPackage InstallPackage(
|
||||
PackageId packageId,
|
||||
public IToolPackage InstallPackage(PackageId packageId,
|
||||
VersionRange versionRange = null,
|
||||
string targetFramework = null,
|
||||
FilePath? nugetConfig = null,
|
||||
DirectoryPath? rootConfigDirectory = null,
|
||||
string source = null,
|
||||
string[] additionalFeeds = null,
|
||||
string verbosity = null)
|
||||
{
|
||||
var packageRootDirectory = _store.GetRootPackageDirectory(packageId);
|
||||
|
@ -65,7 +64,6 @@ namespace Microsoft.DotNet.Tools.Tests.ComponentMocks
|
|||
tempProject,
|
||||
stageDirectory,
|
||||
nugetConfig,
|
||||
source,
|
||||
verbosity);
|
||||
|
||||
if (_installCallback != null)
|
||||
|
|
|
@ -81,17 +81,17 @@ namespace Microsoft.DotNet.Tests.Commands
|
|||
public void WhenRunWithPackageIdWithSourceItShouldCreateValidShim()
|
||||
{
|
||||
const string sourcePath = "http://mysouce.com";
|
||||
ParseResult result = Parser.Instance.Parse($"dotnet install tool -g {PackageId} --source {sourcePath}");
|
||||
ParseResult result = Parser.Instance.Parse($"dotnet install tool -g {PackageId} --source-feed {sourcePath}");
|
||||
AppliedOption appliedCommand = result["dotnet"]["install"]["tool"];
|
||||
ParseResult parseResult =
|
||||
Parser.Instance.ParseFrom("dotnet install", new[] { "tool", PackageId, "--source", sourcePath });
|
||||
Parser.Instance.ParseFrom("dotnet install", new[] { "tool", PackageId, "--source-feed", sourcePath });
|
||||
|
||||
|
||||
var toolToolPackageInstaller = CreateToolPackageInstaller(
|
||||
feeds: new MockFeed[] {
|
||||
new MockFeed
|
||||
{
|
||||
Type = MockFeedType.Source,
|
||||
Type = MockFeedType.ImplicitAdditionalFeed,
|
||||
Uri = sourcePath,
|
||||
Packages = new List<MockFeedPackage>
|
||||
{
|
||||
|
|
|
@ -54,10 +54,29 @@ namespace Microsoft.DotNet.Tests.ParserTests
|
|||
{
|
||||
const string expectedSourceValue = "TestSourceValue";
|
||||
|
||||
var result = Parser.Instance.Parse($"dotnet install tool -g --source {expectedSourceValue} console.test.app");
|
||||
var result =
|
||||
Parser.Instance.Parse($"dotnet install tool -g --source-feed {expectedSourceValue} console.test.app");
|
||||
|
||||
var appliedOptions = result["dotnet"]["install"]["tool"];
|
||||
appliedOptions.ValueOrDefault<string>("source").Should().Be(expectedSourceValue);
|
||||
appliedOptions.ValueOrDefault<string[]>("source-feed").First().Should().Be(expectedSourceValue);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InstallToolParserCanParseMultipleSourceOption()
|
||||
{
|
||||
const string expectedSourceValue1 = "TestSourceValue1";
|
||||
const string expectedSourceValue2 = "TestSourceValue2";
|
||||
|
||||
var result =
|
||||
Parser.Instance.Parse(
|
||||
$"dotnet install tool -g " +
|
||||
$"--source-feed {expectedSourceValue1} " +
|
||||
$"--source-feed {expectedSourceValue2} console.test.app");
|
||||
|
||||
var appliedOptions = result["dotnet"]["install"]["tool"];
|
||||
|
||||
appliedOptions.ValueOrDefault<string[]>("source-feed")[0].Should().Be(expectedSourceValue1);
|
||||
appliedOptions.ValueOrDefault<string[]>("source-feed")[1].Should().Be(expectedSourceValue2);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
@ -62,10 +62,28 @@ namespace Microsoft.DotNet.Tests.ParserTests
|
|||
const string expectedSourceValue = "TestSourceValue";
|
||||
|
||||
var result =
|
||||
Parser.Instance.Parse($"dotnet update tool -g --source {expectedSourceValue} console.test.app");
|
||||
Parser.Instance.Parse($"dotnet update tool -g --source-feed {expectedSourceValue} console.test.app");
|
||||
|
||||
var appliedOptions = result["dotnet"]["update"]["tool"];
|
||||
appliedOptions.ValueOrDefault<string>("source").Should().Be(expectedSourceValue);
|
||||
appliedOptions.ValueOrDefault<string[]>("source-feed").First().Should().Be(expectedSourceValue);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UpdateToolParserCanParseMultipleSourceOption()
|
||||
{
|
||||
const string expectedSourceValue1 = "TestSourceValue1";
|
||||
const string expectedSourceValue2 = "TestSourceValue2";
|
||||
|
||||
var result =
|
||||
Parser.Instance.Parse(
|
||||
$"dotnet update tool -g " +
|
||||
$"--source-feed {expectedSourceValue1} " +
|
||||
$"--source-feed {expectedSourceValue2} console.test.app");
|
||||
|
||||
var appliedOptions = result["dotnet"]["update"]["tool"];
|
||||
|
||||
appliedOptions.ValueOrDefault<string[]>("source-feed")[0].Should().Be(expectedSourceValue1);
|
||||
appliedOptions.ValueOrDefault<string[]>("source-feed")[1].Should().Be(expectedSourceValue2);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue