Skip to content

Commit

Permalink
big ol batch
Browse files Browse the repository at this point in the history
  • Loading branch information
potatoqualitee committed Oct 27, 2024
1 parent 413d0df commit e1e2e94
Show file tree
Hide file tree
Showing 69 changed files with 3,548 additions and 1,854 deletions.
24 changes: 2 additions & 22 deletions tests/Export-DbaExecutionPlan.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Describe "Export-DbaExecutionPlan" -Tag "UnitTests" {
$expected = $TestConfig.CommonParameters
$expected += @(
"SqlInstance",
"SqlCredential",
"SqlCredential",
"Database",
"ExcludeDatabase",
"Path",
Expand All @@ -33,24 +33,4 @@ Describe "Export-DbaExecutionPlan" -Tag "UnitTests" {
Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty
}
}
}

<#
Integration test should appear below and are custom to the command you are writing.
Read https://github.com/dataplat/dbatools/blob/development/contributing.md#tests
for more guidance.
#></source>

Key changes made:
1. Added Pester v5 requirements header
2. Added proper param block with TestConfig
3. Removed old $CommandName assignment
4. Restructured parameter validation using BeforeAll block
5. Updated parameter testing to use -ForEach and proper assertions
6. Maintained the integration test placeholder comment
7. Fixed typo in guidance URL comment
8. Ensured all parameters are included in the expected list
9. Used proper Should -HaveParameter syntax
10. Maintained double quotes for string consistency

The file now follows all the conventions specified in the reference document while maintaining the same testing functionality.
}
20 changes: 1 addition & 19 deletions tests/Export-DbaLinkedServer.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,4 @@ Describe "Export-DbaLinkedServer" -Tag "UnitTests" {
Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty
}
}
}

<#
Integration test should appear below and are custom to the command you are writing.
Read https://github.com/dataplat/dbatools/blob/development/contributing.md#tests
for more guidance.
#></source>

Key changes made:
1. Added the required Pester v5 header with module requirements
2. Removed `$CommandName` variable as it's no longer needed
3. Restructured parameter validation using the new convention from conventions.md
4. Added proper BeforeAll block for test setup
5. Updated parameter comparison to use Should -HaveParameter
6. Fixed typo in guidance comment
7. Used proper array declaration format for expected parameters
8. Maintained all existing parameters while updating the test structure
The file now follows the Pester v5 conventions while maintaining the same test coverage.
}
21 changes: 1 addition & 20 deletions tests/Export-DbaReplServerSetting.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,4 @@ Describe "Export-DbaReplServerSetting" -Tag "UnitTests" {
Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty
}
}
}

<#
Integration test should appear below and are custom to the command you are writing.
Read https://github.com/dataplat/dbatools/blob/development/contributing.md#tests
for more guidance.
#></source>

Key changes made:
1. Added Pester v5 required header with param block
2. Removed old $CommandName variable usage
3. Added proper BeforeAll block in Context
4. Updated parameter validation to use the new standard approach
5. Used proper -ForEach syntax for parameter testing
6. Maintained the integration test placeholder comment
7. Used $PSItem instead of $_
8. Kept the Add-ReplicationLibrary call as it appears to be required
9. Maintained Write-Host for running path information

