Skip to content

Commit

Permalink
finalized expected result
Browse files Browse the repository at this point in the history
  • Loading branch information
Steffen committed Nov 28, 2023
1 parent 2ea35ae commit b27ba3d
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions test/Invoke-Command.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ PRINT 'bar'

It 'continues on error' {
$VerboseOutput = Invoke-SmoCommand -Command $Command -ErrorAction SilentlyContinue -ErrorVariable ErrorOutput -Verbose -InformationVariable InformationOutput -WarningAction SilentlyContinue -WarningVariable WarningOutput 4>&1

$VerboseOutput[0].Message | Should -Be 'Execute SQL script from text.'
$InformationOutput[0].MessageData | Should -Be "SELECT 1/0`r`nPRINT 'foo'"
$ErrorOutput[0].Exception.Message | Should -Be 'An exception occurred while executing a Transact-SQL statement or batch.'
Expand Down Expand Up @@ -109,6 +110,7 @@ PRINT 'bar'
GO
'@
$VerboseOutput = Invoke-SmoCommand -Command $Command -ErrorAction Stop -ErrorVariable ErrorOutput -Verbose -InformationVariable InformationOutput -WarningAction SilentlyContinue -WarningVariable WarningOutput 4>&1

$VerboseOutput[0].Message | Should -Be 'Execute SQL script from text.'
$InformationOutput[0].MessageData | Should -Be "PRINT 'foo'"
$VerboseOutput[1].Message | Should -Be 'foo'
Expand All @@ -129,20 +131,27 @@ GO

It 'works with defined variables' {
$VerboseOutput = Invoke-SmoCommand -Command $Command -Variables @{ foo = 'bar' } -ErrorAction Stop -ErrorVariable ErrorOutput -Verbose -InformationVariable InformationOutput -WarningAction SilentlyContinue -WarningVariable WarningOutput 4>&1

$VerboseOutput[0].Message | Should -Be 'Execute SQL script from text.'
$InformationOutput[0].MessageData | Should -Be "PRINT 'bar'"
$VerboseOutput[1].Message | Should -Be 'bar'
}
}

It 'works with :on error' {
Invoke-SmoCommand -Command @'
$Command = @'
GO
:on error exit
GO
PRINT 'foo'
'@ | Should -BeNullOrEmpty
'@
$VerboseOutput = Invoke-SmoCommand -Command $Command -ErrorAction Stop -ErrorVariable ErrorOutput -Verbose -InformationVariable InformationOutput -WarningAction SilentlyContinue -WarningVariable WarningOutput 4>&1

$VerboseOutput[0].Message | Should -Be 'Execute SQL script from text.'
$WarningOutput[0].Message | Should -Be ':on error is not implemented'
$InformationOutput[0].MessageData | Should -Be "PRINT 'foo'"
$VerboseOutput[1].Message | Should -Be 'foo'
}

It 'works with :setvar' {
Expand All @@ -156,6 +165,7 @@ IF N'$(__IsSqlCmdEnabled)' NOT LIKE N'True'
END
'@
$VerboseOutput = Invoke-SmoCommand -Command $Command -ErrorAction Stop -ErrorVariable ErrorOutput -Verbose -InformationVariable InformationOutput -WarningAction SilentlyContinue -WarningVariable WarningOutput 4>&1

$VerboseOutput[0].Message | Should -Be 'Execute SQL script from text.'
$InformationOutput[0].MessageData | Should -Be @"
IF N'True' NOT LIKE N'True'
Expand All @@ -172,6 +182,7 @@ IF N'True' NOT LIKE N'True'
PRINT '$(foo)'
'@
$VerboseOutput = Invoke-SmoCommand -Command $Command -Variables @{ foo = 'bar' } -ErrorAction Stop -ErrorVariable ErrorOutput -Verbose -InformationVariable InformationOutput -WarningAction SilentlyContinue -WarningVariable WarningOutput 4>&1

$VerboseOutput[0].Message | Should -Be 'Execute SQL script from text.'
$InformationOutput[0].MessageData | Should -Be "PRINT 'bar'"
$VerboseOutput[1].Message | Should -Be 'bar'
Expand All @@ -185,6 +196,7 @@ PRINT '$(foo)'
PRINT '$(foo)'
'@
$VerboseOutput = Invoke-SmoCommand -Command $Command -Variables @{ foo = 'bar' } -ErrorAction Stop -ErrorVariable ErrorOutput -Verbose -InformationVariable InformationOutput -WarningAction SilentlyContinue -WarningVariable WarningOutput 4>&1

$VerboseOutput[0].Message | Should -Be 'Execute SQL script from text.'
$InformationOutput[0].MessageData | Should -Be "PRINT 'bar'"
$VerboseOutput[1].Message | Should -Be 'bar'
Expand Down

0 comments on commit b27ba3d

Please sign in to comment.