Skip to content

Commit

Permalink
Use breadcrumbfiles associated with each asset, versus shared (#6604)
Browse files Browse the repository at this point in the history
* use breadcrumbfiles associated with each asset instead of a single unified breadcrumb
* in tests, exclude the breadcrumb folder when finding the targeted assets directory
  • Loading branch information
scbedd authored Jul 28, 2023
1 parent da98135 commit 72a41da
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 13 deletions.
20 changes: 15 additions & 5 deletions tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/GitStoreTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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"",
Expand All @@ -611,22 +612,31 @@ 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<string>();

// run 3 restore operations
foreach (var assetsJson in folderStructure)
{
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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))"
Expand Down

0 comments on commit 72a41da

Please sign in to comment.