From 7620a2d95ce19f8f52fe4da6aef5afc25742dead Mon Sep 17 00:00:00 2001 From: Scott Beddall <45376673+scbedd@users.noreply.github.com> Date: Mon, 17 Apr 2023 13:09:26 -0700 Subject: [PATCH] Prevent duplicate tag push (#5748) * we use the generated SHA of the assets repo within the tag name that is uploaded. This means that if a set of recordings has already been pushed, we won't attempt to push again and error out erroneously * our tests were not cleaning up after themselves appropriately, update the integrationpushtests to actually clean up _all_ of their created tags. --------- Co-authored-by: Ben Broderick Phillips --- .../GitStoreIntegrationPushTests.cs | 47 ++++++---- .../GitStoreIntegrationResetTests.cs | 18 ++-- .../GitStoreIntegrationRestoreTests.cs | 8 +- .../TestHelpers.cs | 25 +++-- .../RecordingHandler.cs | 4 +- .../Store/GitStore.cs | 12 ++- .../test-scripts/CLIIntegration.Tests.ps1 | 94 +++++++++++++++++-- .../test-scripts/assets.Tests.Helpers.ps1 | 6 +- 8 files changed, 157 insertions(+), 57 deletions(-) diff --git a/tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/IntegrationTests/GitStoreIntegrationPushTests.cs b/tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/IntegrationTests/GitStoreIntegrationPushTests.cs index fefa9cb0e10..c829abf5e2f 100644 --- a/tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/IntegrationTests/GitStoreIntegrationPushTests.cs +++ b/tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/IntegrationTests/GitStoreIntegrationPushTests.cs @@ -42,7 +42,7 @@ public GitStoreIntegrationPushTests() ""AssetsRepoPrefixPath"": ""pull/scenarios"", ""AssetsRepoId"": """", ""TagPrefix"": ""language/tables"", - ""Tag"": ""language/tables_fc54d0"" + ""Tag"": ""python/tables_fc54d0"" }")] [Trait("Category", "Integration")] public async Task Scenario1(string inputJson) @@ -59,8 +59,8 @@ public async Task Scenario1(string inputJson) var testFolder = TestHelpers.DescribeTestFolder(assets, folderStructure, isPushTest:true); try { - // Ensure that the TagPrefix was updated - Assert.NotEqual(originalTagPrefix, assets.TagPrefix); + // Ensure that the Tag was updated + Assert.NotEqual(originalTag, assets.TagPrefix); var jsonFileLocation = Path.Join(testFolder, GitStoretests.AssetsJson); @@ -105,6 +105,7 @@ public async Task Scenario1(string inputJson) finally { DirectoryHelper.DeleteGitDirectory(testFolder); + TestHelpers.CleanupIntegrationTestTag(assets); TestHelpers.CleanupIntegrationTestTag(updatedAssets); } } @@ -141,8 +142,8 @@ public async Task Scenario2(string inputJson) var testFolder = TestHelpers.DescribeTestFolder(assets, folderStructure, isPushTest: true); try { - // Ensure that the TagPrefix was updated - Assert.NotEqual(originalTagPrefix, assets.TagPrefix); + // Ensure that the Tag was updated + Assert.NotEqual(originalTag, assets.Tag); var jsonFileLocation = Path.Join(testFolder, GitStoretests.AssetsJson); @@ -187,6 +188,7 @@ public async Task Scenario2(string inputJson) finally { DirectoryHelper.DeleteGitDirectory(testFolder); + TestHelpers.CleanupIntegrationTestTag(assets); TestHelpers.CleanupIntegrationTestTag(updatedAssets); } } @@ -207,7 +209,7 @@ public async Task Scenario2(string inputJson) ""AssetsRepoPrefixPath"": ""pull/scenarios"", ""AssetsRepoId"": """", ""TagPrefix"": ""language/tables"", - ""Tag"": ""language/tables_9e81fb"" + ""Tag"": ""python/tables_9e81fb"" }")] [Trait("Category", "Integration")] public async Task Scenario3(string inputJson) @@ -223,8 +225,8 @@ public async Task Scenario3(string inputJson) var testFolder = TestHelpers.DescribeTestFolder(assets, folderStructure, isPushTest: true); try { - // Ensure that the TagPrefix was updated - Assert.NotEqual(originalTagPrefix, assets.TagPrefix); + // Ensure that the Tag was updated + Assert.NotEqual(originalTag, assets.Tag); var jsonFileLocation = Path.Join(testFolder, GitStoretests.AssetsJson); @@ -280,6 +282,7 @@ public async Task Scenario3(string inputJson) finally { DirectoryHelper.DeleteGitDirectory(testFolder); + TestHelpers.CleanupIntegrationTestTag(assets); TestHelpers.CleanupIntegrationTestTag(updatedAssets); } } @@ -316,8 +319,8 @@ public async Task Scenario4(string inputJson) var testFolder = TestHelpers.DescribeTestFolder(assets, folderStructure, isPushTest: true); try { - // Ensure that the TagPrefix was updated - Assert.NotEqual(originalTagPrefix, assets.TagPrefix); + // Ensure that the Tag was updated + Assert.NotEqual(originalTag, assets.Tag); var jsonFileLocation = Path.Join(testFolder, GitStoretests.AssetsJson); @@ -362,6 +365,7 @@ public async Task Scenario4(string inputJson) finally { DirectoryHelper.DeleteGitDirectory(testFolder); + TestHelpers.CleanupIntegrationTestTag(assets); TestHelpers.CleanupIntegrationTestTag(updatedAssets); } } @@ -384,7 +388,7 @@ public async Task Scenario4(string inputJson) ""AssetsRepoPrefixPath"": ""pull/scenarios"", ""AssetsRepoId"": """", ""TagPrefix"": ""language/tables"", - ""Tag"": ""language/tables_9e81fb"" + ""Tag"": ""python/tables_9e81fb"" }")] [Trait("Category", "Integration")] public async Task Scenario5(string inputJson) @@ -401,14 +405,15 @@ public async Task Scenario5(string inputJson) // The first restore needs to be done with isPushTest set to true so it creates the branch var testFolder = TestHelpers.DescribeTestFolder(assets, folderStructure, isPushTest: true); // The second restore needs to use the assets that was updated in the first restore so it - // restores from the branch we're going to push to + // restores from the tag we're going to push to var testFolder2 = TestHelpers.DescribeTestFolder(assets, folderStructure); try { - // Ensure that the TagPrefix was updated - Assert.NotEqual(originalTagPrefix, assets.TagPrefix); + // Ensure that the Tag was updated + Assert.NotEqual(originalTag, assets.Tag); var jsonFileLocation = Path.Join(testFolder, GitStoretests.AssetsJson); + assets = TestHelpers.LoadAssetsFromFile(jsonFileLocation); var parsedConfiguration = await _defaultStore.ParseConfigurationFile(jsonFileLocation); await _defaultStore.Restore(jsonFileLocation); @@ -474,10 +479,11 @@ public async Task Scenario5(string inputJson) // Ensure that the targeted tag is present on the repo TestHelpers.CheckExistenceOfTag(updatedAssets, localFilePath); - + // Update the second assets file and do another restore TestHelpers.UpdateAssetsFile(updatedAssets, jsonFileLocation2); await defaultStore2.Restore(jsonFileLocation2); + updatedAssets = TestHelpers.LoadAssetsFromFile(jsonFileLocation2); // Verify the files pushes in another directory are restored correctly here Assert.Equal(3, System.IO.Directory.EnumerateFiles(localFilePath2).Count()); @@ -485,11 +491,15 @@ public async Task Scenario5(string inputJson) Assert.True(TestHelpers.VerifyFileVersion(localFilePath2, "file2.txt", 3)); Assert.True(TestHelpers.VerifyFileVersion(localFilePath2, "file6.txt", 1)); await TestHelpers.CheckBreadcrumbAgainstAssetsJsons(new string[] { jsonFileLocation }); - + } + catch(Exception) + { + throw; } finally { DirectoryHelper.DeleteGitDirectory(testFolder); + TestHelpers.CleanupIntegrationTestTag(assets); TestHelpers.CleanupIntegrationTestTag(updatedAssets); DirectoryHelper.DeleteGitDirectory(testFolder2); } @@ -530,8 +540,8 @@ public async Task LargePushPerformance(int numberOfFiles, double fileSize) try { - // Ensure that the TagPrefix was updated - Assert.NotEqual(originalTagPrefix, assets.TagPrefix); + // Ensure that the Tag was updated + Assert.NotEqual(originalTag, assets.Tag); var jsonFileLocation = Path.Join(testFolder, GitStoretests.AssetsJson); @@ -567,6 +577,7 @@ public async Task LargePushPerformance(int numberOfFiles, double fileSize) finally { DirectoryHelper.DeleteGitDirectory(testFolder); + TestHelpers.CleanupIntegrationTestTag(assets); TestHelpers.CleanupIntegrationTestTag(updatedAssets); } } diff --git a/tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/IntegrationTests/GitStoreIntegrationResetTests.cs b/tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/IntegrationTests/GitStoreIntegrationResetTests.cs index 7aee6f2ef2b..799fc2ea575 100644 --- a/tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/IntegrationTests/GitStoreIntegrationResetTests.cs +++ b/tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/IntegrationTests/GitStoreIntegrationResetTests.cs @@ -37,7 +37,7 @@ public GitStoreIntegrationResetTests() } // Scenario 1 - Changes to existing files only are detected and overridden with Reset response Y - // 1. Restore from Tag language/tables_fc54d0 + // 1. Restore from Tag python/tables_fc54d0 // 2. Expect: 3 files with versions they were checked in with // 3. Update one or more files, incrementing their version // 4. Expect: files updated should be at version 2 @@ -50,7 +50,7 @@ public GitStoreIntegrationResetTests() ""AssetsRepoPrefixPath"": ""pull/scenarios"", ""AssetsRepoId"": """", ""TagPrefix"": ""main"", - ""Tag"": ""language/tables_fc54d0"" + ""Tag"": ""python/tables_fc54d0"" }")] [Trait("Category", "Integration")] public async Task Scenario1(string inputJson) @@ -101,7 +101,7 @@ public async Task Scenario1(string inputJson) } // Scenario 2 - Changes to existing files only are detected and retained with Reset response N - // 1. Restore from Tag language/tables_fc54d0 + // 1. Restore from Tag python/tables_fc54d0 // 2. Expect: 3 files with versions they were checked in with // 3. Update one or more files, incrementing their version // 4. Expect: files updated should be at version 2 @@ -114,7 +114,7 @@ public async Task Scenario1(string inputJson) ""AssetsRepoPrefixPath"": ""pull/scenarios"", ""AssetsRepoId"": """", ""TagPrefix"": ""main"", - ""Tag"": ""language/tables_fc54d0"" + ""Tag"": ""python/tables_fc54d0"" }")] [Trait("Category", "Integration")] public async Task Scenario2(string inputJson) @@ -168,7 +168,7 @@ public async Task Scenario2(string inputJson) } // Scenario 3 - Restore from Tag, add and remove files, Reset response Y - // 1. Restore from Tag language/tables_9e81fb + // 1. Restore from Tag python/tables_9e81fb // 2. Expect: 4 files with versions they were checked in with // 3. Update add/remove files // 4. Expect: Untouched files are the same versions as step 2, added files are version 1, removed files are gone @@ -181,7 +181,7 @@ public async Task Scenario2(string inputJson) ""AssetsRepoPrefixPath"": ""pull/scenarios"", ""AssetsRepoId"": """", ""TagPrefix"": ""main"", - ""Tag"": ""language/tables_9e81fb"" + ""Tag"": ""python/tables_9e81fb"" }")] [Trait("Category", "Integration")] public async Task Scenario3(string inputJson) @@ -244,7 +244,7 @@ public async Task Scenario3(string inputJson) } // Scenario 4 - Restore from Tag, add and remove files, Reset response N - // 1. Restore from Tag language/tables_9e81fb + // 1. Restore from Tag python/tables_9e81fb // 2. Expect: 4 files with versions they were checked in with // 3. Update add/remove files // 4. Expect: Untouched files are the same versions as step 2, added files are version 1, removed files are gone @@ -257,7 +257,7 @@ public async Task Scenario3(string inputJson) ""AssetsRepoPrefixPath"": ""pull/scenarios"", ""AssetsRepoId"": """", ""TagPrefix"": ""main"", - ""Tag"": ""language/tables_9e81fb"" + ""Tag"": ""python/tables_9e81fb"" }")] [Trait("Category", "Integration")] public async Task Scenario4(string inputJson) @@ -319,7 +319,7 @@ public async Task Scenario4(string inputJson) } // Scenario 5 - Restore from Tag, add and remove files, Reset response N, then Reset response Y - // 1. Restore from Tag language/tables_9e81fb + // 1. Restore from Tag python/tables_9e81fb // 2. Expect: 3 files with versions they were checked in with // 3. Update add/remove files // 4. Expect: Untouched files are the same versions as step 2, added files are version 1, removed files are gone diff --git a/tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/IntegrationTests/GitStoreIntegrationRestoreTests.cs b/tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/IntegrationTests/GitStoreIntegrationRestoreTests.cs index fd54cbcadba..b274977abce 100644 --- a/tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/IntegrationTests/GitStoreIntegrationRestoreTests.cs +++ b/tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/IntegrationTests/GitStoreIntegrationRestoreTests.cs @@ -34,7 +34,7 @@ public GitStoreIntegrationRestoreTests() private GitStore _defaultStore = new GitStore(); // Scenario1 - // Tag language/tables_fc54d0 + // Tag python/tables_fc54d0 // This was the initial push of the test files: // Added file1.txt // Added file2.txt @@ -47,7 +47,7 @@ public GitStoreIntegrationRestoreTests() ""AssetsRepoPrefixPath"": ""pull/scenarios"", ""AssetsRepoId"": """", ""TagPrefix"": ""main"", - ""Tag"": ""language/tables_fc54d0"" + ""Tag"": ""python/tables_fc54d0"" }")] [Trait("Category", "Integration")] public async Task Scenario1(string inputJson) @@ -85,7 +85,7 @@ public async Task Scenario1(string inputJson) // Scenario2 - // Tag language/tables_9e81fb + // Tag python/tables_9e81fb // This was the second push of the test files. // Unchanged file1.txt // Updated file2.txt @@ -102,7 +102,7 @@ public async Task Scenario1(string inputJson) ""AssetsRepoPrefixPath"": ""pull/scenarios"", ""AssetsRepoId"": """", ""TagPrefix"": ""main"", - ""Tag"": ""language/tables_9e81fb"" + ""Tag"": ""python/tables_9e81fb"" }")] [Trait("Category", "Integration")] public async Task Scenario2(string inputJson) 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 2daf91a0fb6..30347f3bf23 100644 --- a/tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/TestHelpers.cs +++ b/tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/TestHelpers.cs @@ -181,7 +181,7 @@ public static string DescribeTestFolder(Assets assets, string[] sampleFiles, str InitIntegrationTag(assets, adjustedAssetsRepoTag); // set the TagPrefix to the adjusted test branch - assets.TagPrefix = adjustedAssetsRepoTag; + assets.Tag = adjustedAssetsRepoTag; localAssetsJsonContent = JsonSerializer.Serialize(assets); } @@ -402,8 +402,8 @@ public static async Task CheckBreadcrumbAgainstAssetsJsons(IEnumerable j /// This function is only used by the Push scenarios. It'll clone the assets repository /// /// - /// - public static void InitIntegrationTag(Assets assets, string adjustedAssetsRepoBranch) + /// + public static void InitIntegrationTag(Assets assets, string adjustedAssetsRepoTag) { // generate a test folder root string tmpPath = Path.Join(Path.GetTempPath(), Guid.NewGuid().ToString()); @@ -419,10 +419,10 @@ public static void InitIntegrationTag(Assets assets, string adjustedAssetsRepoBr var gitCloneUrl = GitStore.GetCloneUrl(assets.AssetsRepo, tmpPath); // Clone the original assets repo - GitHandler.Run($"clone {gitCloneUrl} .", tmpPath); + GitHandler.Run($"clone --filter=blob:none {gitCloneUrl} .", tmpPath); - // Check to see if there's already a branch - CommandResult commandResult = GitHandler.Run($"ls-remote --tags {gitCloneUrl} {assets.TagPrefix}", tmpPath); + // Check to see if the tag already exists + CommandResult commandResult = GitHandler.Run($"ls-remote --tags {gitCloneUrl} {assets.Tag}", tmpPath); // If the commandResult response is empty, there's nothing to do and we can return if (!String.IsNullOrWhiteSpace(commandResult.StdOut)) @@ -430,15 +430,14 @@ public static void InitIntegrationTag(Assets assets, string adjustedAssetsRepoBr // If the commandResult response is not empty, the command result will have something // similar to the following: // e4a4949a2b6cc2ff75afd0fe0d97cbcabf7b67b7 refs/heads/scenario_clean_push - GitHandler.Run($"checkout {assets.TagPrefix}", tmpPath); - + GitHandler.Run($"checkout {assets.Tag}", tmpPath); } - // Create the adjustedAssetsRepoBranch from the original branch. The reason being is that pushing + // Create the adjustedAssetsRepoTag from the original branch. The reason being is that pushing // to a branch of a branch is automatic - GitHandler.Run($"tag {adjustedAssetsRepoBranch}", tmpPath); - // Push the contents of the TagPrefix into the adjustedAssetsRepoBranch - GitHandler.Run($"push origin {adjustedAssetsRepoBranch}", tmpPath); + GitHandler.Run($"tag {adjustedAssetsRepoTag}", tmpPath); + // Push the contents of the TagPrefix into the adjustedAssetsRepoTag + GitHandler.Run($"push origin {adjustedAssetsRepoTag}", tmpPath); } finally { @@ -473,7 +472,7 @@ public static void CleanupIntegrationTestTag(Assets assets) Directory.CreateDirectory(tmpPath); GitProcessHandler GitHandler = new GitProcessHandler(); string gitCloneUrl = GitStore.GetCloneUrl(assets.AssetsRepo, Directory.GetCurrentDirectory()); - GitHandler.Run($"clone {gitCloneUrl} .", tmpPath); + GitHandler.Run($"clone --filter=blob:none {gitCloneUrl} .", tmpPath); GitHandler.Run($"push origin --delete {assets.Tag}", tmpPath); } finally diff --git a/tools/test-proxy/Azure.Sdk.Tools.TestProxy/RecordingHandler.cs b/tools/test-proxy/Azure.Sdk.Tools.TestProxy/RecordingHandler.cs index eb2871238d8..af8a23ca1c2 100644 --- a/tools/test-proxy/Azure.Sdk.Tools.TestProxy/RecordingHandler.cs +++ b/tools/test-proxy/Azure.Sdk.Tools.TestProxy/RecordingHandler.cs @@ -564,10 +564,10 @@ public static string GetAssetsJsonLocation(string pathToAssetsJson, string conte if (!Path.IsPathFullyQualified(pathToAssetsJson)) { - path = Path.Join(contextDirectory, pathToAssetsJson.Replace("\\", "/")); + path = Path.Join(contextDirectory, pathToAssetsJson); } - return path; + return path.Replace("\\", "/"); } public async Task Restore(string pathToAssetsJson) diff --git a/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Store/GitStore.cs b/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Store/GitStore.cs index 7c2c8440667..bfebebbb48c 100644 --- a/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Store/GitStore.cs +++ b/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Store/GitStore.cs @@ -124,7 +124,17 @@ public async Task Push(string pathToAssetsJson) { } GitHandler.Run($"tag {generatedTagName}", config); - GitHandler.Run($"push origin {generatedTagName}", config); + + var remoteResult = GitHandler.Run($"ls-remote origin --tags {generatedTagName}", config); + + if (string.IsNullOrWhiteSpace(remoteResult.StdOut)) + { + GitHandler.Run($"push origin {generatedTagName}", config); + } + else + { + _consoleWrapper.WriteLine($"Not attempting to push tag '{generatedTagName}', as it already exists within the assets repo"); + } } catch(GitProcessException e) { diff --git a/tools/test-proxy/scripts/test-scripts/CLIIntegration.Tests.ps1 b/tools/test-proxy/scripts/test-scripts/CLIIntegration.Tests.ps1 index 86ee688428f..6a730c902f2 100644 --- a/tools/test-proxy/scripts/test-scripts/CLIIntegration.Tests.ps1 +++ b/tools/test-proxy/scripts/test-scripts/CLIIntegration.Tests.ps1 @@ -30,7 +30,7 @@ Describe "AssetsModuleTests" { AssetsRepoPrefixPath = "pull/scenarios" AssetsRepoId = "" TagPrefix = "main" - Tag = "language/tables_fc54d0" + Tag = "python/tables_fc54d0" } $files = @( "assets.json" @@ -55,7 +55,7 @@ Describe "AssetsModuleTests" { AssetsRepoPrefixPath = "pull/scenarios" AssetsRepoId = "" TagPrefix = "main" - Tag = "language/tables_9e81fb" + Tag = "python/tables_9e81fb" } $files = @( @@ -112,7 +112,7 @@ Describe "AssetsModuleTests" { AssetsRepoPrefixPath = "pull/scenarios" AssetsRepoId = "" TagPrefix = "main" - Tag = "language/tables_fc54d0" + Tag = "python/tables_fc54d0" } $files = @( "assets.json" @@ -148,7 +148,7 @@ Describe "AssetsModuleTests" { AssetsRepoPrefixPath = "pull/scenarios" AssetsRepoId = "" TagPrefix = "main" - Tag = "language/tables_fc54d0" + Tag = "python/tables_fc54d0" } $files = @( "assets.json" @@ -195,7 +195,7 @@ Describe "AssetsModuleTests" { AssetsRepoPrefixPath = "pull/scenarios" AssetsRepoId = "" TagPrefix = "main" - Tag = "language/tables_fc54d0" + Tag = "python/tables_fc54d0" } $files = @( "assets.json" @@ -253,7 +253,7 @@ Describe "AssetsModuleTests" { AssetsRepoPrefixPath = "pull/scenarios" AssetsRepoId = "" TagPrefix = "language/tables" - Tag = "language/tables_fc54d0" + Tag = "python/tables_fc54d0" } $files = @( "assets.json" @@ -372,7 +372,7 @@ Describe "AssetsModuleTests" { AssetsRepoPrefixPath = "pull/scenarios" AssetsRepoId = "" TagPrefix = "language/tables" - Tag = "language/tables_9e81fb" + Tag = "python/tables_9e81fb" } $files = @( @@ -426,6 +426,86 @@ Describe "AssetsModuleTests" { $exists | Should -Be $true } } + It "Should handle pushing an identical SHA twice, and properly update to the necessary tag without error state." { + if ($env:CLI_TEST_WITH_DOCKER) { + Set-ItResult -Skipped + } + else { + $newTestFolder = "" + try { + $testGuid = [Guid]::NewGuid() + $created_tag_prefix = "test_$testGuid" + $creationPath = Join-Path "sdk" "keyvault" "azure-keyvault-keys" "tests" "recordings" + $file1 = Join-Path $creationPath "file1.txt" + $file2 = Join-Path $creationPath "file2.txt" + $file3 = Join-Path $creationPath "file3.txt" + $recordingJson = [PSCustomObject]@{ + AssetsRepo = "Azure/azure-sdk-assets-integration" + AssetsRepoPrefixPath = "" + AssetsRepoId = "" + TagPrefix = $created_tag_prefix + Tag = "" + } + + $assetsJsonRelativePath = Join-Path "sdk" "keyvault" "azure-keyvault-keys" "assets.json" + + $files = @( + $assetsJsonRelativePath + ) + $testFolder = Describe-TestFolder -AssetsJsonContent $recordingJson -Files $files -IsPushTest $false + + $CommandArgs = "restore --assets-json-path $assetsJsonRelativePath" + Invoke-ProxyCommand -TestProxyExe $TestProxyExe -CommandArgs $CommandArgs -MountDirectory $testFolder + $LASTEXITCODE | Should -Be 0 + + $localAssetsFilePath = Join-Path $testFolder ".assets" + $assetsFolder = $(Get-ChildItem $localAssetsFilePath -Directory)[0].FullName + mkdir -p $(Join-Path $assetsFolder $creationPath) + + # Create new files. These are in a predictable location with predicatable content so we can generate the same SHA twice in a row. + Edit-FileVersion -FilePath $assetsFolder -FileName $file1 -Version 1 + Edit-FileVersion -FilePath $assetsFolder -FileName $file2 -Version 1 + Edit-FileVersion -FilePath $assetsFolder -FileName $file3 -Version 1 + + # Push the changes + $CommandArgs = "push --assets-json-path $assetsJsonRelativePath" + Invoke-ProxyCommand -TestProxyExe $TestProxyExe -CommandArgs $CommandArgs -MountDirectory $testFolder + $LASTEXITCODE | Should -Be 0 + + # now, let's describe an _entirely different_ assets folder, attempt the same push. + # this should result in the SAME tag twice in the assets repo, and we should properly NOT do the full push action + $newTestFolder = Describe-TestFolder -AssetsJsonContent $recordingJson -Files $files -IsPushTest $false + $newAssetsFile = Join-Path $newTestFolder $assetsJsonRelativePath + + $CommandArgs = "restore --assets-json-path $assetsJsonRelativePath" + Invoke-ProxyCommand -TestProxyExe $TestProxyExe -CommandArgs $CommandArgs -MountDirectory $newTestFolder + $LASTEXITCODE | Should -Be 0 + + $newlocalAssetsFilePath = Join-Path $newTestFolder ".assets" + $newAssetsFolder = $(Get-ChildItem $newlocalAssetsFilePath -Directory)[0].FullName + mkdir -p $(Join-Path $newAssetsFolder $creationPath) + + # same file updates. we should have an identical sha! + Edit-FileVersion -FilePath $newAssetsFolder -FileName $file1 -Version 1 + Edit-FileVersion -FilePath $newAssetsFolder -FileName $file2 -Version 1 + Edit-FileVersion -FilePath $newAssetsFolder -FileName $file3 -Version 1 + + $CommandArgs = "push --assets-json-path $assetsJsonRelativePath" + Invoke-ProxyCommand -TestProxyExe $TestProxyExe -CommandArgs $CommandArgs -MountDirectory $newTestFolder + $LASTEXITCODE | Should -Be 0 + + $updatedAssets = Update-AssetsFromFile -AssetsJsonContent $newAssetsFile + + $exists = Test-TagExists -AssetsJsonContent $updatedAssets -WorkingDirectory $localAssetsFilePath + $exists | Should -Be $true + } + finally { + if ($newTestFolder) { + Remove-Test-Folder $newTestFolder + } + } + } + } AfterEach { Remove-Test-Folder $testFolder Remove-Integration-Tag $updatedAssets 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 ec6d0e7e495..83339919c11 100644 --- a/tools/test-proxy/scripts/test-scripts/assets.Tests.Helpers.ps1 +++ b/tools/test-proxy/scripts/test-scripts/assets.Tests.Helpers.ps1 @@ -124,7 +124,7 @@ Function Remove-Integration-Tag { try { Push-Location $tempPath $gitCloneUrl = Get-CloneUrl $Assets.AssetsRepo - Write-Host "git clone $($gitCloneUrl) ." + Write-Host "git clone --filter=blob:none $($gitCloneUrl) ." git clone $($gitCloneUrl) . Write-Host "git push origin --delete $($Assets.Tag)" git push origin --delete $($Assets.Tag) @@ -212,7 +212,7 @@ Function Describe-TestFolder { chmod 777 $testPath } - return $testPath + return $testPath.Replace("`\", "/") } # Cleanup the test folder used for testing. The DISABLE_INTEGRATION_BRANCH_CLEANUP @@ -243,7 +243,7 @@ Function Invoke-ProxyCommand { ) if ($TestProxyExe.Trim().ToLower() -eq "test-proxy") { - $CommandArgs += " --storage-location=`"$MountDirectory`"" + $CommandArgs += " --storage-location=$MountDirectory" Write-Host "$TestProxyExe $CommandArgs" # Need to cast the output into an array otherwise it'll be one long string with no newlines if ($WriteOutput) {