From 018ab370ca45a9f3230ef92d82266ae32cc02f58 Mon Sep 17 00:00:00 2001 From: Marc Paine Date: Thu, 27 Jul 2023 13:32:57 -0700 Subject: [PATCH 1/2] One option for fixing the locked file issue in the test --- .../dotnet-new.Tests/BaseIntegrationTest.cs | 21 ++++++++++++++++++- .../TemplateDiscoveryTests.cs | 4 ++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/Tests/dotnet-new.Tests/BaseIntegrationTest.cs b/src/Tests/dotnet-new.Tests/BaseIntegrationTest.cs index d9a3400ce769..44aa40b3a8ac 100644 --- a/src/Tests/dotnet-new.Tests/BaseIntegrationTest.cs +++ b/src/Tests/dotnet-new.Tests/BaseIntegrationTest.cs @@ -141,7 +141,11 @@ internal static string PackTestNuGetPackage(ITestOutputHelper log, [CallerMember { string outputLocation = CreateTemporaryFolder(testName, "TestNuGetPackage"); - new DotnetPackCommand(log, DotnetNewTestTemplatePackageProjectPath, "-o", outputLocation) + CopyFilesRecursively(Path.GetDirectoryName(DotnetNewTestTemplatePackageProjectPath)!, outputLocation); + + string projectName = Path.GetFileName(DotnetNewTestTemplatePackageProjectPath); + + new DotnetPackCommand(log, $"{outputLocation}\\{projectName}", $"-p:BaseIntermediateOutputPath={outputLocation}\\", "-o", outputLocation) .Execute() .Should() .Pass(); @@ -185,5 +189,20 @@ private static string GetAndVerifyRepoRoot() return repoRoot; } + private static void CopyFilesRecursively(string sourcePath, string targetPath) + { + //Now Create all of the directories + foreach (string dirPath in Directory.GetDirectories(sourcePath, "*", SearchOption.AllDirectories)) + { + Directory.CreateDirectory(dirPath.Replace(sourcePath, targetPath)); + } + + //Copy all the files & Replaces any files with the same name + foreach (string newPath in Directory.GetFiles(sourcePath, "*.*", SearchOption.AllDirectories)) + { + File.Copy(newPath, newPath.Replace(sourcePath, targetPath), true); + } + } + } } diff --git a/src/Tests/dotnet-new.Tests/TemplateDiscoveryTests.cs b/src/Tests/dotnet-new.Tests/TemplateDiscoveryTests.cs index de25bae9722c..a72b48749cb2 100644 --- a/src/Tests/dotnet-new.Tests/TemplateDiscoveryTests.cs +++ b/src/Tests/dotnet-new.Tests/TemplateDiscoveryTests.cs @@ -24,11 +24,11 @@ public async Task CanRunDiscoveryTool() { string home = CreateTemporaryFolder(folderName: "Home"); string testDir = CreateTemporaryFolder(); - string testTemplatesPpackagePath = PackTestNuGetPackage(_log); + string testTemplatesPackagePath = PackTestNuGetPackage(_log); using var packageManager = new PackageManager(); string packagePath = await packageManager.GetNuGetPackage( templatePackName: "Microsoft.Azure.WebJobs.ProjectTemplates", - downloadDirectory: Path.GetDirectoryName(testTemplatesPpackagePath)) + downloadDirectory: Path.GetDirectoryName(testTemplatesPackagePath)) .ConfigureAwait(false); _templateDiscoveryTool.Run( From 82cde6ee47aae61a4bb5b3dde4115dacf2af38d5 Mon Sep 17 00:00:00 2001 From: Marc Paine Date: Fri, 4 Aug 2023 10:28:56 -0700 Subject: [PATCH 2/2] Change the implementation of the fix to use CopyTestAsset similar to how other SDK tests manage this --- .../dotnet-new.Tests/BaseIntegrationTest.cs | 28 ++++--------------- .../TemplateDiscoveryTests.cs | 1 - 2 files changed, 6 insertions(+), 23 deletions(-) diff --git a/src/Tests/dotnet-new.Tests/BaseIntegrationTest.cs b/src/Tests/dotnet-new.Tests/BaseIntegrationTest.cs index 44aa40b3a8ac..3d6e39447408 100644 --- a/src/Tests/dotnet-new.Tests/BaseIntegrationTest.cs +++ b/src/Tests/dotnet-new.Tests/BaseIntegrationTest.cs @@ -137,15 +137,15 @@ internal static string InstallTestTemplate(string templateName, ITestOutputHelpe /// /// Packs test template package and returns path to it. /// - internal static string PackTestNuGetPackage(ITestOutputHelper log, [CallerMemberName] string testName = "UnnamedTest") + internal string PackTestNuGetPackage(ITestOutputHelper log, [CallerMemberName] string testName = "UnnamedTest") { - string outputLocation = CreateTemporaryFolder(testName, "TestNuGetPackage"); + var testAsset = _testAssetsManager.CopyTestAsset("dotnet-new", callingMethod: testName, testAssetSubdirectory: "TestPackages").WithSource(); + string testProject = Path.GetFileName(DotnetNewTestTemplatePackageProjectPath); + string testPath = testAsset.Path; - CopyFilesRecursively(Path.GetDirectoryName(DotnetNewTestTemplatePackageProjectPath)!, outputLocation); + string outputLocation = Path.Combine(testPath, "TestNuGetPackage"); - string projectName = Path.GetFileName(DotnetNewTestTemplatePackageProjectPath); - - new DotnetPackCommand(log, $"{outputLocation}\\{projectName}", $"-p:BaseIntermediateOutputPath={outputLocation}\\", "-o", outputLocation) + new DotnetPackCommand(log, $"{testPath}\\{testProject}", "-o", outputLocation) .Execute() .Should() .Pass(); @@ -188,21 +188,5 @@ private static string GetAndVerifyRepoRoot() } return repoRoot; } - - private static void CopyFilesRecursively(string sourcePath, string targetPath) - { - //Now Create all of the directories - foreach (string dirPath in Directory.GetDirectories(sourcePath, "*", SearchOption.AllDirectories)) - { - Directory.CreateDirectory(dirPath.Replace(sourcePath, targetPath)); - } - - //Copy all the files & Replaces any files with the same name - foreach (string newPath in Directory.GetFiles(sourcePath, "*.*", SearchOption.AllDirectories)) - { - File.Copy(newPath, newPath.Replace(sourcePath, targetPath), true); - } - } - } } diff --git a/src/Tests/dotnet-new.Tests/TemplateDiscoveryTests.cs b/src/Tests/dotnet-new.Tests/TemplateDiscoveryTests.cs index a72b48749cb2..8cf9cbac4fa7 100644 --- a/src/Tests/dotnet-new.Tests/TemplateDiscoveryTests.cs +++ b/src/Tests/dotnet-new.Tests/TemplateDiscoveryTests.cs @@ -22,7 +22,6 @@ public TemplateDiscoveryTests(ITestOutputHelper log, TemplateDiscoveryTool templ [Fact] public async Task CanRunDiscoveryTool() { - string home = CreateTemporaryFolder(folderName: "Home"); string testDir = CreateTemporaryFolder(); string testTemplatesPackagePath = PackTestNuGetPackage(_log); using var packageManager = new PackageManager();