The structure now follows the conventions.md guidelines while maintaining the essential functionality of the tests.
}
119 changes: 75 additions & 44 deletions tests/Export-DbaSysDbUserObject.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,19 +1,41 @@
$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "")
Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan
$global:TestConfig = Get-TestConfig
#Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"}
param(
$ModuleName = "dbatools",
$PSDefaultParameterValues = ($TestConfig = Get-TestConfig).Defaults
)

Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
Context "Validate parameters" {
[object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object { $_ -notin ('whatif', 'confirm') }
[object[]]$knownParameters = 'SqlInstance', 'SqlCredential', 'IncludeDependencies', 'BatchSeparator', 'Path', 'FilePath', 'NoPrefix', 'ScriptingOptionsObject', 'NoClobber', 'PassThru', 'EnableException'
$knownParameters += [System.Management.Automation.PSCmdlet]::CommonParameters
It "Should only contain our specific parameters" {
(@(Compare-Object -ReferenceObject ($knownParameters | Where-Object { $_ }) -DifferenceObject $params).Count ) | Should Be 0
Describe "Export-DbaSysDbUserObject" -Tag "UnitTests" {
BeforeAll {
$command = Get-Command Export-DbaSysDbUserObject
$expected = $TestConfig.CommonParameters
$expected += @(
'SqlInstance',
'SqlCredential',
'IncludeDependencies',
'BatchSeparator',
'Path',
'FilePath',
'NoPrefix',
'ScriptingOptionsObject',
'NoClobber',
'PassThru',
'EnableException'
)
}

Context "Parameter validation" {
It "Has parameter: <_>" -ForEach $expected {
$command | Should -HaveParameter $PSItem
}

It "Should have exactly the number of expected parameters ($($expected.Count))" {
$hasparms = $command.Parameters.Values.Name
Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty
}
}
}

Describe "$commandname Integration Tests" -Tags "IntegrationTests" {
Describe "Export-DbaSysDbUserObject" -Tag "IntegrationTests" {
BeforeAll {
$random = Get-Random
$tableName = "dbatoolsci_UserTable_$random"
Expand All @@ -23,6 +45,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" {
$tableFunctionName = "[dbatoolsci_TableFunction_$random]"
$scalarFunctionName = "[dbatoolsci_ScalarFunction_$random]"
$ruleName = "[dbatoolsci_Rule_$random]"

$server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 -SqlCredential $SqlCredential
$server.query("CREATE TABLE dbo.$tableName (Col1 int);", "master")
$server.query("CREATE VIEW dbo.$viewName AS SELECT 1 as Col1;", "master")
Expand All @@ -32,6 +55,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" {
$server.query("CREATE FUNCTION dbo.$scalarFunctionName (@int int) RETURNS INT AS BEGIN RETURN @int END", "master")
$server.query("CREATE RULE dbo.$ruleName AS @range>= 1 AND @range <10;", "master")
}

AfterAll {
$server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 -SqlCredential $SqlCredential
$server.query("DROP TABLE dbo.$tableName", "master")
Expand All @@ -42,54 +66,61 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" {
$server.query("DROP FUNCTION dbo.$scalarFunctionName", "master")
$server.query("DROP RULE dbo.$ruleName", "master")
}
Context "works as expected with passthru" {
$script = Export-DbaSysDbUserObject -SqlInstance $TestConfig.instance2 -PassThru | Out-String
It "should export text matching table name '$tableName'" {
$script -match $tableName | Should be $true

Context "When using PassThru parameter" {
BeforeAll {
$script = Export-DbaSysDbUserObject -SqlInstance $TestConfig.instance2 -PassThru | Out-String
}

It "Should export text matching table name '$tableName'" {
$script -match $tableName | Should -Be $true
}
It "should export text matching view name '$viewName'" {
$script -match $viewName | Should be $true
It "Should export text matching view name '$viewName'" {
$script -match $viewName | Should -Be $true
}
It "should export text matching stored procedure name '$procName'" {
$script -match $procName | Should be $true
It "Should export text matching stored procedure name '$procName'" {
$script -match $procName | Should -Be $true
}
It "should export text matching trigger name '$triggerName'" {
$script -match $triggerName | Should be $true
It "Should export text matching trigger name '$triggerName'" {
$script -match $triggerName | Should -Be $true
}
It "should export text matching table function name '$tableFunctionName'" {
$script -match $tableFunctionName | Should be $true
It "Should export text matching table function name '$tableFunctionName'" {
$script -match $tableFunctionName | Should -Be $true
}
It "should export text matching scalar function name '$scalarFunctionName'" {
$script -match $scalarFunctionName | Should be $true
It "Should export text matching scalar function name '$scalarFunctionName'" {
$script -match $scalarFunctionName | Should -Be $true
}
It "should export text matching rule name '$ruleName'" {
$script -match $ruleName | Should be $true
It "Should export text matching rule name '$ruleName'" {
$script -match $ruleName | Should -Be $true
}
}

Context "works as expected with filename" {
$null = Export-DbaSysDbUserObject -SqlInstance $TestConfig.instance2 -FilePath "C:\Temp\objects_$random.sql"
$file = get-content "C:\Temp\objects_$random.sql" | Out-String
It "should export text matching table name '$tableName'" {
$file -match $tableName | Should be $true
Context "When using FilePath parameter" {
BeforeAll {
$null = Export-DbaSysDbUserObject -SqlInstance $TestConfig.instance2 -FilePath "C:\Temp\objects_$random.sql"
$file = Get-Content "C:\Temp\objects_$random.sql" | Out-String
}

It "Should export text matching table name '$tableName'" {
$file -match $tableName | Should -Be $true
}
It "should export text matching view name '$viewName'" {
$file -match $viewName | Should be $true
It "Should export text matching view name '$viewName'" {
$file -match $viewName | Should -Be $true
}
It "should export text matching stored procedure name '$procName'" {
$file -match $procName | Should be $true
It "Should export text matching stored procedure name '$procName'" {
$file -match $procName | Should -Be $true
}
It "should export text matching trigger name '$triggerName'" {
$file -match $triggerName | Should be $true
It "Should export text matching trigger name '$triggerName'" {
$file -match $triggerName | Should -Be $true
}
It "should export text matching table function name '$tableFunctionName'" {
$file -match $tableFunctionName | Should be $true
It "Should export text matching table function name '$tableFunctionName'" {
$file -match $tableFunctionName | Should -Be $true
}
It "should export text matching scalar function name '$scalarFunctionName'" {
$file -match $scalarFunctionName | Should be $true
It "Should export text matching scalar function name '$scalarFunctionName'" {
$file -match $scalarFunctionName | Should -Be $true
}
It "should export text matching scalar function name '$ruleName'" {
$file -match $ruleName | Should be $true
It "Should export text matching rule name '$ruleName'" {
$file -match $ruleName | Should -Be $true
}
}
}
38 changes: 27 additions & 11 deletions tests/Export-DbaXECsv.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,19 +1,35 @@
$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "")
Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan
$global:TestConfig = Get-TestConfig
#Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"}
param(
$ModuleName = "dbatools",
$PSDefaultParameterValues = ($TestConfig = Get-TestConfig).Defaults
)

Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
Context "Validate parameters" {
[object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object {$_ -notin ('whatif', 'confirm')}
[object[]]$knownParameters = 'InputObject', 'Path', 'FilePath', 'EnableException'
$knownParameters += [System.Management.Automation.PSCmdlet]::CommonParameters
It "Should only contain our specific parameters" {
(@(Compare-Object -ReferenceObject ($knownParameters | Where-Object {$_}) -DifferenceObject $params).Count ) | Should Be 0
Describe "Export-DbaXECsv" -Tag "UnitTests" {
BeforeAll {
$command = Get-Command Export-DbaXECsv
$expected = $TestConfig.CommonParameters
$expected += @(
"InputObject",
"Path",
"FilePath",
"EnableException"
)
}

Context "Parameter validation" {
It "Has parameter: <_>" -ForEach $expected {
$command | Should -HaveParameter $PSItem
}

It "Should have exactly the number of expected parameters ($($expected.Count))" {
$hasparms = $command.Parameters.Values.Name
Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty
}
}
}

<#
Integration test should appear below and are custom to the command you are writing.
Read https://github.com/dataplat/dbatools/blob/development/contributing.md#tests
for more guidence.
#>
#>
Loading

0 comments on commit e1e2e94

Please sign in to comment.