Skip to content

Fix sdk module test issue #28118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace Microsoft.Azure.PowerShell.AssemblyLoading.Test.UnitTests
{
public class ConditionalAssemblyProviderTests
{
private const string NetFx = "netfx";
private const string Net45 = "net45";
private const string NetStandard20 = "netstandard2.0";
private const string RootPath = "root";

Expand All @@ -44,7 +44,7 @@ public void CanGetAssembliesOnWindowsPowerShell()
Assert.True(assemblies.TryGetValue("Azure.Core", out var azureCore));
Assert.Equal(GetExpectedAssemblyPath(NetStandard20, "Azure.Core"), azureCore.Path);
Assert.True(assemblies.TryGetValue("Newtonsoft.Json", out var newtonsoftJson));
Assert.Equal(GetExpectedAssemblyPath(NetFx, "Newtonsoft.Json"), newtonsoftJson.Path);
Assert.Equal(GetExpectedAssemblyPath(Net45, "Newtonsoft.Json"), newtonsoftJson.Path);

Assert.True(assemblies.TryGetValue("Azure.Identity", out var azureIdentity));
Assert.Equal(GetExpectedAssemblyPath(NetStandard20, "Azure.Identity"), azureIdentity.Path);
Expand Down
37 changes: 23 additions & 14 deletions tools/BuildScripts/BuildScripts.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function Get-CsprojFromModule {
[string]$Configuration
)
$renamedModules = @{
'Storage' = @('Storage.Management');
'Storage' = @('Storage.Management')
'DataFactory' = @('DataFactoryV1', 'DataFactoryV2')
}

Expand Down Expand Up @@ -62,10 +62,15 @@ function Get-CsprojFromModule {
$result += $testCsproj
}
}
} else {
$testCsproj = Join-Path $SourceDirectory $testModule "$testModule.Test" "$testModule.Test.csproj"
if (Test-Path $testCsproj) {
$result += $testCsproj
}
else {
$testModulePath = Join-Path $SourceDirectory $testModule
$testFolders = Get-ChildItem -Path $testModulePath -Filter *.Test -Directory
if ($null -ne $testFolders) {
$testCsproj = $testFolders | Get-ChildItem -Filter *.Test.csproj -File | Select-Object -ExpandProperty FullName
if (Test-Path $testCsproj) {
$result += $testCsproj
}
}
}
}
Expand All @@ -89,17 +94,20 @@ function Invoke-SubModuleGeneration {
$tspLocationPath = Join-Path $GenerateDirectory "tsp-location.yaml"
if (Test-Path $tspLocationPath) {
tsp-client update >> $GenerateLog
} else {
}
else {
if ($IsInvokedByPipeline) {
npx autorest --max-memory-size=8192 >> $GenerateLog
} else {
}
else {
autorest --max-memory-size=8192 >> $GenerateLog
}
}

if ($lastexitcode -ne 0) {
return $false
} else {
}
else {
./build-module.ps1 -DisableAfterBuildTasks
Write-Host "----------End code generation for $GenerateDirectory----------" -ForegroundColor DarkGreen
return $true
Expand Down Expand Up @@ -145,15 +153,15 @@ function Update-GeneratedSubModule {
}

if (-not (Invoke-SubModuleGeneration -GenerateDirectory $SourceDirectory -GenerateLog $GenerateLog -IsInvokedByPipeline $IsInvokedByPipeline)) {
return $false;
return $false
}
# remove $sourceDirectory/generated/modules
$localModulesPath = Join-Path $SourceDirectory 'generated' 'modules'
if (Test-Path $localModulesPath) {
Remove-Item -Path $localModulesPath -Recurse -Force
}
$fileToUpdate = @('generated', 'resources', "Az.$subModuleNameTrimmed.psd1", "Az.$subModuleNameTrimmed.psm1", "Az.$subModuleNameTrimmed.format.ps1xml", 'exports', 'internal', 'test-module.ps1', 'check-dependencies.ps1')
# Copy from src/ to generated/
# Copy from src/ to generated/
$fileToUpdate | Foreach-Object {
$moveFrom = Join-Path $SourceDirectory $_
$moveTo = Join-Path $GeneratedDirectory $_
Expand All @@ -162,7 +170,7 @@ function Update-GeneratedSubModule {
}
# regenerate csproj
New-GeneratedFileFromTemplate -TemplateName 'Az.ModuleName.csproj' -GeneratedFileName "Az.$subModuleNameTrimmed.csproj" -GeneratedDirectory $GeneratedDirectory -ModuleRootName $ModuleRootName -SubModuleName $subModuleNameTrimmed -SubModuleNameFull $SubModuleName

# revert guid in psd1 so that no conflict in updating this file
if ($guid) {
$psd1Path = Join-Path $GeneratedDirectory "Az.$subModuleNameTrimmed.psd1"
Expand Down Expand Up @@ -205,7 +213,8 @@ function New-GeneratedFileFromTemplate {
$templateFile = $templateFile -replace '{LowCaseModuleNamePlaceHolder}', $SubModuleName.ToLower()
if ($SubModuleNameFull) {
$templateFile = $templateFile -replace '{ModuleFolderPlaceHolder}', $SubModuleNameFull
} else {
}
else {
$templateFile = $templateFile -replace '{ModuleFolderPlaceHolder}', "$SubModuleName.Autorest"
}
$templateFile = $templateFile -replace '{RootModuleNamePlaceHolder}', $ModuleRootName
Expand All @@ -228,7 +237,7 @@ function New-GenerateInfoJson {
$generateInfoJson["generate_Id"] = $GenerateId
$generateInfoJson | ConvertTo-Json | Set-Content -Path $generateInfoJsonPath -Force
}
else{
else {
Write-Host "Generating generate-info.json file: $generateInfoJsonPath"
$generateInfoJson | Set-Content -Path $generateInfoJsonPath -Force
}
Expand All @@ -253,4 +262,4 @@ function Update-MappingJson {
$MappingObject = $MappingObject + @{module = $ModuleName; alias = $ModuleName }
ConvertTo-Json $MappingObject -Depth 1 | Set-Content -Path $MappingPath
}
}
}
Loading