Skip to content

Commit

Permalink
Update the data in the test cases (#18496)
Browse files Browse the repository at this point in the history
* Fix the unit tests.

- Parsing the command parameter requires the module to be loaded. On the machine (e.g. build machine) where the Az modules are not installed, the
  parsing doesn't return the parameters names as expected. Some test cases thus fail. The fix is to remove Az cmdlets from the test cases. Instead, we
  use the cmdlet from the built-in modules in the test cases.

* Replace the way of getting the data.

- We used to zip the whole model and read from it. Since we don't need to use Az cmdlet in the test cases, we don't really need to zip the model.
  So we use the json file with crafted built-in PowerShell cmdlet as the data used in the test cases. With that, it's also clear to show the changes
  to the test cases and the data.

Add Dotnet Core 6 in pipeline.

Add logic for global.json

Add logic for global.json
  • Loading branch information
kceiw authored and wyunchi-ms committed Jun 22, 2022
1 parent af693c5 commit 3f3e8ac
Show file tree
Hide file tree
Showing 23 changed files with 341 additions and 172 deletions.
1 change: 1 addition & 0 deletions .azure-pipelines/powershell-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ variables:
BuildTimeoutInMinutes: 120
AnalysisTimeoutInMinutes: 120
TestTimeoutInMinutes: 180
BuildAzPredictor: false

trigger: none

Expand Down
17 changes: 15 additions & 2 deletions .azure-pipelines/util/analyze-steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,27 @@ steps:
pwsh: true

- task: UseDotNet@2
displayName: 'Use .NET Core sdk'
displayName: 'Use .NET Core sdk 3.1.x'
inputs:
packageType: sdk
version: 3.1.x

- task: UseDotNet@2
displayName: 'Use .NET Core sdk 6.0.x'
inputs:
packageType: sdk
version: 6.0.x

- task: PowerShell@2
displayName: Setup global.json
inputs:
targetType: inline
script: "$SdkVersion=(dotnet --list-sdks | Select-String '3.1.\\d{3}').Matches[0].Value; dotnet new globaljson --sdk-version $SdkVersion --force"
pwsh: true

- pwsh: 'Install-Module "platyPS", "PSScriptAnalyzer" -Force -Confirm:$false -Scope CurrentUser'
displayName: 'Install PowerShell Dependencies'

- task: DotNetCoreCLI@2
displayName: 'Generate Help'
inputs:
Expand Down
19 changes: 17 additions & 2 deletions .azure-pipelines/util/build-steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,39 @@ steps:
filePath: tools/CheckIgnoredFile.ps1

- task: UseDotNet@2
displayName: 'Use .NET Core sdk'
displayName: 'Use .NET Core sdk 3.1.x'
inputs:
packageType: sdk
version: 3.1.x

- task: UseDotNet@2
displayName: Use .NET 6.0
displayName: 'Use .NET Core sdk 6.0.x'
inputs:
packageType: sdk
version: 6.0.x

- task: PowerShell@2
displayName: Setup global.json
inputs:
targetType: inline
script: "$SdkVersion=(dotnet --list-sdks | Select-String '3.1.\\d{3}').Matches[0].Value; dotnet new globaljson --sdk-version $SdkVersion --force"
pwsh: true

- task: DotNetCoreCLI@2
displayName: Build
inputs:
command: custom
custom: msbuild
arguments: 'build.proj /t:Build /p:Configuration=${{ parameters.configuration }};TestFramework=${{ parameters.testFramework }};PullRequestNumber=$(System.PullRequest.PullRequestNumber)'

- task: DotNetCoreCLI@2
displayName: Build-AzPredictor
condition: eq(variables.BuildAzPredictor, 'true')
inputs:
command: custom
custom: msbuild
arguments: 'tools/Az.Tools.Predictor/build.proj /t:"clean;build;test"'

- template: publish-artifacts-steps.yml
parameters:
artifactName: build-${{ parameters.testFramework }}
15 changes: 14 additions & 1 deletion .azure-pipelines/util/test-steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,24 @@ steps:
pwsh: true

- task: UseDotNet@2
displayName: 'Use .NET Core sdk'
displayName: 'Use .NET Core sdk 3.1.x'
inputs:
packageType: sdk
version: 3.1.x

- task: UseDotNet@2
displayName: 'Use .NET Core sdk 6.0.x'
inputs:
packageType: sdk
version: 6.0.x

- task: PowerShell@2
displayName: Setup global.json
inputs:
targetType: inline
script: "$SdkVersion=(dotnet --list-sdks | Select-String '3.1.\\d{3}').Matches[0].Value; dotnet new globaljson --sdk-version $SdkVersion --force"
pwsh: true

- task: DotNetCoreCLI@2
displayName: Test
inputs:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ SecurityTmp/
tmp/
FilesChanged.txt
CsprojMappings.json
global.json

obj
bin
Expand Down
6 changes: 1 addition & 5 deletions build.proj
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
<Exec Command="dotnet new sln -n Azure.PowerShell -o $(RepoArtifacts) --force" />
<CallTarget Targets="BuildNormalModules" />

<CallTarget Targets="AzToolsPredictor" Condition="$(SubTasks.Contains('Predictor')) OR $(SubTasks.Contains('all'))" />
<Exec Command="##vso[task.setvariable variable=BuildAzPredictor]true" Condition="$(SubTasks.Contains('Predictor')) OR $(SubTasks.Contains('all'))" />
<CallTarget Targets="AzToolsInstaller" Condition="$(SubTasks.Contains('Installer')) OR $(SubTasks.Contains('all'))" />
</Target>

Expand Down Expand Up @@ -290,10 +290,6 @@
<Exec Command='dotnet msbuild $(RepoTools)/Az.Tools.Installer/build.proj /t:"clean;build;test"' />
</Target>

<Target Name="AzToolsPredictor">
<Exec Command='dotnet msbuild $(RepoTools)/Az.Tools.Predictor/build.proj /t:"clean;build;test"' />
</Target>

<Target Name="ChangeLogErrorMessage">
<Error Text="Modified files were found with no update to their change log. Please add a snippet to the affected modules' change log." />
</Target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
</ItemGroup>

<ItemGroup>
<None Include="Data\CommandsModel.zip" CopyToOutputDirectory="PreserveNewest" />
<None Include="Data\PredictionsModel.zip" CopyToOutputDirectory="PreserveNewest" />
<None Include="Data\CommandsModel.json" CopyToOutputDirectory="PreserveNewest" />
<None Include="Data\PredictionsModel.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void Dispose()
[Fact]
public void VerifyParameterValues()
{
var predictionContext = PredictionContext.Create("Get-AzContext");
var predictionContext = PredictionContext.Create("Set-Content");

Action actual = () => this._service.GetSuggestion(null, 1, 1, CancellationToken.None);
Assert.Throws<ArgumentNullException>(actual);
Expand All @@ -116,14 +116,14 @@ public void VerifyParameterValues()
/// Verifies that the prediction comes from the command based list, not the fallback list.
/// </summary>
[Theory]
[InlineData("CONNECT-AZACCOUNT")]
[InlineData("set-azstorageaccount ")]
[InlineData("Get-AzResourceG")]
[InlineData("Get-AzStorageAcco")]
[InlineData("Get-AzKeyVault -VaultName")]
[InlineData("GET-AZSTORAGEACCOUNTKEY -NAME ")]
[InlineData("new-azresourcegroup -name hello")]
[InlineData("new-azresourcegroup hello")]
[InlineData("SET-CONTENT")]
[InlineData("get-logproperties ")]
[InlineData("Clear-C")]
[InlineData("compare-")]
[InlineData("Clear-Variable -Name")]
[InlineData("CLEAR-CONTENT -PATH test")]
[InlineData("Clear-content -path test")]
[InlineData("clear-content ./Test.log")]
public void VerifyUsingCommandBasedPredictor(string userInput)
{
var predictionContext = PredictionContext.Create(userInput);
Expand Down Expand Up @@ -165,8 +165,8 @@ public void VerifyUsingCommandBasedPredictor(string userInput)
/// Verifies that when no prediction is in the command based list, we'll use the fallback list.
/// </summary>
[Theory]
[InlineData("New-AzApiManagementContext -ResourceGroupName hello -Serv")]
[InlineData("Get-AzAlert -TimeRange '1h' -Incl")]
[InlineData("Set-Variable -Name desc -Value ")]
[InlineData("remove-ite")]
public void VerifyUsingFallbackPredictor(string userInput)
{
var predictionContext = PredictionContext.Create(userInput);
Expand Down Expand Up @@ -209,12 +209,13 @@ public void VerifyUsingFallbackPredictor(string userInput)
/// </summary>
[Theory]
[InlineData(AzPredictorConstants.CommandPlaceholder)]
[InlineData("Get-Help")]
[InlineData("Get-ChildItem")]
[InlineData("new-azresourcegroup -NoExistingParam")]
[InlineData("get-azaccount ")]
[InlineData("NEW-AZCONTEXT")]
[InlineData("Remove-Item -NoExistingParam")]
[InlineData("get-childitem ")]
[InlineData("NEW-CHILDITEM ")]
[InlineData("git status")]
[InlineData("Get-AzContext Name")]
[InlineData("get-item name")]
public void VerifyNoPrediction(string userInput)
{
var predictionContext = PredictionContext.Create(userInput);
Expand All @@ -235,7 +236,7 @@ public void VerifyNoPrediction(string userInput)
/// Verify that it returns null when we cannot parse the user input.
/// </summary>
[Theory]
[InlineData("New-AzVM -Name A $Location")]
[InlineData("Remove-Item -Name A $Location")]
public void VerifyFailToParseUserInput(string userInput)
{
var predictionContext = PredictionContext.Create(userInput);
Expand Down
Loading

0 comments on commit 3f3e8ac

Please sign in to comment.