#Import the psd1 $ModuleName = 'PoshCore' $ModuleManifestName = "$ModuleName.psd1" $ModuleManifestPath = "$PSScriptRoot\..\$ModuleManifestName" Import-Module $ModuleManifestPath -Force -ErrorAction Stop <# Integration/Acceptance Testing for PoshCore-Computer.ps1 Invoke-Pester –Script @{'Path' = 'C:\Githubdata\poshcore\Tests\PoshCore-Computer.Tests.ps1';} Description: Run through all variations of attribute groups and confirm data from core is as expected #> #################### Data to Compare with Output - BEGIN #################### #region <# This data should be updated by pulling the data from core using a known good version of poshcore Using the code found in Tools\PSOGenerationForPesterTests.ps1 This only needs to be done if the data has changed in core or you want to change the devices used for the tests. #> #First Test Device (560559) $ComputerPSO1 = New-Object PSObject -Property @{ account_id = '1103359' account_name = 'International Enterprise Support Test Account' am_queue = 'Account Management - Intensive' attached_devices = '560591' attached_firewalls = '407882' attached_san_or_das = '560591' bw_poller = 'bw1.lon1.core.rackspace.com' bw_subscription = '0' contract = '87732' created = '2014-01-02 10:57:11' datacenter_symbol = 'LON3' date_contract_received = '2014-01-03 03:40:36' date_online = '2014-01-14 10:35:39' domain_name = 'clustertest.local' drac_ips = '10.8.113.155' drac_usernames = 'root' due_date = '2014-01-17 03:40:36' due_to_support_date = '2014-01-13 03:40:36' exnet_zone = 'ExNet-331' has_been_online = 'True' has_drac = 'True' ip_addresses = '10.136.132.234 162.13.38.113' is_behind_net_device = 'True' is_ice_complete = 'True' is_online = 'True' is_server = 'True' is_uk_account = 'True' is_windows = 'True' location = 'XB7-1E[5] (AggExNet)' name = '560559-DB1.rackspace.com' nickname = 'ttt' number = '560559' os = 'DELL PowerEdge R720 Windows' os_name = 'Windows 2012 R2 Standard - 64 bit' os_type = 'Microsoft Windows' platform_model = 'DELL PowerEdge R720 Windows Required' platform_name = 'DELL PowerEdge R720 Windows' platform_type = 'Server' primary_dns = '83.138.151.80' primary_ip = '162.13.38.113' primary_userid = 'swaller' rack_rotation_cycle_number = '8' rba_login_method = 'Customer AD' segment = 'Intensive' segment_queue = 'Intensive (All Teams)' service_level_name = 'Intensive' Skus = ' ' status_name = 'Support Maintenance' support_level = 'Fanatical Support Plus' type = 'DELL PowerEdge R720 Windows' usage_type = 'Test' } #Second Test Device (560570) $ComputerPSO2 = New-Object PSObject -Property @{ account_id = '1103359' account_name = 'International Enterprise Support Test Account' add_userid_to_domain = 'True' am_queue = 'Account Management - Intensive' attached_devices = '560591' attached_firewalls = '407882' attached_san_or_das = '560591' bw_poller = 'bw1.lon1.core.rackspace.com' bw_subscription = '0' contract = '87732' created = '2014-01-02 11:05:14' datacenter_symbol = 'LON3' date_contract_received = '2014-01-03 03:40:39' date_online = '2014-01-14 10:35:40' domain_name = 'lon.intensive.int' drac_ips = '10.8.113.157' drac_usernames = 'root' due_date = '2016-04-19 03:40:39' due_to_support_date = '2016-04-19 03:40:39' exnet_zone = 'ExNet-331' has_been_online = 'True' has_drac = 'True' ip_addresses = '10.136.132.235 134.213.21.4' is_behind_net_device = 'True' is_ice_complete = 'True' is_online = 'True' is_server = 'True' is_uk_account = 'True' is_windows = 'True' location = 'XB7-1E[20] (AggExNet)' name = '560570-DB2.rackspace.com' nickname = 'DB2' number = '560570' os = 'DELL PowerEdge R720 Windows' os_name = 'Windows 2012 R2 Standard - 64 bit' os_type = 'Microsoft Windows' platform_model = 'DELL PowerEdge R720 Windows Required' platform_name = 'DELL PowerEdge R720 Windows' platform_type = 'Server' pre_build_message = 'Master ticket: 160404-03914' primary_dns = '83.138.151.80' primary_ip = '134.213.21.4' primary_userid = 'swaller' rack_rotation_cycle_number = '3' rba_login_method = 'Password Auth' segment = 'Intensive' segment_queue = 'Intensive (All Teams)' service_level_name = 'Intensive' Skus = ' ' status_name = 'Support Maintenance' support_level = 'Fanatical Support Plus' type = 'DELL PowerEdge R720 Windows' usage_type = 'Files' } #endregion ##################### Data to Compare with Output - END ##################### #################### Pester Tests - BEGIN #################### #region #Device numbers and account numbers from PSO's $Device1 = "$($ComputerPSO1.number)" $Device2 = "$($ComputerPSO2.number)" $Account = "$($ComputerPSO1.account_id)" Describe "Find-CoreComputer" { It 'Return a single device from core, compares number' { #Compares the device number in the pso to the one returned from core. $Test1 = Find-CoreComputer -Computers @($Device1) $($Test1.number) | should be $($ComputerPSO1.number) } It 'Return 2 devices from core, compares account_id' { #Compares the account_id in the pso to the ones returned from core. $Test2 = Find-CoreComputer -Computers @("$Device1","$Device2") $($Test2[0].account_id) | should be $($ComputerPSO1.account_id) $($Test2[1].account_id) | should be $($ComputerPSO2.account_id) } It 'Return All devices on an account, checks at least 3 device returned, compares account_name' { #Checks atleast 3 results returned, Compares the account_name in the pso to the ones returned from core. $Test3 = Find-CoreComputer -Account @($Account) $($Test3.count) -gt 3 | should be $true $($Test3[0].account_name) | should be $($ComputerPSO1.account_name) Write-Verbose "Info: number of device returned from account ($Account) = $($Test3.count)" } It 'Return full object from core, checks all root level data e.g. load_arg, QueryTime, class, etc' { $Test4 = Find-CoreComputer -Computers @($Device1) -FullObject $Test4.count | should be 1 $Test4.load_arg | should Not Be $null $test4.result.number | should be $($ComputerPSO1.number) $Test4.class | should match "Computer.Computer" $Test4.QueryTime | should BeGreaterThan 0 $Test4.offset | should be "0" $Test4.limit | should be "100" } It 'Return all devices attribute groups from core and checks one value from each' { $Test5 = Find-CoreComputer -Computers @($Device1) -Attributes @("Default","Network","Drac","Bandwidth","Attached","Backup","Storage","Misc","Domain","Implementation","Is","Os","Password","Skus") $Test5.number | should match $($ComputerPSO1.number) #default $Test5.primary_ip | should match $($ComputerPSO1.primary_ip) #network $Test5.has_drac | should match $($ComputerPSO1.has_drac) #DRAC $Test5.bw_poller | should match $($ComputerPSO1.bw_poller) #Bandwidth $Test5.attached_devices | should match $($ComputerPSO1.attached_devices) #Attached $Test5.is_managed_backup | should match $($ComputerPSO1.is_managed_backup) #Backup #$Test5.number | should match $($ComputerPSO1.number) #Storage - no shared storage. $Test5.location | should be $($ComputerPSO1.location) #Misc $Test5.has_default_account_level_domain | should match $($ComputerPSO1.has_default_account_level_domain) #Domain $Test5.is_ice_complete | should match $($ComputerPSO1.is_ice_complete) #Implementation $Test5.is_windows | should match $($ComputerPSO1.is_windows) #Is $Test5.os_type | should match $($ComputerPSO1.os_type) #Os $Test5.rba_login_method | should match $($ComputerPSO1.rba_login_method) #Password $Test5.Skus | should not be $null #Skus } It 'Return custom device attribute from core, checks contract is returned' { $Test6 = Find-CoreComputer -Computers @($Device1) -CustomAttributes @{"contract"="contract.id"} $Test6.contract | should match $($ComputerPSO1.contract) } It 'Return devices on account based on statusid 12, checks at least 3 device returned' { $Test7 = Find-CoreComputer -Accounts @(1103359) -statusid 12 $($Test7.count) -gt 3 | should be $true Write-Verbose "Info: number of device returned from account ($Account) with statusid 12 = $($Test7.count)" } It 'Return devices on account based on statusname "online/complete", checks at least 3 device returned ' { $Test8 = Find-CoreComputer -Accounts @(1103359) -statusname "online/complete" $($Test8.count) -gt 3 | should be $true Write-Verbose "Info: number of device returned from account ($Account) with statusname online/complete = $($Test8.count)" } It 'Return devices on account based on statusgroup online, checks at least 3 device returned' { $Test9 = Find-CoreComputer -Accounts @(1103359) -statusgroup online $($Test9.count) -gt 3 | should be $true Write-Verbose "Info: number of device returned from account ($Account) with statusgroup online/complete = $($Test9.count)" } It 'Return status logs for device 560559' { $Test9 = Find-CoreComputer -Computers 560559 -Attributes StatusLogs $OldestLog = ($Test9.StatusLogs | Sort-Object timestamp )[0] $OldestLog.new_status | Should be 'Received Contract' $OldestLog.timestamp | Should be '2014-01-03 03:40:34' } } Describe "Set-CoreComputerStatus" { It 'Changes a device status' { $Test10Current = Find-CoreComputer -Computers 560559 if($Test10Current.status_name -ne 'Support Maintenance') { write-warning "Device 560559 is not in Support Maintenance so cannot test Set-CoreComputerStatus" } else { $Test10 = Set-CoreComputerStatus -Computers 560559 -Status 'Online/Complete' -Reason 'Pester tests' $Test10.Result | Should be $True $Test11 = Set-CoreComputerStatus -Computers 560559 -Status 'Support Maintenance' -Reason 'Pester tests' $Test11.Result | Should be $True } } } #endregion ##################### Pester Tests - END ##################### #Log to appstats Try { Set-LogtoAppstats -FunctionID "PoshCore-Computer-Tests" -AppID "PoshCore" } Catch { Write-Warning "Failed to Log to Appstats, Error message: $($_.exception.message))" }