Public/functions/Invoke-DssTest.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
function Invoke-DssTest {
    <#
    .SYNOPSIS
        Runs the specified tests against the specified database(s)
    
    .PARAMETER SqlInstance

    .PARAMETER SqlCredential

    .PARAMETER ConfigPath

    .EXAMPLE
        Invoke-DssTest -SqlInstance localhost -ConfigPath c:\tests\config.json

    .EXAMPLE
        Invoke-DssTest -SqlInstance localhost -ConfigPath http://github.com/someone/SqlTest/raw/config.json

    .EXAMPLE
        Invoke-DssTest -SqlInstance localhost -ConfigPath c:\tests\secrets.json, http://github.com/someone/SqlTest/raw/config.json

    #>

    [CmdletBinding(DefaultParameterSetName = "Default")]
    param (
        [string[]]$ConfigPath,
        [string]$SqlInstance,
        [PSCredential]$SqlCredential,
        [string]$Database,
        [switch]$UserConfig,
        [switch]$RoleConfig,
        [switch]$SchemaConfig,
        [switch]$ObjectConfig,
        [object]$config
    )
    begin {

    }
    process {
        # $config = Get-DssConfig -ConfigPath $ConfigPath

        $srv = Connect-DbaInstance -SqlInstance $SqlInstance -SqlCredential $SqlCredential


        $configSwitch = $true
        if ($UserConfig -or $SchemaConfig -or $RoleConfig -or $ObjectConfig) {
            $configSwitch = $false
        }
        if ($UserConfig -or $configSwitch) {
            Write-Verbose -Message "Testing User config"
            Invoke-Pester -Script @{ Path = "$PSModuleRoot\checks\Users.Tests.ps1"; Parameters = @{SqlInstance = $sqlInstance; SqlCredential = $sqlCredential; Config = $config; Database = $database} }
        } 
        if ($RoleConfig -or $configSwitch) {
            Write-Verbose -Message "Testing Role config"
            Invoke-Pester -Script @{ Path = "$PSModuleRoot\checks\Roles.Tests.ps1"; Parameters = @{SqlInstance = $sqlInstance; SqlCredential = $sqlCredential; Config = $config; Database = $database} }
        } 
        if ($SchemaConfig -or $configSwitch) {
            Write-Verbose -Message "Testing Schema config"
            Invoke-Pester -Script @{ Path = "$PSModuleRoot\checks\Schemas.Tests.ps1"; Parameters = @{SqlInstance = $sqlInstance; SqlCredential = $sqlCredential; Config = $config; Database = $database} }
        } 
        if ($ObjectConfig -or $configSwitch) {
            Write-Verbose -Message "Testing Object config"
            Invoke-Pester -Script @{ Path = "$PSModuleRoot\checks\Objects.Tests.ps1"; Parameters = @{SqlInstance = $sqlInstance; SqlCredential = $sqlCredential; Config = $config; Database = $database} }
            }
    }
    end {}
}