Skip to content

Commit 82e28a2

Browse files
committed
fixing the rest of the tests
1 parent 178ff2a commit 82e28a2

File tree

3 files changed

+104
-53
lines changed

3 files changed

+104
-53
lines changed

tests/oracle/Invoke-DBOQuery.Tests.ps1

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ if (-not (Test-DBOSupportedSystem -Type Oracle)) {
2323

2424
$newDbName = 'test_dbops_invokedboquery'
2525
$connParams = @{
26-
SqlInstance = $script:oracleInstance
27-
Credential = $script:oracleCredential
28-
Type = 'Oracle'
29-
Silent = $true
26+
SqlInstance = $script:oracleInstance
27+
Credential = $script:oracleCredential
28+
Type = 'Oracle'
29+
Silent = $true
3030
ConnectionAttribute = @{
3131
'DBA Privilege' = 'SYSDBA'
3232
}
@@ -37,7 +37,7 @@ Describe "Invoke-DBOQuery Oracle tests" -Tag $commandName, IntegrationTests {
3737
It "should run the query" {
3838
$query = "SELECT 1 AS A, 2 AS B FROM DUAL UNION ALL SELECT NULL AS A, 4 AS B FROM DUAL"
3939
$result = Invoke-DBOQuery -Query $query @connParams -As DataTable
40-
$result.Columns.ColumnName | Should -Be @('A','B')
40+
$result.Columns.ColumnName | Should -Be @('A', 'B')
4141
$result.A | Should -Be 1, ([DBNull]::Value)
4242
$result.B | Should -Be 2, 4
4343
}
@@ -47,23 +47,24 @@ Describe "Invoke-DBOQuery Oracle tests" -Tag $commandName, IntegrationTests {
4747
$result.Columns.ColumnName | Should -Be @('NULL')
4848
$result.NULL | Should -Be ([DBNull]::Value)
4949
}
50-
It "should run the query with semicolon" {
51-
$query = "SELECT 1 AS A, 2 AS B FROM DUAL;
50+
It "should run the query with a slash" {
51+
$query = "SELECT 1 AS A, 2 AS B FROM DUAL
52+
/
5253
SELECT 3 AS A, 4 AS B FROM DUAL"
5354
$result = Invoke-DBOQuery -Query $query @connParams -As DataTable
54-
$result[0].Columns.ColumnName | Should -Be @('A','B')
55-
$result[1].Columns.ColumnName | Should -Be @('A','B')
55+
$result[0].Columns.ColumnName | Should -Be @('A', 'B')
56+
$result[1].Columns.ColumnName | Should -Be @('A', 'B')
5657
$result[0].A | Should -Be 1
5758
$result[0].B | Should -Be 2
5859
$result[1].A | Should -Be 3
5960
$result[1].B | Should -Be 4
6061
}
61-
It "should run the query with semicolon as a dataset" {
62-
$query = "SELECT 1 AS A, 2 AS B FROM DUAL;
62+
It "should run the query with a slash as a dataset" {
63+
$query = "SELECT 1 AS A, 2 AS B FROM DUAL/
6364
SELECT 3 AS A, 4 AS B FROM DUAL"
6465
$result = Invoke-DBOQuery -Query $query @connParams -As Dataset
65-
$result.Tables[0].Columns.ColumnName | Should Be @('A','B')
66-
$result.Tables[1].Columns.ColumnName | Should Be @('A','B')
66+
$result.Tables[0].Columns.ColumnName | Should Be @('A', 'B')
67+
$result.Tables[1].Columns.ColumnName | Should Be @('A', 'B')
6768
$result.Tables[0].A | Should -Be 1
6869
$result.Tables[0].B | Should -Be 2
6970
$result.Tables[1].A | Should -Be 3
@@ -72,7 +73,7 @@ Describe "Invoke-DBOQuery Oracle tests" -Tag $commandName, IntegrationTests {
7273
It "should run the query as a PSObject" {
7374
$query = "SELECT 1 AS A, 2 AS B FROM DUAL UNION ALL SELECT NULL AS A, 4 AS B FROM DUAL"
7475
$result = Invoke-DBOQuery -Query $query @connParams -As PSObject
75-
$result[0].psobject.properties.Name | Should -Be @('A','B')
76+
$result[0].psobject.properties.Name | Should -Be @('A', 'B')
7677
$result.A | Should -Be 1, $null
7778
$result.B | Should -Be 2, 4
7879
}
@@ -87,8 +88,8 @@ Describe "Invoke-DBOQuery Oracle tests" -Tag $commandName, IntegrationTests {
8788
"SELECT 1 AS A, 2 AS B FROM DUAL" | Out-File $file1 -Force
8889
"SELECT 3 AS A, 4 AS B FROM DUAL" | Out-File $file2 -Force -Encoding bigendianunicode
8990
$result = Invoke-DBOQuery -InputFile $file1, $file2 @connParams -As DataTable
90-
$result[0].Columns.ColumnName | Should -Be @('A','B')
91-
$result[1].Columns.ColumnName | Should -Be @('A','B')
91+
$result[0].Columns.ColumnName | Should -Be @('A', 'B')
92+
$result[1].Columns.ColumnName | Should -Be @('A', 'B')
9293
$result[0].A | Should -Be 1
9394
$result[0].B | Should -Be 2
9495
$result[1].A | Should -Be 3
@@ -100,24 +101,24 @@ Describe "Invoke-DBOQuery Oracle tests" -Tag $commandName, IntegrationTests {
100101
"SELECT 1 AS A, 2 AS B FROM DUAL" | Out-File $file1 -Force
101102
"SELECT 3 AS A, 4 AS B FROM DUAL" | Out-File $file2 -Force -Encoding bigendianunicode
102103
$result = Get-Item $file1, $file2 | Invoke-DBOQuery @connParams -As DataTable
103-
$result[0].Columns.ColumnName | Should -Be @('A','B')
104-
$result[1].Columns.ColumnName | Should -Be @('A','B')
104+
$result[0].Columns.ColumnName | Should -Be @('A', 'B')
105+
$result[1].Columns.ColumnName | Should -Be @('A', 'B')
105106
$result[0].A | Should -Be 1
106107
$result[0].B | Should -Be 2
107108
$result[1].A | Should -Be 3
108109
$result[1].B | Should -Be 4
109110
$result = $file1, $file2 | Invoke-DBOQuery @connParams -As DataTable
110-
$result[0].Columns.ColumnName | Should -Be @('A','B')
111-
$result[1].Columns.ColumnName | Should -Be @('A','B')
111+
$result[0].Columns.ColumnName | Should -Be @('A', 'B')
112+
$result[1].Columns.ColumnName | Should -Be @('A', 'B')
112113
$result[0].A | Should -Be 1
113114
$result[0].B | Should -Be 2
114115
$result[1].A | Should -Be 3
115116
$result[1].B | Should -Be 4
116117
}
117118
It "should run the query with custom variables" {
118119
$query = "SELECT '#{Test}' AS A, '#{Test2}' AS B FROM DUAL UNION ALL SELECT '3' AS A, '4' AS B FROM DUAL"
119-
$result = Invoke-DBOQuery -Query $query @connParams -As DataTable -Variables @{ Test = '1'; Test2 = '2'}
120-
$result.Columns.ColumnName | Should -Be @('A','B')
120+
$result = Invoke-DBOQuery -Query $query @connParams -As DataTable -Variables @{ Test = '1'; Test2 = '2' }
121+
$result.Columns.ColumnName | Should -Be @('A', 'B')
121122
$result.A | Should -Be '1', '3'
122123
$result.B | Should -Be '2', '4'
123124
}
@@ -126,13 +127,13 @@ Describe "Invoke-DBOQuery Oracle tests" -Tag $commandName, IntegrationTests {
126127
$result = Invoke-DBOQuery -Type Oracle -Query $query -SqlInstance '#{srv}' -Credential $script:oracleCredential -As DataTable -Variables @{ srv = $script:oracleInstance } -ConnectionAttribute @{
127128
'DBA Privilege' = 'SYSDBA'
128129
}
129-
$result.Columns.ColumnName | Should -Be @('A','B')
130+
$result.Columns.ColumnName | Should -Be @('A', 'B')
130131
$result.A | Should -Be '1', '3'
131132
$result.B | Should -Be '2', '4'
132133
}
133134
It "should run the query with custom parameters" {
134135
$query = "SELECT :p1 AS A, :p2 AS B FROM DUAL"
135-
$result = Invoke-DBOQuery -Query $query @connParams -Parameter @{ p1 = '1'; p2 = 'string'}
136+
$result = Invoke-DBOQuery -Query $query @connParams -Parameter @{ p1 = '1'; p2 = 'string' }
136137
$result.A | Should -Be 1
137138
$result.B | Should -Be string
138139
}
@@ -152,16 +153,16 @@ Describe "Invoke-DBOQuery Oracle tests" -Tag $commandName, IntegrationTests {
152153
}
153154
It "should throw a connection timeout error" {
154155
$query = "SELECT 1/0 FROM DUAL"
155-
try { $null = Invoke-DBOQuery -Type Oracle -Query $query -SqlInstance localhost:6493 -Credential $script:oracleCredential -ConnectionTimeout 1}
156+
try { $null = Invoke-DBOQuery -Type Oracle -Query $query -SqlInstance localhost:6493 -Credential $script:oracleCredential -ConnectionTimeout 1 }
156157
catch { $errVar = $_ }
157158
$errVar.Exception.Message | Should -Match "Connection request timed out"
158159
}
159160
It "should fail when credentials are wrong" {
160161
try { Invoke-DBOQuery -Type Oracle -Query 'SELECT 1 FROM DUAL' -SqlInstance $script:oracleInstance -Credential ([pscredential]::new('nontexistent', ([securestring]::new()))) }
161-
catch {$errVar = $_ }
162+
catch { $errVar = $_ }
162163
$errVar.Exception.Message | Should -Match 'null password given; logon denied'
163164
try { Invoke-DBOQuery -Type Oracle -Query 'SELECT 1 FROM DUAL' -SqlInstance $script:oracleInstance -UserName nontexistent -Password (ConvertTo-SecureString 'foo' -AsPlainText -Force) }
164-
catch {$errVar = $_ }
165+
catch { $errVar = $_ }
165166
$errVar.Exception.Message | Should -Match 'invalid username/password; logon denied'
166167
}
167168
It "should fail when input file is not found" {

tests/oracle/Register-DBOPackage.Tests.ps1

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,28 @@ $adminParams = @{
3636
'DBA Privilege' = 'SYSDBA'
3737
}
3838
}
39-
$createUserScript = "CREATE USER $oraUserName IDENTIFIED BY $oraPassword;
40-
GRANT CONNECT, RESOURCE, CREATE ANY TABLE TO $oraUserName;
41-
GRANT EXECUTE on dbms_lock to $oraUserName;"
42-
$dropUserScript = "DROP USER $oraUserName CASCADE;"
39+
$createUserScript = "CREATE USER $oraUserName IDENTIFIED BY $oraPassword/
40+
GRANT CONNECT, RESOURCE, CREATE ANY TABLE TO $oraUserName/
41+
GRANT EXECUTE on dbms_lock to $oraUserName"
42+
$dropUserScript = "
43+
BEGIN
44+
FOR ln_cur IN (SELECT sid, serial# FROM v`$session WHERE username = '$oraUserName')
45+
LOOP
46+
EXECUTE IMMEDIATE ('ALTER SYSTEM KILL SESSION ''' || ln_cur.sid || ',' || ln_cur.serial# || ''' IMMEDIATE');
47+
END LOOP;
48+
FOR x IN ( SELECT count(*) cnt
49+
FROM DUAL
50+
WHERE EXISTS (SELECT * FROM DBA_USERS WHERE USERNAME = '$oraUserName')
51+
)
52+
LOOP
53+
IF ( x.cnt = 1 ) THEN
54+
EXECUTE IMMEDIATE 'DROP USER $oraUserName CASCADE';
55+
END IF;
56+
END LOOP;
57+
END;
58+
/"
59+
$dropObjectsScript = Join-PSFPath -Normalize "$testRoot\etc\oracle-tests\verification\drop.sql"
60+
4361

4462
$workFolder = Join-PSFPath -Normalize "$testRoot\etc" "$commandName.Tests.dbops"
4563
$logTable = "testdeploy"
@@ -54,24 +72,21 @@ Describe "Register-DBOPackage Oracle integration tests" -Tag $commandName, Integ
5472
BeforeAll {
5573
if ((Test-Path $workFolder) -and $workFolder -like '*.Tests.dbops') { Remove-Item $workFolder -Recurse }
5674
$null = New-Item $workFolder -ItemType Directory -Force
57-
$userExists = Invoke-DBOQuery @adminParams -Query "SELECT USERNAME FROM ALL_USERS WHERE USERNAME = '$oraUserName'" -As SingleValue
58-
if ($userExists) { $null = Invoke-DBOQuery @adminParams -Query $dropUserScript }
75+
$null = Invoke-DBOQuery @adminParams -Query $dropUserScript
76+
$null = Invoke-DBOQuery @adminParams -Query $createUserScript
5977
}
6078
AfterAll {
6179
if ((Test-Path $workFolder) -and $workFolder -like '*.Tests.dbops') { Remove-Item $workFolder -Recurse }
62-
$userExists = Invoke-DBOQuery @adminParams -Query "SELECT USERNAME FROM ALL_USERS WHERE USERNAME = '$oraUserName'" -As SingleValue
63-
if ($userExists) { $null = Invoke-DBOQuery @adminParams -Query $dropUserScript }
80+
$null = Invoke-DBOQuery @adminParams -Query $dropUserScript
6481
}
6582
Context "testing registration of scripts" {
6683
BeforeAll {
6784
$p2 = New-DBOPackage -ScriptPath $v1scripts -Name "$workFolder\pv2" -Build 1.0 -Force
6885
$p2 = Add-DBOBuild -ScriptPath $v2scripts -Package $p2 -Build 2.0
6986
$outputFile = "$workFolder\log.txt"
70-
$null = Invoke-DBOQuery @adminParams -Query $createUserScript
7187
}
7288
AfterAll {
73-
$userExists = Invoke-DBOQuery @adminParams -Query "SELECT USERNAME FROM ALL_USERS WHERE USERNAME = '$oraUserName'" -As SingleValue
74-
if ($userExists) { $null = Invoke-DBOQuery @adminParams -Query $dropUserScript }
89+
$null = Invoke-DBOQuery @connParams -InputFile $dropObjectsScript
7590
}
7691
It "should register version 1.0 without creating any objects" {
7792
$before = Invoke-DBOQuery @connParams -InputFile $verificationScript
@@ -137,11 +152,10 @@ Describe "Register-DBOPackage Oracle integration tests" -Tag $commandName, Integ
137152
Context "$commandName whatif tests" {
138153
BeforeAll {
139154
$p1 = New-DBOPackage -ScriptPath $v1scripts -Name "$workFolder\pv1" -Build 1.0 -Force
140-
$null = Invoke-DBOQuery @adminParams -Query $createUserScript
155+
$null = Invoke-DBOQuery @connParams -InputFile $dropObjectsScript
141156
}
142157
AfterAll {
143-
$userExists = Invoke-DBOQuery @adminParams -Query "SELECT USERNAME FROM ALL_USERS WHERE USERNAME = '$oraUserName'" -As SingleValue
144-
if ($userExists) { $null = Invoke-DBOQuery @adminParams -Query $dropUserScript }
158+
$null = Invoke-DBOQuery @connParams -InputFile $dropObjectsScript
145159
}
146160
It "should deploy nothing" {
147161
$testResults = Register-DBOPackage $p1 @connParams -SchemaVersionTable $logTable -WhatIf

tests/oracle/deploy.ps1.Tests.ps1

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,42 @@ $packageName = Join-PSFPath -Normalize $workFolder 'TempDeployment.zip'
2828
$oraUserName = 'DBOPSDEPLOYPS1'
2929
$oraPassword = 'S3cur_pAss'
3030
$testCredentials = [pscredential]::new($oraUserName, (ConvertTo-SecureString $oraPassword -AsPlainText -Force))
31-
$createUserScript = "CREATE USER $oraUserName IDENTIFIED BY $oraPassword; GRANT CONNECT, RESOURCE TO $oraUserName"
32-
$dropUserScript = "DROP USER $oraUserName CASCADE;"
31+
$connParams = @{
32+
Type = 'Oracle'
33+
SqlInstance = $script:oracleInstance
34+
Silent = $true
35+
Credential = $testCredentials
36+
}
37+
$adminParams = @{
38+
Type = 'Oracle'
39+
SqlInstance = $script:oracleInstance
40+
Silent = $true
41+
Credential = $script:oracleCredential
42+
ConnectionAttribute = @{
43+
'DBA Privilege' = 'SYSDBA'
44+
}
45+
}
46+
$createUserScript = "CREATE USER $oraUserName IDENTIFIED BY $oraPassword/
47+
GRANT CONNECT, RESOURCE, CREATE ANY TABLE TO $oraUserName/
48+
GRANT EXECUTE on dbms_lock to $oraUserName"
49+
$dropUserScript = "
50+
BEGIN
51+
FOR ln_cur IN (SELECT sid, serial# FROM v`$session WHERE username = '$oraUserName')
52+
LOOP
53+
EXECUTE IMMEDIATE ('ALTER SYSTEM KILL SESSION ''' || ln_cur.sid || ',' || ln_cur.serial# || ''' IMMEDIATE');
54+
END LOOP;
55+
FOR x IN ( SELECT count(*) cnt
56+
FROM DUAL
57+
WHERE EXISTS (SELECT * FROM DBA_USERS WHERE USERNAME = '$oraUserName')
58+
)
59+
LOOP
60+
IF ( x.cnt = 1 ) THEN
61+
EXECUTE IMMEDIATE 'DROP USER $oraUserName CASCADE';
62+
END IF;
63+
END LOOP;
64+
END;
65+
/"
66+
$dropObjectsScript = Join-PSFPath -Normalize "$testRoot\etc\oracle-tests\verification\drop.sql"
3367

3468
Describe "deploy.ps1 Oracle integration tests" -Tag $commandName, IntegrationTests {
3569
BeforeEach {
@@ -41,15 +75,16 @@ Describe "deploy.ps1 Oracle integration tests" -Tag $commandName, IntegrationTes
4175
$null = New-Item $unpackedFolder -ItemType Directory -Force
4276
$packageName = New-DBOPackage -Path $packageName -ScriptPath $v1scripts -Build 1.0 -Force
4377
$null = Expand-Archive -Path $packageName -DestinationPath $workFolder -Force
44-
$null = Invoke-DBOQuery -Type Oracle -SqlInstance $script:oracleInstance -Silent -Credential $script:oracleCredential -Query $createUserScript
78+
$null = Invoke-DBOQuery @adminParams -Query $dropUserScript
79+
$null = Invoke-DBOQuery @adminParams -Query $createUserScript
4580
}
4681
AfterAll {
47-
$null = Invoke-DBOQuery -Type Oracle -SqlInstance $script:oracleInstance -Silent -Credential $script:oracleCredential -Query $dropUserScript
4882
if ((Test-Path $workFolder) -and $workFolder -like '*.Tests.dbops') { Remove-Item $workFolder -Recurse }
83+
$null = Invoke-DBOQuery @adminParams -Query $dropUserScript
4984
}
5085
Context "testing deployment of extracted package" {
5186
BeforeEach {
52-
$null = Invoke-DBOQuery -Type Oracle -SqlInstance $script:oracleInstance -Silent -Credential $script:oracleCredential -Query $dropUserScript, $createUserScript
87+
$null = Invoke-DBOQuery @connParams -InputFile $dropObjectsScript
5388
}
5489
It "should deploy with a -Configuration parameter" {
5590
$deploymentConfig = @{
@@ -75,15 +110,15 @@ Describe "deploy.ps1 Oracle integration tests" -Tag $commandName, IntegrationTes
75110
'Upgrade successful' | Should BeIn $testResults.DeploymentLog
76111

77112
#Verifying objects
78-
$testResults = Invoke-DBOQuery -Type Oracle -SqlInstance $script:oracleInstance -Silent -Credential $testCredentials -InputFile $verificationScript
113+
$testResults = Invoke-DBOQuery @connParams -InputFile $verificationScript
79114
$logTable | Should BeIn $testResults.name
80115
'a' | Should BeIn $testResults.name
81116
'b' | Should BeIn $testResults.name
82117
'c' | Should Not BeIn $testResults.name
83118
'd' | Should Not BeIn $testResults.name
84119
}
85120
It "should deploy with a set of parameters" {
86-
$testResults = & $workFolder\deploy.ps1 -Type Oracle -SqlInstance $script:oracleInstance -Credential $testCredentials -SchemaVersionTable $logTable -OutputFile "$workFolder\log.txt" -Silent
121+
$testResults = & $workFolder\deploy.ps1 @connParams -SchemaVersionTable $logTable -OutputFile "$workFolder\log.txt"
87122
$testResults.Successful | Should Be $true
88123
$testResults.Scripts.Name | Should Be $v1Journal
89124
$testResults.SqlInstance | Should Be $script:oracleInstance
@@ -99,7 +134,7 @@ Describe "deploy.ps1 Oracle integration tests" -Tag $commandName, IntegrationTes
99134
'Upgrade successful' | Should BeIn $testResults.DeploymentLog
100135

101136
#Verifying objects
102-
$testResults = Invoke-DBOQuery -Type Oracle -SqlInstance $script:oracleInstance -Silent -Credential $testCredentials -InputFile $verificationScript
137+
$testResults = Invoke-DBOQuery @connParams -InputFile $verificationScript
103138
$logTable | Should BeIn $testResults.name
104139
'a' | Should BeIn $testResults.name
105140
'b' | Should BeIn $testResults.name
@@ -109,12 +144,13 @@ Describe "deploy.ps1 Oracle integration tests" -Tag $commandName, IntegrationTes
109144
}
110145
Context "$commandName whatif tests" {
111146
BeforeAll {
112-
$null = Invoke-DBOQuery -Type Oracle -SqlInstance $script:oracleInstance -Silent -Credential $script:oracleCredential -Query $dropUserScript, $createUserScript
147+
$null = Invoke-DBOQuery @connParams -InputFile $dropObjectsScript
113148
}
114149
AfterAll {
150+
$null = Invoke-DBOQuery @connParams -InputFile $dropObjectsScript
115151
}
116152
It "should deploy nothing" {
117-
$testResults = & $workFolder\deploy.ps1 -Type Oracle -SqlInstance $script:oracleInstance -Credential $testCredentials -SchemaVersionTable $logTable -OutputFile "$workFolder\log.txt" -Silent -WhatIf
153+
$testResults = & $workFolder\deploy.ps1 @connParams -SchemaVersionTable $logTable -OutputFile "$workFolder\log.txt" -WhatIf
118154
$testResults.Successful | Should Be $true
119155
$testResults.Scripts.Name | Should Be $v1Journal
120156
$testResults.SqlInstance | Should Be $script:oracleInstance
@@ -131,12 +167,12 @@ Describe "deploy.ps1 Oracle integration tests" -Tag $commandName, IntegrationTes
131167
$v1Journal | ForEach-Object { "$_ would have been executed - WhatIf mode." } | Should BeIn $testResults.DeploymentLog
132168

133169
#Verifying objects
134-
$testResults = Invoke-DBOQuery -Type Oracle -SqlInstance $script:oracleInstance -Silent -Credential $testCredentials -InputFile $verificationScript
170+
$testResults = Invoke-DBOQuery @connParams -InputFile $verificationScript
135171
$logTable | Should Not BeIn $testResults.name
136172
'a' | Should Not BeIn $testResults.name
137173
'b' | Should Not BeIn $testResults.name
138174
'c' | Should Not BeIn $testResults.name
139175
'd' | Should Not BeIn $testResults.name
140176
}
141177
}
142-
}
178+
}

0 commit comments

Comments
 (0)