Skip to content

Commit cce6ffd

Browse files
committed
added more tests, added testing initialization
1 parent a3186db commit cce6ffd

File tree

3 files changed

+74
-23
lines changed

3 files changed

+74
-23
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
## initialization code for use by multiple *.Tests.ps1 files for testing vNugglets.Utility PowerShell module
2+
3+
$strNameOfModuleToTest = "vNugglets.Utility"
4+
## if module not already loaded, try to load it (assumes that module is in PSModulePath)
5+
if (-not ($oModuleInfo = Get-Module $strNameOfModuleToTest)) {
6+
$oModuleInfo = Import-Module $strNameOfModuleToTest -PassThru
7+
if (-not ($oModuleInfo -is [System.Management.Automation.PSModuleInfo])) {Throw "Could not load module '$strNameOfModuleToTest' -- is it available in the PSModulePath? You can manually load the module and start tests again"}
8+
} ## end if
9+
Write-Verbose -Verbose ("Starting testing of module '{0}' (version '{1}' from '{2}')" -f $oModuleInfo.Name, $oModuleInfo.Version, $oModuleInfo.Path)
10+
11+
## ensure that this session is connected to at least one vCenter server (prompt to do so if not already connected)
12+
$oSomeVCConnection = if (-not (($global:DefaultVIServers | Measure-Object).Count -gt 0)) {
13+
$hshParamForConnectVIServer = @{Server = $(Read-Host -Prompt "vCenter server name to which to connect for testing")}
14+
ConnVIServer @hshParamForConnectVIServer
15+
} ## end if
16+
else {$global:DefaultVIServers[0]}
Lines changed: 53 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<# .Description
2-
Pester tests for vNugglets.Utility PowerShell module. Expects that:
2+
Pester tests for vNugglets.Utility PowerShell module. Will expect that (once fully written):
33
0) vNugglets.Utility module is already loaded (but, will try to load it if not)
44
1) a connection to at least one vCenter is in place (but, will prompt for vCenter to which to connect if not)
55
#>
66

77
## initialize things, preparing for tests
8-
# . $PSScriptRoot\vNugglets.Utility.TestingInit.ps1
8+
. $PSScriptRoot\vNugglets.Utility.TestingInit.ps1
99

1010
Write-Verbose -Verbose "tests not yet fully written"
1111

@@ -21,24 +21,59 @@ Get-VNVMByVirtualPortGroup
2121
Get-VNVMDiskAndRDM
2222
Get-VNVMEVCInfo
2323
Get-VNVMHostBrokenUplink
24-
Get-VNVMHostFirmwareInfo
25-
Get-VNVMHostLogicalVolumeInfo
26-
Get-VNVMHostNICFirmwareAndDriverInfo
2724
Invoke-VNEvacuateDatastore
2825
Move-VNTemplateFromVMHost
2926
Update-VNTitleBarForPowerCLI
3027
#>
3128

