From 72a41dabc6665457c0c50f33f360dbc72dc15576 Mon Sep 17 00:00:00 2001 From: Scott Beddall <45376673+scbedd@users.noreply.github.com> Date: Fri, 28 Jul 2023 12:14:10 -0700 Subject: [PATCH] Use breadcrumbfiles associated with each asset, versus shared (#6604) * use breadcrumbfiles associated with each asset instead of a single unified breadcrumb * in tests, exclude the breadcrumb folder when finding the targeted assets directory --- .../GitStoreTests.cs | 20 ++++++++++++++----- .../TestHelpers.cs | 2 +- .../Store/GitStoreBreadcrumb.cs | 9 ++++++++- .../test-scripts/CLIIntegration.Tests.ps1 | 5 ++--- .../test-scripts/assets.Tests.Helpers.ps1 | 7 ++++--- 5 files changed, 30 insertions(+), 13 deletions(-) diff --git a/tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/GitStoreTests.cs b/tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/GitStoreTests.cs index 23d1cda2a67..96abbca37ef 100644 --- a/tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/GitStoreTests.cs +++ b/tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/GitStoreTests.cs @@ -9,6 +9,7 @@ using System.Linq; using System.ComponentModel; using Azure.Sdk.tools.TestProxy.Common; +using System.Collections.Generic; namespace Azure.Sdk.Tools.TestProxy.Tests { @@ -584,7 +585,7 @@ public async Task GetPathResolves(string inputJson) [EnvironmentConditionalSkipFact] [Trait("Category", "Integration")] - public async Task BreadcrumbContainsMultipleAssetRefs() + public async Task BreadCrumbMaintainsMultipleBreadCrumbs() { var inputJson = @"{ ""AssetsRepo"": ""Azure/azure-sdk-assets-integration"", @@ -611,7 +612,8 @@ public async Task BreadcrumbContainsMultipleAssetRefs() try { var assetStore = (await _defaultStore.ParseConfigurationFile(Path.Join(testFolder, target1))).ResolveAssetsStoreLocation(); - var breadCrumbFile = Path.Join(assetStore.ToString(), ".breadcrumb"); + + var breadCrumbs = new List(); // run 3 restore operations foreach (var assetsJson in folderStructure) @@ -619,14 +621,22 @@ public async Task BreadcrumbContainsMultipleAssetRefs() var jsonFileLocation = Path.Join(testFolder, assetsJson); var parsedJson = await _defaultStore.ParseConfigurationFile(jsonFileLocation); - await _defaultStore.Restore(jsonFileLocation); + var breadCrumbFile = Path.Join(assetStore.ToString(), "breadcrumb", $"{parsedJson.AssetRepoShortHash}.breadcrumb"); + breadCrumbs.Add(breadCrumbFile); + + await _defaultStore.Restore(jsonFileLocation); TestHelpers.CheckBreadcrumbAgainstAssetsConfig(parsedJson); } - var crumbs = File.ReadAllLines(breadCrumbFile).Select(x => new BreadcrumbLine(x)); + // double verify they are where we expect + foreach(var crumbFile in breadCrumbs) + { + Assert.True(File.Exists(crumbFile)); + } + // we have already validated that each tag contains what we expect, just confirm we aren't eliminating lines now. - Assert.Equal(3, crumbs.Count()); + Assert.Equal(3, breadCrumbs.Count()); } finally { diff --git a/tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/TestHelpers.cs b/tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/TestHelpers.cs index 30347f3bf23..7ab242bf91b 100644 --- a/tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/TestHelpers.cs +++ b/tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/TestHelpers.cs @@ -355,7 +355,7 @@ public static void CreateFileWithInitialVersion(string testFolder, string fileNa public static void CheckBreadcrumbAgainstAssetsConfig(GitAssetsConfiguration configuration) { var assetsStorePath = configuration.ResolveAssetsStoreLocation(); - var breadCrumbFile = Path.Join(assetsStorePath.ToString(), ".breadcrumb"); + var breadCrumbFile = Path.Join(assetsStorePath.ToString(), "breadcrumb", $"{configuration.AssetRepoShortHash}.breadcrumb"); var targetKey = configuration.AssetsJsonRelativeLocation.ToString(); Assert.True(File.Exists(breadCrumbFile)); diff --git a/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Store/GitStoreBreadcrumb.cs b/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Store/GitStoreBreadcrumb.cs index f9129f50aea..7e491d0ead8 100644 --- a/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Store/GitStoreBreadcrumb.cs +++ b/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Store/GitStoreBreadcrumb.cs @@ -73,7 +73,14 @@ public GitStoreBreadcrumb() { } public string GetBreadCrumbLocation(GitAssetsConfiguration configuration) { - return Path.Join(configuration.ResolveAssetsStoreLocation().ToString(), ".breadcrumb"); + var breadCrumbFolder = Path.Combine(configuration.ResolveAssetsStoreLocation().ToString(), "breadcrumb"); + + if (!Directory.Exists(breadCrumbFolder)) + { + Directory.CreateDirectory(breadCrumbFolder); + } + + return Path.Join(breadCrumbFolder, $"{configuration.AssetRepoShortHash}.breadcrumb"); } /// diff --git a/tools/test-proxy/scripts/test-scripts/CLIIntegration.Tests.ps1 b/tools/test-proxy/scripts/test-scripts/CLIIntegration.Tests.ps1 index 58cfc6fffc2..b8cff2a47ee 100644 --- a/tools/test-proxy/scripts/test-scripts/CLIIntegration.Tests.ps1 +++ b/tools/test-proxy/scripts/test-scripts/CLIIntegration.Tests.ps1 @@ -482,7 +482,7 @@ Describe "AssetsModuleTests" { $LASTEXITCODE | Should -Be 0 $newlocalAssetsFilePath = Join-Path $newTestFolder ".assets" - $newAssetsFolder = $(Get-ChildItem $newlocalAssetsFilePath -Directory)[0].FullName + $newAssetsFolder = $(Get-ChildItem $newlocalAssetsFilePath -Directory | Where-Object { $_.Name -ne "breadcrumb" })[0].FullName mkdir -p $(Join-Path $newAssetsFolder $creationPath) # same file updates. we should have an identical sha! @@ -585,7 +585,7 @@ Describe "AssetsModuleTests" { Invoke-ProxyCommand -TestProxyExe $TestProxyExe -CommandArgs $CommandArgs -MountDirectory $testFolder $LASTEXITCODE | Should -Be 0 $localAssetsFilePath = Join-Path $testFolder ".assets" - $assetsFolder = $(Get-ChildItem $localAssetsFilePath -Directory)[0].FullName + $assetsFolder = $(Get-ChildItem $localAssetsFilePath -Directory | Where-Object { $_.Name -ne "breadcrumb" })[0].FullName mkdir -p $(Join-Path $assetsFolder $creationPath) # Create new files. These are in a predictable location with predicatable content so we can be certain they are around @@ -603,7 +603,6 @@ Describe "AssetsModuleTests" { Invoke-ProxyCommand -TestProxyExe $TestProxyExe -CommandArgs $CommandArgs -MountDirectory $testFolder $LASTEXITCODE | Should -Be 0 - Test-Path -Path (Join-Path $assetsFolder $file1) | Should -Be $false Test-Path -Path (Join-Path $assetsFolder $file2) | Should -Be $false Test-Path -Path (Join-Path $assetsFolder $file3) | Should -Be $false diff --git a/tools/test-proxy/scripts/test-scripts/assets.Tests.Helpers.ps1 b/tools/test-proxy/scripts/test-scripts/assets.Tests.Helpers.ps1 index 83339919c11..306de629280 100644 --- a/tools/test-proxy/scripts/test-scripts/assets.Tests.Helpers.ps1 +++ b/tools/test-proxy/scripts/test-scripts/assets.Tests.Helpers.ps1 @@ -311,9 +311,10 @@ Function Get-AssetsFilePath { $assetsDir = Split-Path -Path $AssetsJsonFile $startingPath = Join-Path -Path $assetsDir -ChildPath ".assets" } - # It's odd that $folder.Count and $folders.Lenght work and we need to do this - $numDirs = Get-ChildItem $startingPath -Directory | Measure-Object | ForEach-Object{$_.Count} - $folders = Get-ChildItem $startingPath -Directory + # It's odd that $folder.Count and $folders.Length work and we need to do this + $numDirs = Get-ChildItem $startingPath -Directory | Where-Object { $_.Name -ne "breadcrumb" } | Measure-Object | ForEach-Object { $_.Count } + $folders = Get-ChildItem $startingPath -Directory | Where-Object { $_.Name -ne "breadcrumb" } + # There should only be one folder if (1 -ne $numDirs) { LogError "The assets directory ($startingPath) should only contain 1 subfolder not $numDirs ($folders -join $([Environment]::NewLine))"