From 9c8997d47ca4b522d49e6984caf78c2c12a8cca8 Mon Sep 17 00:00:00 2001 From: Konrad Jamrozik Date: Mon, 13 Feb 2023 22:40:23 -0800 Subject: [PATCH 1/2] use CodeownersFile.UseRegexMatcherDefault everywhere where applicable --- .../Azure.Sdk.Tools.RetrieveCodeOwners/Program.cs | 6 +++--- tools/code-owners-parser/CodeOwnersParser/CodeownersFile.cs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/code-owners-parser/Azure.Sdk.Tools.RetrieveCodeOwners/Program.cs b/tools/code-owners-parser/Azure.Sdk.Tools.RetrieveCodeOwners/Program.cs index c08bc05c840..0b2d2dc2d65 100644 --- a/tools/code-owners-parser/Azure.Sdk.Tools.RetrieveCodeOwners/Program.cs +++ b/tools/code-owners-parser/Azure.Sdk.Tools.RetrieveCodeOwners/Program.cs @@ -53,7 +53,7 @@ public static int Main( bool excludeNonUserAliases = false, string? targetDir = null, string ignoredPathPrefixes = DefaultIgnoredPrefixes, - bool useRegexMatcher = false) + bool useRegexMatcher = CodeownersFile.UseRegexMatcherDefault) { try { @@ -109,7 +109,7 @@ private static Dictionary GetCodeownersForGlobPath( string codeownersFilePathOrUrl, bool excludeNonUserAliases, string[]? ignoredPathPrefixes = null, - bool useRegexMatcher = false) + bool useRegexMatcher = CodeownersFile.UseRegexMatcherDefault) { ignoredPathPrefixes ??= Array.Empty(); @@ -131,7 +131,7 @@ private static CodeownersEntry GetCodeownersForSimplePath( string targetPath, string codeownersFilePathOrUrl, bool excludeNonUserAliases, - bool useRegexMatcher = false) + bool useRegexMatcher = CodeownersFile.UseRegexMatcherDefault) { CodeownersEntry codeownersEntry = CodeownersFile.GetMatchingCodeownersEntry( diff --git a/tools/code-owners-parser/CodeOwnersParser/CodeownersFile.cs b/tools/code-owners-parser/CodeOwnersParser/CodeownersFile.cs index 3d13f2431ef..ba90dcde5f8 100644 --- a/tools/code-owners-parser/CodeOwnersParser/CodeownersFile.cs +++ b/tools/code-owners-parser/CodeOwnersParser/CodeownersFile.cs @@ -8,7 +8,7 @@ namespace Azure.Sdk.Tools.CodeOwnersParser { public static class CodeownersFile { - private const bool UseRegexMatcherDefault = true; + public const bool UseRegexMatcherDefault = true; public static List GetCodeownersEntriesFromFileOrUrl( string codeownersFilePathOrUrl) From 43c0d72129b0f61a2346734bdad4d52ee03ba23a Mon Sep 17 00:00:00 2001 From: Konrad Jamrozik Date: Mon, 13 Feb 2023 22:45:46 -0800 Subject: [PATCH 2/2] remove obsolete tests --- eng/common/scripts/get-codeowners.ps1 | 19 +++--- .../ProgramSimplePathTests.cs | 63 ------------------- 2 files changed, 12 insertions(+), 70 deletions(-) delete mode 100644 tools/code-owners-parser/Azure.Sdk.Tools.RetrieveCodeOwners.Tests/ProgramSimplePathTests.cs diff --git a/eng/common/scripts/get-codeowners.ps1 b/eng/common/scripts/get-codeowners.ps1 index 87271a6230d..4264d472a5c 100644 --- a/eng/common/scripts/get-codeowners.ps1 +++ b/eng/common/scripts/get-codeowners.ps1 @@ -81,13 +81,18 @@ function TestGetCodeOwner([string]$targetDirectory, [string]$codeOwnerFileLocati } if($Test) { - $testFile = (Resolve-Path $PSScriptRoot/../../../tools/code-owners-parser/Azure.Sdk.Tools.RetrieveCodeOwners.Tests/TestData/simple_path_CODEOWNERS) - TestGetCodeOwner -targetDirectory "sdk" -codeOwnerFileLocation $testFile -includeNonUserAliases $true -expectReturn @("person1", "person2") - TestGetCodeOwner -targetDirectory "sdk/noPath" -codeOwnerFileLocation $testFile -includeNonUserAliases $true -expectReturn @("person1", "person2") - TestGetCodeOwner -targetDirectory "/sdk/azconfig" -codeOwnerFileLocation $testFile -includeNonUserAliases $true -expectReturn @("person3", "person4") - TestGetCodeOwner -targetDirectory "/sdk/azconfig/package" -codeOwnerFileLocation $testFile -includeNonUserAliases $true $testFile -expectReturn @("person3", "person4") - TestGetCodeOwner -targetDirectory "/sd" -codeOwnerFileLocation $testFile -includeNonUserAliases $true -expectReturn @() - TestGetCodeOwner -targetDirectory "/sdk/testUser/" -codeOwnerFileLocation $testFile -expectReturn @("azure-sdk") + # These tests have been removed; now instead we should run tests from RetrieveCodeOwnersProgramTests, and in a way as explained in: + # https://github.com/Azure/azure-sdk-tools/issues/5434 + # https://github.com/Azure/azure-sdk-tools/pull/5103#discussion_r1068680818 + Write-Host "These tests have been removed. Please see https://github.com/Azure/azure-sdk-tools/issues/5434 for more." + # + # $testFile = (Resolve-Path $PSScriptRoot/../../../tools/code-owners-parser/Azure.Sdk.Tools.RetrieveCodeOwners.Tests/TestData/simple_path_CODEOWNERS) + # TestGetCodeOwner -targetDirectory "sdk" -codeOwnerFileLocation $testFile -includeNonUserAliases $true -expectReturn @("person1", "person2") + # TestGetCodeOwner -targetDirectory "sdk/noPath" -codeOwnerFileLocation $testFile -includeNonUserAliases $true -expectReturn @("person1", "person2") + # TestGetCodeOwner -targetDirectory "/sdk/azconfig" -codeOwnerFileLocation $testFile -includeNonUserAliases $true -expectReturn @("person3", "person4") + # TestGetCodeOwner -targetDirectory "/sdk/azconfig/package" -codeOwnerFileLocation $testFile -includeNonUserAliases $true $testFile -expectReturn @("person3", "person4") + # TestGetCodeOwner -targetDirectory "/sd" -codeOwnerFileLocation $testFile -includeNonUserAliases $true -expectReturn @() + # TestGetCodeOwner -targetDirectory "/sdk/testUser/" -codeOwnerFileLocation $testFile -expectReturn @("azure-sdk") exit 0 } else { diff --git a/tools/code-owners-parser/Azure.Sdk.Tools.RetrieveCodeOwners.Tests/ProgramSimplePathTests.cs b/tools/code-owners-parser/Azure.Sdk.Tools.RetrieveCodeOwners.Tests/ProgramSimplePathTests.cs deleted file mode 100644 index d493836184d..00000000000 --- a/tools/code-owners-parser/Azure.Sdk.Tools.RetrieveCodeOwners.Tests/ProgramSimplePathTests.cs +++ /dev/null @@ -1,63 +0,0 @@ -using System.Collections.Generic; -using System.Text.Json; -using Azure.Sdk.Tools.CodeOwnersParser; -using NUnit.Framework; - -namespace Azure.Sdk.Tools.RetrieveCodeOwners.Tests -{ - /// - /// Test class for Azure.Sdk.Tools.RetrieveCodeOwners.Program.Main(), - /// for scenario in which targetPath is a simple path, i.e. - /// targetPath.IsGlobPath() returns false. - /// - [TestFixture] - public class ProgramSimplePathTests - { - private const string CodeownersFilePath = "./TestData/simple_path_CODEOWNERS"; - - private static readonly object[] sourceLists = - { - new object[] {"sdk", false, new List { "person1", "person2" } }, - new object[] { "/sdk", false, new List { "person1", "person2" } }, - new object[] { "sdk/noPath", false, new List { "person1", "person2" } }, - new object[] { "/sdk/azconfig", false, new List { "person3", "person4" } }, - new object[] { "/sdk/azconfig/package", false, new List { "person3", "person4" } }, - new object[] { "/sdk/testUser/", true, new List { "azure-sdk" } }, - new object[] { "/sd", true, new List() } - }; - - [TestCaseSource(nameof(sourceLists))] - public void OutputsCodeownersForSimplePath( - string targetPath, - bool excludeNonUserAliases, - List expectedOwners) - { - using var consoleOutput = new ConsoleOutput(); - - // Act - Program.Main(targetPath, CodeownersFilePath, excludeNonUserAliases); - - string actualOutput = consoleOutput.GetStdout(); - AssertOwners(actualOutput, expectedOwners); - } - - [TestCase("PathNotExist")] - [TestCase("http://testLink")] - [TestCase("https://testLink")] - public void ErrorsOutOnInvalidInputs(string codeownersPath) - { - Assert.That(Program.Main("sdk", codeownersPath), Is.EqualTo(1)); - } - - private static void AssertOwners(string actualOutput, List expectedOwners) - { - CodeownersEntry? actualEntry = JsonSerializer.Deserialize(actualOutput); - List actualOwners = actualEntry!.Owners; - Assert.That(actualOwners, Has.Count.EqualTo(expectedOwners.Count)); - for (int i = 0; i < actualOwners.Count; i++) - { - Assert.That(actualOwners[i], Is.EqualTo(expectedOwners[i])); - } - } - } -}