From 7bb693bff557f0edf80da4c3322aa6a389ed2fe4 Mon Sep 17 00:00:00 2001 From: Livar Cunha Date: Tue, 28 Aug 2018 17:16:58 -0700 Subject: [PATCH] We have a few tests that write their own NuGet.Config file to use during restore. Those tests need access to the ExternalRestoreSources value to be added to this NuGet config so that they can restore properly. This change writes a file in the test/artifacts folder containing the value of ExternalRestoreSources value. The tests can then use it to write that to their NuGet.Config. There is a failure in ProdCon that this addresses. --- build/Test.targets | 6 ++++ .../GivenAProjectToolsCommandResolver.cs | 4 +-- .../TestAssetInstance.cs | 8 +++-- .../RepoDirectoriesProvider.cs | 4 +++ .../TestAssetInstanceExtensions.cs | 33 +++++++++++++++++++ 5 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 test/Microsoft.DotNet.Tools.Tests.Utilities/TestAssetInstanceExtensions.cs diff --git a/build/Test.targets b/build/Test.targets index 9f4ce8778..f9642c6a3 100644 --- a/build/Test.targets +++ b/build/Test.targets @@ -10,6 +10,7 @@ $(TestOutputDir)/packages/ $(TestOutputDir)/artifacts/ $(TestOutputDir)/results/ + $(TestArtifactsDir)/ExternalRestoreSourcesForTestsContainer.txt + + + $externalRestoreSources$ "; - content = content.Replace("$fullpath$", nugetCache); + content = content + .Replace("$fullpath$", nugetCache) + .Replace("$externalRestoreSources$", externalRestoreSources); using (var newNuGetConfigStream = new FileStream(newNuGetConfig.FullName, FileMode.Create, FileAccess.Write)) diff --git a/test/Microsoft.DotNet.Tools.Tests.Utilities/RepoDirectoriesProvider.cs b/test/Microsoft.DotNet.Tools.Tests.Utilities/RepoDirectoriesProvider.cs index 7de277852..de2af4896 100644 --- a/test/Microsoft.DotNet.Tools.Tests.Utilities/RepoDirectoriesProvider.cs +++ b/test/Microsoft.DotNet.Tools.Tests.Utilities/RepoDirectoriesProvider.cs @@ -22,6 +22,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities private string _stage2WithBackwardsCompatibleRuntimesDirectory; private string _testPackages; private string _testWorkingFolder; + private string _testArtifactsFolder; public static string RepoRoot { @@ -92,6 +93,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities public string Stage2WithBackwardsCompatibleRuntimesDirectory => _stage2WithBackwardsCompatibleRuntimesDirectory; public string TestPackages => _testPackages; public string TestWorkingFolder => _testWorkingFolder; + public string TestArtifactsFolder => _testArtifactsFolder; public RepoDirectoriesProvider( string artifacts = null, @@ -123,6 +125,8 @@ namespace Microsoft.DotNet.Tools.Test.Utilities _testPackages = Path.Combine(_artifacts, "test", "packages"); } + _testArtifactsFolder = Path.Combine(_artifacts, "test", "artifacts"); + _testWorkingFolder = Path.Combine(RepoRoot, "bin", (previousStage + 1).ToString(), diff --git a/test/Microsoft.DotNet.Tools.Tests.Utilities/TestAssetInstanceExtensions.cs b/test/Microsoft.DotNet.Tools.Tests.Utilities/TestAssetInstanceExtensions.cs new file mode 100644 index 000000000..a1cf95916 --- /dev/null +++ b/test/Microsoft.DotNet.Tools.Tests.Utilities/TestAssetInstanceExtensions.cs @@ -0,0 +1,33 @@ +// 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 System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; +using Microsoft.DotNet.Cli.Utils; +using Microsoft.DotNet.TestFramework; +using Microsoft.DotNet.Tools.Common; + +namespace Microsoft.DotNet.Tools.Test.Utilities +{ + public static class TestAssetInstanceExtensions + { + public static TestAssetInstance WithNuGetConfigAndExternalRestoreSources( + this TestAssetInstance testAssetInstance, string nugetCache) + { + var externalRestoreSourcesForTests = Path.Combine( + new RepoDirectoriesProvider().TestArtifactsFolder, "ExternalRestoreSourcesForTestsContainer.txt"); + var externalRestoreSources = File.Exists(externalRestoreSourcesForTests) ? + File.ReadAllText(externalRestoreSourcesForTests) : + string.Empty; + + return testAssetInstance.WithNuGetConfig(nugetCache, externalRestoreSources); + } + } +} \ No newline at end of file