-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModule.Tests.ps1
More file actions
69 lines (60 loc) · 2.63 KB
/
Copy pathModule.Tests.ps1
File metadata and controls
69 lines (60 loc) · 2.63 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
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$functionFolder = "$here\functions"
$module = "DosInstallUtilities.Menu"
Get-Module "$module" | Remove-Module -Force
Import-Module "$here\$module.psm1" -Force
# $Credential = Get-Credential -UserName "$env:USERNAME@$env:USERDNSDOMAIN" -Message "login please"
# Connect-AzureRmAccount -Credential $Credential
LoginToAzure -Verbose
Describe "$module Tests" {
It "has the root module $module.psm1" {
"$here\$module.psm1" | Should Exist
}
It "has the manifest file for $module.psm1" {
"$here\$module.psd1" | Should Exist
}
It "$module folder has functions" {
"$functionFolder" | Should Exist
}
It "$module is valid Powershell Code" {
$psFile = Get-Content -Path "$here\$module.psm1" -ErrorAction Stop
$errors = $null
$null = [System.Management.Automation.PSParser]::Tokenize($psFile, [ref]$errors)
$errors.Count | Should Be 0
}
$files = $(Get-ChildItem -Path $functionFolder -Recurse -File | Where {$_.Name -notcontains "Tests.ps1"} | % { $_.FullName })
foreach($file in $files)
{
# Write-Host "file: $file"
[string]$function = $file
$function = $function.Replace($functionFolder,"")
$function = $function.Replace(".ps1","")
# Write-Host "function: $function"
if(!$function.EndsWith("Tests")){
Context "Test Function $function" {
It "$function.ps1 should exist" {
"$functionFolder\$function.ps1" | Should Exist
}
It "$function.ps1 should be an advanced function" {
"$functionFolder\$function.ps1" | Should Contain 'function'
"$functionFolder\$function.ps1" | Should Contain 'cmdletbinding'
"$functionFolder\$function.ps1" | Should Contain 'param'
}
It "$function.ps1 should contain Write-Verbose blocks" {
"$functionFolder\$function.ps1" | Should Contain 'Write-Verbose'
}
It "$function.ps1 is valid Powershell Code" {
$psFile = Get-Content -Path "$functionFolder\$function.ps1" -ErrorAction Stop
$errors = $null
$null = [System.Management.Automation.PSParser]::Tokenize($psFile, [ref]$errors)
$errors.Count | Should Be 0
}
}
Context "$function has tests" {
It "$function.Tests.ps1 should exist" {
"$functionFolder\$function.Tests.ps1" | Should Exist
}
}
}
}
}