-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInvoke-PSWorkflowController.1.publishing.tests.ps1
More file actions
102 lines (89 loc) · 3.95 KB
/
Invoke-PSWorkflowController.1.publishing.tests.ps1
File metadata and controls
102 lines (89 loc) · 3.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
$scriptToAnalyze=".\Invoke-PSWorkflowController.ps1"
$scriptName="Invoke-PSWorkflowController"
Describe -Name "reposiroty structure tests"{
It -name "Should have a README.MD file" {
"README.MD" | Should exist
}
try {
$ScriptFileInfo = Test-ScriptFileInfo -Path $scriptToAnalyze -ErrorAction Stop
} catch {
$ScriptFileInfo = "TestFailed"
}
It -name "Should meet PowerShell Gallery Requirements" {
$ScriptFileInfo | Should -Not -Be "TestFailed"
}
try {
$scriptInGallery=Find-Script -Name $scriptName -ErrorAction Stop -WarningAction Stop
} catch {
if($error[0].Exception.Message.Contains("No match was found for the specified search criteria and script name")) {
$scriptInGallery=$null
} else {
$scriptInGallery="Gallery failed"
}
}
if($null -ne $scriptInGallery -and $scriptInGallery -ne "Gallery failed") {
It -name "Should be owned by me" {
$scriptInGallery.Author | Should -Be $ScriptFileInfo.Author
}
} else {
It -name "Should not have another script in the gallery named the same" {
$scriptInGallery | Should -BeNullOrEmpty
}
}
It -name "Script Analyzer should not produce any recommendations" {
Invoke-ScriptAnalyzer -Path $scriptToAnalyze -IncludeRule @('PSUseApprovedVerbs',
'PSReservedCmdletChar',
'PSReservedParams',
'PSShouldProcess',
'PSUseShouldProcessForStateChangingFunctions',
'PSUseSingularNouns',
'PSMissingModuleManifestField',
'PSAvoidDefaultValueSwitchParameter',
'PSAvoidUsingCmdletAliases',
'PSAvoidUsingWMICmdlet',
'PSAvoidUsingEmptyCatchBlock',
'PSUseCmdletCorrectly',
'PSUseShouldProcessForStateChangingFunctions',
'PSAvoidUsingPositionalParameters',
'PSAvoidGlobalVars',
'PSUseDeclaredVarsMoreThanAssignments',
'PSAvoidUsingInvokeExpression',
'PSAvoidUsingPlainTextForPassword',
'PSAvoidUsingComputerNameHardcoded',
'PSUsePSCredentialType',
'PSDSC*' ) | Should -BeNullorEmpty
}
}
Describe -Name "documentation (comment based help) tests" {
It -name "Should contain start for the Help block <#" {
Get-Content -Path $scriptToAnalyze | Should -Contain '<#'
}
It -name "Should contain a SYNOPSIS section" {
Get-Content -Path $scriptToAnalyze | Should -Contain ' .SYNOPSIS'
}
It -name "Should contain a DESCRIPTION section" {
Get-Content -Path $scriptToAnalyze | Should -Contain ' .DESCRIPTION'
}
$bindings=@("Verbose","Debug","ErrorAction","WarningAction","InformationAction","ErrorVariable","WarningVariable","InformationVariable","OutVariable","OutBuffer","PipelineVariable")
$parameters=(Get-Command -Name $scriptToAnalyze | Select-Object -ExpandProperty Parameters).Keys | Where-Object { $_ -notin $bindings }
foreach ($parameter in $parameters) {
It -name "Should contain PARAMETER $parameter section" {
Get-Content -Path $scriptToAnalyze | Should -Contain " .PARAMETER $parameter"
}
}
It -name "Should contain at least 1 example" {
Get-Content -Path $scriptToAnalyze | Should -Contain ' .EXAMPLE'
}
It -name "Should contain a LINK section" {
Get-Content -Path $scriptToAnalyze | Should -Contain ' .LINK'
}
It -name "Should contain an INPUTS section" {
Get-Content -Path $scriptToAnalyze | Should -Contain ' .INPUTS'
}
It -name "Should contain an OUTPUTS section" {
Get-Content -Path $scriptToAnalyze | Should -Contain ' .OUTPUTS'
}
It -name "Should contain closure for the Help block #>" {
Get-Content -Path $scriptToAnalyze | Should -Contain '#>'
}
}