Repository navigation
Set up spector tests generation for http-client-csharp-mgmt #54206
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
Changes from 3 commits
1203f1f
e1a9701
9f002db
02a7753
9cf5891
ca9c2ff
e04b06d
a646e35
e89e815
2fe3176
8e7d85b
e334453
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,113 @@ | ||||||||||||||||||||
| $repoRoot = Resolve-Path (Join-Path $PSScriptRoot '..') | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # These are specs that are not yet building correctly with the management generator | ||||||||||||||||||||
| # Add specs here as needed when they fail to build | ||||||||||||||||||||
| $failingSpecs = @( | ||||||||||||||||||||
| ) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| function Capitalize-FirstLetter { | ||||||||||||||||||||
| param ( | ||||||||||||||||||||
| [string]$inputString | ||||||||||||||||||||
| ) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if ([string]::IsNullOrEmpty($inputString)) { | ||||||||||||||||||||
| return $inputString | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| $firstChar = $inputString[0].ToString().ToUpper() | ||||||||||||||||||||
| $restOfString = $inputString.Substring(1) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| return $firstChar + $restOfString | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| function Get-Namespace { | ||||||||||||||||||||
| param ( | ||||||||||||||||||||
| [string]$dir | ||||||||||||||||||||
| ) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| $words = $dir.Split('-') | ||||||||||||||||||||
| $namespace = "" | ||||||||||||||||||||
| foreach ($word in $words) { | ||||||||||||||||||||
| $namespace += Capitalize-FirstLetter $word | ||||||||||||||||||||
| } | ||||||||||||||||||||
| return $namespace | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| function IsValidSpecDir { | ||||||||||||||||||||
| param ( | ||||||||||||||||||||
| [string]$fullPath | ||||||||||||||||||||
| ) | ||||||||||||||||||||
| if (-not(Test-Path "$fullPath/main.tsp")){ | ||||||||||||||||||||
| return $false; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| $subPath = Get-SubPath $fullPath | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if ($failingSpecs.Contains($subPath)) { | ||||||||||||||||||||
| Write-Host "Skipping $subPath" -ForegroundColor Yellow | ||||||||||||||||||||
| return $false | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| return $true | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| function Get-Azure-Specs-Directory { | ||||||||||||||||||||
| $packageRoot = Resolve-Path (Join-Path $PSScriptRoot '..' '..') | ||||||||||||||||||||
| return Join-Path $packageRoot 'node_modules' '@azure-tools' 'azure-http-specs' | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| function Get-Sorted-Specs { | ||||||||||||||||||||
| $azureSpecsDirectory = Get-Azure-Specs-Directory | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # Only get azure resource-manager specs | ||||||||||||||||||||
| $resourceManagerPath = Join-Path $azureSpecsDirectory "specs" "azure" "resource-manager" | ||||||||||||||||||||
| $directories = @(Get-ChildItem -Path $resourceManagerPath -Directory -Recurse) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| $sep = [System.IO.Path]::DirectorySeparatorChar | ||||||||||||||||||||
| $pattern = "${sep}specs${sep}" | ||||||||||||||||||||
|
|
||||||||||||||||||||
| return $directories | Where-Object { IsValidSpecDir $_.FullName } | ForEach-Object { | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # Pick client.tsp if it exists, otherwise main.tsp | ||||||||||||||||||||
| $specFile = Join-Path $_.FullName "client.tsp" | ||||||||||||||||||||
| if (-not (Test-Path $specFile)) { | ||||||||||||||||||||
| $specFile = Join-Path $_.FullName "main.tsp" | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # Extract the relative path after "specs/" and normalize slashes | ||||||||||||||||||||
| $relativePath = ($specFile -replace '[\\\/]', '/').Substring($_.FullName.IndexOf($pattern) + $pattern.Length) | ||||||||||||||||||||
|
||||||||||||||||||||
| $relativePath = ($specFile -replace '[\\\/]', '/').Substring($_.FullName.IndexOf($pattern) + $pattern.Length) | |
| $normalizedFullName = $_.FullName -replace '[\\\/]', '/' | |
| $patternIndex = $normalizedFullName.IndexOf($pattern) | |
| if ($patternIndex -ge 0) { | |
| $relativePath = ($specFile -replace '[\\\/]', '/').Substring($patternIndex + $pattern.Length) | |
| } else { | |
| Write-Host "Warning: Pattern '$pattern' not found in '$normalizedFullName'. Skipping this item." -ForegroundColor Yellow | |
| $relativePath = "" | |
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,82 @@ | ||||||
| #Requires -Version 7.0 | ||||||
|
|
||||||
| param($filter) | ||||||
|
|
||||||
| Import-Module "$PSScriptRoot\Generation.psm1" -DisableNameChecking -Force; | ||||||
| Import-Module "$PSScriptRoot\Spector-Helper.psm1" -DisableNameChecking -Force; | ||||||
|
|
||||||
| $packageRoot = Resolve-Path (Join-Path $PSScriptRoot '..' '..') | ||||||
|
|
||||||
| Refresh-Mgmt-Build | ||||||
|
|
||||||
| $spectorRoot = Join-Path $packageRoot 'generator' 'TestProjects' 'Spector' | ||||||
| $spectorCsproj = Join-Path $packageRoot 'generator' 'TestProjects' 'Spector.Tests' 'TestProjects.Spector.Tests.csproj' | ||||||
|
|
||||||
| $coverageDir = Join-Path $packageRoot 'generator' 'artifacts' 'coverage' | ||||||
|
|
||||||
| if (-not (Test-Path $coverageDir)) { | ||||||
| New-Item -ItemType Directory -Path $coverageDir | Out-Null | ||||||
| } | ||||||
|
|
||||||
| foreach ($specFile in Get-Sorted-Specs) { | ||||||
| $subPath = Get-SubPath $specFile | ||||||
|
|
||||||
| # skip the HTTP root folder when computing the namespace filter | ||||||
| $folders = $subPath.Split([System.IO.Path]::DirectorySeparatorChar) | Select-Object -Skip 1 | ||||||
|
|
||||||
| if (-not (Compare-Paths $subPath $filter)) { | ||||||
| continue | ||||||
| } | ||||||
|
|
||||||
| $testPath = Join-Path "$spectorRoot.Tests" "Http" | ||||||
| $testFilter = "TestProjects.Spector.Tests.Http" | ||||||
| foreach ($folder in $folders) { | ||||||
| $segment = "$(Get-Namespace $folder)" | ||||||
|
|
||||||
| # the test directory names match the test namespace names, but the source directory names will not have the leading underscore | ||||||
| # so check to see if the filter should contain a leading underscore by comparing with the test directory | ||||||
| if (-not (Test-Path (Join-Path $testPath $segment))) { | ||||||
| $testFilter += "._$segment" | ||||||
| $testPath = Join-Path $testPath "_$segment" | ||||||
| } | ||||||
| else{ | ||||||
|
||||||
| else{ | |
| else { |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using NUnit.Framework; | ||
|
|
||
| namespace TestProjects.Spector.Tests | ||
| { | ||
| [SetUpFixture] | ||
| public static class AssemblyCleanFixture | ||
| { | ||
| [OneTimeTearDown] | ||
| public static void RunOnAssemblyCleanUp() | ||
| { | ||
| SpectorServerSession.Start().Server?.Dispose(); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System; | ||
| using NUnit.Framework; | ||
|
|
||
| namespace TestProjects.Spector.Tests | ||
| { | ||
| public static class BinaryDataAssert | ||
| { | ||
| public static void AreEqual(BinaryData expected, BinaryData result) | ||
| { | ||
| CollectionAssert.AreEqual(expected?.ToArray(), result?.ToArray()); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System; | ||
|
|
||
| namespace TestProjects.Spector.Tests | ||
| { | ||
| [AttributeUsage(AttributeTargets.Assembly)] | ||
| internal sealed class BuildPropertiesAttribute : Attribute | ||
| { | ||
| public string RepoRoot { get; } | ||
| public string ArtifactsDirectory { get; } | ||
|
|
||
| public BuildPropertiesAttribute(string repoRoot, string artifactsDirectory) | ||
| { | ||
| RepoRoot = repoRoot; | ||
| ArtifactsDirectory = artifactsDirectory; | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System.ClientModel.Primitives; | ||
| using Azure.Generator.Management.Tests.Common; | ||
|
|
||
| namespace TestProjects.Spector.Tests.Infrastructure | ||
| { | ||
| public abstract class SpectorModelJsonTests<T> : SpectorModelTests<T> where T : IJsonModel<T> | ||
| { | ||
| [SpectorTest] | ||
| public void RoundTripWithJsonInterfaceOfTWire() | ||
| => RoundTripTest("W", new JsonInterfaceStrategy<T>()); | ||
|
|
||
| [SpectorTest] | ||
| public void RoundTripWithJsonInterfaceOfTJson() | ||
| => RoundTripTest("J", new JsonInterfaceStrategy<T>()); | ||
|
|
||
| [SpectorTest] | ||
| public void RoundTripWithJsonInterfaceNonGenericWire() | ||
| => RoundTripTest("W", new JsonInterfaceAsObjectStrategy<T>()); | ||
|
|
||
| [SpectorTest] | ||
| public void RoundTripWithJsonInterfaceNonGenericJson() | ||
| => RoundTripTest("J", new JsonInterfaceAsObjectStrategy<T>()); | ||
|
|
||
| [SpectorTest] | ||
| public void RoundTripWithJsonInterfaceUtf8ReaderWire() | ||
| => RoundTripTest("W", new JsonInterfaceUtf8ReaderStrategy<T>()); | ||
|
|
||
| [SpectorTest] | ||
| public void RoundTripWithJsonInterfaceUtf8ReaderJson() | ||
| => RoundTripTest("J", new JsonInterfaceUtf8ReaderStrategy<T>()); | ||
|
|
||
| [SpectorTest] | ||
| public void RoundTripWithJsonInterfaceUtf8ReaderNonGenericWire() | ||
| => RoundTripTest("W", new JsonInterfaceUtf8ReaderAsObjectStrategy<T>()); | ||
|
|
||
| [SpectorTest] | ||
| public void RoundTripWithJsonInterfaceUtf8ReaderNonGenericJson() | ||
| => RoundTripTest("J", new JsonInterfaceUtf8ReaderAsObjectStrategy<T>()); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot revert the change in this file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted the changes to Generation.psm1 in e04b06d.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot after reverting, regenerate the spector tests as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regenerated the spector tests after the revert. The generated code remains unchanged because the Spector generation uses
-g MgmtStubGeneratorflag directly via launchSettings profiles, which is not affected by theplugin-nameoption in Generation.psm1.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we update the flag from
MgmtStubGeneratortoStubGeneratorand make the regen work with stubbed version?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot check the comment above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to use
AzureStubGeneratorin a646e35. Changed the-gflag fromMgmtStubGeneratortoAzureStubGeneratorin Generate.ps1 and regenerated the launchSettings.json.