Skip to content

Commit 7f57e61

Browse files
committed
Add simple command tests for AzF profile
1 parent b700465 commit 7f57e61

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

Tests/Rules/UseCompatibleCommands.Tests.ps1

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ $script:Win10_5_profile = 'win-48_x64_10.0.17763.0_5.1.17763.316_x64_4.0.30319.4
1515
$script:Win10_6_1_profile = 'win-48_x64_10.0.17763.0_6.1.3_x64_4.0.30319.42000_core'
1616
$script:Ubuntu1804_6_1_profile = 'ubuntu_x64_18.04_6.1.3_x64_4.0.30319.42000_core'
1717

18+
$script:AzF_profile = Resolve-Path "$PSScriptRoot/../../PSCompatibilityCollector/optional_profiles/azurefunctions.json"
19+
$script:AzA_profile = Resolve-Path "$PSScriptRoot/../../PSCompatibilityCollector/optional_profiles/azureautomation.json"
20+
1821
$script:CompatibilityTestCases = @(
1922
@{ Target = $script:Srv2012_3_profile; Script = 'Write-Information "Information"'; Commands = @("Write-Information"); Version = "3.0"; OS = "Windows"; ProblemCount = 1 }
2023
@{ Target = $script:Srv2012_3_profile; Script = '"Hello World" | ConvertFrom-String | Get-Member'; Commands = @("ConvertFrom-String"); Version = "3.0"; OS = "Windows"; ProblemCount = 1 }
@@ -299,4 +302,53 @@ Describe 'UseCompatibleCommands' {
299302
$diagnostics.Count | Should -Be 0
300303
}
301304
}
305+
306+
Context 'Targeting new-form Az profiles alongside older profiles' {
307+
BeforeAll {
308+
$settings = @{
309+
Rules = @{
310+
$script:RuleName = @{
311+
$script:TargetProfileConfigKey = @(
312+
$script:AzF_profile
313+
$script:AzA_profile
314+
$script:Win10_5_profile
315+
)
316+
}
317+
}
318+
}
319+
}
320+
321+
It "Finds AzF problems with a script" {
322+
$diagnostics = Invoke-ScriptAnalyzer -IncludeRule $script:RuleName -Settings $settings -ScriptDefinition '
323+
Get-WmiObject Win32_Process
324+
New-SelfSignedCertificate
325+
Invoke-MySpecialFunction
326+
'
327+
328+
$diagnostics.Count | Should -Be 2
329+
$diagnosticGroups = Group-Object $diagnostics -Property Command
330+
foreach ($group in $diagnosticGroups)
331+
{
332+
switch ($group.Name)
333+
{
334+
'Get-WmiObject'
335+
{
336+
$group.Count | Should -Be 1
337+
$group.Group[0].Command | Should -BeExactly 'Get-WmiObject'
338+
}
339+
340+
'New-SelfSignedCertificate'
341+
{
342+
$group.Count | Should -Be 1
343+
$group.Group[0].Command | Should -BeExactly 'New-SelfSignedCertificate'
344+
}
345+
346+
default
347+
{
348+
$group | Should -Be $null
349+
}
350+
}
351+
}
352+
}
353+
}
302354
}

0 commit comments

Comments
 (0)