32-
Describe -Tags "Get" -Name "Get-VNVMHostHBAWWN" {
33-
It "Gets VMHost HBA WWN information" {
34-
## the NoteProperties that the return objects should have
35-
$arrExpectedReturnObjNotePropertyNames = Write-Output DeviceName HBANodeWWN HBAPortWWN HBAStatus VMHostName
36-
$arrReturnObj = Get-VMHost -State Connected | Select-Object -First 1 | Get-VNVMHostHBAWWN
37-
$arrReturnTypes = $arrReturnObj | Get-Member | Select-Object -Unique -ExpandProperty TypeName
38-
$bGetsOnlyPSCustomObjectType = $arrReturnTypes -eq "System.Management.Automation.PSCustomObject"
39-
## does the array of names of NoteProperties in the set of return objects have only the values expected for return objects? (does the comparison of the arrays return no difference objects?)
40-
$bHasExpectedNoteProperties = $null -eq (Compare-Object -ReferenceObject $arrExpectedReturnObjNotePropertyNames -DifferenceObject ($arrReturnObj | Get-Member -MemberType NoteProperty).Name)
41-
$bGetsOnlyPSCustomObjectType | Should Be $true
42-
$bHasExpectedNoteProperties | Should Be $true
43-
} ## end it
44-
} ## end describe
29+
$oTestVMHost = Get-VMHost -State Connected | Select-Object -First 1
30+
31+
## array of objects, each with information about what and how to test for the given cmdlet; used to create, for each cmdlet, the actual tests below
32+
$arrInfoOnCmdletsToTest = @(
33+
New-Object -Type PSObject -Property @{
34+
CmdletName = "Get-VNVMHostFirmwareInfo"
35+
TestDescription = "Gets VMHost physical server's firmware information (HP-focused)"
36+
ExpectedReturnTypename = "System.Management.Automation.PSCustomObject"
37+
ExpectedReturnObjNotePropertyNames = Write-Output HPSmartArray iLOFirmware Model SystemBIOS VMHostName
38+
TestScriptblock = {$oTestVMHost | Get-VNVMHostFirmwareInfo}
39+
}
40+
New-Object -Type PSObject -Property @{
41+
CmdletName = "Get-VNVMHostHBAWWN"
42+
TestDescription = "Gets VMHost HBA WWN information"
43+
ExpectedReturnTypename = "System.Management.Automation.PSCustomObject"
44+
ExpectedReturnObjNotePropertyNames = Write-Output DeviceName HBANodeWWN HBAPortWWN HBAStatus VMHostName
45+
TestScriptblock = {$oTestVMHost | Get-VNVMHostHBAWWN}
46+
}
47+
New-Object -Type PSObject -Property @{
48+
CmdletName = "Get-VNVMHostLogicalVolumeInfo"
49+
TestDescription = "Gets VMHost's logical volume information"
50+
ExpectedReturnTypename = "System.Management.Automation.PSCustomObject"
51+
ExpectedReturnObjNotePropertyNames = Write-Output LogicalVolume VMHostName
52+
TestScriptblock = {$oTestVMHost | Get-VNVMHostLogicalVolumeInfo}
53+
}
54+
New-Object -Type PSObject -Property @{
55+
CmdletName = "Get-VNVMHostNICFirmwareAndDriverInfo"
56+
TestDescription = "Gets VMHost's NIC drive and firmware information"
57+
ExpectedReturnTypename = "System.Management.Automation.PSCustomObject"
58+
ExpectedReturnObjNotePropertyNames = Write-Output NicDriverVersion NicFirmwareVersion VMHostName
59+
TestScriptblock = {$oTestVMHost | Get-VNVMHostNICFirmwareAndDriverInfo}
60+
}
61+
)
62+
63+
## perform the actual tests for standard Get- types of cmdlets
64+
$arrInfoOnCmdletsToTest | Foreach-Object {
65+
$oInfoForThisCmdletTest = $_
66+
Describe -Tags "Get" -Name $oInfoForThisCmdletTest.CmdletName {
67+
It $oInfoForThisCmdletTest.TestDescription {
68+
## the NoteProperties that the return objects should have
69+
$arrExpectedReturnObjNotePropertyNames = $oInfoForThisCmdletTest.ExpectedReturnObjNotePropertyNames
70+
$arrReturnObj = & $oInfoForThisCmdletTest.TestScriptblock
71+
$arrReturnTypes = $arrReturnObj | Get-Member | Select-Object -Unique -ExpandProperty TypeName
72+
$bGetsOnlyExpectedObjectType = $arrReturnTypes -eq $oInfoForThisCmdletTest.ExpectedReturnTypename
73+
## does the array of names of NoteProperties in the set of return objects have only the values expected for return objects? (does the comparison of the arrays return no difference objects?)
74+
$bHasExpectedNoteProperties = $null -eq (Compare-Object -ReferenceObject $arrExpectedReturnObjNotePropertyNames -DifferenceObject ($arrReturnObj | Get-Member -MemberType NoteProperty).Name)
75+
$bGetsOnlyExpectedObjectType | Should Be $true
76+
$bHasExpectedNoteProperties | Should Be $true
77+
} ## end it
78+
} ## end describe
79+
} ## end foreach-object

vNugglets.Utility/vNuggletsUtilityMod_functions.ps1

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ function Connect-VNVIServer {
799799
Function to use for connecting to VIServers instead of the default "Connect-VIServer" cmdlet -- includes call to function to update PowerShell window's title bar with the VIServer(s) to which the current session has connections
800800
801801
.Example
802-
Connect-VNVIServer -Credential $myCred -VIServer myVC0.dom.com, myVC1.dom.com
802+
Connect-VNVIServer -Credential $myCred -Server myVC0.dom.com, myVC1.dom.com
803803
Connects to the given vCenters using the given credentials, and updates the PowerShell window's title bar accordingly
804804
805805
.Link
@@ -812,15 +812,15 @@ function Connect-VNVIServer {
812812
#>
813813
param(
814814
## Name of VI server to which to connect
815-
[parameter(Mandatory=$true, Position=0)][string[]]$VIServer,
815+
[parameter(Mandatory=$true, Position=0)][string[]]$Server,
816816

817817
## Credential to use for connection
818818
[parameter(Position=1)][ValidateNotNullOrEmpty()][System.Management.Automation.PSCredential]$Credential
819819
) ## end param
820820

821821
process {
822822
## check that given target VIServers are responsive to ping requests (assumes that ICMP echo traffic is allowed from the target machine)
823-
$arrVIServersToWhichToConnect = $VIServer | Foreach-Object {
823+
$arrVIServersToWhichToConnect = $Server | Foreach-Object {
824824
$strVIServerToWhichToConnect = $_
825825
if (-not (Test-Connection -Quiet -Count 2 $strVIServerToWhichToConnect)) {Write-Warning "server at '$strVIServerToWhichToConnect' not reachable; not trying to connect"}
826826
else {$strVIServerToWhichToConnect}
@@ -854,11 +854,11 @@ function Disconnect-VNVIServer {
854854
#>
855855
param (
856856
## Name(s) of the VIServers from which to disconnect. Accepts wildcards. Disconnects from all VIServer if none specified here.
857-
[string[]]$VIServer = "*"
857+
[string[]]$Server = "*"
858858
) ## end param
859859

860860
process {
861-
Disconnect-VIServer -Server $VIServer -Confirm:$false
861+
Disconnect-VIServer -Server $Server -Confirm:$false
862862
## update the PowerShell WindowTitle
863863
Update-VNTitleBarForPowerCLI
864864
} ## end process

0 commit comments

Comments
 (0)