From 932f4bfa78ef02bff8ead531e7983b0f53eaed11 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Sat, 11 May 2024 11:15:50 +0200 Subject: [PATCH] Fix integ test --- ...Install-SqlDscServer.Integration.Tests.ps1 | 26 ++++++++++++++----- .../Prerequisites.Integration.Tests.ps1 | 10 +------ 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/tests/Integration/Commands/Install-SqlDscServer.Integration.Tests.ps1 b/tests/Integration/Commands/Install-SqlDscServer.Integration.Tests.ps1 index d8604fd21..944e3df9f 100644 --- a/tests/Integration/Commands/Install-SqlDscServer.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Install-SqlDscServer.Integration.Tests.ps1 @@ -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 = @{ @@ -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' @@ -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 @@ -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 } diff --git a/tests/Integration/Commands/Prerequisites.Integration.Tests.ps1 b/tests/Integration/Commands/Prerequisites.Integration.Tests.ps1 index e956fac06..3dac6db6e 100644 --- a/tests/Integration/Commands/Prerequisites.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Prerequisites.Integration.Tests.ps1 @@ -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