Skip to content

Commit

Permalink
Fix integ test
Browse files Browse the repository at this point in the history
  • Loading branch information
johlju committed May 11, 2024
1 parent b51de3d commit 932f4bf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ Describe 'Install-SqlDscServer' -Tag @('Integration_SQL2016', 'Integration_SQL20
Context 'When installing database engine default instance' {
It 'Should run the command without throwing' {
{
param
(
[Parameter(Mandatory = $true)]
[System.String]
$IsoDrivePath,

[Parameter(Mandatory = $true)]
[System.String]
$ComputerName
)

$installScriptBlock = {
# Set splatting parameters for Install-SqlDscServer
$installSqlDscServerParameters = @{
Expand All @@ -36,12 +47,12 @@ Describe 'Install-SqlDscServer' -Tag @('Integration_SQL2016', 'Integration_SQL20
InstanceName = 'MSSQLSERVER'
Features = 'SQLENGINE'
SqlSysAdminAccounts = @(
('{0}\SqlAdmin' -f (Get-ComputerName))
('{0}\SqlAdmin' -f $ComputerName)
)
SqlSvcAccount = '{0}\svc-SqlPrimary' -f (Get-ComputerName)
SqlSvcAccount = '{0}\svc-SqlPrimary' -f $ComputerName
SqlSvcPassword = ConvertTo-SecureString -String 'yig-C^Equ3' -AsPlainText -Force
SqlSvcStartupType = 'Automatic'
AgtSvcAccount = '{0}\svc-SqlAgentPri' -f (Get-ComputerName)
AgtSvcAccount = '{0}\svc-SqlAgentPri' -f $ComputerName
AgtSvcPassword = ConvertTo-SecureString -String 'yig-C^Equ3' -AsPlainText -Force
AgtSvcStartupType = 'Automatic'
BrowserSvcStartupType = 'Automatic'
Expand All @@ -50,7 +61,7 @@ Describe 'Install-SqlDscServer' -Tag @('Integration_SQL2016', 'Integration_SQL20
SqlCollation = 'Finnish_Swedish_CI_AS'
InstallSharedDir = 'C:\Program Files\Microsoft SQL Server'
InstallSharedWOWDir = 'C:\Program Files (x86)\Microsoft SQL Server'
MediaPath = $env:IsoDrivePath # Already set by the prerequisites tests
MediaPath = $IsoDrivePath
Verbose = $true
ErrorAction = 'Stop'
Force = $true
Expand All @@ -59,12 +70,15 @@ Describe 'Install-SqlDscServer' -Tag @('Integration_SQL2016', 'Integration_SQL20
Install-SqlDscServer @installSqlDscServerParameters
}

$invokeCommandUsername = '{0}\SqlInstall' -f (Get-ComputerName)
$invokeCommandUsername = '{0}\SqlInstall' -f $ComputerName
$invokeCommandPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force
$invokeCommandCredential = New-Object System.Management.Automation.PSCredential ($invokeCommandUsername, $invokeCommandPassword)

# Runs command as SqlInstall user.
Invoke-Command -ComputerName localhost -Credential $invokeCommandCredential -ScriptBlock $installScriptBlock
Invoke-Command -ComputerName localhost -Credential $invokeCommandCredential -ScriptBlock $installScriptBlock -ArgumentList @(
$env:IsoDrivePath, # Already set by the prerequisites tests
(Get-ComputerName)
)
} | Should -Not -Throw
}

Expand Down
10 changes: 1 addition & 9 deletions tests/Integration/Commands/Prerequisites.Integration.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,7 @@ Describe 'Prerequisites' {
}

Context 'Test PS Remoting to localhost' -Tag @('Integration_SQL2016', 'Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') {
It 'Should enable PS Remoting' {
#winrm quickconfig -quiet
#Enable-PSRemoting -Force -SkipNetworkProfileCheck -Verbose -ErrorAction 'Stop'
#Test-WSMan -ComputerName $env:COMPUTERNAME -ErrorAction 'Stop'
#winrm enumerate winrm/config/listener
#winrm enumerate winrm/config/listener | Should -Contain 'Transport = HTTP'
# # allows remote access from public networks from any remote location
# Set-NetFirewallRule -Name 'WINRM-HTTP-In-TCP' -RemoteAddress Any -Verbose -ErrorAction 'Stop'

It 'Should successfully run a command on localhost using PS Remoting' {
$result = Invoke-Command -ComputerName 'localhost' -ScriptBlock { 1 } -ErrorAction 'Stop'

$result | Should -Be 1
Expand Down

0 comments on commit 932f4bf

Please sign in to comment.