diff --git a/.aider.conf.yml b/.aider.conf.yml new file mode 100644 index 0000000000..a6701ab261 --- /dev/null +++ b/.aider.conf.yml @@ -0,0 +1,109 @@ +## General Settings + +## Load environment variables from a specified file (default: .env in git root) +env-file: .aider/.env + +## Specify the model to use for chat and code assistance +## Available models: gpt-4o, claude-3-5-sonnet, o1-preview, deepseek, etc. +# model: gpt-4o + +## Model for editing code +# editor-model: gpt-4o + +## Suggested number of tokens to use for repo map, use 0 to disable (default: 1024) +map-tokens: 0 + +## Control how often the repo map is refreshed. Options: auto, always, files, manual (default: auto) +map-refresh: manual + +## Enable dark mode for a better terminal appearance on dark backgrounds +dark-mode: true + +## Enable pretty, colorized output (default: true) +pretty: true + +## Disable streaming responses; waits for full response before displaying +## helps with estimating costs +stream: false +no-stream: true + +## Enable caching of prompts to reduce token costs (default: false) +cache-prompts: true + +## Show the differences between current and previous file versions +show-diffs: false + +## Disable automatic commits after changes made by the AI +auto-commits: false + +## Prevent the AI from suggesting shell commands during chats +no-suggest-shell-commands: true + +## Number of pings to keep the prompt cache alive at 5-minute intervals (default: 0) +cache-keepalive-pings: 5 + +## Add aider-specific files to .gitignore (default: true) +gitignore: false + +## Automatically lints code after changes using PSScriptAnalyzer (PowerShell linting) +auto-lint: true + +## map +show-repo-map: false +#aiderignore: .aider/.aiderignore + +## Command to lint PowerShell code using PSScriptAnalyzer +lint-cmd: "pwsh -Command Invoke-ScriptAnalyzer -Path *.ps1" + +## Automatically runs tests after code changes using Pester +auto-test: false + +## Command to run PowerShell tests using Pester +#test-cmd: "pwsh -Command Invoke-Pester -Path .\\Tests" + +## Control verbosity of the output (default: false) +verbose: false + +## Specify the input history file +input-history-file: .aider/aider.input.history + +## Specify the chat history file +chat-history-file: .aider/aider.chat.history.md + +## Specify the LLM history file +llm-history-file: .aider/aider.llm.history + +## Specify model-specific settings +model-settings-file: .aider/aider.model.settings.yml +model-metadata-file: .aider/aider.model.metadata.json + +## Completion and Suggestions + +## Disable completion suggestions for shell commands +suggest-shell-commands: false + +## Git Integration + +## Enable Git integration to track file changes +git: false + +## Completion Menu Colors + +## Set the colors for the completion menu +#completion-menu-color: "cyan" +#completion-menu-bg-color: "black" +#completion-menu-current-color: "white" +#completion-menu-current-bg-color: "blue" + +## Miscellaneous Settings + +## Code Theme +#code-theme: "monokai" + +## edit the whole file +edit-format: whole + +## yesss +yes-always: true + +show-prompts: false \ No newline at end of file diff --git a/.aider/.env.example b/.aider/.env.example new file mode 100644 index 0000000000..e3af213e69 --- /dev/null +++ b/.aider/.env.example @@ -0,0 +1,41 @@ +########################################################## +# Environment Configuration for Aider and LLMs +# Store API keys and optional settings for OpenAI and Anthropic +########################################################## + +# OpenAI API Key for authentication (required) +OPENAI_API_KEY=your-openai-api-key + +# Optional: Custom OpenAI API base URL (if using a custom deployment) +# Uncomment and modify if necessary +# OPENAI_API_BASE=https://api.openai.com + +# Optional: OpenAI API type and version (customize if needed) +# OPENAI_API_TYPE=custom +# OPENAI_API_VERSION=v1 + +# Optional: Specify the OpenAI Organization ID if part of an organization +# OPENAI_ORGANIZATION_ID=your-organization-id + +########################################################## +# Anthropic API Key and Model Configuration (Optional) +########################################################## + +# aider --model claude/ +# aider --model claude-3-opus-20240229 +# Anthropic API Key for Claude models (uncomment if using Claude) +# ANTHROPIC_API_KEY=your-anthropic-api-key + +# Optional: Specify a Claude model (e.g., Claude 3.5 Sonnet) +# Uncomment to set a specific Claude model +# AIDER_MODEL=claude-3-5-sonnet-20240620 + +########################################################## +# Azure OpenAI config (Optional) +########################################################## + +# aider --model azure/ +# aider --model azure/gpt-4o +#export AZURE_API_KEY=abcd1234etcetcetcetcetcetcetcetc +#export AZURE_API_VERSION=2024-08-01-preview +#export AZURE_API_BASE=https://.openai.azure.com/openai/deployments//chat/completions \ No newline at end of file diff --git a/.aider/aider.psm1 b/.aider/aider.psm1 new file mode 100644 index 0000000000..67cccaac31 --- /dev/null +++ b/.aider/aider.psm1 @@ -0,0 +1,459 @@ +function Update-PesterTest { + <# + .SYNOPSIS + Updates Pester tests to v5 format for dbatools commands. + + .DESCRIPTION + Updates existing Pester tests to v5 format for dbatools commands. This function processes test files + and converts them to use the newer Pester v5 parameter validation syntax. It skips files that have + already been converted or exceed the specified size limit. + + .PARAMETER First + Specifies the maximum number of commands to process. Defaults to 1000. + + .PARAMETER Skip + Specifies the number of commands to skip before processing. Defaults to 0. + + .PARAMETER PromptFilePath + The path to the template file containing the prompt structure. + Defaults to "/workspace/.aider/prompts/template.md". + + .PARAMETER CacheFilePath + The path to the file containing cached conventions. + Defaults to "/workspace/.aider/prompts/conventions.md". + + .PARAMETER MaxFileSize + The maximum size of test files to process, in bytes. Files larger than this will be skipped. + Defaults to 8KB. + + .NOTES + Tags: Testing, Pester + Author: dbatools team + + .EXAMPLE + PS C:\> Update-PesterTest + Updates all eligible Pester tests to v5 format using default parameters. + + .EXAMPLE + PS C:\> Update-PesterTest -First 10 -Skip 5 + Updates 10 test files starting from the 6th command, skipping the first 5. + #> + [CmdletBinding(SupportsShouldProcess)] + param ( + [int]$First = 1000, + [int]$Skip = 0, + [string[]]$PromptFilePath = "/workspace/.aider/prompts/template.md", + [string[]]$CacheFilePath = "/workspace/.aider/prompts/conventions.md", + [int]$MaxFileSize = 8kb + ) + # Full prompt path + if (-not (Get-Module dbatools.library -ListAvailable)) { + Write-Warning "dbatools.library not found, installing" + Install-Module dbatools.library -Scope CurrentUser -Force + } + Import-Module /workspace/dbatools.psm1 -Force + + $promptTemplate = Get-Content $PromptFilePath + $commands = Get-Command -Module dbatools -Type Function, Cmdlet | Select-Object -First $First -Skip $Skip + + $commonParameters = [System.Management.Automation.PSCmdlet]::CommonParameters + + foreach ($command in $commands) { + $cmdName = $command.Name + $filename = "/workspace/tests/$cmdName.Tests.ps1" + + if (-not (Test-Path $filename)) { + Write-Warning "No tests found for $cmdName" + Write-Warning "$filename not found" + continue + } + + # if it matches Should -HaveParameter then skip becuase it's been done + if (Select-String -Path $filename -Pattern "Should -HaveParameter") { + Write-Warning "Skipping $cmdName because it's already been converted to Pester v5" + continue + } + + # if file is larger than 8kb, skip + if ((Get-Item $filename).Length -gt $MaxFileSize) { + Write-Warning "Skipping $cmdName because it's too large" + continue + } + + $parameters = $command.Parameters.Values | Where-Object Name -notin $commonParameters + $cmdPrompt = $promptTemplate -replace "--CMDNAME--", $cmdName + $cmdPrompt = $cmdPrompt -replace "--PARMZ--", ($parameters.Name -join "`n") + $cmdprompt = $cmdPrompt -join "`n" + + $aiderParams = @{ + Message = $cmdPrompt + File = $filename + YesAlways = $true + Stream = $false + CachePrompts = $true + ReadFile = $CacheFilePath + } + + Invoke-Aider @aiderParams + } +} + +function Repair-Error { + <# + .SYNOPSIS + Repairs errors in dbatools Pester test files. + + .DESCRIPTION + Processes and repairs errors found in dbatools Pester test files. This function reads error + information from a JSON file and attempts to fix the identified issues in the test files. + + .PARAMETER First + Specifies the maximum number of commands to process. Defaults to 1000. + + .PARAMETER Skip + Specifies the number of commands to skip before processing. Defaults to 0. + + .PARAMETER PromptFilePath + The path to the template file containing the prompt structure. + Defaults to "/workspace/.aider/prompts/fix-errors.md". + + .PARAMETER CacheFilePath + The path to the file containing cached conventions. + Defaults to "/workspace/.aider/prompts/conventions.md". + + .PARAMETER ErrorFilePath + The path to the JSON file containing error information. + Defaults to "/workspace/.aider/prompts/errors.json". + + .NOTES + Tags: Testing, Pester, ErrorHandling + Author: dbatools team + + .EXAMPLE + PS C:\> Repair-Error + Processes and attempts to fix all errors found in the error file using default parameters. + + .EXAMPLE + PS C:\> Repair-Error -ErrorFilePath "custom-errors.json" + Processes and repairs errors using a custom error file. + #> + [CmdletBinding()] + param ( + [int]$First = 1000, + [int]$Skip = 0, + [string[]]$PromptFilePath = "/workspace/.aider/prompts/fix-errors.md", + [string[]]$CacheFilePath = "/workspace/.aider/prompts/conventions.md", + [string]$ErrorFilePath = "/workspace/.aider/prompts/errors.json" + ) + + $promptTemplate = Get-Content $PromptFilePath + $testerrors = Get-Content $ErrorFilePath | ConvertFrom-Json + $commands = $testerrors | Select-Object -ExpandProperty Command -Unique | Sort-Object + + foreach ($command in $commands) { + $filename = "/workspace/tests/$command.Tests.ps1" + Write-Output "Processing $command" + + if (-not (Test-Path $filename)) { + Write-Warning "No tests found for $command" + Write-Warning "$filename not found" + continue + } + + $cmdPrompt = $promptTemplate -replace "--CMDNAME--", $command + + $testerr = $testerrors | Where-Object Command -eq $command + foreach ($err in $testerr) { + $cmdPrompt += "`n`n" + $cmdPrompt += "Error: $($err.ErrorMessage)`n" + $cmdPrompt += "Line: $($err.LineNumber)`n" + } + + $aiderParams = @{ + Message = $cmdPrompt + File = $filename + Stream = $false + CachePrompts = $true + ReadFile = $CacheFilePath + } + + Invoke-Aider @aiderParams + } +} + +function Repair-ParameterTest { + <# + .SYNOPSIS + Repairs parameter tests in dbatools Pester test files. + + .DESCRIPTION + Processes and repairs parameter-related tests in dbatools Pester test files. This function + specifically focuses on fixing parameter validation tests and ensures they follow the correct format. + + .PARAMETER First + Specifies the maximum number of commands to process. Defaults to 1000. + + .PARAMETER Skip + Specifies the number of commands to skip before processing. Defaults to 0. + + .PARAMETER Model + The AI model to use for processing. Defaults to "azure/gpt-4o-mini". + + .PARAMETER PromptFilePath + The path to the template file containing the prompt structure. + Defaults to "/workspace/.aider/prompts/fix-errors.md". + + .NOTES + Tags: Testing, Pester, Parameters + Author: dbatools team + + .EXAMPLE + PS C:\> Repair-ParameterTest + Repairs parameter tests for all eligible commands using default parameters. + + .EXAMPLE + PS C:\> Repair-ParameterTest -First 5 -Model "different-model" + Repairs parameter tests for the first 5 commands using a specified AI model. + #> + [cmdletbinding()] + param ( + [int]$First = 1000, + [int]$Skip = 0, + [string]$Model = "azure/gpt-4o-mini", + [string[]]$PromptFilePath = "/workspace/.aider/prompts/fix-errors.md" + ) + # Full prompt path + if (-not (Get-Module dbatools.library -ListAvailable)) { + Write-Warning "dbatools.library not found, installing" + Install-Module dbatools.library -Scope CurrentUser -Force + } + Import-Module /workspace/dbatools.psm1 -Force + + $promptTemplate = Get-Content $PromptFilePath + + $commands = Get-Command -Module dbatools -Type Function, Cmdlet | Select-Object -First $First -Skip $Skip + $commonParameters = [System.Management.Automation.PSCmdlet]::CommonParameters + + foreach ($command in $commands) { + $cmdName = $command.Name + $filename = "/workspace/tests/$cmdName.Tests.ps1" + + if (-not (Test-Path $filename)) { + Write-Warning "No tests found for $cmdName" + Write-Warning "$filename not found" + continue + } + + $parameters = $command.Parameters.Values | Where-Object Name -notin $commonParameters + + $parameters = $parameters.Name -join ", " + $cmdPrompt = $promptTemplate -replace "--PARMZ--", $parameters + + $aiderParams = @{ + Message = $cmdPrompt + File = $filename + YesAlways = $true + Stream = $false + Model = $Model + } + + Invoke-Aider @aiderParams + } +} + +function Invoke-Aider { + <# + .SYNOPSIS + PowerShell wrapper for the aider CLI tool. + + .DESCRIPTION + Provides a PowerShell interface to the aider command-line tool, allowing for easier integration + with PowerShell scripts and workflows. Supports core functionality including model selection, + caching, and various output options. + + .PARAMETER Message + The message or prompt to send to aider. + + .PARAMETER File + The file(s) to process with aider. + + .PARAMETER Model + Specify the AI model to use (e.g., gpt-4o, claude-3-5-sonnet). + + .PARAMETER EditorModel + Specify the model to use for editing code. + + .PARAMETER Pretty + Enable/disable pretty, colorized output. Defaults to $true. + + .PARAMETER Stream + Enable/disable streaming responses. Defaults to $true. + + .PARAMETER YesAlways + Automatically confirm all prompts. + + .PARAMETER CachePrompts + Enable caching of prompts to reduce token costs. + + .PARAMETER MapTokens + Number of tokens to use for repo map. Use 0 to disable. + + .PARAMETER MapRefresh + Control how often the repo map is refreshed (auto/always/files/manual). + + .PARAMETER AutoLint + Enable/disable automatic linting after changes. + + .PARAMETER AutoTest + Enable/disable automatic testing after changes. + + .PARAMETER ShowPrompts + Show system prompts. + + .PARAMETER VerboseOutput + Enable verbose output. + + .PARAMETER EditFormat + Specify the edit format (e.g., 'whole' for whole file). + + .PARAMETER MessageFile + File containing the message to send to aider. + + .PARAMETER ReadFile + Specify read-only files. + + .PARAMETER Encoding + Specify the encoding for input and output. Defaults to 'utf-8'. + + .NOTES + Tags: AI, Automation + Author: dbatools team + + .EXAMPLE + PS C:\> Invoke-Aider -Message "Fix the bug" -File "script.ps1" + Runs aider with the specified message and file. + + .EXAMPLE + PS C:\> $params = @{ + >> Message = "Update tests" + >> File = "tests.ps1" + >> Model = "gpt-4o" + >> CachePrompts = $true + >> } + PS C:\> Invoke-Aider @params + Runs aider using GPT-4 model with prompt caching enabled. + #> + [CmdletBinding()] + param ( + [Parameter(Mandatory)] + [string]$Message, + + [Parameter(Mandatory)] + [string[]]$File, + + [string]$Model, + [string]$EditorModel, + [bool]$Pretty = $true, + [bool]$Stream = $true, + [switch]$YesAlways, + [switch]$CachePrompts, + [int]$MapTokens = 0, + [ValidateSet('auto', 'always', 'files', 'manual')] + [string]$MapRefresh = 'manual', + [bool]$AutoLint = $true, + [bool]$AutoTest = $false, + [switch]$ShowPrompts, + [switch]$VerboseOutput, + [string]$EditFormat = 'whole', + [string]$MessageFile, + [string[]]$ReadFile, + [ValidateSet('utf-8', 'ascii', 'unicode', 'utf-16', 'utf-32', 'utf-7')] + [string]$Encoding = 'utf-8' + ) + + $params = @( + "--message", $Message + ) + + foreach ($f in $File) { + $params += "--file" + $params += $f + } + + if ($Model) { + $params += "--model" + $params += $Model + } + + if ($EditorModel) { + $params += "--editor-model" + $params += $EditorModel + } + + if (-not $Pretty) { + $params += "--no-pretty" + } + + if (-not $Stream) { + $params += "--no-stream" + } + + if ($YesAlways) { + $params += "--yes-always" + } + + if ($CachePrompts) { + $params += "--cache-prompts" + # Always set keepalive pings to 5 when caching is enabled + $params += "--cache-keepalive-pings" + $params += "5" + } + + if ($MapTokens -ge 0) { + $params += "--map-tokens" + $params += $MapTokens.ToString() + } + + if ($MapRefresh) { + $params += "--map-refresh" + $params += $MapRefresh + } + + if (-not $AutoLint) { + $params += "--no-auto-lint" + } + + if ($AutoTest) { + $params += "--auto-test" + } + + if ($ShowPrompts) { + $params += "--show-prompts" + } + + if ($VerboseOutput) { + $params += "--verbose" + } + + if ($EditFormat) { + $params += "--edit-format" + $params += $EditFormat + } + + if ($MessageFile) { + $params += "--message-file" + $params += $MessageFile + } + + foreach ($rf in $ReadFile) { + $params += "--read" + $params += $rf + } + + if ($Encoding) { + $params += "--encoding" + $params += $Encoding + } + + aider @params +} diff --git a/.aider/prompts/conventions.md b/.aider/prompts/conventions.md new file mode 100644 index 0000000000..48a778af33 --- /dev/null +++ b/.aider/prompts/conventions.md @@ -0,0 +1,172 @@ +# Tasks + +1. **Restructure Test Code:** + - Move all test code into appropriate blocks: `It`, `BeforeAll`, `BeforeEach`, `AfterAll`, or `AfterEach`. + - Place any file setup code, including the import of `constants.ps1`, into the appropriate blocks at the beginning of each test file. + +2. **Update `Describe` and `Context` Blocks:** + - Ensure that no test code is directly inside `Describe` or `Context` blocks. + - Properly nest `Context` blocks within `Describe` blocks. + +3. **Refactor Skip Conditions:** + - Move skip logic outside of `BeforeAll` blocks. + - Use global read-only variables for skip conditions where appropriate. + - Ensure that `-Skip` parameters evaluate to `$true` or `$false`, not a string. + +4. **Update `TestCases`:** + - Define `TestCases` in a way that is compatible with Pester v5's discovery phase. + +5. **Update Assertion Syntax:** + - Replace assertions like `Should Be` with `Should -Be`. + - Update other assertion operators as needed (e.g., `Should Throw` to `Should -Throw`). + +6. **Modify `InModuleScope` Usage:** + - Remove `InModuleScope` from around `Describe` and `It` blocks. + - Use the `-ModuleName` parameter on `Mock` commands where possible. + +7. **Update `Invoke-Pester` Calls:** + - Modify `Invoke-Pester` parameters to align with Pester v5's simple or advanced interface. + - **Do not use the Legacy parameter set**, as it is deprecated and may not work correctly. + +8. **Adjust Mocking Syntax:** + - Update any mock definitions to Pester v5 syntax. + +9. **Remove Parameter Testing Using `knownparameters`:** + - Identify any existing "Validate parameters" contexts that use `knownparameters` sections + - Remove the entire "Validate parameters" context and replace it with the Pester v5 approach using `Should -HaveParameter`, as shown in the example Pester v5 test script. + +10. **Use TestCases Whenever Possible:** + - Look for opportunities to use TestCases in the test code. + - Convert existing tests to use TestCases when applicable. + - Define TestCases using the `ForEach` parameter in the `It` block, as shown in the example below. + +## Instructions + +- **Importing Constants:** + - Include the contents of `constants.ps1` at the appropriate place in the test script. + - Since the variables defined in `constants.ps1` are needed during the discovery phase (e.g., for `-ForEach` loops), import `constants.ps1` within the `BeforeDiscovery` block. + - This ensures that all global variables are available during both the discovery and execution phases. + +- **Variable Scoping:** + - Replace all `$script:` variable scopes with `$global:` to align with Pester v5 scoping rules. + +- **Comments and Debugging Notes:** + - Leave comments like `#$script:instance2 for appveyor` intact for debugging purposes. + - But change `$script:instance2` to `$global:instance2` for proper scoping. + - So it should look like this: `#$global:instance2 for appveyor`. + +- **Consistency with Example:** + - Follow the structure and conventions used in the example Pester v5 test script provided below. + +- **SQL Server-Specific Scenarios:** + - If you encounter any SQL Server-specific testing scenarios that require special handling, implement the necessary adjustments while maintaining the integrity of the tests. + +## Example Pester v5 Test Script + +```powershell +param($ModuleName = 'dbatools') + +Describe "Connect-DbaInstance" { + BeforeDiscovery { + . (Join-Path $PSScriptRoot 'constants.ps1') + } + + Context "Validate parameters" { + BeforeAll { + $command = Get-Command Connect-DbaInstance + } + $parms = @( + "SqlInstance", + "SqlCredential", + "Database" + ) + It "Has required parameter: <_>" -ForEach $parms { + $command | Should -HaveParameter $PSItem + } + } + + Context "Connects using newly created login" -ForEach $global:instances { + BeforeAll { + $loginName = "dbatoolsci_login_$(Get-Random)" + $securePassword = ConvertTo-SecureString -String "P@ssw0rd$(Get-Random)" -AsPlainText -Force + $credential = [PSCredential]::new($loginName, $securePassword) + New-DbaLogin -SqlInstance $PSItem -Login $loginName -Password $securePassword -Confirm:$false + } + + AfterAll { + Remove-DbaLogin -SqlInstance $PSItem -Login $loginName -Confirm:$false + } + + It "Connects successfully" { + $instance = Connect-DbaInstance -SqlInstance $PSItem -SqlCredential $credential + $instance.Name | Should -Be $PSItem.Split('\')[0] + } + } +} +``` + +## Example Pester v5 Test Script with TestCases + +```powershell +param($ModuleName = 'dbatools') + +Describe "Add-Numbers" { + It "Should calculate the correct result" -ForEach @( + @{ Input1 = 1; Input2 = 2; Expected = 3 } + @{ Input1 = 2; Input2 = 3; Expected = 5 } + @{ Input1 = 3; Input2 = 4; Expected = 7 } + ) { + $result = Add-Numbers -Number1 $Input1 -Number2 $Input2 + $result | Should -Be $Expected + } +} +``` + +## Additional Guidelines +* Start with `param($ModuleName = 'dbatools')` like in the example above. +* -Skip:(whatever) should return true or false, not a string + + +## Style and instructions + +Remember to REMOVE the knownparameters and validate parameters this way: + +Context "Validate parameters" { + BeforeAll { + $command = Get-Command Connect-DbaInstance + } + $parms = @( + "SqlInstance", + "SqlCredential", + "Database" + ) + It "Has required parameter: <_>" -ForEach $parms { + $command | Should -HaveParameter $PSItem + } +} + +## DO NOT list parameters like this + +```powershell +$parms = @('SqlInstance','SqlCredential','Database') +``` + +## DO list parameters like this + +```powershell +$parms = @( + 'SqlInstance', + 'SqlCredential', + 'Database' +) +``` + +## DO use the $parms variable when referencing parameters + +## more instructions + +DO NOT USE: +$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") + +DO USE: +The static command name provided in the prompt \ No newline at end of file diff --git a/.aider/prompts/fix-errors.md b/.aider/prompts/fix-errors.md new file mode 100644 index 0000000000..a96372a764 --- /dev/null +++ b/.aider/prompts/fix-errors.md @@ -0,0 +1,15 @@ +Analyze and update the Pester test file for the dbatools PowerShell module at /workspace/tests/--CMDNAME--.Tests.ps1. Focus on the following: + +1. Review the provided errors and their line numbers. +2. Remember these are primarily INTEGRATION tests. Only mock when absolutely necessary. +3. Make minimal changes required to make the tests pass. Avoid over-engineering. +4. DO NOT replace $global: variables with $script: variables +5. DO NOT change the names of variables unless you're 100% certain it will solve the given error. +6. The is provided for your reference to better understand the constants used in the tests. +7. Preserve existing comments in the code. +8. If there are multiple ways to fix an error, explain your decision-making process. +9. Flag any potential issues that cannot be resolved within the given constraints. + +Edit the test and provide a summary of the changes made, including explanations for any decisions between multiple fix options and any unresolved issues. + +Errors to address: diff --git a/.aider/prompts/fix-params.md b/.aider/prompts/fix-params.md new file mode 100644 index 0000000000..deee07a432 --- /dev/null +++ b/.aider/prompts/fix-params.md @@ -0,0 +1,17 @@ +Required parameters for this command: +--PARMZ-- + +AND HaveParameter tests must be structured EXACTLY like this: + +```powershell +$params = @( + "parameter1", + "parameter2", + "etc" +) +It "has the required parameter: <_>" -ForEach $params { + $currentTest | Should -HaveParameter $PSItem +} +``` + +NO OTHER CHANGES SHOULD BE MADE TO THE TEST FILE \ No newline at end of file diff --git a/.aider/prompts/template.md b/.aider/prompts/template.md new file mode 100644 index 0000000000..3c0e4623fb --- /dev/null +++ b/.aider/prompts/template.md @@ -0,0 +1,11 @@ +# Pester v4 to v5 Migration + +You are an AI assistant created by Anthropic to help migrate Pester tests for the **dbatools PowerShell module** from version 4 to version 5. Analyze and update the file `/workspace/tests/--CMDNAME--.Tests.ps1` according to the instructions in conventions.md. + +Required parameters for this command: +--PARMZ-- + +Command name: +--CMDNAME-- + +Before responding, verify that your answer adheres to the specified coding and migration guidelines. \ No newline at end of file diff --git a/.aider/readme.md b/.aider/readme.md new file mode 100644 index 0000000000..f77c615860 --- /dev/null +++ b/.aider/readme.md @@ -0,0 +1,120 @@ +# Aider PowerShell Module + +This module provides automation tools for PowerShell development in devcontainers, focusing on test maintenance and error handling for PowerShell modules. + +## Key Functions + +### Invoke-Aider +Core wrapper for the aider CLI tool. Used by other functions to interact with AI models for code improvements. + +```powershell +# Basic usage +Invoke-Aider -Message "Fix the bug in parameter validation" -File "tests/Get-Something.Tests.ps1" + +# Advanced usage with caching and custom model +$params = @{ + Message = "Update parameter tests" + File = "tests/Update-Database.Tests.ps1" + Model = "gpt-4o" + CachePrompts = $true + AutoTest = $true +} +Invoke-Aider @params +``` + +### Update-PesterTest +Modernizes Pester tests to v5 format, particularly useful when maintaining legacy test suites. + +```powershell +# Update first 10 test files +Update-PesterTest -First 10 + +# Skip already processed files and update next batch +Update-PesterTest -Skip 10 -First 5 -MaxFileSize 12kb +``` + +### Repair-Error +Automatically fixes common test errors using AI assistance. + +```powershell +# Process all errors from default error file +Repair-Error + +# Use custom error file +Repair-Error -ErrorFilePath "custom-errors.json" -First 5 +``` + +### Repair-ParameterTest +Focuses on fixing parameter validation tests. + +```powershell +# Fix parameter tests using default settings +Repair-ParameterTest + +# Use specific model and limit to first 5 commands +Repair-ParameterTest -First 5 -Model "azure/gpt-4o-mini" +``` + +## Directory Structure + +``` +.aider/ +├── aider.psm1 # PowerShell module with automation functions +├── prompts/ # AI prompt templates +│ ├── template.md # Base templates for AI interactions +│ ├── fix-errors.md # Error fixing prompts +│ └── conventions.md # Coding conventions cache +└── .env # Environment configuration +``` + +## Configuration + +### .aider.conf.yml +Main configuration file controlling AI behavior, linting, and testing settings. Example: + +```yaml +model: azure/gpt-4o-mini +edit_format: whole +auto_lint: true +cache_prompts: true +encoding: utf-8 +``` + +### Environment Variables +Create a `.env` file based on `.env.example` to configure: +- API keys for AI services +- Custom model endpoints +- Project-specific settings + +## Best Practices + +1. Always use `-CachePrompts` when making multiple similar changes to reduce API costs +2. Set appropriate `-MaxFileSize` limits to prevent processing overly complex files +3. Use `-YesAlways` for batch operations, but review changes in version control +4. Keep prompt templates in `/prompts` directory for consistency +5. Leverage `-ReadFile` for including coding conventions in AI context + +## Common Workflows + +### Modernizing Test Suite +```powershell +# Step 1: Update to Pester v5 +Update-PesterTest -First 1000 + +# Step 2: Fix any parameter validation issues +Repair-ParameterTest -Model "azure/gpt-4o-mini" + +# Step 3: Address remaining errors +Repair-Error +``` + +### Maintaining Conventions +```powershell +# Update tests with new conventions +$params = @{ + Message = "Update parameter validation style" + File = "tests/*.Tests.ps1" + ReadFile = ".aider/prompts/conventions.md" + CachePrompts = $true +} +Invoke-Aider @params diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 5d79df7a17..6f7a3eaaa3 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,14 +1,16 @@ -FROM mcr.microsoft.com/mssql/server:2019-latest -USER root -# Install PowerShell -RUN apt-get update && apt install -y powershell -# install git -RUN apt install -y git +FROM mcr.microsoft.com/mssql/server:latest -# some cleanup -RUN apt-get autoremove -y \ - && apt-get clean -y +# Switch to root for installing packages +USER root +# Install dependencies, PowerShell, Python pip, Git, and cleanup in one go +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + powershell python3-pip git libsndfile1 && \ + python3 -m pip install aider-chat && \ + apt-get autoremove -y && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* ENV GIT_PROMPT_START='\033[1;36dbatools>\033[0m\033[0;33m\w\a\033[0m' # Save command line history diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 7db7034993..1cd99186d4 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -18,7 +18,10 @@ "usernamehw.errorlens", "oderwat.indent-rainbow", "wengerk.highlight-bad-chars", - "streetsidesoftware.code-spell-checker" + "dbatools.search", + "streetsidesoftware.code-spell-checker", + "bedirt.gpt-token-counter-live", + "saoudrizwan.claude-dev" ], "settings": { "powershell.powerShellAdditionalExePaths": { diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index a8ede1551a..47fead2163 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -4,7 +4,7 @@ - [ ] Bug fix (non-breaking change, fixes # ) - [ ] New feature (non-breaking change, adds functionality, fixes # ) - [ ] Breaking change (affects multiple commands or functionality, fixes # ) - - [ ] Ran manual Pester test and has passed (`.\tests\manual.pester.ps1`) + - [ ] Ran manual Pester test and has passed (`Invoke-ManualPester`) - [ ] Adding code coverage to existing functionality - [ ] Pester test is included - [ ] If new file reference added for test, has is been added to github.com/dataplat/appveyor-lab ? diff --git a/.gitignore b/.gitignore index 9e243ba673..67a399dacf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,40 +1,51 @@ -dbatools-startmigration-transcript.txt -dbatools-exceptions.txt -*TempPoint* -*.pssproj - -# ignore the settings folder and files for VSCode -.vscode/* -*.psproj -dbatools.psprojs - -# ignore the settings folder and files for Visual Studio -.vs/* - -# VIM backup files -*~ - -# msbuild log file and structured binary log file -msbuild.log -msbuild.binlog - -# Local constant file -tests/constants.local.ps1 - -# For those that want to use Docker images for testing -# Integration with Docker requires the docker compose file to exist within the project folder -docker-compose.yml - -### NCrunch ### -# NCrunch -*.ncrunch* -_NCrunch_* -*.crunch.xml -*.ncrunchsolution* -nCrunchTemp_* - +dbatools-startmigration-transcript.txt +dbatools-exceptions.txt +*TempPoint* +*.pssproj + +# ignore the settings folder and files for VSCode +.vscode/* +*.psproj +dbatools.psprojs + +# ignore the settings folder and files for Visual Studio +.vs/* + +# VIM backup files +*~ + +# msbuild log file and structured binary log file +msbuild.log +msbuild.binlog + +# Local constant file +tests/constants.local.ps1 + +# For those that want to use Docker images for testing +# Integration with Docker requires the docker compose file to exist within the project folder +docker-compose.yml + +### NCrunch ### +# NCrunch +*.ncrunch* +_NCrunch_* +*.crunch.xml +*.ncrunchsolution* +nCrunchTemp_* + debug.log en-us/dbatools-help.xml dbatools.ps1 dbatools.dat allcommands.ps1 + +# Environment files +**/.env + +# Aider files +/.aider.tags.cache.v3 +.aider/.aider.chat.history.md +.aider/.aider.input.history +.aider/aider.chat.history.md +.aider/aider.input.history +.aider/aider.llm.history \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index c44f3d5962..2a1cc3e739 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -86,5 +86,8 @@ "Viorel", "Wsfc", "wsmelton" - ] + ], + "files.exclude": { + "**/.aider.tags.cache.v3": true + } } \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml index df77dc5a69..b2f56e6e17 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -4,9 +4,6 @@ configuration: "Debug" build_script: - ps: Set-Service wuauserv -StartupType Manual #otherwise, choco command exits with code 1058 - - ps: choco install dotnet-5.0-sdk | Out-String | Out-Null - - ps: choco install dotnetcore-sdk | Out-String | Out-Null -# - ps: Push-Location bin\projects\dbatools; dotnet build ;Pop-Location version: 2.1.{build} diff --git a/dbatools.psm1 b/dbatools.psm1 index 1ec91a8a1a..034f6c1a5c 100644 --- a/dbatools.psm1 +++ b/dbatools.psm1 @@ -166,6 +166,11 @@ if (-not (Test-Path -Path "$script:PSModuleRoot\dbatools.dat") -or $script:seria . $file.FullName } + # All internal functions privately available within the toolset + foreach ($file in (Get-ChildItem -Path "$script:PSModuleRoot/private/testing/" -Recurse -Filter *.ps1)) { + . $file.FullName + } + Write-ImportTime -Text "Loading internal commands via dotsource" # All exported functions diff --git a/private/testing/Get-TestConfig.ps1 b/private/testing/Get-TestConfig.ps1 new file mode 100644 index 0000000000..cd7e8d38cd --- /dev/null +++ b/private/testing/Get-TestConfig.ps1 @@ -0,0 +1,62 @@ +function Get-TestConfig { + param( + [string]$LocalConfigPath = "$script:PSModuleRoot/tests/constants.local.ps1" + ) + $config = [ordered]@{} + + if (Test-Path $LocalConfigPath) { + Write-Host "Tests will use local constants file: tests\constants.local.ps1." -ForegroundColor Cyan + . $LocalConfigPath + # Note: Local constants are sourced but not explicitly added to $config + } elseif ($env:CODESPACES -and ($env:TERM_PROGRAM -eq 'vscode' -and $env:REMOTE_CONTAINERS)) { + $config['Instance1'] = "dbatools1" + $config['Instance2'] = "dbatools2" + $config['Instance3'] = "dbatools3" + $config['Instances'] = @($config['Instance1'], $config['Instance2']) + + $config['SqlCred'] = [PSCredential]::new('sa', (ConvertTo-SecureString $env:SA_PASSWORD -AsPlainText -Force)) + $config['PSDefaultParameterValues'] = @{ + "*:SqlCredential" = $config['SqlCred'] + } + } elseif ($env:GITHUB_WORKSPACE) { + $config['DbaToolsCi_Computer'] = "localhost" + $config['Instance1'] = "localhost" + $config['Instance2'] = "localhost:14333" + $config['Instance2SQLUserName'] = $null # placeholders for -SqlCredential testing + $config['Instance2SQLPassword'] = $null + $config['Instance3'] = "localhost" + $config['Instance2_Detailed'] = "localhost,14333" # Just to make sure things parse a port properly + $config['AppveyorLabRepo'] = "/tmp/appveyor-lab" + $config['Instances'] = @($config['Instance1'], $config['Instance2']) + $config['SsisServer'] = "localhost\sql2016" + $config['AzureBlob'] = "https://dbatools.blob.core.windows.net/sql" + $config['AzureBlobAccount'] = "dbatools" + $config['AzureServer'] = 'psdbatools.database.windows.net' + $config['AzureSqlDbLogin'] = "appveyor@clemairegmail.onmicrosoft.com" + } else { + $config['DbaToolsCi_Computer'] = "localhost" + $config['Instance1'] = "localhost\sql2008r2sp2" + $config['Instance2'] = "localhost\sql2016" + $config['Instance2SQLUserName'] = $null # placeholders for -SqlCredential testing + $config['Instance2SQLPassword'] = $null + $config['Instance3'] = "localhost\sql2017" + $config['Instance2_Detailed'] = "localhost,14333\sql2016" # Just to make sure things parse a port properly + $config['AppveyorLabRepo'] = "C:\github\appveyor-lab" + $config['Instances'] = @($config['Instance1'], $config['Instance2']) + $config['SsisServer'] = "localhost\sql2016" + $config['AzureBlob'] = "https://dbatools.blob.core.windows.net/sql" + $config['AzureBlobAccount'] = "dbatools" + $config['AzureServer'] = 'psdbatools.database.windows.net' + $config['AzureSqlDbLogin'] = "appveyor@clemairegmail.onmicrosoft.com" + $config['BigDatabaseBackup'] = 'C:\github\StackOverflowMini.bak' + $config['BigDatabaseBackupSourceUrl'] = 'https://github.com/BrentOzarULTD/Stack-Overflow-Database/releases/download/20230114/StackOverflowMini.bak' + } + + if ($env:appveyor) { + $config['PSDefaultParameterValues'] = @{ + '*:WarningAction' = 'SilentlyContinue' + } + } + + [pscustomobject]$config +} \ No newline at end of file diff --git a/private/testing/Invoke-ManualPester.ps1 b/private/testing/Invoke-ManualPester.ps1 new file mode 100644 index 0000000000..6db58748aa --- /dev/null +++ b/private/testing/Invoke-ManualPester.ps1 @@ -0,0 +1,252 @@ +function Invoke-ManualPester { +<# + .SYNOPSIS + Runs dbatools tests. + + .DESCRIPTION + This is an helper to automate running tests locally + + .PARAMETER Path + The Path to the test files to run. It accepts multiple test file paths passed in (e.g. .\Find-DbaOrphanedFile.Tests.ps1) as well + as simple strings (e.g. "orphaned" will run all files matching .\*orphaned*.Tests.ps1) + + .PARAMETER Show + Gets passed down to Pester's -Show parameter (useful if you want to reduce verbosity) + + .PARAMETER PassThru + Gets passed down to Pester's -PassThru parameter (useful if you want to return an object to analyze) + + .PARAMETER TestIntegration + dbatools's suite has unittests and integrationtests. This switch enables IntegrationTests, which need live instances + see Get-TestConfig for customizations + + .PARAMETER Coverage + Enables measuring code coverage on the tested function + + .PARAMETER DependencyCoverage + Enables measuring code coverage also of "lower level" (i.e. called) functions + + .PARAMETER ScriptAnalyzer + Enables checking the called function's code with Invoke-ScriptAnalyzer, with dbatools's profile + + .EXAMPLE + Invoke-ManualPester -Path Find-DbaOrphanedFile.Tests.ps1 -TestIntegration -Coverage -DependencyCoverage -ScriptAnalyzer + + The most complete number of checks: + - Runs both unittests and integrationtests + - Gathers and shows code coverage measurement for Find-DbaOrphanedFile and all its dependencies + - Checks Find-DbaOrphanedFile with Invoke-ScriptAnalyzer + + .EXAMPLE + Invoke-ManualPester -Path Find-DbaOrphanedFile.Tests.ps1 + + Runs unittests stored in Find-DbaOrphanedFile.Tests.ps1 + + .EXAMPLE + Invoke-ManualPester -Path Find-DbaOrphanedFile.Tests.ps1 -PassThru + + Runs unittests stored in Find-DbaOrphanedFile.Tests.ps1 and returns an object that can be analyzed + + .EXAMPLE + Invoke-ManualPester -Path orphan + + Runs unittests for all tests matching in `*orphan*.Tests.ps1 + + .EXAMPLE + Invoke-ManualPester -Path Find-DbaOrphanedFile.Tests.ps1 -Show Default + + Runs unittests stored in Find-DbaOrphanedFile.Tests.ps1, with reduced verbosity + + .EXAMPLE + Invoke-ManualPester -Path Find-DbaOrphanedFile.Tests.ps1 -TestIntegration + + Runs both unittests and integrationtests stored in Find-DbaOrphanedFile.Tests.ps1 + + .EXAMPLE + Invoke-ManualPester -Path Find-DbaOrphanedFile.Tests.ps1 -TestIntegration -Coverage + + Gathers and shows code coverage measurement for Find-DbaOrphanedFile + + .EXAMPLE + Invoke-ManualPester -Path Find-DbaOrphanedFile.Tests.ps1 -TestIntegration -Coverage -DependencyCoverage + + Gathers and shows code coverage measurement for Find-DbaOrphanedFile and all its dependencies + +#> + + [CmdletBinding()] + param ( + [Parameter(Position = 0, ValueFromPipeline, ValueFromPipelineByPropertyName)] + [Alias('FullName')] + [string[]]$Path, + [ValidateSet('None', 'Default', 'Passed', 'Failed', 'Pending', 'Skipped', 'Inconclusive', 'Describe', 'Context', 'Summary', 'Header', 'All', 'Fails')] + [string]$Show = "All", + [switch]$PassThru, + [switch]$TestIntegration, + [switch]$Coverage, + [switch]$DependencyCoverage, + [switch]$ScriptAnalyzer + ) + + <# + Remove-Module -Name Pester + Import-Module -name Pester -MaximumVersion 4.* + #> + + $invokeFormatterVersion = (Get-Command Invoke-Formatter -ErrorAction SilentlyContinue).Version + $HasScriptAnalyzer = $null -ne $invokeFormatterVersion + $MinimumPesterVersion = [Version] '3.4.5.0' # Because this is when -Show was introduced + $MaximumPesterVersion = [Version] '5.0.0.0' # Because our tests (and runners) are only compatible with 4.* + $PesterVersion = (Get-Command Invoke-Pester -ErrorAction SilentlyContinue).Version + $HasPester = $null -ne $PesterVersion + $ScriptAnalyzerCorrectVersion = '1.18.2' + + if (!($HasScriptAnalyzer)) { + Write-Warning "Please install PSScriptAnalyzer" + Write-Warning " Install-Module -Name PSScriptAnalyzer -RequiredVersion '$ScriptAnalyzerCorrectVersion'" + Write-Warning " or go to https://github.com/PowerShell/PSScriptAnalyzer" + } else { + if ($invokeFormatterVersion -ne $ScriptAnalyzerCorrectVersion) { + Remove-Module PSScriptAnalyzer + try { + Import-Module PSScriptAnalyzer -RequiredVersion $ScriptAnalyzerCorrectVersion -ErrorAction Stop + } catch { + Write-Warning "Please install PSScriptAnalyzer $ScriptAnalyzerCorrectVersion" + Write-Warning " Install-Module -Name PSScriptAnalyzer -RequiredVersion '$ScriptAnalyzerCorrectVersion'" + } + } + } + if (!($HasPester)) { + Write-Warning "Please install Pester" + Write-Warning " Install-Module -Name Pester -Force -SkipPublisherCheck" + Write-Warning " or go to https://github.com/pester/Pester" + } + if ($PesterVersion -lt $MinimumPesterVersion) { + Write-Warning "Please update Pester to at least 3.4.5" + Write-Warning " Install-Module -Name Pester -MaximumVersion '4.10' -Force -SkipPublisherCheck" + Write-Warning " or go to https://github.com/pester/Pester" + } + if ($PesterVersion -gt $MaximumPesterVersion) { + Write-Warning "Please get Pester to the 4.* release" + Write-Warning " Install-Module -Name Pester -MaximumVersion '4.10' -Force -SkipPublisherCheck" + Write-Warning " or go to https://github.com/pester/Pester" + } + + if (($HasPester -and $HasScriptAnalyzer -and ($PesterVersion -ge $MinimumPesterVersion) -and ($PesterVersion -lt $MaximumPesterVersion) -and ($invokeFormatterVersion -eq $ScriptAnalyzerCorrectVersion)) -eq $false) { + Write-Warning "Exiting..." + return + } + + $ModuleBase = Split-Path -Path $PSScriptRoot -Parent + + if (-not(Test-Path "$ModuleBase\.git" -Type Container)) { + New-Item -Type Container -Path "$ModuleBase\.git" -Force + } + + #removes previously imported dbatools, if any + # No need the force will do it + # Remove-Module dbatools -ErrorAction Ignore + #imports the module making sure DLL is loaded ok + Import-Module "$ModuleBase\dbatools.psd1" -DisableNameChecking -Force + #imports the psm1 to be able to use internal functions in tests + Import-Module "$ModuleBase\dbatools.psm1" -DisableNameChecking -Force + + $ScriptAnalyzerRulesExclude = @('PSUseOutputTypeCorrectly', 'PSAvoidUsingPlainTextForPassword', 'PSUseBOMForUnicodeEncodedFile') + + $testInt = $false + if ($config_TestIntegration) { + $testInt = $true + } + if ($TestIntegration) { + $testInt = $true + } + + function Get-CoverageIndications($Path, $ModuleBase) { + # takes a test file path and figures out what to analyze for coverage (i.e. dependencies) + $CBHRex = [regex]'(?smi)<#(.*)#>' + $everything = (Get-Module dbatools).ExportedCommands.Values + $everyfunction = $everything.Name + $funcs = @() + $leaf = Split-Path $path -Leaf + # assuming Get-DbaFoo.Tests.ps1 wants coverage for "Get-DbaFoo" + # but allowing also Get-DbaFoo.one.Tests.ps1 and Get-DbaFoo.two.Tests.ps1 + $func_name += ($leaf -replace '^([^.]+)(.+)?.Tests.ps1', '$1') + if ($func_name -in $everyfunction) { + $funcs += $func_name + $f = $everything | Where-Object Name -eq $func_name + $source = $f.Definition + $CBH = $CBHRex.match($source).Value + $cmdonly = $source.Replace($CBH, '') + foreach ($e in $everyfunction) { + # hacky, I know, but every occurrence of any function plus a space kinda denotes usage !? + $searchme = "$e " + if ($cmdonly.contains($searchme)) { + $funcs += $e + } + } + } + $testpaths = @() + $allfiles = Get-ChildItem -File -Path "$ModuleBase\private\functions", "$ModuleBase\public" -Filter '*.ps1' + foreach ($f in $funcs) { + # exclude always used functions ?! + if ($f -in ('Connect-DbaInstance', 'Select-DefaultView', 'Stop-Function', 'Write-Message')) { continue } + # can I find a correspondence to a physical file (again, on the convenience of having Get-DbaFoo.ps1 actually defining Get-DbaFoo)? + $res = $allfiles | Where-Object { $_.Name.Replace('.ps1', '') -eq $f } + if ($res.count -gt 0) { + $testpaths += $res.FullName + } + } + return @() + ($testpaths | Select-Object -Unique) + } + + $files = @() + + if ($Path) { + foreach ($item in $path) { + if (Test-Path $item) { + $files += Get-ChildItem -Path $item + } else { + $files += Get-ChildItem -Path "$ModuleBase\tests\*$item*.Tests.ps1" + } + } + } + + if ($files.Length -eq 0) { + Write-Warning "No tests to be run" + } + + $AllTestsWithinScenario = $files + + foreach ($f in $AllTestsWithinScenario) { + $PesterSplat = @{ + 'Script' = $f.FullName + 'Show' = $show + 'PassThru' = $passThru + } + #opt-in + $HeadFunctionPath = $f.FullName + + if ($Coverage -or $ScriptAnalyzer) { + $CoverFiles = Get-CoverageIndications -Path $f -ModuleBase $ModuleBase + $HeadFunctionPath = $CoverFiles | Select-Object -First 1 + } + if ($Coverage) { + if ($DependencyCoverage) { + $CoverFilesPester = $CoverFiles + } else { + $CoverFilesPester = $HeadFunctionPath + } + $PesterSplat['CodeCoverage'] = $CoverFilesPester + } + if (!($testInt)) { + $PesterSplat['ExcludeTag'] = "IntegrationTests" + } + Invoke-Pester @PesterSplat + if ($ScriptAnalyzer) { + if ($Show -ne "None") { + Write-Host -ForegroundColor green -Object "ScriptAnalyzer check for $HeadFunctionPath" + } + Invoke-ScriptAnalyzer -Path $HeadFunctionPath -ExcludeRule $ScriptAnalyzerRulesExclude + } + } +} \ No newline at end of file diff --git a/public/Get-DbaDbMailServer.ps1 b/public/Get-DbaDbMailServer.ps1 index cec0636db7..8277abfa36 100644 --- a/public/Get-DbaDbMailServer.ps1 +++ b/public/Get-DbaDbMailServer.ps1 @@ -97,7 +97,7 @@ function Get-DbaDbMailServer { $servers | Add-Member -Force -MemberType NoteProperty -Name ComputerName -value $mailserver.ComputerName $servers | Add-Member -Force -MemberType NoteProperty -Name InstanceName -value $mailserver.InstanceName $servers | Add-Member -Force -MemberType NoteProperty -Name SqlInstance -value $mailserver.SqlInstance - $servers | Add-Member -Force -MemberType NoteProperty -Name Account -value $servers[0].Parent.Name + $servers | Add-Member -Force -MemberType NoteProperty -Name Account -value $servers.Parent.Name $servers | Select-DefaultView -Property ComputerName, InstanceName, SqlInstance, Account, Name, Port, EnableSsl, ServerType, UserName, UseDefaultCredentials, NoCredentialChange } } catch { diff --git a/public/New-DbaAgentJob.ps1 b/public/New-DbaAgentJob.ps1 index c5a6480fc4..f0e6da53ff 100644 --- a/public/New-DbaAgentJob.ps1 +++ b/public/New-DbaAgentJob.ps1 @@ -250,7 +250,7 @@ function New-DbaAgentJob { if ($PSCmdlet.ShouldProcess($instance, "Removing the job $Job on $instance")) { try { - Remove-DbaAgentJob -SqlInstance $server -Job $Job -EnableException -Confirm:$false + $null = Remove-DbaAgentJob -SqlInstance $server -Job $Job -EnableException -Confirm:$false $server.JobServer.Refresh() } catch { Stop-Function -Message "Couldn't remove job $Job from $instance" -Target $instance -Continue -ErrorRecord $_ diff --git a/tests/Add-DbaAgDatabase.Tests.ps1 b/tests/Add-DbaAgDatabase.Tests.ps1 index 77971674ab..59717a15f6 100644 --- a/tests/Add-DbaAgDatabase.Tests.ps1 +++ b/tests/Add-DbaAgDatabase.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,14 +15,14 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $null = Get-DbaProcess -SqlInstance $script:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue - $server = Connect-DbaInstance -SqlInstance $script:instance3 + $null = Get-DbaProcess -SqlInstance $TestConfig.instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance3 $agname = "dbatoolsci_addagdb_agroup" $dbname = "dbatoolsci_addagdb_agroupdb" $newdbname = "dbatoolsci_addag_agroupdb_2" $server.Query("create database $dbname") - $backup = Get-DbaDatabase -SqlInstance $script:instance3 -Database $dbname | Backup-DbaDatabase - $ag = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Database $dbname -Confirm:$false -Certificate dbatoolsci_AGCert + $backup = Get-DbaDatabase -SqlInstance $TestConfig.instance3 -Database $dbname | Backup-DbaDatabase + $ag = New-DbaAvailabilityGroup -Primary $TestConfig.instance3 -Name $agname -ClusterType None -FailoverMode Manual -Database $dbname -Confirm:$false -Certificate dbatoolsci_AGCert } AfterAll { $null = Remove-DbaAvailabilityGroup -SqlInstance $server -AvailabilityGroup $agname -Confirm:$false @@ -31,11 +31,11 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { Context "adds ag db" { It "returns proper results" { $server.Query("create database $newdbname") - $backup = Get-DbaDatabase -SqlInstance $script:instance3 -Database $newdbname | Backup-DbaDatabase - $results = Add-DbaAgDatabase -SqlInstance $script:instance3 -AvailabilityGroup $agname -Database $newdbname -Confirm:$false + $backup = Get-DbaDatabase -SqlInstance $TestConfig.instance3 -Database $newdbname | Backup-DbaDatabase + $results = Add-DbaAgDatabase -SqlInstance $TestConfig.instance3 -AvailabilityGroup $agname -Database $newdbname -Confirm:$false $results.AvailabilityGroup | Should -Be $agname $results.Name | Should -Be $newdbname $results.IsJoined | Should -Be $true } } -} #$script:instance2 for appveyor \ No newline at end of file +} #$TestConfig.instance2 for appveyor diff --git a/tests/Add-DbaAgListener.Tests.ps1 b/tests/Add-DbaAgListener.Tests.ps1 index 1483f1519c..bb709e865b 100644 --- a/tests/Add-DbaAgListener.Tests.ps1 +++ b/tests/Add-DbaAgListener.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -17,13 +17,13 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { $agname = "dbatoolsci_ag_newlistener" $listenerName = 'dbatoolsci_listener' - $ag = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Confirm:$false -Certificate dbatoolsci_AGCert + $ag = New-DbaAvailabilityGroup -Primary $TestConfig.instance3 -Name $agname -ClusterType None -FailoverMode Manual -Confirm:$false -Certificate dbatoolsci_AGCert } AfterEach { - $null = Remove-DbaAgListener -SqlInstance $script:instance3 -Listener $listenerName -AvailabilityGroup $agname -Confirm:$false + $null = Remove-DbaAgListener -SqlInstance $TestConfig.instance3 -Listener $listenerName -AvailabilityGroup $agname -Confirm:$false } AfterAll { - $null = Remove-DbaAvailabilityGroup -SqlInstance $script:instance3 -AvailabilityGroup $agname -Confirm:$false + $null = Remove-DbaAvailabilityGroup -SqlInstance $TestConfig.instance3 -AvailabilityGroup $agname -Confirm:$false } Context "creates a listener" { It "returns results with proper data" { @@ -31,4 +31,4 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { $results.PortNumber | Should -Be 14330 } } -} #$script:instance2 for appveyor \ No newline at end of file +} #$TestConfig.instance2 for appveyor diff --git a/tests/Add-DbaAgReplica.Tests.ps1 b/tests/Add-DbaAgReplica.Tests.ps1 index 5a8c75c922..085d9329bc 100644 --- a/tests/Add-DbaAgReplica.Tests.ps1 +++ b/tests/Add-DbaAgReplica.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$commandname Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,31 +15,32 @@ Describe "$commandname Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { $agname = "dbatoolsci_agroup" - $ag = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Certificate dbatoolsci_AGCert -Confirm:$false + $ag = New-DbaAvailabilityGroup -Primary $TestConfig.instance3 -Name $agname -ClusterType None -FailoverMode Manual -Certificate dbatoolsci_AGCert -Confirm:$false $replicaName = $ag.PrimaryReplica } AfterAll { - $null = Remove-DbaAvailabilityGroup -SqlInstance $script:instance3 -AvailabilityGroup $agname -Confirm:$false + $null = Remove-DbaAvailabilityGroup -SqlInstance $TestConfig.instance3 -AvailabilityGroup $agname -Confirm:$false } Context "gets ag replicas" { # the only way to test, really, is to call New-DbaAvailabilityGroup which calls Add-DbaAgReplica $agname = "dbatoolsci_add_replicagroup" - $ag = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Certificate dbatoolsci_AGCert -Confirm:$false + $ag = New-DbaAvailabilityGroup -Primary $TestConfig.instance3 -Name $agname -ClusterType None -FailoverMode Manual -Certificate dbatoolsci_AGCert -Confirm:$false $replicaName = $ag.PrimaryReplica It "returns results with proper data" { - $results = Get-DbaAgReplica -SqlInstance $script:instance3 + $results = Get-DbaAgReplica -SqlInstance $TestConfig.instance3 $results.AvailabilityGroup | Should -Contain $agname $results.Role | Should -Contain 'Primary' $results.AvailabilityMode | Should -Contain 'SynchronousCommit' $results.FailoverMode | Should -Contain 'Manual' } It "returns just one result" { - $results = Get-DbaAgReplica -SqlInstance $script:instance3 -Replica $replicaName -AvailabilityGroup $agname + $results = Get-DbaAgReplica -SqlInstance $TestConfig.instance3 -Replica $replicaName -AvailabilityGroup $agname $results.AvailabilityGroup | Should -Be $agname $results.Role | Should -Be 'Primary' $results.AvailabilityMode | Should -Be 'SynchronousCommit' $results.FailoverMode | Should -Be 'Manual' } } -} #$script:instance2 for appveyor +} #$TestConfig.instance2 for appveyor + diff --git a/tests/Add-DbaComputerCertificate.Tests.ps1 b/tests/Add-DbaComputerCertificate.Tests.ps1 index 316f03e0ce..df9646380c 100644 --- a/tests/Add-DbaComputerCertificate.Tests.ps1 +++ b/tests/Add-DbaComputerCertificate.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,7 +15,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Certificate is added properly" { - $results = Add-DbaComputerCertificate -Path $script:appveyorlabrepo\certificates\localhost.crt -Confirm:$false + $results = Add-DbaComputerCertificate -Path "$($TestConfig.appveyorlabrepo)\certificates\localhost.crt" -Confirm:$false It "Should show the proper thumbprint has been added" { $results.Thumbprint | Should Be "29C469578D6C6211076A09CEE5C5797EEA0C2713" @@ -27,4 +27,4 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Remove-DbaComputerCertificate -Thumbprint 29C469578D6C6211076A09CEE5C5797EEA0C2713 -Confirm:$false } -} \ No newline at end of file +} diff --git a/tests/Add-DbaDbMirrorMonitor.Tests.ps1 b/tests/Add-DbaDbMirrorMonitor.Tests.ps1 index f0b2ad6848..3f3ef63d76 100644 --- a/tests/Add-DbaDbMirrorMonitor.Tests.ps1 +++ b/tests/Add-DbaDbMirrorMonitor.Tests.ps1 @@ -1,6 +1,6 @@ $commandname = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Validate parameters" { @@ -15,14 +15,14 @@ Describe "$CommandName Unit Tests" -Tags "UnitTests" { Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $null = Remove-DbaDbMirrorMonitor -SqlInstance $script:instance2 -WarningAction SilentlyContinue + $null = Remove-DbaDbMirrorMonitor -SqlInstance $TestConfig.instance2 -WarningAction SilentlyContinue } AfterAll { - $null = Remove-DbaDbMirrorMonitor -SqlInstance $script:instance2 -WarningAction SilentlyContinue + $null = Remove-DbaDbMirrorMonitor -SqlInstance $TestConfig.instance2 -WarningAction SilentlyContinue } It "adds the mirror monitor" { - $results = Add-DbaDbMirrorMonitor -SqlInstance $script:instance2 -WarningAction SilentlyContinue + $results = Add-DbaDbMirrorMonitor -SqlInstance $TestConfig.instance2 -WarningAction SilentlyContinue $results.MonitorStatus | Should -Be 'Added' } -} \ No newline at end of file +} diff --git a/tests/Add-DbaDbRoleMember.Tests.ps1 b/tests/Add-DbaDbRoleMember.Tests.ps1 index 9799d91aa3..956e9226b0 100644 --- a/tests/Add-DbaDbRoleMember.Tests.ps1 +++ b/tests/Add-DbaDbRoleMember.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Validate parameters" { @@ -15,31 +15,31 @@ Describe "$CommandName Unit Tests" -Tags "UnitTests" { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $user1 = "dbatoolssci_user1_$(Get-Random)" $user2 = "dbatoolssci_user2_$(Get-Random)" $role = "dbatoolssci_role_$(Get-Random)" - $null = New-DbaLogin -SqlInstance $script:instance2 -Login $user1 -Password ('Password1234!' | ConvertTo-SecureString -asPlainText -Force) - $null = New-DbaLogin -SqlInstance $script:instance2 -Login $user2 -Password ('Password1234!' | ConvertTo-SecureString -asPlainText -Force) + $null = New-DbaLogin -SqlInstance $TestConfig.instance2 -Login $user1 -Password ('Password1234!' | ConvertTo-SecureString -asPlainText -Force) + $null = New-DbaLogin -SqlInstance $TestConfig.instance2 -Login $user2 -Password ('Password1234!' | ConvertTo-SecureString -asPlainText -Force) $dbname = "dbatoolsci_$(Get-Random)" - $null = New-DbaDatabase -SqlInstance $script:instance2 -Name $dbname -Owner sa - $null = New-DbaDbUser -SqlInstance $script:instance2 -Database $dbname -Login $user1 -Username $user1 - $null = New-DbaDbUser -SqlInstance $script:instance2 -Database $dbname -Login $user2 -Username $user2 - $null = New-DbaDbUser -SqlInstance $script:instance2 -Database msdb -Login $user1 -Username $user1 -IncludeSystem - $null = New-DbaDbUser -SqlInstance $script:instance2 -Database msdb -Login $user2 -Username $user2 -IncludeSystem + $null = New-DbaDatabase -SqlInstance $TestConfig.instance2 -Name $dbname -Owner sa + $null = New-DbaDbUser -SqlInstance $TestConfig.instance2 -Database $dbname -Login $user1 -Username $user1 + $null = New-DbaDbUser -SqlInstance $TestConfig.instance2 -Database $dbname -Login $user2 -Username $user2 + $null = New-DbaDbUser -SqlInstance $TestConfig.instance2 -Database msdb -Login $user1 -Username $user1 -IncludeSystem + $null = New-DbaDbUser -SqlInstance $TestConfig.instance2 -Database msdb -Login $user2 -Username $user2 -IncludeSystem $null = $server.Query("CREATE ROLE $role", $dbname) } AfterAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $null = $server.Query("DROP USER $user1", 'msdb') $null = $server.Query("DROP USER $user2", 'msdb') - $null = Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbname -confirm:$false - $null = Remove-DbaLogin -SqlInstance $script:instance2 -Login $user1, $user2 -confirm:$false + $null = Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname -confirm:$false + $null = Remove-DbaLogin -SqlInstance $TestConfig.instance2 -Login $user1, $user2 -confirm:$false } Context "Functionality" { It 'Adds User to Role' { - Add-DbaDbRoleMember -SqlInstance $script:instance2 -Role $role -Member $user1 -Database $dbname -confirm:$false + Add-DbaDbRoleMember -SqlInstance $TestConfig.instance2 -Role $role -Member $user1 -Database $dbname -confirm:$false $roleDBAfter = Get-DbaDbRoleMember -SqlInstance $server -Database $dbname -Role $role $roleDBAfter.Role | Should Be $role @@ -49,7 +49,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { It 'Adds User to Multiple Roles' { $roleDB = Get-DbaDbRoleMember -SqlInstance $server -Database msdb -Role db_datareader, SQLAgentReaderRole - Add-DbaDbRoleMember -SqlInstance $script:instance2 -Role db_datareader, SQLAgentReaderRole -Member $user1 -Database msdb -confirm:$false + Add-DbaDbRoleMember -SqlInstance $TestConfig.instance2 -Role db_datareader, SQLAgentReaderRole -Member $user1 -Database msdb -confirm:$false $roleDBAfter = Get-DbaDbRoleMember -SqlInstance $server -Database msdb -Role db_datareader, SQLAgentReaderRole $roleDBAfter.Count | Should BeGreaterThan $roleDB.Count @@ -69,17 +69,18 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } It 'Skip adding user to role if already a member' { - $messages = Add-DbaDbRoleMember -SqlInstance $script:instance2 -Role $role -Member $user1 -Database $dbname -confirm:$false -Verbose 4>&1 + $messages = Add-DbaDbRoleMember -SqlInstance $TestConfig.instance2 -Role $role -Member $user1 -Database $dbname -confirm:$false -Verbose 4>&1 $messageCount = ($messages -match 'Adding user').Count $messageCount | Should Be 0 } It 'Adds Role to Role' { - Add-DbaDbRoleMember -SqlInstance $script:instance2 -Role db_datawriter -Member $role -Database $dbname -confirm:$false + Add-DbaDbRoleMember -SqlInstance $TestConfig.instance2 -Role db_datawriter -Member $role -Database $dbname -confirm:$false $roleDBAfter = Get-DbaDbRoleMember -SqlInstance $server -Database $dbname -Role db_datawriter $roleDBAfter.MemberRole | Should Contain $role } } } + diff --git a/tests/Add-DbaExtendedProperty.Tests.ps1 b/tests/Add-DbaExtendedProperty.Tests.ps1 index 251328389c..ba4339484b 100644 --- a/tests/Add-DbaExtendedProperty.Tests.ps1 +++ b/tests/Add-DbaExtendedProperty.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,7 +16,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BeforeAll { $random = Get-Random - $server2 = Connect-DbaInstance -SqlInstance $script:instance2 + $server2 = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $null = Get-DbaProcess -SqlInstance $server2 | Where-Object Program -match dbatools | Stop-DbaProcess -Confirm:$false $newDbName = "dbatoolsci_newdb_$random" $db = New-DbaDatabase -SqlInstance $server2 -Name $newDbName @@ -34,4 +34,4 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $ep.Value | Should -Be "Sup" } } -} \ No newline at end of file +} diff --git a/tests/Add-DbaPfDataCollectorCounter.Tests.ps1 b/tests/Add-DbaPfDataCollectorCounter.Tests.ps1 index 69212aa44e..3d7b0a2213 100644 --- a/tests/Add-DbaPfDataCollectorCounter.Tests.ps1 +++ b/tests/Add-DbaPfDataCollectorCounter.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Add-DbaRegServer.Tests.ps1 b/tests/Add-DbaRegServer.Tests.ps1 index 367fc9149d..76bacdcd5b 100644 --- a/tests/Add-DbaRegServer.Tests.ps1 +++ b/tests/Add-DbaRegServer.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Validate parameters" { @@ -20,25 +20,25 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $group = "dbatoolsci-group1" $regSrvName = "dbatoolsci-server12" $regSrvDesc = "dbatoolsci-server123" - $groupobject = Add-DbaRegServerGroup -SqlInstance $script:instance1 -Name $group + $groupobject = Add-DbaRegServerGroup -SqlInstance $TestConfig.instance1 -Name $group } AfterAll { - Get-DbaRegServer -SqlInstance $script:instance1, $script:instance2 | Where-Object Name -match dbatoolsci | Remove-DbaRegServer -Confirm:$false - Get-DbaRegServerGroup -SqlInstance $script:instance1, $script:instance2 | Where-Object Name -match dbatoolsci | Remove-DbaRegServerGroup -Confirm:$false + Get-DbaRegServer -SqlInstance $TestConfig.instance1, $TestConfig.instance2 | Where-Object Name -match dbatoolsci | Remove-DbaRegServer -Confirm:$false + Get-DbaRegServerGroup -SqlInstance $TestConfig.instance1, $TestConfig.instance2 | Where-Object Name -match dbatoolsci | Remove-DbaRegServerGroup -Confirm:$false } It "adds a registered server" { - $results1 = Add-DbaRegServer -SqlInstance $script:instance1 -ServerName $srvName + $results1 = Add-DbaRegServer -SqlInstance $TestConfig.instance1 -ServerName $srvName $results1.Name | Should -Be $srvName $results1.ServerName | Should -Be $srvName $results1.SqlInstance | Should -Not -Be $null } It "adds a registered server with extended properties" { - $results2 = Add-DbaRegServer -SqlInstance $script:instance1 -ServerName $RegsrvName -Name $srvName -Group $groupobject -Description $regSrvDesc + $results2 = Add-DbaRegServer -SqlInstance $TestConfig.instance1 -ServerName $RegsrvName -Name $srvName -Group $groupobject -Description $regSrvDesc $results2.ServerName | Should -Be $regSrvName $results2.Description | Should -Be $regSrvDesc $results2.Name | Should -Be $srvName $results2.SqlInstance | Should -Not -Be $null } } -} \ No newline at end of file +} diff --git a/tests/Add-DbaRegServerGroup.Tests.ps1 b/tests/Add-DbaRegServerGroup.Tests.ps1 index c28d01ef27..14df3ef2b0 100644 --- a/tests/Add-DbaRegServerGroup.Tests.ps1 +++ b/tests/Add-DbaRegServerGroup.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Validate parameters" { @@ -22,34 +22,34 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $descriptionUpdated = "group description updated" } AfterAll { - Get-DbaRegServerGroup -SqlInstance $script:instance1 | Where-Object Name -match dbatoolsci | Remove-DbaRegServerGroup -Confirm:$false + Get-DbaRegServerGroup -SqlInstance $TestConfig.instance1 | Where-Object Name -match dbatoolsci | Remove-DbaRegServerGroup -Confirm:$false } It "adds a registered server group" { - $results = Add-DbaRegServerGroup -SqlInstance $script:instance1 -Name $group + $results = Add-DbaRegServerGroup -SqlInstance $TestConfig.instance1 -Name $group $results.Name | Should -Be $group $results.SqlInstance | Should -Not -Be $null } It "adds a registered server group with extended properties" { - $results = Add-DbaRegServerGroup -SqlInstance $script:instance1 -Name $group2 -Description $description + $results = Add-DbaRegServerGroup -SqlInstance $TestConfig.instance1 -Name $group2 -Description $description $results.Name | Should -Be $group2 $results.Description | Should -Be $description $results.SqlInstance | Should -Not -Be $null } It "supports hella pipe" { - $results = Get-DbaRegServerGroup -SqlInstance $script:instance1 -Id 1 | Add-DbaRegServerGroup -Name dbatoolsci-first | Add-DbaRegServerGroup -Name dbatoolsci-second | Add-DbaRegServerGroup -Name dbatoolsci-third | Add-DbaRegServer -ServerName dbatoolsci-test -Description ridiculous + $results = Get-DbaRegServerGroup -SqlInstance $TestConfig.instance1 -Id 1 | Add-DbaRegServerGroup -Name dbatoolsci-first | Add-DbaRegServerGroup -Name dbatoolsci-second | Add-DbaRegServerGroup -Name dbatoolsci-third | Add-DbaRegServer -ServerName dbatoolsci-test -Description ridiculous $results.Group | Should -Be 'dbatoolsci-first\dbatoolsci-second\dbatoolsci-third' } It "adds a registered server group and sub-group when not exists" { - $results = Add-DbaRegServerGroup -SqlInstance $script:instance1 -Name "$group\$group2" -Description $description + $results = Add-DbaRegServerGroup -SqlInstance $TestConfig.instance1 -Name "$group\$group2" -Description $description $results.Name | Should -Be $group2 $results.SqlInstance | Should -Not -Be $null } It "updates description of sub-group when it already exists" { - $results = Add-DbaRegServerGroup -SqlInstance $script:instance1 -Name "$group\$group2" -Description $descriptionUpdated + $results = Add-DbaRegServerGroup -SqlInstance $TestConfig.instance1 -Name "$group\$group2" -Description $descriptionUpdated $results.Name | Should -Be $group2 $results.Description | Should -Be $descriptionUpdated $results.SqlInstance | Should -Not -Be $null } } -} \ No newline at end of file +} diff --git a/tests/Add-DbaReplArticle.Tests.ps1 b/tests/Add-DbaReplArticle.Tests.ps1 index 78d16d32ff..aed3185e0f 100644 --- a/tests/Add-DbaReplArticle.Tests.ps1 +++ b/tests/Add-DbaReplArticle.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Add-DbaServerRoleMember.Tests.ps1 b/tests/Add-DbaServerRoleMember.Tests.ps1 index 4c0cb0e748..aac1596439 100644 --- a/tests/Add-DbaServerRoleMember.Tests.ps1 +++ b/tests/Add-DbaServerRoleMember.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Validate parameters" { @@ -15,23 +15,23 @@ Describe "$CommandName Unit Tests" -Tags "UnitTests" { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $login1 = "dbatoolsci_login1_$(Get-Random)" $login2 = "dbatoolsci_login2_$(Get-Random)" $customServerRole = "dbatoolsci_customrole_$(Get-Random)" $fixedServerRoles = 'dbcreator','processadmin' - $null = New-DbaLogin -SqlInstance $script:instance2 -Login $login1 -Password ('Password1234!' | ConvertTo-SecureString -asPlainText -Force) - $null = New-DbaLogin -SqlInstance $script:instance2 -Login $login2 -Password ('Password1234!' | ConvertTo-SecureString -asPlainText -Force) - $null = New-DbaServerRole -SqlInstance $script:instance2 -ServerRole $customServerRole -Owner sa + $null = New-DbaLogin -SqlInstance $TestConfig.instance2 -Login $login1 -Password ('Password1234!' | ConvertTo-SecureString -asPlainText -Force) + $null = New-DbaLogin -SqlInstance $TestConfig.instance2 -Login $login2 -Password ('Password1234!' | ConvertTo-SecureString -asPlainText -Force) + $null = New-DbaServerRole -SqlInstance $TestConfig.instance2 -ServerRole $customServerRole -Owner sa } AfterAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 - $null = Remove-DbaLogin -SqlInstance $script:instance2 -Login $login1, $login2 -Confirm:$false + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 + $null = Remove-DbaLogin -SqlInstance $TestConfig.instance2 -Login $login1, $login2 -Confirm:$false } Context "Functionality" { It 'Adds Login to Role' { - Add-DbaServerRoleMember -SqlInstance $script:instance2 -ServerRole $fixedServerRoles[0] -Login $login1 -Confirm:$false + Add-DbaServerRoleMember -SqlInstance $TestConfig.instance2 -ServerRole $fixedServerRoles[0] -Login $login1 -Confirm:$false $roleAfter = Get-DbaServerRole -SqlInstance $server -ServerRole $fixedServerRoles[0] $roleAfter.Role | Should -Be $fixedServerRoles[0] @@ -40,7 +40,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { It 'Adds Login to Multiple Roles' { $serverRoles = Get-DbaServerRole -SqlInstance $server -ServerRole $fixedServerRoles - Add-DbaServerRoleMember -SqlInstance $script:instance2 -ServerRole $serverRoles -Login $login1 -Confirm:$false + Add-DbaServerRoleMember -SqlInstance $TestConfig.instance2 -ServerRole $serverRoles -Login $login1 -Confirm:$false $roleDBAfter = Get-DbaServerRole -SqlInstance $server -ServerRole $fixedServerRoles $roleDBAfter.Count | Should -Be $serverRoles.Count @@ -49,7 +49,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } It 'Adds Customer Server-Level Role Membership' { - Add-DbaServerRoleMember -SqlInstance $script:instance2 -ServerRole $customServerRole -Role $fixedServerRoles[-1] -Confirm:$false + Add-DbaServerRoleMember -SqlInstance $TestConfig.instance2 -ServerRole $customServerRole -Role $fixedServerRoles[-1] -Confirm:$false $roleAfter = Get-DbaServerRole -SqlInstance $server -ServerRole $fixedServerRoles[-1] $roleAfter.Role | Should -Be $fixedServerRoles[-1] @@ -64,4 +64,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $roleAfter.EnumMemberNames().Contains($login2) | Should -Be $true } } -} \ No newline at end of file +} diff --git a/tests/Backup-DbaComputerCertificate.Tests.ps1 b/tests/Backup-DbaComputerCertificate.Tests.ps1 index 365c7c10b1..a1064dccfe 100644 --- a/tests/Backup-DbaComputerCertificate.Tests.ps1 +++ b/tests/Backup-DbaComputerCertificate.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,11 +15,11 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Certificate is added properly" { - $null = Add-DbaComputerCertificate -Path $script:appveyorlabrepo\certificates\localhost.crt -Confirm:$false + $null = Add-DbaComputerCertificate -Path "$($TestConfig.appveyorlabrepo)\certificates\localhost.crt" -Confirm:$false It "returns the proper results" { $result = Get-DbaComputerCertificate -Thumbprint 29C469578D6C6211076A09CEE5C5797EEA0C2713 | Backup-DbaComputerCertificate -Path C:\temp $result.Name -match '29C469578D6C6211076A09CEE5C5797EEA0C2713.cer' } $null = Remove-DbaComputerCertificate -Thumbprint 29C469578D6C6211076A09CEE5C5797EEA0C2713 -Confirm:$false } -} \ No newline at end of file +} diff --git a/tests/Backup-DbaDatabase.Tests.ps1 b/tests/Backup-DbaDatabase.Tests.ps1 index 997f4cf0fc..1ffcfdf525 100644 --- a/tests/Backup-DbaDatabase.Tests.ps1 +++ b/tests/Backup-DbaDatabase.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,7 +16,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Properly restores a database on the local drive using Path" { - $results = Backup-DbaDatabase -SqlInstance $script:instance1 -BackupDirectory C:\temp\backups + $results = Backup-DbaDatabase -SqlInstance $TestConfig.instance1 -BackupDirectory C:\temp\backups It "Should return a database name, specifically master" { ($results.DatabaseName -contains 'master') | Should -Be $true } @@ -32,25 +32,25 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { if (-Not(Test-Path $DestBackupDir)) { New-Item -Type Container -Path $DestBackupDir } - Get-DbaDatabase -SqlInstance $script:instance1 -Database "dbatoolsci_singlerestore" | Remove-DbaDatabase -Confirm:$false - Get-DbaDatabase -SqlInstance $script:instance2 -Database $DestDbRandom | Remove-DbaDatabase -Confirm:$false + Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database "dbatoolsci_singlerestore" | Remove-DbaDatabase -Confirm:$false + Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $DestDbRandom | Remove-DbaDatabase -Confirm:$false } AfterAll { - Get-DbaDatabase -SqlInstance $script:instance1 -Database "dbatoolsci_singlerestore" | Remove-DbaDatabase -Confirm:$false - Get-DbaDatabase -SqlInstance $script:instance2 -Database $DestDbRandom | Remove-DbaDatabase -Confirm:$false + Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database "dbatoolsci_singlerestore" | Remove-DbaDatabase -Confirm:$false + Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $DestDbRandom | Remove-DbaDatabase -Confirm:$false if (Test-Path $DestBackupDir) { Remove-Item "$DestBackupDir\*" -Force -Recurse } } Context "Should not backup if database and exclude match" { - $results = Backup-DbaDatabase -SqlInstance $script:instance1 -BackupDirectory $DestBackupDir -Database master -Exclude master + $results = Backup-DbaDatabase -SqlInstance $TestConfig.instance1 -BackupDirectory $DestBackupDir -Database master -Exclude master It "Should not return object" { $results | Should -Be $null } } Context "No database found to backup should raise warning and null output" { - $results = Backup-DbaDatabase -SqlInstance $script:instance1 -BackupDirectory $DestBackupDir -Database AliceDoesntDBHereAnyMore -WarningVariable warnvar 3> $null + $results = Backup-DbaDatabase -SqlInstance $TestConfig.instance1 -BackupDirectory $DestBackupDir -Database AliceDoesntDBHereAnyMore -WarningVariable warnvar 3> $null It "Should not return object" { $results | Should -Be $null } @@ -60,18 +60,18 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } Context "Database should backup 1 database" { - $results = Backup-DbaDatabase -SqlInstance $script:instance1 -BackupDirectory $DestBackupDir -Database master + $results = Backup-DbaDatabase -SqlInstance $TestConfig.instance1 -BackupDirectory $DestBackupDir -Database master It "Database backup object count Should Be 1" { $results.DatabaseName.Count | Should -Be 1 $results.BackupComplete | Should -Be $true } It "Database ID should be returned" { - $results.DatabaseID | Should -Be (Get-DbaDatabase -SqlInstance $script:instance1 -Database master).ID + $results.DatabaseID | Should -Be (Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database master).ID } } Context "Database should backup 2 databases" { - $results = Backup-DbaDatabase -SqlInstance $script:instance1 -BackupDirectory $DestBackupDir -Database master, msdb + $results = Backup-DbaDatabase -SqlInstance $TestConfig.instance1 -BackupDirectory $DestBackupDir -Database master, msdb It "Database backup object count Should Be 2" { $results.DatabaseName.Count | Should -Be 2 $results.BackupComplete | Should -Be @($true, $true) @@ -79,7 +79,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } Context "Should take path and filename" { - $results = Backup-DbaDatabase -SqlInstance $script:instance1 -BackupDirectory $DestBackupDir -Database master -BackupFileName 'PesterTest.bak' + $results = Backup-DbaDatabase -SqlInstance $TestConfig.instance1 -BackupDirectory $DestBackupDir -Database master -BackupFileName 'PesterTest.bak' It "Should report it has backed up to the path with the correct name" { $results.Fullname | Should -BeLike "$DestBackupDir*PesterTest.bak" } @@ -89,7 +89,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } Context "Database parameter works when using pipes (fixes #5044)" { - $results = Get-DbaDatabase -SqlInstance $script:instance1 | Backup-DbaDatabase -Database master -BackupFileName PesterTest.bak -BackupDirectory $DestBackupDir + $results = Get-DbaDatabase -SqlInstance $TestConfig.instance1 | Backup-DbaDatabase -Database master -BackupFileName PesterTest.bak -BackupDirectory $DestBackupDir It "Should report it has backed up to the path with the correct name" { $results.Fullname | Should -BeLike "$DestBackupDir*PesterTest.bak" } @@ -99,7 +99,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } Context "ExcludeDatabase parameter works when using pipes (fixes #5044)" { - $results = Get-DbaDatabase -SqlInstance $script:instance1 | Backup-DbaDatabase -ExcludeDatabase master, tempdb, msdb, model + $results = Get-DbaDatabase -SqlInstance $TestConfig.instance1 | Backup-DbaDatabase -ExcludeDatabase master, tempdb, msdb, model It "Should report it has backed up to the path with the correct name" { $results.DatabaseName | Should -Not -Contain master $results.DatabaseName | Should -Not -Contain tempdb @@ -111,12 +111,12 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Handling backup paths that don't exist" { $MissingPathTrailing = "$DestBackupDir\Missing1\Awol2\" $MissingPath = "$DestBackupDir\Missing1\Awol2" - $null = Backup-DbaDatabase -SqlInstance $script:instance1 -Database master -BackupDirectory $MissingPath -WarningVariable warnvar *>$null + $null = Backup-DbaDatabase -SqlInstance $TestConfig.instance1 -Database master -BackupDirectory $MissingPath -WarningVariable warnvar *>$null It "Should warn and fail if path doesn't exist and BuildPath not set" { $warnvar | Should -BeLike "*$MissingPath*" } # $MissingPathTrailing has a trailing slash but we normalize the path before doing the actual backup - $results = Backup-DbaDatabase -SqlInstance $script:instance1 -Database master -BackupDirectory $MissingPathTrailing -BuildPath + $results = Backup-DbaDatabase -SqlInstance $TestConfig.instance1 -Database master -BackupDirectory $MissingPathTrailing -BuildPath It "Should have backed up to $MissingPath" { $results.BackupFolder | Should -Be "$MissingPath" $results.Path | Should -Not -BeLike '*\\*' @@ -124,7 +124,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } Context "CreateFolder switch should append the databasename to the backup path" { - $results = Backup-DbaDatabase -SqlInstance $script:instance1 -Database master -BackupDirectory $DestBackupDir -CreateFolder + $results = Backup-DbaDatabase -SqlInstance $TestConfig.instance1 -Database master -BackupDirectory $DestBackupDir -CreateFolder It "Should have appended master to the backup path" { $results.BackupFolder | Should -Be "$DestBackupDir\master" } @@ -132,7 +132,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "CreateFolder switch should append the databasename to the backup path even when striping" { $backupPaths = "$DestBackupDir\stripewithdb1", "$DestBackupDir\stripewithdb2" - $results = Backup-DbaDatabase -SqlInstance $script:instance1 -Database master -BackupDirectory $backupPaths -CreateFolder + $results = Backup-DbaDatabase -SqlInstance $TestConfig.instance1 -Database master -BackupDirectory $backupPaths -CreateFolder It "Should have appended master to all backup paths" { foreach ($path in $results.BackupFolder) { ($results.BackupFolder | Sort-Object) | Should -Be ($backupPaths | Sort-Object | ForEach-Object { [IO.Path]::Combine($_, 'master') }) @@ -142,7 +142,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "A fully qualified path should override a backupfolder" { - $results = Backup-DbaDatabase -SqlInstance $script:instance1 -Database master -BackupDirectory c:\temp -BackupFileName "$DestBackupDir\PesterTest2.bak" + $results = Backup-DbaDatabase -SqlInstance $TestConfig.instance1 -Database master -BackupDirectory c:\temp -BackupFileName "$DestBackupDir\PesterTest2.bak" It "Should report backed up to $DestBackupDir" { $results.FullName | Should -BeLike "$DestBackupDir\PesterTest2.bak" $results.BackupFolder | Should Not Be 'c:\temp' @@ -157,7 +157,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $null = New-Item -Path $backupPaths -ItemType Directory - $results = Backup-DbaDatabase -SqlInstance $script:instance1 -Database master -BackupDirectory $backupPaths + $results = Backup-DbaDatabase -SqlInstance $TestConfig.instance1 -Database master -BackupDirectory $backupPaths It "Should have created 3 backups" { $results.BackupFilesCount | Should -Be 3 } @@ -172,14 +172,14 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } # Assure that striping logic favours -BackupDirectory and not -Filecount - $results = Backup-DbaDatabase -SqlInstance $script:instance1 -Database master -BackupDirectory $backupPaths -FileCount 2 + $results = Backup-DbaDatabase -SqlInstance $TestConfig.instance1 -Database master -BackupDirectory $backupPaths -FileCount 2 It "Should have created 3 backups, even when FileCount is different" { $results.BackupFilesCount | Should -Be 3 } } Context "Should stripe on filecount > 1" { - $results = Backup-DbaDatabase -SqlInstance $script:instance1 -Database master -BackupDirectory $DestBackupDir -FileCount 3 + $results = Backup-DbaDatabase -SqlInstance $TestConfig.instance1 -Database master -BackupDirectory $DestBackupDir -FileCount 3 It "Should have created 3 backups" { $results.BackupFilesCount | Should -Be 3 } @@ -195,7 +195,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Should prefix the filenames when IncrementPrefix set" { $fileCount = 3 - $results = Backup-DbaDatabase -SqlInstance $script:instance1 -Database master -BackupDirectory $DestBackupDir -FileCount $fileCount -IncrementPrefix + $results = Backup-DbaDatabase -SqlInstance $TestConfig.instance1 -Database master -BackupDirectory $DestBackupDir -FileCount $fileCount -IncrementPrefix It "Should have created 3 backups" { $results.BackupFilesCount | Should -Be 3 } @@ -207,8 +207,8 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } Context "Should Backup to default path if none specified" { - $results = Backup-DbaDatabase -SqlInstance $script:instance1 -Database master -BackupFileName 'PesterTest.bak' - $DefaultPath = (Get-DbaDefaultPath -SqlInstance $script:instance1).Backup + $results = Backup-DbaDatabase -SqlInstance $TestConfig.instance1 -Database master -BackupFileName 'PesterTest.bak' + $DefaultPath = (Get-DbaDefaultPath -SqlInstance $TestConfig.instance1).Backup It "Should report it has backed up to the path with the corrrect name" { $results.Fullname | Should -BeLike "$DefaultPath*PesterTest.bak" } @@ -219,33 +219,33 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Test backup verification" { It "Should perform a full backup and verify it" { - $b = Backup-DbaDatabase -SqlInstance $script:instance1 -Database master -Type full -Verify + $b = Backup-DbaDatabase -SqlInstance $TestConfig.instance1 -Database master -Type full -Verify $b.BackupComplete | Should -Be $True $b.Verified | Should -Be $True $b.count | Should -Be 1 } It -Skip "Should perform a diff backup and verify it" { - $b = Backup-DbaDatabase -SqlInstance $script:instance1 -Database backuptest -Type diff -Verify + $b = Backup-DbaDatabase -SqlInstance $TestConfig.instance1 -Database backuptest -Type diff -Verify $b.BackupComplete | Should -Be $True $b.Verified | Should -Be $True } It -Skip "Should perform a log backup and verify it" { - $b = Backup-DbaDatabase -SqlInstance $script:instance1 -Database backuptest -Type log -Verify + $b = Backup-DbaDatabase -SqlInstance $TestConfig.instance1 -Database backuptest -Type log -Verify $b.BackupComplete | Should -Be $True $b.Verified | Should -Be $True } } Context "Backup can pipe to restore" { - $null = Restore-DbaDatabase -SqlInstance $script:instance1 -Path $script:appveyorlabrepo\singlerestore\singlerestore.bak -DatabaseName "dbatoolsci_singlerestore" - $results = Backup-DbaDatabase -SqlInstance $script:instance1 -BackupDirectory $DestBackupDir -Database "dbatoolsci_singlerestore" | Restore-DbaDatabase -SqlInstance $script:instance2 -DatabaseName $DestDbRandom -TrustDbBackupHistory -ReplaceDbNameInFile + $null = Restore-DbaDatabase -SqlInstance $TestConfig.instance1 -Path "$($TestConfig.appveyorlabrepo)\singlerestore\singlerestore.bak" -DatabaseName "dbatoolsci_singlerestore" + $results = Backup-DbaDatabase -SqlInstance $TestConfig.instance1 -BackupDirectory $DestBackupDir -Database "dbatoolsci_singlerestore" | Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -DatabaseName $DestDbRandom -TrustDbBackupHistory -ReplaceDbNameInFile It "Should return successful restore" { $results.RestoreComplete | Should -Be $true } } Context "Test Backup-DbaDatabase can take pipe input" { - $results = Get-DbaDatabase -SqlInstance $script:instance1 -Database master | Backup-DbaDatabase -confirm:$false -WarningVariable warnvar 3> $null + $results = Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database master | Backup-DbaDatabase -confirm:$false -WarningVariable warnvar 3> $null It "Should not warn" { $warnvar | Should -BeNullOrEmpty } @@ -256,7 +256,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } Context "Should handle NUL as an input path" { - $results = Backup-DbaDatabase -SqlInstance $script:instance1 -Database master -BackupFileName NUL + $results = Backup-DbaDatabase -SqlInstance $TestConfig.instance1 -Database master -BackupFileName NUL It "Should return succesful backup" { $results.BackupComplete | Should -Be $true } @@ -266,7 +266,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } Context "Should only output a T-SQL String if OutputScriptOnly specified" { - $results = Backup-DbaDatabase -SqlInstance $script:instance1 -Database master -BackupFileName c:\notexists\file.bak -OutputScriptOnly + $results = Backup-DbaDatabase -SqlInstance $TestConfig.instance1 -Database master -BackupFileName c:\notexists\file.bak -OutputScriptOnly It "Should return a string" { $results.GetType().ToString() | Should -Be 'System.String' } @@ -285,7 +285,7 @@ go CREATE DATABASE encrypted go "@ - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Query $sqlencrypt -Database Master + $null = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Query $sqlencrypt -Database Master $createdb = @" CREATE DATABASE ENCRYPTION KEY @@ -296,12 +296,13 @@ ALTER DATABASE encrypted SET ENCRYPTION ON; GO "@ - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Query $createdb -Database encrypted + $null = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Query $createdb -Database encrypted It "Should compress an encrypted db" { - $results = Backup-DbaDatabase -SqlInstance $script:instance2 -Database encrypted -Compress + $results = Backup-DbaDatabase -SqlInstance $TestConfig.instance2 -Database encrypted -Compress + Invoke-Command2 -ComputerName $TestConfig.instance2 -ScriptBlock { Remove-Item -Path $args[0] } -ArgumentList $results.FullName $results.script | Should -BeLike '*D, COMPRESSION,*' } - Remove-DbaDatabase -SqlInstance $script:instance2 -Database encrypted -confirm:$false + Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database encrypted -confirm:$false $sqldrop = @" drop certificate MyServerCert @@ -309,91 +310,92 @@ go drop master key go "@ - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Query $sqldrop -Database Master + $null = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Query $sqldrop -Database Master } Context "Custom TimeStamp" { # Test relies on DateFormat bobob returning bobob as the values aren't interpreted, check here in case .Net rules change - $results = Backup-DbaDatabase -SqlInstance $script:instance1 -Database master -BackupDirectory $DestBackupDir -TimeStampFormat bobob + $results = Backup-DbaDatabase -SqlInstance $TestConfig.instance1 -Database master -BackupDirectory $DestBackupDir -TimeStampFormat bobob It "Should apply the corect custom Timestamp" { ($results | Where-Object { $_.BackupPath -like '*bobob*' }).count | Should -Be $results.count } } Context "Test Backup templating" { - $results = Backup-DbaDatabase -SqlInstance $script:instance1 -Database master, msdb -BackupDirectory $DestBackupDir\dbname\instancename\backuptype\ -BackupFileName dbname-backuptype.bak -ReplaceInName -BuildPath + $results = Backup-DbaDatabase -SqlInstance $TestConfig.instance1 -Database master, msdb -BackupDirectory $DestBackupDir\dbname\instancename\backuptype\ -BackupFileName dbname-backuptype.bak -ReplaceInName -BuildPath It "Should have replaced the markers" { - $results[0].BackupPath | Should -BeLike "$DestBackupDir\master\$(($script:instance1).split('\')[1])\Full\master-Full.bak" - $results[1].BackupPath | Should -BeLike "$DestBackupDir\msdb\$(($script:instance1).split('\')[1])\Full\msdb-Full.bak" + $results[0].BackupPath | Should -BeLike "$DestBackupDir\master\$(($TestConfig.instance1).split('\')[1])\Full\master-Full.bak" + $results[1].BackupPath | Should -BeLike "$DestBackupDir\msdb\$(($TestConfig.instance1).split('\')[1])\Full\msdb-Full.bak" } } Context "Test Backup templating when db object piped in issue 8100" { - $results = Get-DbaDatabase -SqlInstance $script:instance1 -Database master,msdb | Backup-DbaDatabase -BackupDirectory $DestBackupDir\db2\dbname\instancename\backuptype\ -BackupFileName dbname-backuptype.bak -ReplaceInName -BuildPath + $results = Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database master,msdb | Backup-DbaDatabase -BackupDirectory $DestBackupDir\db2\dbname\instancename\backuptype\ -BackupFileName dbname-backuptype.bak -ReplaceInName -BuildPath It "Should have replaced the markers" { - $results[0].BackupPath | Should -BeLike "$DestBackupDir\db2\master\$(($script:instance1).split('\')[1])\Full\master-Full.bak" - $results[1].BackupPath | Should -BeLike "$DestBackupDir\db2\msdb\$(($script:instance1).split('\')[1])\Full\msdb-Full.bak" + $results[0].BackupPath | Should -BeLike "$DestBackupDir\db2\master\$(($TestConfig.instance1).split('\')[1])\Full\master-Full.bak" + $results[1].BackupPath | Should -BeLike "$DestBackupDir\db2\msdb\$(($TestConfig.instance1).split('\')[1])\Full\msdb-Full.bak" } } Context "Test Backup Encryption with Certificate" { $securePass = ConvertTo-SecureString "estBackupDir\master\script:instance1).split('\')[1])\Full\master-Full.bak" -AsPlainText -Force - New-DbaDbMasterKey -SqlInstance $script:instance2 -Database Master -SecurePassword $securePass -confirm:$false -ErrorAction SilentlyContinue - $cert = New-DbaDbCertificate -SqlInstance $script:instance2 -Database master -Name BackupCertt -Subject BackupCertt - $encBackupResults = Backup-DbaDatabase -SqlInstance $script:instance2 -Database master -EncryptionAlgorithm AES128 -EncryptionCertificate BackupCertt -BackupFileName 'encryptiontest.bak' -Description "Encrypted backup" + New-DbaDbMasterKey -SqlInstance $TestConfig.instance2 -Database Master -SecurePassword $securePass -confirm:$false -ErrorAction SilentlyContinue + $cert = New-DbaDbCertificate -SqlInstance $TestConfig.instance2 -Database master -Name BackupCertt -Subject BackupCertt + $encBackupResults = Backup-DbaDatabase -SqlInstance $TestConfig.instance2 -Database master -EncryptionAlgorithm AES128 -EncryptionCertificate BackupCertt -BackupFileName 'encryptiontest.bak' -Description "Encrypted backup" + Invoke-Command2 -ComputerName $TestConfig.instance2 -ScriptBlock { Remove-Item -Path $args[0] } -ArgumentList $encBackupResults.FullName It "Should encrypt the backup" { $encBackupResults.EncryptorType | Should Be "CERTIFICATE" $encBackupResults.KeyAlgorithm | Should Be "aes_128" } - Remove-DbaDbCertificate -SqlInstance $script:instance2 -Database master -Certificate BackupCertt -Confirm:$false - Remove-DbaDbMasterKey -SqlInstance $script:instance2 -Database Master -confirm:$false + Remove-DbaDbCertificate -SqlInstance $TestConfig.instance2 -Database master -Certificate BackupCertt -Confirm:$false + Remove-DbaDbMasterKey -SqlInstance $TestConfig.instance2 -Database Master -confirm:$false } # Context "Test Backup Encryption with Asymmetric Key" { - # $key = New-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Database master -Name BackupKey - # $encBackupResults = Backup-DbaDatabase -SqlInstance $script:instance2 -Database master -EncryptionAlgorithm AES128 -EncryptionKey BackupKey + # $key = New-DbaDbAsymmetricKey -SqlInstance $TestConfig.instance2 -Database master -Name BackupKey + # $encBackupResults = Backup-DbaDatabase -SqlInstance $TestConfig.instance2 -Database master -EncryptionAlgorithm AES128 -EncryptionKey BackupKey # It "Should encrypt the backup" { # $encBackupResults.EncryptorType | Should Be "CERTIFICATE" # $encBackupResults.KeyAlgorithm | Should Be "aes_128" # } - # remove-DbaDbCertificate -SqlInstance $script:instance2 -Database master -Certificate BackupCertt -Confirm:$false + # remove-DbaDbCertificate -SqlInstance $TestConfig.instance2 -Database master -Certificate BackupCertt -Confirm:$false # } if ($env:azurepasswd) { Context "Azure works" { BeforeAll { - Get-DbaDatabase -SqlInstance $script:instance2 -Database "dbatoolsci_azure" | Remove-DbaDatabase -Confirm:$false - $server = Connect-DbaInstance -SqlInstance $script:instance2 - if (Get-DbaCredential -SqlInstance $script:instance2 -Name "[$script:azureblob]" ) { - $sql = "DROP CREDENTIAL [$script:azureblob]" + Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database "dbatoolsci_azure" | Remove-DbaDatabase -Confirm:$false + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 + if (Get-DbaCredential -SqlInstance $TestConfig.instance2 -Name "[$TestConfig.azureblob]" ) { + $sql = "DROP CREDENTIAL [$TestConfig.azureblob]" $server.Query($sql) } - $sql = "CREATE CREDENTIAL [$script:azureblob] WITH IDENTITY = N'SHARED ACCESS SIGNATURE', SECRET = N'$env:azurepasswd'" + $sql = "CREATE CREDENTIAL [$TestConfig.azureblob] WITH IDENTITY = N'SHARED ACCESS SIGNATURE', SECRET = N'$env:azurepasswd'" $server.Query($sql) $server.Query("CREATE DATABASE dbatoolsci_azure") - if (Get-DbaCredential -SqlInstance $script:instance2 -name dbatools_ci) { + if (Get-DbaCredential -SqlInstance $TestConfig.instance2 -name dbatools_ci) { $sql = "DROP CREDENTIAL dbatools_ci" $server.Query($sql) } - $sql = "CREATE CREDENTIAL [dbatools_ci] WITH IDENTITY = N'$script:azureblobaccount', SECRET = N'$env:azurelegacypasswd'" + $sql = "CREATE CREDENTIAL [dbatools_ci] WITH IDENTITY = N'$TestConfig.azureblobaccount', SECRET = N'$env:azurelegacypasswd'" $server.Query($sql) } AfterAll { - Get-DbaDatabase -SqlInstance $script:instance2 -Database "dbatoolsci_azure" | Remove-DbaDatabase -Confirm:$false - $server.Query("DROP CREDENTIAL [$script:azureblob]") + Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database "dbatoolsci_azure" | Remove-DbaDatabase -Confirm:$false + $server.Query("DROP CREDENTIAL [$TestConfig.azureblob]") } It "backs up to Azure properly using SHARED ACCESS SIGNATURE" { - $results = Backup-DbaDatabase -SqlInstance $script:instance2 -AzureBaseUrl $script:azureblob -Database dbatoolsci_azure -BackupFileName dbatoolsci_azure.bak -WithFormat + $results = Backup-DbaDatabase -SqlInstance $TestConfig.instance2 -AzureBaseUrl $TestConfig.azureblob -Database dbatoolsci_azure -BackupFileName dbatoolsci_azure.bak -WithFormat $results.Database | Should -Be 'dbatoolsci_azure' $results.DeviceType | Should -Be 'URL' $results.BackupFile | Should -Be 'dbatoolsci_azure.bak' } It "backs up to Azure properly using legacy credential" { - $results = Backup-DbaDatabase -SqlInstance $script:instance2 -AzureBaseUrl $script:azureblob -Database dbatoolsci_azure -BackupFileName dbatoolsci_azure2.bak -WithFormat -AzureCredential dbatools_ci + $results = Backup-DbaDatabase -SqlInstance $TestConfig.instance2 -AzureBaseUrl $TestConfig.azureblob -Database dbatoolsci_azure -BackupFileName dbatoolsci_azure2.bak -WithFormat -AzureCredential dbatools_ci $results.Database | Should -Be 'dbatoolsci_azure' $results.DeviceType | Should -Be 'URL' $results.BackupFile | Should -Be 'dbatoolsci_azure2.bak' } } } -} \ No newline at end of file +} diff --git a/tests/Backup-DbaDbCertificate.Tests.ps1 b/tests/Backup-DbaDbCertificate.Tests.ps1 index 445de01875..d6d04b86db 100644 --- a/tests/Backup-DbaDbCertificate.Tests.ps1 +++ b/tests/Backup-DbaDbCertificate.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -17,33 +17,33 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { $random = Get-Random $db1Name = "dbatoolscli_$random" - $db1 = New-DbaDatabase -SqlInstance $script:instance1 -Name $db1Name + $db1 = New-DbaDatabase -SqlInstance $TestConfig.instance1 -Name $db1Name $pw = ConvertTo-SecureString -String "GoodPass1234!" -AsPlainText -Force - if (-not (Get-DbaDbMasterKey -SqlInstance $script:instance1 -Database $db1Name)) { - $masterkey = New-DbaDbMasterKey -SqlInstance $script:instance1 -Database $db1Name -Password $pw -Confirm:$false + if (-not (Get-DbaDbMasterKey -SqlInstance $TestConfig.instance1 -Database $db1Name)) { + $masterkey = New-DbaDbMasterKey -SqlInstance $TestConfig.instance1 -Database $db1Name -Password $pw -Confirm:$false } - $cert = New-DbaDbCertificate -SqlInstance $script:instance1 -Database $db1Name -Confirm:$false -Password $pw -Name dbatoolscli_cert1_$random - $cert2 = New-DbaDbCertificate -SqlInstance $script:instance1 -Database $db1Name -Confirm:$false -Password $pw -Name dbatoolscli_cert2_$random + $cert = New-DbaDbCertificate -SqlInstance $TestConfig.instance1 -Database $db1Name -Confirm:$false -Password $pw -Name dbatoolscli_cert1_$random + $cert2 = New-DbaDbCertificate -SqlInstance $TestConfig.instance1 -Database $db1Name -Confirm:$false -Password $pw -Name dbatoolscli_cert2_$random } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance1 -Database $db1Name -Confirm:$false + Remove-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $db1Name -Confirm:$false } Context "Can create and backup a database certificate" { It "backs up the db cert" { - $results = Backup-DbaDbCertificate -SqlInstance $script:instance1 -Certificate $cert.Name -Database $db1Name -EncryptionPassword $pw -DecryptionPassword $pw + $results = Backup-DbaDbCertificate -SqlInstance $TestConfig.instance1 -Certificate $cert.Name -Database $db1Name -EncryptionPassword $pw -DecryptionPassword $pw $null = Get-ChildItem -Path $results.Path -ErrorAction Ignore | Remove-Item -Confirm:$false -ErrorAction Ignore $results.Certificate | Should -Be $cert.Name $results.Status -match "Success" - $results.DatabaseID | Should -Be (Get-DbaDatabase -SqlInstance $script:instance1 -Database $db1Name).ID + $results.DatabaseID | Should -Be (Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $db1Name).ID } It "warns the caller if the cert cannot be found" { $invalidDBCertName = "dbatoolscli_invalidCertName" $invalidDBCertName2 = "dbatoolscli_invalidCertName2" - $results = Backup-DbaDbCertificate -SqlInstance $script:instance1 -Certificate $invalidDBCertName, $invalidDBCertName2, $cert2.Name -Database $db1Name -EncryptionPassword $pw -DecryptionPassword $pw -WarningVariable warnVariable 3> $null + $results = Backup-DbaDbCertificate -SqlInstance $TestConfig.instance1 -Certificate $invalidDBCertName, $invalidDBCertName2, $cert2.Name -Database $db1Name -EncryptionPassword $pw -DecryptionPassword $pw -WarningVariable warnVariable 3> $null $null = Get-ChildItem -Path $results.Path -ErrorAction Ignore | Remove-Item -Confirm:$false -ErrorAction Ignore #$results.Certificate | Should -Be $cert2.Name $warnVariable | Should -BeLike "*Database certificate(s) * not found*" @@ -51,7 +51,7 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { # works locally, gah It -Skip "backs up all db certs for a database" { - $results = Backup-DbaDbCertificate -SqlInstance $script:instance1 -Database $db1Name -EncryptionPassword $pw -DecryptionPassword $pw + $results = Backup-DbaDbCertificate -SqlInstance $TestConfig.instance1 -Database $db1Name -EncryptionPassword $pw -DecryptionPassword $pw $null = Get-ChildItem -Path $results.Path -ErrorAction Ignore | Remove-Item -Confirm:$false -ErrorAction Ignore $results.length | Should -Be 2 $results.Certificate | Should -Be $cert.Name, $cert2.Name @@ -59,9 +59,9 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { # Skip this test as there's a mix of certs, some require a password and some don't and i'll fix later It -Skip "backs up all db certs for an instance" { - $results = Backup-DbaDbCertificate -SqlInstance $script:instance1 -EncryptionPassword $pw + $results = Backup-DbaDbCertificate -SqlInstance $TestConfig.instance1 -EncryptionPassword $pw $null = Get-ChildItem -Path $results.Path -ErrorAction Ignore | Remove-Item -Confirm:$false -ErrorAction Ignore # $results.length | Should -BeGreaterOrEqual 2 } } -} \ No newline at end of file +} diff --git a/tests/Backup-DbaDbMasterKey.Tests.ps1 b/tests/Backup-DbaDbMasterKey.Tests.ps1 index dd61c1a96e..5c1a0366b6 100644 --- a/tests/Backup-DbaDbMasterKey.Tests.ps1 +++ b/tests/Backup-DbaDbMasterKey.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,15 +16,15 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Can create a database certificate" { BeforeAll { - if (-not (Get-DbaDbMasterKey -SqlInstance $script:instance1 -Database tempdb)) { - $masterkey = New-DbaDbMasterKey -SqlInstance $script:instance1 -Database tempdb -Password $(ConvertTo-SecureString -String "GoodPass1234!" -AsPlainText -Force) -Confirm:$false + if (-not (Get-DbaDbMasterKey -SqlInstance $TestConfig.instance1 -Database tempdb)) { + $masterkey = New-DbaDbMasterKey -SqlInstance $TestConfig.instance1 -Database tempdb -Password $(ConvertTo-SecureString -String "GoodPass1234!" -AsPlainText -Force) -Confirm:$false } } AfterAll { - (Get-DbaDbMasterKey -SqlInstance $script:instance1 -Database tempdb) | Remove-DbaDbMasterKey -Confirm:$false + (Get-DbaDbMasterKey -SqlInstance $TestConfig.instance1 -Database tempdb) | Remove-DbaDbMasterKey -Confirm:$false } - $results = Backup-DbaDbMasterKey -SqlInstance $script:instance1 -Confirm:$false -Database tempdb -Password $(ConvertTo-SecureString -String "GoodPass1234!" -AsPlainText -Force) + $results = Backup-DbaDbMasterKey -SqlInstance $TestConfig.instance1 -Confirm:$false -Database tempdb -Password $(ConvertTo-SecureString -String "GoodPass1234!" -AsPlainText -Force) $null = Remove-Item -Path $results.Path -ErrorAction SilentlyContinue -Confirm:$false It "backs up the db cert" { @@ -33,7 +33,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } It "Database ID should be returned" { - $results.DatabaseID | Should -Be (Get-DbaDatabase -SqlInstance $script:instance1 -Database tempdb).ID + $results.DatabaseID | Should -Be (Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database tempdb).ID } } -} \ No newline at end of file +} diff --git a/tests/Backup-DbaServiceMasterKey.Tests.ps1 b/tests/Backup-DbaServiceMasterKey.Tests.ps1 index 13e0d764fe..c04b886400 100644 --- a/tests/Backup-DbaServiceMasterKey.Tests.ps1 +++ b/tests/Backup-DbaServiceMasterKey.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,11 +15,11 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Can backup a service master key" { - $results = Backup-DbaServiceMasterKey -SqlInstance $script:instance1 -Confirm:$false -Password $(ConvertTo-SecureString -String "GoodPass1234!" -AsPlainText -Force) + $results = Backup-DbaServiceMasterKey -SqlInstance $TestConfig.instance1 -Confirm:$false -Password $(ConvertTo-SecureString -String "GoodPass1234!" -AsPlainText -Force) $null = Remove-Item -Path $results.Path -ErrorAction SilentlyContinue -Confirm:$false It "backs up the SMK" { $results.Status -eq "Success" } } -} \ No newline at end of file +} diff --git a/tests/Clear-DbaConnectionPool.Tests.ps1 b/tests/Clear-DbaConnectionPool.Tests.ps1 index cbbfd7fb83..53bb663354 100644 --- a/tests/Clear-DbaConnectionPool.Tests.ps1 +++ b/tests/Clear-DbaConnectionPool.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Clear-DbaLatchStatistics.Tests.ps1 b/tests/Clear-DbaLatchStatistics.Tests.ps1 index 99b6241406..634451dfff 100644 --- a/tests/Clear-DbaLatchStatistics.Tests.ps1 +++ b/tests/Clear-DbaLatchStatistics.Tests.ps1 @@ -1,6 +1,6 @@ $commandname = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Validate parameters" { @@ -15,10 +15,10 @@ Describe "$CommandName Unit Tests" -Tags "UnitTests" { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Command executes properly and returns proper info" { - $results = Clear-DbaLatchStatistics -SqlInstance $script:instance1 -Confirm:$false + $results = Clear-DbaLatchStatistics -SqlInstance $TestConfig.instance1 -Confirm:$false It "returns success" { $results.Status -eq 'Success' | Should Be $true } } -} \ No newline at end of file +} diff --git a/tests/Clear-DbaPlanCache.Tests.ps1 b/tests/Clear-DbaPlanCache.Tests.ps1 index 00d6f9d3c2..c33d5476d3 100644 --- a/tests/Clear-DbaPlanCache.Tests.ps1 +++ b/tests/Clear-DbaPlanCache.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -17,15 +17,15 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { Context "doesn't clear plan cache" { It "returns correct datatypes" { # Make plan cache way higher than likely for a test rig - $results = Clear-DbaPlanCache -SqlInstance $script:instance1 -Threshold 10240 + $results = Clear-DbaPlanCache -SqlInstance $TestConfig.instance1 -Threshold 10240 $results.Size -is [dbasize] | Should -Be $true $results.Status -match 'below' | Should -Be $true } It "supports piping" { # Make plan cache way higher than likely for a test rig - $results = Get-DbaPlanCache -SqlInstance $script:instance1 | Clear-DbaPlanCache -Threshold 10240 + $results = Get-DbaPlanCache -SqlInstance $TestConfig.instance1 | Clear-DbaPlanCache -Threshold 10240 $results.Size -is [dbasize] | Should -Be $true $results.Status -match 'below' | Should -Be $true } } -} \ No newline at end of file +} diff --git a/tests/Clear-DbaWaitStatistics.Tests.ps1 b/tests/Clear-DbaWaitStatistics.Tests.ps1 index 31b0904f25..120ce455e6 100644 --- a/tests/Clear-DbaWaitStatistics.Tests.ps1 +++ b/tests/Clear-DbaWaitStatistics.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,10 +15,10 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Command executes properly and returns proper info" { - $results = Clear-DbaWaitStatistics -SqlInstance $script:instance1 -Confirm:$false + $results = Clear-DbaWaitStatistics -SqlInstance $TestConfig.instance1 -Confirm:$false It "returns success" { $results.Status -eq 'Success' | Should Be $true } } -} \ No newline at end of file +} diff --git a/tests/Connect-DbaInstance.Tests.ps1 b/tests/Connect-DbaInstance.Tests.ps1 index 3f849bf67e..d0ffe01b2e 100644 --- a/tests/Connect-DbaInstance.Tests.ps1 +++ b/tests/Connect-DbaInstance.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -22,7 +22,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { if ($env:azuredbpasswd -eq "failstoooften") { Context "Connect to Azure" { $securePassword = ConvertTo-SecureString $env:azuredbpasswd -AsPlainText -Force - $cred = New-Object System.Management.Automation.PSCredential ($script:azuresqldblogin, $securePassword) + $cred = New-Object System.Management.Automation.PSCredential ($TestConfig.azuresqldblogin, $securePassword) It "Should login to Azure" { $s = Connect-DbaInstance -SqlInstance psdbatools.database.windows.net -SqlCredential $cred -Database test @@ -69,11 +69,11 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { 'StatementTimeout' = 0 'ApplicationIntent' = 'ReadOnly' } - $server = Connect-DbaInstance -SqlInstance $script:instance1 @params + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance1 @params } It "returns the proper name" { - $server.Name | Should -Be $script:instance1 + $server.Name | Should -Be $TestConfig.instance1 } It "sets connectioncontext parameters that are provided" { @@ -107,11 +107,11 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "connection is properly made using a connection string" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance "Data Source=$script:instance1;Initial Catalog=tempdb;Integrated Security=True" + $server = Connect-DbaInstance -SqlInstance "Data Source=$($TestConfig.instance1);Initial Catalog=tempdb;Integrated Security=True" } It "returns the proper name" { - $server.Name | Should -Be $script:instance1 + $server.Name | Should -Be $TestConfig.instance1 } It "returns more than one database" { @@ -125,10 +125,10 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } - if ($script:instance1 -match 'localhost') { + if ($TestConfig.instance1 -match 'localhost') { Context "connection is properly made using a dot" { BeforeAll { - $newinstance = $script:instance1.Replace("localhost", ".") + $newinstance = $TestConfig.instance1.Replace("localhost", ".") $server = Connect-DbaInstance -SqlInstance $newinstance } @@ -151,13 +151,13 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "connection is properly made using a connection object" { BeforeAll { Set-DbatoolsConfig -FullName commands.connect-dbainstance.smo.computername.source -Value 'instance.ComputerName' - [Microsoft.Data.SqlClient.SqlConnection]$sqlconnection = "Data Source=$script:instance1;Initial Catalog=tempdb;Integrated Security=True;Encrypt=False;Trust Server Certificate=True" + [Microsoft.Data.SqlClient.SqlConnection]$sqlconnection = "Data Source=$($TestConfig.instance1);Initial Catalog=tempdb;Integrated Security=True;Encrypt=False;Trust Server Certificate=True" $server = Connect-DbaInstance -SqlInstance $sqlconnection Set-DbatoolsConfig -FullName commands.connect-dbainstance.smo.computername.source -Value $null } It "returns the proper name" { - $server.Name | Should -Be $script:instance1 + $server.Name | Should -Be $TestConfig.instance1 } It "returns more than one database" { @@ -173,7 +173,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "connection is properly cloned from an existing connection" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance1 } It "clones when using parameter Database" { @@ -208,7 +208,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } It "clones when using Backup-DabInstace" { - $server = Connect-DbaInstance -SqlInstance $script:instance1 -Database tempdb + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance1 -Database tempdb $null = Backup-DbaDatabase -SqlInstance $server -Database msdb $null = Backup-DbaDatabase -SqlInstance $server -Database msdb -WarningVariable warn $warn | Should -BeNullOrEmpty @@ -217,24 +217,24 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "multiple connections are properly made using strings" { It "returns the proper names" { - $server = Connect-DbaInstance -SqlInstance $script:instance1, $script:instance2 - $server[0].Name | Should -Be $script:instance1 - $server[1].Name | Should -Be $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance1, $TestConfig.instance2 + $server[0].Name | Should -Be $TestConfig.instance1 + $server[1].Name | Should -Be $TestConfig.instance2 } } Context "multiple dedicated admin connections are properly made using strings" { # This might fail if a parallel test uses DAC - how can we ensure that this is the only test that is run? It "opens and closes the connections" { - $server = Connect-DbaInstance -SqlInstance $script:instance1, $script:instance2 -DedicatedAdminConnection - $server[0].Name | Should -Be "ADMIN:$script:instance1" - $server[1].Name | Should -Be "ADMIN:$script:instance2" + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance1, $TestConfig.instance2 -DedicatedAdminConnection + $server[0].Name | Should -Be "ADMIN:$($TestConfig.instance1)" + $server[1].Name | Should -Be "ADMIN:$($TestConfig.instance2)" $null = $server | Disconnect-DbaInstance # DAC is not reopened in the background Start-Sleep -Seconds 10 - $server = Connect-DbaInstance -SqlInstance $script:instance1, $script:instance2 -DedicatedAdminConnection + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance1, $TestConfig.instance2 -DedicatedAdminConnection $server.Count | Should -Be 2 $null = $server | Disconnect-DbaInstance } } -} \ No newline at end of file +} diff --git a/tests/Convert-DbaLsn.Tests.ps1 b/tests/Convert-DbaLsn.Tests.ps1 index c7f97a532d..226c2bfc87 100644 --- a/tests/Convert-DbaLsn.Tests.ps1 +++ b/tests/Convert-DbaLsn.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Convert-DbaMaskingValue.Tests.ps1 b/tests/Convert-DbaMaskingValue.Tests.ps1 index 3531c82407..bed662ab4a 100644 --- a/tests/Convert-DbaMaskingValue.Tests.ps1 +++ b/tests/Convert-DbaMaskingValue.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/ConvertTo-DbaDataTable.Tests.ps1 b/tests/ConvertTo-DbaDataTable.Tests.ps1 index 4d1fb2a3a3..dcb2f1eb1a 100644 --- a/tests/ConvertTo-DbaDataTable.Tests.ps1 +++ b/tests/ConvertTo-DbaDataTable.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/ConvertTo-DbaTimeline.Tests.ps1 b/tests/ConvertTo-DbaTimeline.Tests.ps1 index 5653044053..cf7f8d4f87 100644 --- a/tests/ConvertTo-DbaTimeline.Tests.ps1 +++ b/tests/ConvertTo-DbaTimeline.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/ConvertTo-DbaXESession.Tests.ps1 b/tests/ConvertTo-DbaXESession.Tests.ps1 index d8d0a67166..c675a40aa0 100644 --- a/tests/ConvertTo-DbaXESession.Tests.ps1 +++ b/tests/ConvertTo-DbaXESession.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -92,21 +92,21 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { -- display trace id for future references select TraceID=@TraceID" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $traceid = ($server.Query($sql)).TraceID - $script:name = "dbatoolsci-session" + $TestConfig.name = "dbatoolsci-session" } AfterAll { - $null = Remove-DbaXESession -SqlInstance $script:instance2 -Session $script:name - $null = Remove-DbaTrace -SqlInstance $script:instance2 -Id $traceid + $null = Remove-DbaXESession -SqlInstance $TestConfig.instance2 -Session $TestConfig.name + $null = Remove-DbaTrace -SqlInstance $TestConfig.instance2 -Id $traceid Remove-Item C:\windows\temp\temptrace.trc -ErrorAction SilentlyContinue } Context "Test Trace Conversion" { - $results = Get-DbaTrace -SqlInstance $script:instance2 -Id $traceid | ConvertTo-DbaXESession -Name $script:name | Start-DbaXESession + $results = Get-DbaTrace -SqlInstance $TestConfig.instance2 -Id $traceid | ConvertTo-DbaXESession -Name $TestConfig.name | Start-DbaXESession It "returns the right results" { - $results.Name | Should Be $script:name + $results.Name | Should Be $TestConfig.name $results.Status | Should Be "Running" $results.Targets.Name | Should Be "package0.event_file" } } -} \ No newline at end of file +} diff --git a/tests/Copy-DbaAgentAlert.Tests.ps1 b/tests/Copy-DbaAgentAlert.Tests.ps1 index b4361ae41f..e40e27fe13 100644 --- a/tests/Copy-DbaAgentAlert.Tests.ps1 +++ b/tests/Copy-DbaAgentAlert.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -19,7 +19,7 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { $alert2 = 'dbatoolsci test alert 2' $operatorName = 'Dan the man Levitan' $operatorEmail = 'levitan@dbatools.io' - $server = Connect-DbaInstance -SqlInstance $script:instance2 -Database master + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 -Database master $server.Query("EXEC msdb.dbo.sp_add_alert @name=N'$($alert1)', @message_id=0, @@ -47,34 +47,34 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { @notification_method = 1 ;") } AfterAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 -Database master + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 -Database master $server.Query("EXEC msdb.dbo.sp_delete_alert @name=N'$($alert1)'") $server.Query("EXEC msdb.dbo.sp_delete_alert @name=N'$($alert2)'") $server.Query("EXEC msdb.dbo.sp_delete_operator @name = '$($operatorName)'") - $server = Connect-DbaInstance -SqlInstance $script:instance3 -Database master + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance3 -Database master $server.Query("EXEC msdb.dbo.sp_delete_alert @name=N'$($alert1)'") } It "Copies the sample alert" { - $results = Copy-DbaAgentAlert -Source $script:instance2 -Destination $script:instance3 -Alert $alert1 + $results = Copy-DbaAgentAlert -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -Alert $alert1 $results.Name -eq 'dbatoolsci test alert', 'dbatoolsci test alert' $results.Status -eq 'Successful', 'Successful' } It "Skips alerts where destination is missing the operator" { - $results = Copy-DbaAgentAlert -Source $script:instance2 -Destination $script:instance3 -Alert $alert2 -WarningAction SilentlyContinue + $results = Copy-DbaAgentAlert -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -Alert $alert2 -WarningAction SilentlyContinue $results.Status -eq 'Skipped', 'Skipped' } It "Doesn't overwrite existing alerts" { - $results = Copy-DbaAgentAlert -Source $script:instance2 -Destination $script:instance3 -Alert $alert1 + $results = Copy-DbaAgentAlert -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -Alert $alert1 $results.Name -eq 'dbatoolsci test alert' $results.Status -eq 'Skipped' } It "The newly copied alert exists" { - $results = Get-DbaAgentAlert -SqlInstance $script:instance2 + $results = Get-DbaAgentAlert -SqlInstance $TestConfig.instance2 $results.Name -contains 'dbatoolsci test alert' } -} \ No newline at end of file +} diff --git a/tests/Copy-DbaAgentJob.Tests.ps1 b/tests/Copy-DbaAgentJob.Tests.ps1 index aeb6367215..81151184f7 100644 --- a/tests/Copy-DbaAgentJob.Tests.ps1 +++ b/tests/Copy-DbaAgentJob.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,18 +15,18 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $null = New-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_copyjob - $null = New-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_copyjob_disabled - $sourcejobs = Get-DbaAgentJob -SqlInstance $script:instance2 - $destjobs = Get-DbaAgentJob -SqlInstance $script:instance3 + $null = New-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job dbatoolsci_copyjob + $null = New-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job dbatoolsci_copyjob_disabled + $sourcejobs = Get-DbaAgentJob -SqlInstance $TestConfig.instance2 + $destjobs = Get-DbaAgentJob -SqlInstance $TestConfig.instance3 } AfterAll { - $null = Remove-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_copyjob, dbatoolsci_copyjob_disabled -Confirm:$false - $null = Remove-DbaAgentJob -SqlInstance $script:instance3 -Job dbatoolsci_copyjob, dbatoolsci_copyjob_disabled -Confirm:$false + $null = Remove-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job dbatoolsci_copyjob, dbatoolsci_copyjob_disabled -Confirm:$false + $null = Remove-DbaAgentJob -SqlInstance $TestConfig.instance3 -Job dbatoolsci_copyjob, dbatoolsci_copyjob_disabled -Confirm:$false } Context "Command copies jobs properly" { - $results = Copy-DbaAgentJob -Source $script:instance2 -Destination $script:instance3 -Job dbatoolsci_copyjob + $results = Copy-DbaAgentJob -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -Job dbatoolsci_copyjob It "returns one success" { $results.Name | Should -Be "dbatoolsci_copyjob" @@ -34,16 +34,16 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { } It "did not copy dbatoolsci_copyjob_disabled" { - Get-DbaAgentJob -SqlInstance $script:instance3 -Job dbatoolsci_copyjob_disabled | Should -Be $null + Get-DbaAgentJob -SqlInstance $TestConfig.instance3 -Job dbatoolsci_copyjob_disabled | Should -Be $null } It "disables jobs when requested" { - (Get-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_copyjob_disabled).Enabled - $results = Copy-DbaAgentJob -Source $script:instance2 -Destination $script:instance3 -Job dbatoolsci_copyjob_disabled -DisableOnSource -DisableOnDestination -Force + (Get-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job dbatoolsci_copyjob_disabled).Enabled + $results = Copy-DbaAgentJob -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -Job dbatoolsci_copyjob_disabled -DisableOnSource -DisableOnDestination -Force $results.Name | Should -Be "dbatoolsci_copyjob_disabled" $results.Status | Should -Be "Successful" - (Get-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_copyjob_disabled).Enabled | Should -Be $false - (Get-DbaAgentJob -SqlInstance $script:instance3 -Job dbatoolsci_copyjob_disabled).Enabled | Should -Be $false + (Get-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job dbatoolsci_copyjob_disabled).Enabled | Should -Be $false + (Get-DbaAgentJob -SqlInstance $TestConfig.instance3 -Job dbatoolsci_copyjob_disabled).Enabled | Should -Be $false } } -} \ No newline at end of file +} diff --git a/tests/Copy-DbaAgentJobCategory.Tests.ps1 b/tests/Copy-DbaAgentJobCategory.Tests.ps1 index d6c4745b30..943c31d943 100644 --- a/tests/Copy-DbaAgentJobCategory.Tests.ps1 +++ b/tests/Copy-DbaAgentJobCategory.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,23 +15,23 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $null = New-DbaAgentJobCategory -SqlInstance $script:instance2 -Category 'dbatoolsci test category' + $null = New-DbaAgentJobCategory -SqlInstance $TestConfig.instance2 -Category 'dbatoolsci test category' } AfterAll { - $null = Remove-DbaAgentJobCategory -SqlInstance $script:instance2 -Category 'dbatoolsci test category' -Confirm:$false + $null = Remove-DbaAgentJobCategory -SqlInstance $TestConfig.instance2 -Category 'dbatoolsci test category' -Confirm:$false } Context "Command copies jobs properly" { It "returns one success" { - $results = Copy-DbaAgentJobCategory -Source $script:instance2 -Destination $script:instance3 -JobCategory 'dbatoolsci test category' + $results = Copy-DbaAgentJobCategory -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -JobCategory 'dbatoolsci test category' $results.Name -eq "dbatoolsci test category" $results.Status -eq "Successful" } It "does not overwrite" { - $results = Copy-DbaAgentJobCategory -Source $script:instance2 -Destination $script:instance3 -JobCategory 'dbatoolsci test category' + $results = Copy-DbaAgentJobCategory -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -JobCategory 'dbatoolsci test category' $results.Name -eq "dbatoolsci test category" $results.Status -eq "Skipped" } } -} \ No newline at end of file +} diff --git a/tests/Copy-DbaAgentOperator.Tests.ps1 b/tests/Copy-DbaAgentOperator.Tests.ps1 index 3b33a2d478..361ebf9a1d 100644 --- a/tests/Copy-DbaAgentOperator.Tests.ps1 +++ b/tests/Copy-DbaAgentOperator.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,20 +15,20 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $sql = "EXEC msdb.dbo.sp_add_operator @name=N'dbatoolsci_operator', @enabled=1, @pager_days=0" $server.Query($sql) $sql = "EXEC msdb.dbo.sp_add_operator @name=N'dbatoolsci_operator2', @enabled=1, @pager_days=0" $server.Query($sql) } AfterAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $sql = "EXEC msdb.dbo.sp_delete_operator @name=N'dbatoolsci_operator'" $server.Query($sql) $sql = "EXEC msdb.dbo.sp_delete_operator @name=N'dbatoolsci_operator2'" $server.Query($sql) - $server = Connect-DbaInstance -SqlInstance $script:instance3 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance3 $sql = "EXEC msdb.dbo.sp_delete_operator @name=N'dbatoolsci_operator'" $server.Query($sql) $sql = "EXEC msdb.dbo.sp_delete_operator @name=N'dbatoolsci_operator2'" @@ -36,7 +36,7 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { } Context "Copies operators" { - $results = Copy-DbaAgentOperator -Source $script:instance2 -Destination $script:instance3 -Operator dbatoolsci_operator, dbatoolsci_operator2 + $results = Copy-DbaAgentOperator -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -Operator dbatoolsci_operator, dbatoolsci_operator2 It "returns two results" { $results.Count -eq 2 @@ -44,8 +44,8 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { } It "return one result that's skipped" { - $results = Copy-DbaAgentOperator -Source $script:instance2 -Destination $script:instance3 -Operator dbatoolsci_operator + $results = Copy-DbaAgentOperator -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -Operator dbatoolsci_operator $results.Status -eq "Skipped" } } -} \ No newline at end of file +} diff --git a/tests/Copy-DbaAgentProxy.Tests.ps1 b/tests/Copy-DbaAgentProxy.Tests.ps1 index 5b4e8f25c0..867a6ca36f 100644 --- a/tests/Copy-DbaAgentProxy.Tests.ps1 +++ b/tests/Copy-DbaAgentProxy.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,24 +15,24 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $sql = "CREATE CREDENTIAL dbatoolsci_credential WITH IDENTITY = 'sa', SECRET = 'dbatools'" $server.Query($sql) $sql = "EXEC msdb.dbo.sp_add_proxy @proxy_name = 'dbatoolsci_agentproxy', @enabled = 1, @credential_name = 'dbatoolsci_credential'" $server.Query($sql) - $server = Connect-DbaInstance -SqlInstance $script:instance3 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance3 $sql = "CREATE CREDENTIAL dbatoolsci_credential WITH IDENTITY = 'sa', SECRET = 'dbatools'" $server.Query($sql) } AfterAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $sql = "EXEC msdb.dbo.sp_delete_proxy @proxy_name = 'dbatoolsci_agentproxy'" $server.Query($sql) $sql = "DROP CREDENTIAL dbatoolsci_credential" $server.Query($sql) - $server = Connect-DbaInstance -SqlInstance $script:instance3 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance3 $sql = "EXEC msdb.dbo.sp_delete_proxy @proxy_name = 'dbatoolsci_agentproxy'" $server.Query($sql) $sql = "DROP CREDENTIAL dbatoolsci_credential" @@ -40,7 +40,7 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { } Context "Copies Agent Proxy" { - $results = Copy-DbaAgentProxy -Source $script:instance2 -Destination $script:instance3 -ProxyAccount dbatoolsci_agentproxy + $results = Copy-DbaAgentProxy -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -ProxyAccount dbatoolsci_agentproxy It "returns one results" { $results.Count -eq 1 @@ -48,8 +48,8 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { } It "return one result that's skipped" { - $results = Get-DbaAgentProxy -SqlInstance $script:instance3 -Proxy dbatoolsci_agentproxy + $results = Get-DbaAgentProxy -SqlInstance $TestConfig.instance3 -Proxy dbatoolsci_agentproxy $results.Count -eq 1 } } -} \ No newline at end of file +} diff --git a/tests/Copy-DbaAgentSchedule.Tests.ps1 b/tests/Copy-DbaAgentSchedule.Tests.ps1 index a622127b7e..6d23d68ece 100644 --- a/tests/Copy-DbaAgentSchedule.Tests.ps1 +++ b/tests/Copy-DbaAgentSchedule.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,23 +15,23 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $sql = "EXEC msdb.dbo.sp_add_schedule @schedule_name = N'dbatoolsci_DailySchedule' , @freq_type = 4, @freq_interval = 1, @active_start_time = 010000" $server.Query($sql) } AfterAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $sql = "EXEC msdb.dbo.sp_delete_schedule @schedule_name = 'dbatoolsci_DailySchedule'" $server.Query($sql) - $server = Connect-DbaInstance -SqlInstance $script:instance3 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance3 $sql = "EXEC msdb.dbo.sp_delete_schedule @schedule_name = 'dbatoolsci_DailySchedule'" $server.Query($sql) } Context "Copies Agent Schedule" { - $results = Copy-DbaAgentSchedule -Source $script:instance2 -Destination $script:instance3 + $results = Copy-DbaAgentSchedule -Source $TestConfig.instance2 -Destination $TestConfig.instance3 It "returns one results" { $results.Count | Should -BeGreaterThan 1 @@ -39,8 +39,8 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { } It "return one result of Start Time 1:00 AM" { - $results = Get-DbaAgentSchedule -SqlInstance $script:instance3 -Schedule dbatoolsci_DailySchedule + $results = Get-DbaAgentSchedule -SqlInstance $TestConfig.instance3 -Schedule dbatoolsci_DailySchedule $results.ActiveStartTimeOfDay -eq '01:00:00' } } -} \ No newline at end of file +} diff --git a/tests/Copy-DbaAgentServer.Tests.ps1 b/tests/Copy-DbaAgentServer.Tests.ps1 index 99190ba341..b691e7ae93 100644 --- a/tests/Copy-DbaAgentServer.Tests.ps1 +++ b/tests/Copy-DbaAgentServer.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Copy-DbaBackupDevice.Tests.ps1 b/tests/Copy-DbaBackupDevice.Tests.ps1 index 70d7ba6260..4766c988c3 100644 --- a/tests/Copy-DbaBackupDevice.Tests.ps1 +++ b/tests/Copy-DbaBackupDevice.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -18,15 +18,15 @@ if (-not $env:appveyor) { Context "Setup" { BeforeAll { $devicename = "dbatoolsci-backupdevice" - $backupdir = (Get-DbaDefaultPath -SqlInstance $script:instance1).Backup + $backupdir = (Get-DbaDefaultPath -SqlInstance $TestConfig.instance1).Backup $backupfilename = "$backupdir\$devicename.bak" - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance1 $server.Query("EXEC master.dbo.sp_addumpdevice @devtype = N'disk', @logicalname = N'$devicename',@physicalname = N'$backupfilename'") $server.Query("BACKUP DATABASE master TO DISK = '$backupfilename'") } AfterAll { $server.Query("EXEC master.dbo.sp_dropdevice @logicalname = N'$devicename'") - $server1 = Connect-DbaInstance -SqlInstance $script:instance2 + $server1 = Connect-DbaInstance -SqlInstance $TestConfig.instance2 try { $server1.Query("EXEC master.dbo.sp_dropdevice @logicalname = N'$devicename'") } catch { @@ -35,7 +35,7 @@ if (-not $env:appveyor) { Get-ChildItem -Path $backupfilename | Remove-Item } - $results = Copy-DbaBackupDevice -Source $script:instance1 -Destination $script:instance2 -WarningVariable warn -WarningAction SilentlyContinue 3> $null + $results = Copy-DbaBackupDevice -Source $TestConfig.instance1 -Destination $TestConfig.instance2 -WarningVariable warn -WarningAction SilentlyContinue 3> $null if ($warn) { It "warns if it has a problem moving (issue for local to local)" { $warn | Should -Match "backup device to destination" @@ -46,10 +46,10 @@ if (-not $env:appveyor) { } } - $results = Copy-DbaBackupDevice -Source $script:instance1 -Destination $script:instance2 + $results = Copy-DbaBackupDevice -Source $TestConfig.instance1 -Destination $TestConfig.instance2 It "Should say skipped" { $results.Status -ne "Successful" | Should be $true } } } -} \ No newline at end of file +} diff --git a/tests/Copy-DbaCredential.Tests.ps1 b/tests/Copy-DbaCredential.Tests.ps1 index 326f47ccf1..23171901ec 100644 --- a/tests/Copy-DbaCredential.Tests.ps1 +++ b/tests/Copy-DbaCredential.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig . "$PSScriptRoot\..\private\functions\Invoke-Command2.ps1" Describe "$CommandName Unit Tests" -Tag 'UnitTests' { @@ -20,13 +20,13 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $plaintext = "BigOlPassword!" $password = ConvertTo-SecureString $plaintext -AsPlainText -Force - $server2 = Connect-DbaInstance -SqlInstance $script:instance2 - $server3 = Connect-DbaInstance -SqlInstance $script:instance3 + $server2 = Connect-DbaInstance -SqlInstance $TestConfig.instance2 + $server3 = Connect-DbaInstance -SqlInstance $TestConfig.instance3 # Add user foreach ($login in $logins) { - $null = Invoke-Command2 -ScriptBlock { net user $args[0] $args[1] /add *>&1 } -ArgumentList $login, $plaintext -ComputerName $script:instance2 - $null = Invoke-Command2 -ScriptBlock { net user $args[0] $args[1] /add *>&1 } -ArgumentList $login, $plaintext -ComputerName $script:instance3 + $null = Invoke-Command2 -ScriptBlock { net user $args[0] $args[1] /add *>&1 } -ArgumentList $login, $plaintext -ComputerName $TestConfig.instance2 + $null = Invoke-Command2 -ScriptBlock { net user $args[0] $args[1] /add *>&1 } -ArgumentList $login, $plaintext -ComputerName $TestConfig.instance3 } <# @@ -68,8 +68,8 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { (Get-DbaCredential -SqlInstance $server3 -Identity dbatoolsci_thor, dbatoolsci_thorsmomma, dbatoolsci_thor_crypto -ErrorAction Stop -WarningAction SilentlyContinue).Drop() foreach ($login in $logins) { - $null = Invoke-Command2 -ScriptBlock { net user $args /delete *>&1 } -ArgumentList $login -ComputerName $script:instance2 - $null = Invoke-Command2 -ScriptBlock { net user $args /delete *>&1 } -ArgumentList $login -ComputerName $script:instance3 + $null = Invoke-Command2 -ScriptBlock { net user $args /delete *>&1 } -ArgumentList $login -ComputerName $TestConfig.instance2 + $null = Invoke-Command2 -ScriptBlock { net user $args /delete *>&1 } -ArgumentList $login -ComputerName $TestConfig.instance3 } } @@ -134,4 +134,4 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $results.Notes | Should -Match "The cryptographic provider $cryptoProvider needs to be configured and enabled on" } } -} \ No newline at end of file +} diff --git a/tests/Copy-DbaCustomError.Tests.ps1 b/tests/Copy-DbaCustomError.Tests.ps1 index ea8f41df93..c87d1a9f42 100644 --- a/tests/Copy-DbaCustomError.Tests.ps1 +++ b/tests/Copy-DbaCustomError.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,31 +15,31 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 -Database master + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 -Database master $server.Query("EXEC sp_addmessage @msgnum = 60000, @severity = 16,@msgtext = N'The item named %s already exists in %s.',@lang = 'us_english';") $server.Query("EXEC sp_addmessage @msgnum = 60000, @severity = 16, @msgtext = N'L''élément nommé %1! existe déjà dans %2!',@lang = 'French';") } AfterAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 -Database master + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 -Database master $server.Query("EXEC sp_dropmessage @msgnum = 60000, @lang = 'all';") - $server = Connect-DbaInstance -SqlInstance $script:instance3 -Database master + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance3 -Database master $server.Query("EXEC sp_dropmessage @msgnum = 60000, @lang = 'all';") } It "copies the sample custom errror" { - $results = Copy-DbaCustomError -Source $script:instance2 -Destination $script:instance3 -CustomError 60000 + $results = Copy-DbaCustomError -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -CustomError 60000 $results.Name -eq "60000:'us_english'", "60000:'Français'" $results.Status -eq 'Successful', 'Successful' } It "doesn't overwrite existing custom errors" { - $results = Copy-DbaCustomError -Source $script:instance2 -Destination $script:instance3 -CustomError 60000 + $results = Copy-DbaCustomError -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -CustomError 60000 $results.Name -eq "60000:'us_english'", "60000:'Français'" $results.Status -eq 'Skipped', 'Skipped' } It "the newly copied custom error exists" { - $results = Get-DbaCustomError -SqlInstance $script:instance2 + $results = Get-DbaCustomError -SqlInstance $TestConfig.instance2 $results.ID -contains 60000 } -} \ No newline at end of file +} diff --git a/tests/Copy-DbaDataCollector.Tests.ps1 b/tests/Copy-DbaDataCollector.Tests.ps1 index 16402e6910..62af2cfc21 100644 --- a/tests/Copy-DbaDataCollector.Tests.ps1 +++ b/tests/Copy-DbaDataCollector.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Copy-DbaDatabase.Tests.ps1 b/tests/Copy-DbaDatabase.Tests.ps1 index a85b00c3e9..446c3f42d4 100644 --- a/tests/Copy-DbaDatabase.Tests.ps1 +++ b/tests/Copy-DbaDatabase.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -21,28 +21,28 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { $backuprestoredb2 = "dbatoolsci_backuprestoreother$random" $detachattachdb = "dbatoolsci_detachattach$random" $supportDbs = @("ReportServer", "ReportServerTempDB", "distribution", "SSISDB") - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance2, $script:instance3 -Database $backuprestoredb, $detachattachdb + Remove-DbaDatabase -Confirm:$false -SqlInstance $TestConfig.instance2, $TestConfig.instance3 -Database $backuprestoredb, $detachattachdb - $server = Connect-DbaInstance -SqlInstance $script:instance3 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance3 $server.Query("CREATE DATABASE $backuprestoredb2; ALTER DATABASE $backuprestoredb2 SET AUTO_CLOSE OFF WITH ROLLBACK IMMEDIATE") - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $server.Query("CREATE DATABASE $backuprestoredb; ALTER DATABASE $backuprestoredb SET AUTO_CLOSE OFF WITH ROLLBACK IMMEDIATE") $server.Query("CREATE DATABASE $detachattachdb; ALTER DATABASE $detachattachdb SET AUTO_CLOSE OFF WITH ROLLBACK IMMEDIATE") $server.Query("CREATE DATABASE $backuprestoredb2; ALTER DATABASE $backuprestoredb2 SET AUTO_CLOSE OFF WITH ROLLBACK IMMEDIATE") foreach ($db in $supportDbs) { $server.Query("CREATE DATABASE [$db]; ALTER DATABASE [$db] SET AUTO_CLOSE OFF WITH ROLLBACK IMMEDIATE;") } - $null = Set-DbaDbOwner -SqlInstance $script:instance2 -Database $backuprestoredb, $detachattachdb -TargetLogin sa + $null = Set-DbaDbOwner -SqlInstance $TestConfig.instance2 -Database $backuprestoredb, $detachattachdb -TargetLogin sa } AfterAll { - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance2, $script:instance3 -Database $backuprestoredb, $detachattachdb, $backuprestoredb2 - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance2 -Database $supportDbs + Remove-DbaDatabase -Confirm:$false -SqlInstance $TestConfig.instance2, $TestConfig.instance3 -Database $backuprestoredb, $detachattachdb, $backuprestoredb2 + Remove-DbaDatabase -Confirm:$false -SqlInstance $TestConfig.instance2 -Database $supportDbs } Context "Support databases are excluded when AllDatabase selected" { $SupportDbs = "ReportServer", "ReportServerTempDB", "distribution", "SSISDB" - $results = Copy-DbaDatabase -Source $script:instance2 -Destination $script:instance3 -AllDatabase -BackupRestore -UseLastBackup + $results = Copy-DbaDatabase -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -AllDatabase -BackupRestore -UseLastBackup It "Support databases should not be migrated" { $SupportDbs | Should -Not -BeIn $results.Name @@ -52,12 +52,12 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { # if failed Disable-NetFirewallRule -DisplayName 'Core Networking - Group Policy (TCP-Out)' Context "Detach Attach" { It "Should be success" { - $results = Copy-DbaDatabase -Source $script:instance2 -Destination $script:instance3 -Database $detachattachdb -DetachAttach -Reattach -Force #-WarningAction SilentlyContinue + $results = Copy-DbaDatabase -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -Database $detachattachdb -DetachAttach -Reattach -Force #-WarningAction SilentlyContinue $results.Status | Should Be "Successful" } - $db1 = Get-DbaDatabase -SqlInstance $script:instance2 -Database $detachattachdb - $db2 = Get-DbaDatabase -SqlInstance $script:instance3 -Database $detachattachdb + $db1 = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $detachattachdb + $db2 = Get-DbaDatabase -SqlInstance $TestConfig.instance3 -Database $detachattachdb It "should not be null" { $db1.Name | Should Be $detachattachdb @@ -73,15 +73,15 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { } It "Should say skipped" { - $results = Copy-DbaDatabase -Source $script:instance2 -Destination $script:instance3 -Database $detachattachdb -DetachAttach -Reattach + $results = Copy-DbaDatabase -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -Database $detachattachdb -DetachAttach -Reattach $results.Status | Should be "Skipped" $results.Notes | Should be "Already exists on destination" } } Context "Backup restore" { - Get-DbaProcess -SqlInstance $script:instance2, $script:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue - $results = Copy-DbaDatabase -Source $script:instance2 -Destination $script:instance3 -Database $backuprestoredb -BackupRestore -SharedPath $NetworkPath 3>$null + Get-DbaProcess -SqlInstance $TestConfig.instance2, $TestConfig.instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue + $results = Copy-DbaDatabase -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -Database $backuprestoredb -BackupRestore -SharedPath $NetworkPath 3>$null It "copies a database successfully" { $results.Name -eq $backuprestoredb @@ -89,7 +89,7 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { } It "retains its name, recovery model, and status." { - $dbs = Get-DbaDatabase -SqlInstance $script:instance2, $script:instance3 -Database $backuprestoredb + $dbs = Get-DbaDatabase -SqlInstance $TestConfig.instance2, $TestConfig.instance3 -Database $backuprestoredb $dbs[0].Name -ne $null # Compare its variables $dbs[0].Name -eq $dbs[1].Name @@ -100,7 +100,7 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { # needs regr test that uses $backuprestoredb once #3377 is fixed It "Should say skipped" { - $result = Copy-DbaDatabase -Source $script:instance2 -Destination $script:instance3 -Database $backuprestoredb2 -BackupRestore -SharedPath $NetworkPath 3>$null + $result = Copy-DbaDatabase -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -Database $backuprestoredb2 -BackupRestore -SharedPath $NetworkPath 3>$null $result.Status | Should be "Skipped" $result.Notes | Should be "Already exists on destination" } @@ -109,26 +109,26 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { if (-not $env:appveyor) { It "Should overwrite when forced to" { #regr test for #3358 - $result = Copy-DbaDatabase -Source $script:instance2 -Destination $script:instance3 -Database $backuprestoredb2 -BackupRestore -SharedPath $NetworkPath -Force + $result = Copy-DbaDatabase -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -Database $backuprestoredb2 -BackupRestore -SharedPath $NetworkPath -Force $result.Status | Should be "Successful" } } } Context "UseLastBackup - read backup history" { BeforeAll { - Get-DbaProcess -SqlInstance $script:instance2, $script:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance3 -Database $backuprestoredb + Get-DbaProcess -SqlInstance $TestConfig.instance2, $TestConfig.instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue + Remove-DbaDatabase -Confirm:$false -SqlInstance $TestConfig.instance3 -Database $backuprestoredb } It "copies a database successfully using backup history" { # It should already have a backup history by this time - $results = Copy-DbaDatabase -Source $script:instance2 -Destination $script:instance3 -Database $backuprestoredb -BackupRestore -UseLastBackup 3>$null + $results = Copy-DbaDatabase -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -Database $backuprestoredb -BackupRestore -UseLastBackup 3>$null $results.Name -eq $backuprestoredb $results.Status -eq "Successful" } It "retains its name, recovery model, and status." { - $dbs = Get-DbaDatabase -SqlInstance $script:instance2, $script:instance3 -Database $backuprestoredb + $dbs = Get-DbaDatabase -SqlInstance $TestConfig.instance2, $TestConfig.instance3 -Database $backuprestoredb $dbs[0].Name -ne $null # Compare its variables $dbs[0].Name -eq $dbs[1].Name @@ -139,23 +139,23 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { } Context "UseLastBackup with -Continue" { BeforeAll { - Get-DbaProcess -SqlInstance $script:instance2, $script:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance3 -Database $backuprestoredb + Get-DbaProcess -SqlInstance $TestConfig.instance2, $TestConfig.instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue + Remove-DbaDatabase -Confirm:$false -SqlInstance $TestConfig.instance3 -Database $backuprestoredb #Pre-stage the restore - $null = Get-DbaDbBackupHistory -SqlInstance $script:instance2 -Database $backuprestoredb -LastFull | Restore-DbaDatabase -SqlInstance $script:instance3 -DatabaseName $backuprestoredb -NoRecovery 3>$null + $null = Get-DbaDbBackupHistory -SqlInstance $TestConfig.instance2 -Database $backuprestoredb -LastFull | Restore-DbaDatabase -SqlInstance $TestConfig.instance3 -DatabaseName $backuprestoredb -NoRecovery 3>$null #Run diff now - $null = Backup-DbaDatabase -SqlInstance $script:instance2 -Database $backuprestoredb -BackupDirectory $NetworkPath -Type Diff + $null = Backup-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $backuprestoredb -BackupDirectory $NetworkPath -Type Diff } It "continues the restore over existing database using backup history" { # It should already have a backup history (full+diff) by this time - $results = Copy-DbaDatabase -Source $script:instance2 -Destination $script:instance3 -Database $backuprestoredb -BackupRestore -UseLastBackup -Continue 3>$null + $results = Copy-DbaDatabase -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -Database $backuprestoredb -BackupRestore -UseLastBackup -Continue 3>$null $results.Name -eq $backuprestoredb $results.Status -eq "Successful" } It "retains its name, recovery model, and status." { - $dbs = Get-DbaDatabase -SqlInstance $script:instance2, $script:instance3 -Database $backuprestoredb + $dbs = Get-DbaDatabase -SqlInstance $TestConfig.instance2, $TestConfig.instance3 -Database $backuprestoredb $dbs[0].Name -ne $null # Compare its variables $dbs[0].Name -eq $dbs[1].Name @@ -166,99 +166,99 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { } Context "Copying with renames using backup/restore" { BeforeAll { - Get-DbaProcess -SqlInstance $script:instance2, $script:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue - Get-DbaDatabase -SqlInstance $script:instance3 -ExcludeSystem | Remove-DbaDatabase -Confirm:$false + Get-DbaProcess -SqlInstance $TestConfig.instance2, $TestConfig.instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue + Get-DbaDatabase -SqlInstance $TestConfig.instance3 -ExcludeSystem | Remove-DbaDatabase -Confirm:$false } AfterAll { - Get-DbaProcess -SqlInstance $script:instance2, $script:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue - Get-DbaDatabase -SqlInstance $script:instance3 -ExcludeSystem | Remove-DbaDatabase -Confirm:$false + Get-DbaProcess -SqlInstance $TestConfig.instance2, $TestConfig.instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue + Get-DbaDatabase -SqlInstance $TestConfig.instance3 -ExcludeSystem | Remove-DbaDatabase -Confirm:$false } It "Should have renamed a single db" { $newname = "copy$(Get-Random)" - $results = Copy-DbaDatabase -Source $script:instance2 -Destination $script:instance3 -Database $backuprestoredb -BackupRestore -SharedPath $NetworkPath -NewName $newname + $results = Copy-DbaDatabase -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -Database $backuprestoredb -BackupRestore -SharedPath $NetworkPath -NewName $newname $results[0].DestinationDatabase | Should -Be $newname - $files = Get-DbaDbFile -Sqlinstance $script:instance3 -Database $newname + $files = Get-DbaDbFile -Sqlinstance $TestConfig.instance3 -Database $newname ($files.PhysicalName -like "*$newname*").count | Should -Be $files.count } It "Should warn if trying to rename and prefix" { - $null = Copy-DbaDatabase -Source $script:instance2 -Destination $script:instance3 -Database $backuprestoredb -BackupRestore -SharedPath $NetworkPath -NewName $newname -prefix pre -WarningVariable warnvar 3> $null + $null = Copy-DbaDatabase -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -Database $backuprestoredb -BackupRestore -SharedPath $NetworkPath -NewName $newname -prefix pre -WarningVariable warnvar 3> $null $warnvar | Should -BeLike "*NewName and Prefix are exclusive options, cannot specify both" } It "Should prefix databasename and files" { $prefix = "da$(Get-Random)" - $results = Copy-DbaDatabase -Source $script:instance2 -Destination $script:instance3 -Database $backuprestoredb -BackupRestore -SharedPath $NetworkPath -Prefix $prefix + $results = Copy-DbaDatabase -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -Database $backuprestoredb -BackupRestore -SharedPath $NetworkPath -Prefix $prefix $results[0].DestinationDatabase | Should -Be "$prefix$backuprestoredb" - $files = Get-DbaDbFile -Sqlinstance $script:instance3 -Database "$prefix$backuprestoredb" + $files = Get-DbaDbFile -Sqlinstance $TestConfig.instance3 -Database "$prefix$backuprestoredb" ($files.PhysicalName -like "*$prefix$backuprestoredb*").count | Should -Be $files.count } } Context "Copying with renames using detachattach" { BeforeAll { - Get-DbaProcess -SqlInstance $script:instance2, $script:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance3 -Database $backuprestoredb + Get-DbaProcess -SqlInstance $TestConfig.instance2, $TestConfig.instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue + Remove-DbaDatabase -Confirm:$false -SqlInstance $TestConfig.instance3 -Database $backuprestoredb } It "Should have renamed a single db" { $newname = "copy$(Get-Random)" - $results = Copy-DbaDatabase -Source $script:instance2 -Destination $script:instance3 -Database $backuprestoredb -DetachAttach -NewName $newname -Reattach + $results = Copy-DbaDatabase -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -Database $backuprestoredb -DetachAttach -NewName $newname -Reattach $results[0].DestinationDatabase | Should -Be $newname - $files = Get-DbaDbFile -Sqlinstance $script:instance3 -Database $newname + $files = Get-DbaDbFile -Sqlinstance $TestConfig.instance3 -Database $newname ($files.PhysicalName -like "*$newname*").count | Should -Be $files.count - $null = Remove-DbaDatabase -SqlInstance $script:instance3 -Database $newname + $null = Remove-DbaDatabase -SqlInstance $TestConfig.instance3 -Database $newname } It "Should prefix databasename and files" { $prefix = "copy$(Get-Random)" - $results = Copy-DbaDatabase -Source $script:instance2 -Destination $script:instance3 -Database $backuprestoredb -DetachAttach -Reattach -Prefix $prefix + $results = Copy-DbaDatabase -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -Database $backuprestoredb -DetachAttach -Reattach -Prefix $prefix $results[0].DestinationDatabase | Should -Be "$prefix$backuprestoredb" - $files = Get-DbaDbFile -Sqlinstance $script:instance3 -Database "$prefix$backuprestoredb" + $files = Get-DbaDbFile -Sqlinstance $TestConfig.instance3 -Database "$prefix$backuprestoredb" ($files.PhysicalName -like "*$prefix$backuprestoredb*").count | Should -Be $files.count - $null = Remove-DbaDatabase -SqlInstance $script:instance3 -Database "$prefix$backuprestoredb" + $null = Remove-DbaDatabase -SqlInstance $TestConfig.instance3 -Database "$prefix$backuprestoredb" } - $null = Restore-DbaDatabase -SqlInstance $script:instance2 -path $script:appveyorlabrepo\RestoreTimeClean2016 -useDestinationDefaultDirectories + $null = Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -path "$($TestConfig.appveyorlabrepo)\RestoreTimeClean2016" -useDestinationDefaultDirectories It "Should warn and exit if newname and >1 db specified" { - $null = Copy-DbaDatabase -Source $script:instance2 -Destination $script:instance3 -Database $backuprestoredb, RestoreTimeClean -DetachAttach -Reattach -NewName warn -WarningVariable warnvar 3> $null + $null = Copy-DbaDatabase -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -Database $backuprestoredb, RestoreTimeClean -DetachAttach -Reattach -NewName warn -WarningVariable warnvar 3> $null $warnvar | Should -BeLike "*Cannot use NewName when copying multiple databases" - $null = Remove-DbaDatabase -SqlInstance $script:instance2 -Database RestoreTimeClean + $null = Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database RestoreTimeClean } } if ($env:azurepasswd) { Context "Copying via Azure storage" { BeforeAll { - Get-DbaProcess -SqlInstance $script:instance2, $script:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance3 -Database $backuprestoredb - $server = Connect-DbaInstance -SqlInstance $script:instance2 - $sql = "CREATE CREDENTIAL [$script:azureblob] WITH IDENTITY = N'SHARED ACCESS SIGNATURE', SECRET = N'$env:azurepasswd'" + Get-DbaProcess -SqlInstance $TestConfig.instance2, $TestConfig.instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue + Remove-DbaDatabase -Confirm:$false -SqlInstance $TestConfig.instance3 -Database $backuprestoredb + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 + $sql = "CREATE CREDENTIAL [$TestConfig.azureblob] WITH IDENTITY = N'SHARED ACCESS SIGNATURE', SECRET = N'$env:azurepasswd'" $server.Query($sql) - $sql = "CREATE CREDENTIAL [dbatools_ci] WITH IDENTITY = N'$script:azureblobaccount', SECRET = N'$env:azurelegacypasswd'" + $sql = "CREATE CREDENTIAL [dbatools_ci] WITH IDENTITY = N'$TestConfig.azureblobaccount', SECRET = N'$env:azurelegacypasswd'" $server.Query($sql) - $server3 = Connect-DbaInstance -SqlInstance $script:instance3 - $sql = "CREATE CREDENTIAL [$script:azureblob] WITH IDENTITY = N'SHARED ACCESS SIGNATURE', SECRET = N'$env:azurepasswd'" + $server3 = Connect-DbaInstance -SqlInstance $TestConfig.instance3 + $sql = "CREATE CREDENTIAL [$TestConfig.azureblob] WITH IDENTITY = N'SHARED ACCESS SIGNATURE', SECRET = N'$env:azurepasswd'" $server3.Query($sql) - $sql = "CREATE CREDENTIAL [dbatools_ci] WITH IDENTITY = N'$script:azureblobaccount', SECRET = N'$env:azurelegacypasswd'" + $sql = "CREATE CREDENTIAL [dbatools_ci] WITH IDENTITY = N'$TestConfig.azureblobaccount', SECRET = N'$env:azurelegacypasswd'" $server3.Query($sql) } AfterAll { - Get-DbaDatabase -SqlInstance $script:instance3 -Database $backuprestoredb | Remove-DbaDatabase -Confirm:$false - $server = Connect-DbaInstance -SqlInstance $script:instance2 - $server.Query("DROP CREDENTIAL [$script:azureblob]") + Get-DbaDatabase -SqlInstance $TestConfig.instance3 -Database $backuprestoredb | Remove-DbaDatabase -Confirm:$false + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 + $server.Query("DROP CREDENTIAL [$TestConfig.azureblob]") $server.Query("DROP CREDENTIAL dbatools_ci") - $server = Connect-DbaInstance -SqlInstance $script:instance3 - $server.Query("DROP CREDENTIAL [$script:azureblob]") + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance3 + $server.Query("DROP CREDENTIAL [$TestConfig.azureblob]") $server.Query("DROP CREDENTIAL dbatools_ci") } - $results = Copy-DbaDatabase -source $script:instance2 -Destination $script:instance3 -Database $backuprestoredb -BackupRestore -SharedPath $script:azureblob -AzureCredential dbatools_ci + $results = Copy-DbaDatabase -source $TestConfig.instance2 -Destination $TestConfig.instance3 -Database $backuprestoredb -BackupRestore -SharedPath $TestConfig.azureblob -AzureCredential dbatools_ci It "Should Copy $backuprestoredb via Azure legacy credentials" { $results[0].Name | Should -Be $backuprestoredb $results[0].Status | Should -BeLike 'Successful*' } # Because I think the backup are tripping over each other with the names Start-Sleep -Seconds 60 - $results = Copy-DbaDatabase -source $script:instance2 -Destination $script:instance3 -Database $backuprestoredb -Newname djkhgfkjghfdjgd -BackupRestore -SharedPath $script:azureblob + $results = Copy-DbaDatabase -source $TestConfig.instance2 -Destination $TestConfig.instance3 -Database $backuprestoredb -Newname djkhgfkjghfdjgd -BackupRestore -SharedPath $TestConfig.azureblob It "Should Copy $backuprestoredb via Azure new credentials" { $results[0].Name | Should -Be $backuprestoredb $results[0].DestinationDatabase | Should -Be 'djkhgfkjghfdjgd' @@ -267,3 +267,4 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { } } } + diff --git a/tests/Copy-DbaDbAssembly.Tests.ps1 b/tests/Copy-DbaDbAssembly.Tests.ps1 index f0efe59544..d8d84a17ee 100644 --- a/tests/Copy-DbaDbAssembly.Tests.ps1 +++ b/tests/Copy-DbaDbAssembly.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,17 +15,17 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $server3 = Connect-DbaInstance -SqlInstance $script:instance3 + $server3 = Connect-DbaInstance -SqlInstance $TestConfig.instance3 $server3.Query("CREATE DATABASE dbclrassembly") $server3.Query("EXEC sp_configure 'CLR ENABLED' , '1'") $server3.Query("RECONFIGURE") - $server2 = Connect-DbaInstance -SqlInstance $script:instance2 + $server2 = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $server2.Query("CREATE DATABASE dbclrassembly") $server2.Query("EXEC sp_configure 'CLR ENABLED' , '1'") $server2.Query("RECONFIGURE") - $instance2DB = Get-DbaDatabase -SqlInstance $script:instance2 -Database dbclrassembly + $instance2DB = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database dbclrassembly $instance2DB.Query("CREATE ASSEMBLY [resolveDNS] AUTHORIZATION [dbo] FROM 0x4D5A90000300000004000000FFFF0000B800000000000000400000000000000000000000000000000000000000000000000000000000000000000000800000000E1FBA0E00B409CD21B8014CCD21546869732070726F6772616D2063616E6E6F742062652072756E20696E20444F53206D6F64652E0D0D0A2400000000000000504500004C010300457830570000000000000000E00002210B010B000008000000060000000000002E260000002000000040000000000010002000000002000004000000000000000400000000000000008000000002000000000000030040850000100000100000000010000010000000000000100000000000000000000000E02500004B00000000400000B002000000000000000000000000000000000000006000000C000000A82400001C0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000080000000000000000000000082000004800000000000000000000002E7465787400000034060000002000000008000000020000000000000000000000000000200000602E72737263000000B00200000040000000040000000A0000000000000000000000000000400000402E72656C6F6300000C0000000060000000020000000E0000000000000000000000000000400000420000000000000000000000000000000010260000000000004800000002000500A42000000404000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001B3001002F000000010000110000026F0500000A280600000A6F0700000A6F0800000A0A06730900000A0BDE0B260002730900000A0BDE0000072A0001100000000001002021000B010000011E02280A00000A2A42534A4201000100000000000C00000076322E302E35303732370000000005006C00000070010000237E0000DC010000A401000023537472696E67730000000080030000080000002355530088030000100000002347554944000000980300006C00000023426C6F620000000000000002000001471502000900000000FA253300160000010000000A0000000200000002000000010000000A0000000400000001000000010000000300000000000A0001000000000006003E0037000A006600510006009D008A000F00B10000000600E000C00006000001C0000A00440129010600590137000E00700165010E007401650100000000010000000000010001000100100019000000050001000100502000000000960070000A0001009C200000000086187D001000020000000100830019007D00140029007D001A0031007D00100039007D00100041006001240049008001280051008D01240009009A01240011007D002E0009007D001000200023001F002E000B0039002E00130042002E001B004B0033000480000000000000000000000000000000001E01000002000000000000000000000001002E00000000000200000000000000000000000100450000000000020000000000000000000000010037000000000000000000003C4D6F64756C653E007265736F6C7665444E532E646C6C0055736572446566696E656446756E6374696F6E73006D73636F726C69620053797374656D004F626A6563740053797374656D2E446174610053797374656D2E446174612E53716C54797065730053716C537472696E67004950746F486F73744E616D65002E63746F72006970616464720053797374656D2E446961676E6F73746963730044656275676761626C6541747472696275746500446562756767696E674D6F6465730053797374656D2E52756E74696D652E436F6D70696C6572536572766963657300436F6D70696C6174696F6E52656C61786174696F6E734174747269627574650052756E74696D65436F6D7061746962696C697479417474726962757465007265736F6C7665444E53004D6963726F736F66742E53716C5365727665722E5365727665720053716C46756E6374696F6E41747472696275746500537472696E67005472696D0053797374656D2E4E657400446E73004950486F7374456E74727900476574486F7374456E747279006765745F486F73744E616D6500546F537472696E6700000003200000000000BBBB2D2F51E12E4791398BFA79459ABA0008B77A5C561934E08905000111090E03200001052001011111042001010804010000000320000E05000112290E042001010E0507020E11090801000701000000000801000800000000001E01000100540216577261704E6F6E457863657074696F6E5468726F7773010000000000004578305700000000020000001C010000C4240000C40600005253445357549849C5462E43AD588F97CA53634201000000633A5C74656D705C4461746162617365315C4461746162617365315C6F626A5C44656275675C7265736F6C7665444E532E706462000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000826000000000000000000001E260000002000000000000000000000000000000000000000000000102600000000000000005F436F72446C6C4D61696E006D73636F7265652E646C6C0000000000FF25002000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100100000001800008000000000000000000000000000000100010000003000008000000000000000000000000000000100000000004800000058400000540200000000000000000000540234000000560053005F00560045005200530049004F004E005F0049004E0046004F0000000000BD04EFFE00000100000000000000000000000000000000003F000000000000000400000002000000000000000000000000000000440000000100560061007200460069006C00650049006E0066006F00000000002400040000005400720061006E0073006C006100740069006F006E00000000000000B004B4010000010053007400720069006E006700460069006C00650049006E0066006F0000009001000001003000300030003000300034006200300000002C0002000100460069006C0065004400650073006300720069007000740069006F006E000000000020000000300008000100460069006C006500560065007200730069006F006E000000000030002E0030002E0030002E003000000040000F00010049006E007400650072006E0061006C004E0061006D00650000007200650073006F006C007600650044004E0053002E0064006C006C00000000002800020001004C006500670061006C0043006F00700079007200690067006800740000002000000048000F0001004F0072006900670069006E0061006C00460069006C0065006E0061006D00650000007200650073006F006C007600650044004E0053002E0064006C006C0000000000340008000100500072006F006400750063007400560065007200730069006F006E00000030002E0030002E0030002E003000000038000800010041007300730065006D0062006C0079002000560065007200730069006F006E00000030002E0030002E0030002E003000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000C000000303600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000") $hash = $instance2DB.Query("SELECT HASHBYTES('SHA2_512', content) AS SHA2_512 FROM sys.assembly_files WHERE name = 'resolveDNS'") @@ -40,7 +40,7 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { , @description = @assemblyName") } AfterAll { - Get-DbaDatabase -SqlInstance $script:instance2, $script:instance3 -Database dbclrassembly | Remove-DbaDatabase -Confirm:$false + Get-DbaDatabase -SqlInstance $TestConfig.instance2, $TestConfig.instance3 -Database dbclrassembly | Remove-DbaDatabase -Confirm:$false $server3.Query(" DECLARE @hash VARBINARY(64) = $hexStr @@ -53,29 +53,29 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { } It "copies the sample database assembly" { - $results = Copy-DbaDbAssembly -Source $script:instance2 -Destination $script:instance3 -Assembly dbclrassembly.resolveDNS + $results = Copy-DbaDbAssembly -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -Assembly dbclrassembly.resolveDNS $results.Name | Should -Be resolveDns $results.Status | Should -Be Successful $results.Type | Should -Be "Database Assembly" - $results.SourceDatabaseID | Should -Be (Get-DbaDatabase -SqlInstance $script:instance2 -Database dbclrassembly).ID - $results.DestinationDatabaseID | Should -Be (Get-DbaDatabase -SqlInstance $script:instance3 -Database dbclrassembly).ID + $results.SourceDatabaseID | Should -Be (Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database dbclrassembly).ID + $results.DestinationDatabaseID | Should -Be (Get-DbaDatabase -SqlInstance $TestConfig.instance3 -Database dbclrassembly).ID } It "excludes an assembly" { - $results = Copy-DbaDbAssembly -Source $script:instance2 -Destination $script:instance3 -Assembly dbclrassembly.resolveDNS -ExcludeAssembly dbclrassembly.resolveDNS + $results = Copy-DbaDbAssembly -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -Assembly dbclrassembly.resolveDNS -ExcludeAssembly dbclrassembly.resolveDNS $results | Should -BeNullOrEmpty } It "forces a drop/create of the assembly in the target server" { - $results = Copy-DbaDbAssembly -Source $script:instance2 -Destination $script:instance3 -Assembly dbclrassembly.resolveDNS + $results = Copy-DbaDbAssembly -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -Assembly dbclrassembly.resolveDNS $results.Status | Should -Be Skipped $results.Notes | Should -Be "Already exists on destination" - $results = Copy-DbaDbAssembly -Source $script:instance2 -Destination $script:instance3 -Assembly dbclrassembly.resolveDNS -Force + $results = Copy-DbaDbAssembly -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -Assembly dbclrassembly.resolveDNS -Force $results.Name | Should -Be resolveDns $results.Status | Should -Be Successful $results.Type | Should -Be "Database Assembly" - $results.SourceDatabaseID | Should -Be (Get-DbaDatabase -SqlInstance $script:instance2 -Database dbclrassembly).ID - $results.DestinationDatabaseID | Should -Be (Get-DbaDatabase -SqlInstance $script:instance3 -Database dbclrassembly).ID + $results.SourceDatabaseID | Should -Be (Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database dbclrassembly).ID + $results.DestinationDatabaseID | Should -Be (Get-DbaDatabase -SqlInstance $TestConfig.instance3 -Database dbclrassembly).ID } -} \ No newline at end of file +} diff --git a/tests/Copy-DbaDbCertificate.Tests.ps1 b/tests/Copy-DbaDbCertificate.Tests.ps1 index 8909f2cee4..7fd3634d71 100644 --- a/tests/Copy-DbaDbCertificate.Tests.ps1 +++ b/tests/Copy-DbaDbCertificate.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -17,12 +17,12 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Can create a database certificate" { BeforeAll { $passwd = $(ConvertTo-SecureString -String "GoodPass1234!" -AsPlainText -Force) - $masterkey = New-DbaDbMasterKey -SqlInstance $script:instance2 -Database master -SecurePassword $passwd -Confirm:$false -ErrorAction SilentlyContinue + $masterkey = New-DbaDbMasterKey -SqlInstance $TestConfig.instance2 -Database master -SecurePassword $passwd -Confirm:$false -ErrorAction SilentlyContinue - $newdbs = New-DbaDatabase -SqlInstance $script:instance2, $script:instance3 -Name dbatoolscopycred - $null = New-DbaDbMasterKey -SqlInstance $script:instance2 -Database dbatoolscopycred -SecurePassword $passwd -Confirm:$false + $newdbs = New-DbaDatabase -SqlInstance $TestConfig.instance2, $TestConfig.instance3 -Name dbatoolscopycred + $null = New-DbaDbMasterKey -SqlInstance $TestConfig.instance2 -Database dbatoolscopycred -SecurePassword $passwd -Confirm:$false $certificateName2 = "Cert_$(Get-Random)" - $null = New-DbaDbCertificate -SqlInstance $script:instance2 -Name $certificateName2 -Database dbatoolscopycred -Confirm:$false + $null = New-DbaDbCertificate -SqlInstance $TestConfig.instance2 -Name $certificateName2 -Database dbatoolscopycred -Confirm:$false } AfterAll { $null = $newdbs | Remove-DbaDatabase -Confirm:$false -ErrorAction SilentlyContinue @@ -34,20 +34,20 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { It -Skip "Successfully copies a certificate" { $passwd = $(ConvertTo-SecureString -String "GoodPass1234!" -AsPlainText -Force) $paramscopydb = @{ - Source = $script:instance2 - Destination = $script:instance3 + Source = $TestConfig.instance2 + Destination = $TestConfig.instance3 EncryptionPassword = $passwd MasterKeyPassword = $passwd Database = "dbatoolscopycred" - SharedPath = $script:appveyorlabrepo + SharedPath = $($TestConfig.appveyorlabrepo) } $results = Copy-DbaDbCertificate @paramscopydb -Confirm:$false | Where-Object SourceDatabase -eq dbatoolscopycred | Select-Object -First 1 $results.Notes | Should -Be $null $results.Status | Should -Be "Successful" - $results.SourceDatabaseID | Should -Be (Get-DbaDatabase -SqlInstance $script:instance2 -Database dbatoolscopycred).ID - $results.DestinationDatabaseID | Should -Be (Get-DbaDatabase -SqlInstance $script:instance3 -Database dbatoolscopycred).ID + $results.SourceDatabaseID | Should -Be (Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database dbatoolscopycred).ID + $results.DestinationDatabaseID | Should -Be (Get-DbaDatabase -SqlInstance $TestConfig.instance3 -Database dbatoolscopycred).ID - Get-DbaDbCertificate -SqlInstance $script:instance3 -Database dbatoolscopycred -Certificate $certificateName2 | Should -Not -BeNullOrEmpty + Get-DbaDbCertificate -SqlInstance $TestConfig.instance3 -Database dbatoolscopycred -Certificate $certificateName2 | Should -Not -BeNullOrEmpty } } -} \ No newline at end of file +} diff --git a/tests/Copy-DbaDbMail.Tests.ps1 b/tests/Copy-DbaDbMail.Tests.ps1 index 2b282dc4f4..494007e91e 100644 --- a/tests/Copy-DbaDbMail.Tests.ps1 +++ b/tests/Copy-DbaDbMail.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,7 +15,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $servers = Connect-DbaInstance -SqlInstance $script:instance2, $script:instance3 + $servers = Connect-DbaInstance -SqlInstance $TestConfig.instance2, $TestConfig.instance3 foreach ($s in $servers) { if ( (Get-DbaSpConfigure -SqlInstance $s -Name 'Database Mail XPs').RunningValue -ne 1 ) { Set-DbaSpConfigure -SqlInstance $s -Name 'Database Mail XPs' -Value 1 @@ -35,7 +35,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $splat1 = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 Name = $accountName Description = $account_description EmailAddress = $email_address @@ -46,7 +46,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $null = New-DbaDbMailAccount @splat1 -Force $splat2 = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 Name = $profilename Description = $profile_description MailAccountName = $email_address @@ -56,7 +56,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } AfterAll { - $servers = Connect-DbaInstance -SqlInstance $script:instance2, $script:instance3 + $servers = Connect-DbaInstance -SqlInstance $TestConfig.instance2, $TestConfig.instance3 foreach ($s in $servers) { $mailAccountSettings = "EXEC msdb.dbo.sysmail_delete_account_sp @account_name = '$accountname';" @@ -67,40 +67,40 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } } - Context "Copy DbMail to $script:instance3" { - $results = Copy-DbaDbMail -Source $script:instance2 -Destination $script:instance3 + Context "Copy DbMail to $($TestConfig.instance3)" { + $results = Copy-DbaDbMail -Source $TestConfig.instance2 -Destination $TestConfig.instance3 It "Should have copied database mailitems" { $results | Should Not Be $null } foreach ($r in $results) { if ($r.type -in @('Mail Configuration', 'Mail Account', 'Mail Profile')) { - It "Should have copied $($r.type) from $script:instance2" { - $r.SourceServer | Should Be "$script:instance2" + It "Should have copied $($r.type) from $($TestConfig.instance2)" { + $r.SourceServer | Should Be $TestConfig.instance2 } - It "Should have copied $($r.type) to $script:instance3" { - $r.DestinationServer | Should Be "$script:instance3" + It "Should have copied $($r.type) to $($TestConfig.instance3)" { + $r.DestinationServer | Should Be $TestConfig.instance3 } } } } Context "Copy MailServers specifically" { - $results = Copy-DbaDbMail -Source $script:instance2 -Destination $script:instance3 -Type MailServers + $results = Copy-DbaDbMail -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -Type MailServers It "Should have copied database mailitems" { $results | Should Not Be $null } foreach ($r in $results) { - It "Should have $($r.status) $($r.type) from $script:instance2" { - $r.SourceServer | Should Be "$script:instance2" + It "Should have $($r.status) $($r.type) from $($TestConfig.instance2)" { + $r.SourceServer | Should Be $TestConfig.instance2 $r.status | Should Be 'Skipped' } - It "Should have $($r.status) $($r.type) to $script:instance3" { - $r.DestinationServer | Should Be "$script:instance3" + It "Should have $($r.status) $($r.type) to $($TestConfig.instance3)" { + $r.DestinationServer | Should Be $TestConfig.instance3 $r.status | Should Be 'Skipped' } } } -} \ No newline at end of file +} diff --git a/tests/Copy-DbaDbQueryStoreOption.Tests.ps1 b/tests/Copy-DbaDbQueryStoreOption.Tests.ps1 index 3ae73a5444..a75b2782cf 100644 --- a/tests/Copy-DbaDbQueryStoreOption.Tests.ps1 +++ b/tests/Copy-DbaDbQueryStoreOption.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,7 +16,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Verifying query store options are copied" { BeforeAll { - $server2 = Connect-DbaInstance -SqlInstance $script:instance2 + $server2 = Connect-DbaInstance -SqlInstance $TestConfig.instance2 } BeforeEach { $db1Name = "dbatoolsci_querystoretest1" @@ -83,4 +83,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $db4QSOptions.DataFlushIntervalInSeconds | Should -Be $originalQSOptionValue } } -} \ No newline at end of file +} diff --git a/tests/Copy-DbaDbTableData.Tests.ps1 b/tests/Copy-DbaDbTableData.Tests.ps1 index d864cfb16f..4f4b0aedee 100644 --- a/tests/Copy-DbaDbTableData.Tests.ps1 +++ b/tests/Copy-DbaDbTableData.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,8 +15,8 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { } Describe "$commandname Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $db = Get-DbaDatabase -SqlInstance $script:instance1 -Database tempdb - $db2 = Get-DbaDatabase -SqlInstance $script:instance2 -Database tempdb + $db = Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database tempdb + $db2 = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database tempdb $null = $db.Query("CREATE TABLE dbo.dbatoolsci_example (id int); INSERT dbo.dbatoolsci_example SELECT top 10 1 @@ -51,7 +51,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } Context "Data movement" { It "copies the table data" { - $results = Copy-DbaDbTableData -SqlInstance $script:instance1 -Database tempdb -Table dbatoolsci_example -DestinationTable dbatoolsci_example2 + $results = Copy-DbaDbTableData -SqlInstance $TestConfig.instance1 -Database tempdb -Table dbatoolsci_example -DestinationTable dbatoolsci_example2 $table1count = $db.Query("select id from dbo.dbatoolsci_example") $table2count = $db.Query("select id from dbo.dbatoolsci_example2") $table1count.Count | Should -Be $table2count.Count @@ -60,39 +60,39 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } It "copies the table data to another instance" { - $null = Copy-DbaDbTableData -SqlInstance $script:instance1 -Destination $script:instance2 -Database tempdb -Table tempdb.dbo.dbatoolsci_example -DestinationTable dbatoolsci_example3 + $null = Copy-DbaDbTableData -SqlInstance $TestConfig.instance1 -Destination $TestConfig.instance2 -Database tempdb -Table tempdb.dbo.dbatoolsci_example -DestinationTable dbatoolsci_example3 $table1count = $db.Query("select id from dbo.dbatoolsci_example") $table2count = $db2.Query("select id from dbo.dbatoolsci_example3") $table1count.Count | Should -Be $table2count.Count } It "Copy data using a query that relies on the default source database" { - $result = Copy-DbaDbTableData -SqlInstance $script:instance2 -Database tempdb -Table dbo.dbatoolsci_example4 -Query "SELECT TOP (1) Id FROM dbo.dbatoolsci_example4 ORDER BY Id DESC" -DestinationTable dbatoolsci_example3 -Truncate + $result = Copy-DbaDbTableData -SqlInstance $TestConfig.instance2 -Database tempdb -Table dbo.dbatoolsci_example4 -Query "SELECT TOP (1) Id FROM dbo.dbatoolsci_example4 ORDER BY Id DESC" -DestinationTable dbatoolsci_example3 -Truncate $result.RowsCopied | Should -Be 1 } It "Copy data using a query that uses a 3 part query" { - $result = Copy-DbaDbTableData -SqlInstance $script:instance2 -Database tempdb -Table dbo.dbatoolsci_example4 -Query "SELECT TOP (1) Id FROM tempdb.dbo.dbatoolsci_example4 ORDER BY Id DESC" -DestinationTable dbatoolsci_example3 -Truncate + $result = Copy-DbaDbTableData -SqlInstance $TestConfig.instance2 -Database tempdb -Table dbo.dbatoolsci_example4 -Query "SELECT TOP (1) Id FROM tempdb.dbo.dbatoolsci_example4 ORDER BY Id DESC" -DestinationTable dbatoolsci_example3 -Truncate $result.RowsCopied | Should -Be 1 } } Context "Functionality checks" { It "supports piping" { - $null = Get-DbaDbTable -SqlInstance $script:instance1 -Database tempdb -Table dbatoolsci_example | Copy-DbaDbTableData -DestinationTable dbatoolsci_example2 -Truncate + $null = Get-DbaDbTable -SqlInstance $TestConfig.instance1 -Database tempdb -Table dbatoolsci_example | Copy-DbaDbTableData -DestinationTable dbatoolsci_example2 -Truncate $table1count = $db.Query("select id from dbo.dbatoolsci_example") $table2count = $db.Query("select id from dbo.dbatoolsci_example2") $table1count.Count | Should -Be $table2count.Count } It "supports piping more than one table" { - $results = Get-DbaDbTable -SqlInstance $script:instance1 -Database tempdb -Table dbatoolsci_example2, dbatoolsci_example | Copy-DbaDbTableData -DestinationTable dbatoolsci_example3 + $results = Get-DbaDbTable -SqlInstance $TestConfig.instance1 -Database tempdb -Table dbatoolsci_example2, dbatoolsci_example | Copy-DbaDbTableData -DestinationTable dbatoolsci_example3 $results.Count | Should -Be 2 $results.RowsCopied | Measure-Object -Sum | Select-Object -Expand Sum | Should -Be 20 } It "opens and closes connections properly" { #regression test, see #3468 - $results = Get-DbaDbTable -SqlInstance $script:instance1 -Database tempdb -Table 'dbo.dbatoolsci_example', 'dbo.dbatoolsci_example4' | Copy-DbaDbTableData -Destination $script:instance2 -DestinationDatabase tempdb -KeepIdentity -KeepNulls -BatchSize 5000 -Truncate + $results = Get-DbaDbTable -SqlInstance $TestConfig.instance1 -Database tempdb -Table 'dbo.dbatoolsci_example', 'dbo.dbatoolsci_example4' | Copy-DbaDbTableData -Destination $TestConfig.instance2 -DestinationDatabase tempdb -KeepIdentity -KeepNulls -BatchSize 5000 -Truncate $results.Count | Should -Be 2 $table1DbCount = $db.Query("select id from dbo.dbatoolsci_example") $table4DbCount = $db2.Query("select id from dbo.dbatoolsci_example4") @@ -107,25 +107,25 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } It "Should return nothing if Source and Destination are same" { - $result = Copy-DbaDbTableData -SqlInstance $script:instance1 -Database tempdb -Table dbatoolsci_example -Truncate + $result = Copy-DbaDbTableData -SqlInstance $TestConfig.instance1 -Database tempdb -Table dbatoolsci_example -Truncate $result | Should -Be $null } It "Should warn if the destinaton table doesn't exist" { - $result = Copy-DbaDbTableData -SqlInstance $script:instance1 -Database tempdb -Table dbatoolsci_example -DestinationTable dbatoolsci_doesntexist -WarningVariable tablewarning 3> $null + $result = Copy-DbaDbTableData -SqlInstance $TestConfig.instance1 -Database tempdb -Table dbatoolsci_example -DestinationTable dbatoolsci_doesntexist -WarningVariable tablewarning 3> $null $result | Should -Be $null $tablewarning | Should -Match Auto } It "automatically creates the table" { - $result = Copy-DbaDbTableData -SqlInstance $script:instance1 -Database tempdb -Table dbatoolsci_example -DestinationTable dbatoolsci_willexist -AutoCreateTable + $result = Copy-DbaDbTableData -SqlInstance $TestConfig.instance1 -Database tempdb -Table dbatoolsci_example -DestinationTable dbatoolsci_willexist -AutoCreateTable $result.DestinationTable | Should -Be 'dbatoolsci_willexist' } It "Should warn if the source database doesn't exist" { - $result = Copy-DbaDbTableData -SqlInstance $script:instance2 -Database tempdb_invalid -Table dbatoolsci_example -DestinationTable dbatoolsci_doesntexist -WarningVariable tablewarning 3> $null + $result = Copy-DbaDbTableData -SqlInstance $TestConfig.instance2 -Database tempdb_invalid -Table dbatoolsci_example -DestinationTable dbatoolsci_doesntexist -WarningVariable tablewarning 3> $null $result | Should -Be $null $tablewarning | Should -Match "cannot open database" } } -} \ No newline at end of file +} diff --git a/tests/Copy-DbaDbViewData.Tests.ps1 b/tests/Copy-DbaDbViewData.Tests.ps1 index 9e4e641814..4d78215b69 100644 --- a/tests/Copy-DbaDbViewData.Tests.ps1 +++ b/tests/Copy-DbaDbViewData.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -42,8 +42,8 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Remove-TempObject $d dbo.dbatoolsci_view_example4_table } } - $db = Get-DbaDatabase -SqlInstance $script:instance1 -Database tempdb - $db2 = Get-DbaDatabase -SqlInstance $script:instance2 -Database tempdb + $db = Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database tempdb + $db2 = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database tempdb Remove-TempObjects $db, $db2 $null = $db.Query("CREATE TABLE dbo.dbatoolsci_example (id int); INSERT dbo.dbatoolsci_example @@ -71,35 +71,35 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } It "copies the view data" { - $null = Copy-DbaDbViewData -SqlInstance $script:instance1 -Database tempdb -View dbatoolsci_view_example -DestinationTable dbatoolsci_example2 + $null = Copy-DbaDbViewData -SqlInstance $TestConfig.instance1 -Database tempdb -View dbatoolsci_view_example -DestinationTable dbatoolsci_example2 $table1count = $db.Query("select id from dbo.dbatoolsci_view_example") $table2count = $db.Query("select id from dbo.dbatoolsci_example2") $table1count.Count | Should -Be $table2count.Count } It "copies the view data to another instance" { - $null = Copy-DbaDbViewData -SqlInstance $script:instance1 -Destination $script:instance2 -Database tempdb -View dbatoolsci_view_example -DestinationTable dbatoolsci_view_example3 + $null = Copy-DbaDbViewData -SqlInstance $TestConfig.instance1 -Destination $TestConfig.instance2 -Database tempdb -View dbatoolsci_view_example -DestinationTable dbatoolsci_view_example3 $table1count = $db.Query("select id from dbo.dbatoolsci_view_example") $table2count = $db2.Query("select id from dbo.dbatoolsci_view_example3") $table1count.Count | Should -Be $table2count.Count } It "supports piping" { - $null = Get-DbaDbView -SqlInstance $script:instance1 -Database tempdb -View dbatoolsci_view_example | Copy-DbaDbViewData -DestinationTable dbatoolsci_example2 -Truncate + $null = Get-DbaDbView -SqlInstance $TestConfig.instance1 -Database tempdb -View dbatoolsci_view_example | Copy-DbaDbViewData -DestinationTable dbatoolsci_example2 -Truncate $table1count = $db.Query("select id from dbo.dbatoolsci_view_example") $table2count = $db.Query("select id from dbo.dbatoolsci_example2") $table1count.Count | Should -Be $table2count.Count } It "supports piping more than one view" { - $results = Get-DbaDbView -SqlInstance $script:instance1 -Database tempdb -View dbatoolsci_view_example2, dbatoolsci_view_example | Copy-DbaDbViewData -DestinationTable dbatoolsci_example3 + $results = Get-DbaDbView -SqlInstance $TestConfig.instance1 -Database tempdb -View dbatoolsci_view_example2, dbatoolsci_view_example | Copy-DbaDbViewData -DestinationTable dbatoolsci_example3 $results.Count | Should -Be 2 $results.RowsCopied | Measure-Object -Sum | Select -Expand Sum | Should -Be 20 } It "opens and closes connections properly" { #regression test, see #3468 - $results = Get-DbaDbView -SqlInstance $script:instance1 -Database tempdb -View 'dbo.dbatoolsci_view_example', 'dbo.dbatoolsci_view_example4' | Copy-DbaDbViewData -Destination $script:instance2 -DestinationDatabase tempdb -KeepIdentity -KeepNulls -BatchSize 5000 -Truncate + $results = Get-DbaDbView -SqlInstance $TestConfig.instance1 -Database tempdb -View 'dbo.dbatoolsci_view_example', 'dbo.dbatoolsci_view_example4' | Copy-DbaDbViewData -Destination $TestConfig.instance2 -DestinationDatabase tempdb -KeepIdentity -KeepNulls -BatchSize 5000 -Truncate $results.Count | Should -Be 2 $table1dbcount = $db.Query("select id from dbo.dbatoolsci_view_example") $table4dbcount = $db2.Query("select id from dbo.dbatoolsci_view_example4") @@ -114,35 +114,35 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } It "Should warn and return nothing if Source and Destination are same" { - $result = Copy-DbaDbViewData -SqlInstance $script:instance1 -Database tempdb -View dbatoolsci_view_example -Truncate -WarningVariable tablewarning 3> $null + $result = Copy-DbaDbViewData -SqlInstance $TestConfig.instance1 -Database tempdb -View dbatoolsci_view_example -Truncate -WarningVariable tablewarning 3> $null $result | Should -Be $null $tablewarning | Should -match "Cannot copy dbatoolsci_view_example into itself" } It "Should warn if the destination table doesn't exist" { - $result = Copy-DbaDbViewData -SqlInstance $script:instance1 -Database tempdb -View tempdb.dbo.dbatoolsci_view_example -DestinationTable dbatoolsci_view_does_not_exist -WarningVariable tablewarning 3> $null + $result = Copy-DbaDbViewData -SqlInstance $TestConfig.instance1 -Database tempdb -View tempdb.dbo.dbatoolsci_view_example -DestinationTable dbatoolsci_view_does_not_exist -WarningVariable tablewarning 3> $null $result | Should -Be $null $tablewarning | Should -match Auto } It "automatically creates the table" { - $result = Copy-DbaDbViewData -SqlInstance $script:instance1 -Database tempdb -View dbatoolsci_view_example -DestinationTable dbatoolsci_view_will_exist -AutoCreateTable + $result = Copy-DbaDbViewData -SqlInstance $TestConfig.instance1 -Database tempdb -View dbatoolsci_view_example -DestinationTable dbatoolsci_view_will_exist -AutoCreateTable $result.DestinationTable | Should -Be 'dbatoolsci_view_will_exist' } It "Should warn if the source database doesn't exist" { - $result = Copy-DbaDbViewData -SqlInstance $script:instance2 -Database tempdb_invalid -View dbatoolsci_view_example -DestinationTable dbatoolsci_doesntexist -WarningVariable tablewarning 3> $null + $result = Copy-DbaDbViewData -SqlInstance $TestConfig.instance2 -Database tempdb_invalid -View dbatoolsci_view_example -DestinationTable dbatoolsci_doesntexist -WarningVariable tablewarning 3> $null $result | Should -Be $null $tablewarning | Should -match "Failure" } It "Copy data using a query that relies on the default source database" { - $result = Copy-DbaDbViewData -SqlInstance $script:instance1 -Database tempdb -View dbatoolsci_view_example -Query "SELECT TOP (1) Id FROM dbo.dbatoolsci_view_example4 ORDER BY Id DESC" -DestinationTable dbatoolsci_example3 -Truncate + $result = Copy-DbaDbViewData -SqlInstance $TestConfig.instance1 -Database tempdb -View dbatoolsci_view_example -Query "SELECT TOP (1) Id FROM dbo.dbatoolsci_view_example4 ORDER BY Id DESC" -DestinationTable dbatoolsci_example3 -Truncate $result.RowsCopied | Should -Be 1 } It "Copy data using a query that uses a 3 part query" { - $result = Copy-DbaDbViewData -SqlInstance $script:instance1 -Database tempdb -View dbatoolsci_view_example -Query "SELECT TOP (1) Id FROM tempdb.dbo.dbatoolsci_view_example4 ORDER BY Id DESC" -DestinationTable dbatoolsci_example3 -Truncate + $result = Copy-DbaDbViewData -SqlInstance $TestConfig.instance1 -Database tempdb -View dbatoolsci_view_example -Query "SELECT TOP (1) Id FROM tempdb.dbo.dbatoolsci_view_example4 ORDER BY Id DESC" -DestinationTable dbatoolsci_example3 -Truncate $result.RowsCopied | Should -Be 1 } -} \ No newline at end of file +} diff --git a/tests/Copy-DbaEndpoint.Tests.ps1 b/tests/Copy-DbaEndpoint.Tests.ps1 index 19ad45eb6d..66e582f39f 100644 --- a/tests/Copy-DbaEndpoint.Tests.ps1 +++ b/tests/Copy-DbaEndpoint.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -20,22 +20,21 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $endpoint = Get-DbaEndpoint -SqlInstance $script:instance2 | Where-Object EndpointType -eq DatabaseMirroring - $create = $endpoint | Export-DbaScript -Passthru - $null = $endpoint | Remove-DbaEndpoint -Confirm:$false - $results = New-DbaEndpoint -SqlInstance $script:instance2 -Type DatabaseMirroring -Role Partner -Name Mirroring -Confirm:$false + Get-DbaEndpoint -SqlInstance $TestConfig.instance2 -Type DatabaseMirroring | Remove-DbaEndpoint -Confirm:$false + New-DbaEndpoint -SqlInstance $TestConfig.instance2 -Name dbatoolsci_MirroringEndpoint -Type DatabaseMirroring -Port 5022 -Owner sa + Get-DbaEndpoint -SqlInstance $TestConfig.instance3 -Type DatabaseMirroring | Remove-DbaEndpoint -Confirm:$false } AfterAll { - if ($create) { - $null = Get-DbaEndpoint -SqlInstance $script:instance2, $script:instance3 | Where-Object EndpointType -eq DatabaseMirroring | Remove-DbaEndpoint -Confirm:$false - Invoke-DbaQuery -SqlInstance $script:instance2 -Query "$create" - } + Get-DbaEndpoint -SqlInstance $TestConfig.instance2 -Type DatabaseMirroring | Remove-DbaEndpoint -Confirm:$false + New-DbaEndpoint -SqlInstance $TestConfig.instance2 -Name dbatoolsci_MirroringEndpoint -Type DatabaseMirroring -Port 5022 -Owner sa + Get-DbaEndpoint -SqlInstance $TestConfig.instance3 -Type DatabaseMirroring | Remove-DbaEndpoint -Confirm:$false + New-DbaEndpoint -SqlInstance $TestConfig.instance3 -Name dbatoolsci_MirroringEndpoint -Type DatabaseMirroring -Port 5023 -Owner sa } It "copies an endpoint" { - $results = Copy-DbaEndpoint -Source $script:instance2 -Destination $script:instance3 -Endpoint Mirroring - $results.DestinationServer | Should -Be $script:instance3 + $results = Copy-DbaEndpoint -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -Endpoint dbatoolsci_MirroringEndpoint + $results.DestinationServer | Should -Be $TestConfig.instance3 $results.Status | Should -Be 'Successful' - $results.Name | Should -Be 'Mirroring' + $results.Name | Should -Be 'dbatoolsci_MirroringEndpoint' } -} \ No newline at end of file +} diff --git a/tests/Copy-DbaInstanceAudit.Tests.ps1 b/tests/Copy-DbaInstanceAudit.Tests.ps1 index cde4bc9f51..6b735c4db7 100644 --- a/tests/Copy-DbaInstanceAudit.Tests.ps1 +++ b/tests/Copy-DbaInstanceAudit.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Copy-DbaInstanceAuditSpecification.Tests.ps1 b/tests/Copy-DbaInstanceAuditSpecification.Tests.ps1 index e7ec302cc3..6c2b2b7986 100644 --- a/tests/Copy-DbaInstanceAuditSpecification.Tests.ps1 +++ b/tests/Copy-DbaInstanceAuditSpecification.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Copy-DbaInstanceTrigger.Tests.ps1 b/tests/Copy-DbaInstanceTrigger.Tests.ps1 index 91e5839e7f..59afe9b311 100644 --- a/tests/Copy-DbaInstanceTrigger.Tests.ps1 +++ b/tests/Copy-DbaInstanceTrigger.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -21,25 +21,25 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { ON ALL SERVER FOR LOGON -- Tells you it's a logon trigger AS PRINT 'hello'" - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance1 $server.Query($sql) } AfterAll { $server.Query("DROP TRIGGER [$triggername] ON ALL SERVER") try { - $server1 = Connect-DbaInstance -SqlInstance $script:instance2 + $server1 = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $server1.Query("DROP TRIGGER [$triggername] ON ALL SERVER") } catch { # don't care } } - $results = Copy-DbaInstanceTrigger -Source $script:instance1 -Destination $script:instance2 -WarningAction SilentlyContinue + $results = Copy-DbaInstanceTrigger -Source $TestConfig.instance1 -Destination $TestConfig.instance2 -WarningAction SilentlyContinue It "should report success" { $results.Status | Should Be "Successful" } # same properties need to be added } -} \ No newline at end of file +} diff --git a/tests/Copy-DbaLinkedServer.Tests.ps1 b/tests/Copy-DbaLinkedServer.Tests.ps1 index dee8d0121d..3bc272778b 100644 --- a/tests/Copy-DbaLinkedServer.Tests.ps1 +++ b/tests/Copy-DbaLinkedServer.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -20,8 +20,8 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { EXEC master.dbo.sp_addlinkedserver @server = N'dbatoolsci_localhost2', @srvproduct=N'', @provider=N'SQLNCLI10'; EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=N'dbatoolsci_localhost2',@useself=N'False',@locallogin=NULL,@rmtuser=N'testuser1',@rmtpassword='supfool';" - $server1 = Connect-DbaInstance -SqlInstance $script:instance2 - $server2 = Connect-DbaInstance -SqlInstance $script:instance3 + $server1 = Connect-DbaInstance -SqlInstance $TestConfig.instance2 + $server2 = Connect-DbaInstance -SqlInstance $TestConfig.instance3 $server1.Query($createsql) } AfterAll { @@ -36,7 +36,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Copy linked server with the same properties" { It "copies successfully" { - $result = Copy-DbaLinkedServer -Source $script:instance2 -Destination $script:instance3 -LinkedServer dbatoolsci_localhost -WarningAction SilentlyContinue + $result = Copy-DbaLinkedServer -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -LinkedServer dbatoolsci_localhost -WarningAction SilentlyContinue $result | Select-Object -ExpandProperty Name -Unique | Should Be "dbatoolsci_localhost" $result | Select-Object -ExpandProperty Status -Unique | Should Be "Successful" } @@ -51,16 +51,17 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } It "skips existing linked servers" { - $results = Copy-DbaLinkedServer -Source $script:instance2 -Destination $script:instance3 -LinkedServer dbatoolsci_localhost -WarningAction SilentlyContinue + $results = Copy-DbaLinkedServer -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -LinkedServer dbatoolsci_localhost -WarningAction SilentlyContinue $results.Status | Should Be "Skipped" } - It "upgrades SQLNCLI provider based on what is registered" { - $result = Copy-DbaLinkedServer -Source $script:instance2 -Destination $script:instance3 -LinkedServer dbatoolsci_localhost2 -UpgradeSqlClient - $server1 = Connect-DbaInstance -SqlInstance $script:instance2 - $server2 = Connect-DbaInstance -SqlInstance $script:instance3 + # SQLNCLI10 and SQLNCLI11 are not used on newer versions, not sure which versions, but skipping if later than 2017 + It -Skip:$($server1.VersionMajor -gt 14 -or $server2.VersionMajor -gt 14) "upgrades SQLNCLI provider based on what is registered" { + $result = Copy-DbaLinkedServer -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -LinkedServer dbatoolsci_localhost2 -UpgradeSqlClient + $server1 = Connect-DbaInstance -SqlInstance $TestConfig.instance2 + $server2 = Connect-DbaInstance -SqlInstance $TestConfig.instance3 $server1.LinkedServers.Script() -match 'SQLNCLI10' | Should -Be $true $server2.LinkedServers.Script() -match 'SQLNCLI11' | Should -Be $true } } -} \ No newline at end of file +} diff --git a/tests/Copy-DbaLogin.Tests.ps1 b/tests/Copy-DbaLogin.Tests.ps1 index 02bf8f2695..afad303739 100644 --- a/tests/Copy-DbaLogin.Tests.ps1 +++ b/tests/Copy-DbaLogin.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -40,17 +40,17 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } # create objects - $null = Invoke-DbaQuery -SqlInstance $script:instance1 -InputFile $script:appveyorlabrepo\sql2008-scripts\logins.sql + $null = Invoke-DbaQuery -SqlInstance $TestConfig.instance1 -InputFile "$($TestConfig.appveyorlabrepo)\sql2008-scripts\logins.sql" $tableQuery = @("CREATE TABLE tester_table (a int)", "CREATE USER tester FOR LOGIN tester", "GRANT INSERT ON tester_table TO tester;") - $null = Invoke-DbaQuery -SqlInstance $script:instance1 -Database tempdb -Query ($tableQuery -join '; ') - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -Query $tableQuery[0] + $null = Invoke-DbaQuery -SqlInstance $TestConfig.instance1 -Database tempdb -Query ($tableQuery -join '; ') + $null = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database tempdb -Query $tableQuery[0] } BeforeEach { # cleanup targets - Initialize-TestLogin -Instance $script:instance2 -Login tester - Initialize-TestLogin -Instance $script:instance1 -Login tester_new + Initialize-TestLogin -Instance $TestConfig.instance2 -Login tester + Initialize-TestLogin -Instance $TestConfig.instance1 -Login tester_new } AfterAll { # cleanup everything @@ -66,10 +66,10 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Copy login with the same properties." { It "Should copy successfully" { - $results = Copy-DbaLogin -Source $script:instance1 -Destination $script:instance2 -Login Tester + $results = Copy-DbaLogin -Source $TestConfig.instance1 -Destination $TestConfig.instance2 -Login Tester $results.Status | Should -Be "Successful" - $login1 = Get-DbaLogin -SqlInstance $script:instance1 -login Tester - $login2 = Get-DbaLogin -SqlInstance $script:instance2 -login Tester + $login1 = Get-DbaLogin -SqlInstance $TestConfig.instance1 -login Tester + $login2 = Get-DbaLogin -SqlInstance $TestConfig.instance2 -login Tester $login2 | Should -Not -BeNullOrEmpty @@ -90,16 +90,16 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { It "Should login with newly created Sql Login (also tests credential login) and gets name" { $password = ConvertTo-SecureString -Force -AsPlainText tester1 $cred = New-Object System.Management.Automation.PSCredential ("tester", $password) - $s = Connect-DbaInstance -SqlInstance $script:instance1 -SqlCredential $cred - $s.Name | Should -Be $script:instance1 + $s = Connect-DbaInstance -SqlInstance $TestConfig.instance1 -SqlCredential $cred + $s.Name | Should -Be $TestConfig.instance1 } } Context "No overwrite" { BeforeAll { - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -InputFile $script:appveyorlabrepo\sql2008-scripts\logins.sql + $null = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -InputFile "$($TestConfig.appveyorlabrepo)\sql2008-scripts\logins.sql" } - $results = Copy-DbaLogin -Source $script:instance1 -Destination $script:instance2 -Login tester + $results = Copy-DbaLogin -Source $TestConfig.instance1 -Destination $TestConfig.instance2 -Login tester It "Should say skipped" { $results.Status | Should -Be "Skipped" $results.Notes | Should -Be "Already exists on destination" @@ -107,7 +107,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } Context "ExcludeSystemLogins Parameter" { - $results = Copy-DbaLogin -Source $script:instance1 -Destination $script:instance2 -ExcludeSystemLogins + $results = Copy-DbaLogin -Source $TestConfig.instance1 -Destination $TestConfig.instance2 -ExcludeSystemLogins It "Should say skipped" { $results.Status.Contains('Skipped') | Should -Be $true $results.Notes.Contains('System login') | Should -Be $true @@ -115,7 +115,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } Context "Supports pipe" { - $results = Get-DbaLogin -SqlInstance $script:instance1 -Login tester | Copy-DbaLogin -Destination $script:instance2 -Force + $results = Get-DbaLogin -SqlInstance $TestConfig.instance1 -Login tester | Copy-DbaLogin -Destination $TestConfig.instance2 -Force It "migrates the one tester login" { $results.Name | Should -Be "tester" $results.Status | Should -Be "Successful" @@ -124,25 +124,25 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Supports cloning" { It "clones the one tester login" { - $results = Copy-DbaLogin -Source $script:instance1 -Login tester -Destination $script:instance1 -Force -LoginRenameHashtable @{ tester = 'tester_new' } -NewSid + $results = Copy-DbaLogin -Source $TestConfig.instance1 -Login tester -Destination $TestConfig.instance1 -Force -LoginRenameHashtable @{ tester = 'tester_new' } -NewSid $results.Name | Should -Be "tester_new" $results.Status | Should -Be "Successful" - Get-DbaLogin -SqlInstance $script:instance1 -Login tester_new | Should -Not -BeNullOrEmpty + Get-DbaLogin -SqlInstance $TestConfig.instance1 -Login tester_new | Should -Not -BeNullOrEmpty } It "clones the one tester login using pipe" { - $results = Get-DbaLogin -SqlInstance $script:instance1 -Login tester | Copy-DbaLogin -Destination $script:instance1 -Force -LoginRenameHashtable @{ tester = 'tester_new' } -NewSid + $results = Get-DbaLogin -SqlInstance $TestConfig.instance1 -Login tester | Copy-DbaLogin -Destination $TestConfig.instance1 -Force -LoginRenameHashtable @{ tester = 'tester_new' } -NewSid $results.Name | Should -Be "tester_new" $results.Status | Should -Be "Successful" - Get-DbaLogin -SqlInstance $script:instance1 -Login tester_new | Should -Not -BeNullOrEmpty + Get-DbaLogin -SqlInstance $TestConfig.instance1 -Login tester_new | Should -Not -BeNullOrEmpty } It "clones the one tester login to a different server with a new name" { 'tester', 'tester_new' | ForEach-Object { - Initialize-TestLogin -Instance $script:instance2 -Login $_ + Initialize-TestLogin -Instance $TestConfig.instance2 -Login $_ } - $results = Get-DbaLogin -SqlInstance $script:instance1 -Login tester | Copy-DbaLogin -Destination $script:instance2 -LoginRenameHashtable @{ tester = 'tester_new' } + $results = Get-DbaLogin -SqlInstance $TestConfig.instance1 -Login tester | Copy-DbaLogin -Destination $TestConfig.instance2 -LoginRenameHashtable @{ tester = 'tester_new' } $results.Name | Should -Be "tester_new" $results.Status | Should -Be "Successful" - $login = (Connect-DbaInstance -SqlInstance $script:instance2).Logins['tester_new'] + $login = (Connect-DbaInstance -SqlInstance $TestConfig.instance2).Logins['tester_new'] $login | Should -Not -BeNullOrEmpty $login | Remove-DbaLogin -Force } @@ -154,34 +154,34 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } BeforeEach { 'tester', 'tester_new' | ForEach-Object { - Initialize-TestLogin -Instance $script:instance2 -Login $_ + Initialize-TestLogin -Instance $TestConfig.instance2 -Login $_ } } AfterAll { Remove-Item -Path $tempExportFile -Force } It "clones the one tester login with sysadmin permissions" { - $results = Copy-DbaLogin -Source $script:instance1 -Login tester -Destination $script:instance2 -LoginRenameHashtable @{ tester = 'tester_new' } + $results = Copy-DbaLogin -Source $TestConfig.instance1 -Login tester -Destination $TestConfig.instance2 -LoginRenameHashtable @{ tester = 'tester_new' } $results.Name | Should -Be "tester_new" $results.Status | Should -Be "Successful" - $i2 = Connect-DbaInstance -SqlInstance $script:instance2 + $i2 = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $login = $i2.Logins['tester_new'] $login | Should -Not -BeNullOrEmpty $role = $i2.Roles['sysadmin'] $role.EnumMemberNames() | Should -Contain $results.Name } It "clones the one tester login with object permissions" { - $results = Copy-DbaLogin -Source $script:instance1 -Login tester -Destination $script:instance2 -LoginRenameHashtable @{ tester = 'tester_new' } -ObjectLevel + $results = Copy-DbaLogin -Source $TestConfig.instance1 -Login tester -Destination $TestConfig.instance2 -LoginRenameHashtable @{ tester = 'tester_new' } -ObjectLevel $results.Name | Should -Be "tester_new" $results.Status | Should -Be "Successful" - $i2 = Connect-DbaInstance -SqlInstance $script:instance2 + $i2 = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $login = $i2.Logins['tester_new'] $login | Should -Not -BeNullOrEmpty - $permissions = Export-DbaUser -SqlInstance $script:instance2 -Database tempdb -User tester_new -Passthru + $permissions = Export-DbaUser -SqlInstance $TestConfig.instance2 -Database tempdb -User tester_new -Passthru $permissions | Should -BeLike '*GRANT INSERT ON OBJECT::`[dbo`].`[tester_table`] TO `[tester_new`]*' } It "scripts out two tester login with object permissions" { - $results = Copy-DbaLogin -Source $script:instance1 -Login tester, port -OutFile $tempExportFile -ObjectLevel + $results = Copy-DbaLogin -Source $TestConfig.instance1 -Login tester, port -OutFile $tempExportFile -ObjectLevel $results | Should -Be $tempExportFile $permissions = Get-Content $tempExportFile -Raw $permissions | Should -BeLike '*CREATE LOGIN `[tester`]*' @@ -191,4 +191,4 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $permissions | Should -BeLike '*GRANT CONNECT SQL TO `[port`]*' } } -} \ No newline at end of file +} diff --git a/tests/Copy-DbaPolicyManagement.Tests.ps1 b/tests/Copy-DbaPolicyManagement.Tests.ps1 index bfa02e4d14..d07cb1296f 100644 --- a/tests/Copy-DbaPolicyManagement.Tests.ps1 +++ b/tests/Copy-DbaPolicyManagement.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Copy-DbaRegServer.Tests.ps1 b/tests/Copy-DbaRegServer.Tests.ps1 index e8df0c654a..a995598688 100644 --- a/tests/Copy-DbaRegServer.Tests.ps1 +++ b/tests/Copy-DbaRegServer.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,7 +16,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Setup" { BeforeAll { - $server = Connect-DbaInstance $script:instance2 + $server = Connect-DbaInstance $TestConfig.instance2 $regstore = New-Object Microsoft.SqlServer.Management.RegisteredServers.RegisteredServersStore($server.ConnectionContext.SqlConnectionObject) $dbstore = $regstore.DatabaseEngineServerGroup @@ -37,14 +37,14 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } AfterAll { $newgroup.Drop() - $server = Connect-DbaInstance $script:instance1 + $server = Connect-DbaInstance $TestConfig.instance1 $regstore = New-Object Microsoft.SqlServer.Management.RegisteredServers.RegisteredServersStore($server.ConnectionContext.SqlConnectionObject) $dbstore = $regstore.DatabaseEngineServerGroup $groupstore = $dbstore.ServerGroups[$group] $groupstore.Drop() } - $results = Copy-DbaRegServer -Source $script:instance2 -Destination $script:instance1 -WarningAction SilentlyContinue -CMSGroup $group + $results = Copy-DbaRegServer -Source $TestConfig.instance2 -Destination $TestConfig.instance1 -WarningAction SilentlyContinue -CMSGroup $group It "should report success" { $results.Status | Should Be "Successful", "Successful" @@ -52,4 +52,4 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { # Property Comparisons will come later when we have the commands } -} \ No newline at end of file +} diff --git a/tests/Copy-DbaResourceGovernor.Tests.ps1 b/tests/Copy-DbaResourceGovernor.Tests.ps1 index 3cce240275..5381e0912a 100644 --- a/tests/Copy-DbaResourceGovernor.Tests.ps1 +++ b/tests/Copy-DbaResourceGovernor.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -21,29 +21,29 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { MAX_CPU_PERCENT = 100, MIN_CPU_PERCENT = 50 )" - Invoke-DbaQuery -WarningAction SilentlyContinue -SqlInstance $script:instance2 -Query $sql + Invoke-DbaQuery -WarningAction SilentlyContinue -SqlInstance $TestConfig.instance2 -Query $sql $sql = "CREATE WORKLOAD GROUP dbatoolsci_prodprocessing WITH ( IMPORTANCE = MEDIUM ) USING dbatoolsci_prod" - Invoke-DbaQuery -WarningAction SilentlyContinue -SqlInstance $script:instance2 -Query $sql + Invoke-DbaQuery -WarningAction SilentlyContinue -SqlInstance $TestConfig.instance2 -Query $sql $sql = "CREATE RESOURCE POOL dbatoolsci_offhoursprocessing WITH ( MAX_CPU_PERCENT = 50, MIN_CPU_PERCENT = 0 )" - Invoke-DbaQuery -WarningAction SilentlyContinue -SqlInstance $script:instance2 -Query $sql + Invoke-DbaQuery -WarningAction SilentlyContinue -SqlInstance $TestConfig.instance2 -Query $sql $sql = "CREATE WORKLOAD GROUP dbatoolsci_goffhoursprocessing WITH ( IMPORTANCE = LOW ) USING dbatoolsci_offhoursprocessing" - Invoke-DbaQuery -WarningAction SilentlyContinue -SqlInstance $script:instance2 -Query $sql + Invoke-DbaQuery -WarningAction SilentlyContinue -SqlInstance $TestConfig.instance2 -Query $sql $sql = "ALTER RESOURCE GOVERNOR RECONFIGURE" - Invoke-DbaQuery -WarningAction SilentlyContinue -SqlInstance $script:instance2 -Query $sql + Invoke-DbaQuery -WarningAction SilentlyContinue -SqlInstance $TestConfig.instance2 -Query $sql $sql = "CREATE FUNCTION dbatoolsci_fnRG() RETURNS sysname WITH SCHEMABINDING @@ -51,30 +51,30 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BEGIN RETURN N'dbatoolsci_goffhoursprocessing' END" - Invoke-DbaQuery -WarningAction SilentlyContinue -SqlInstance $script:instance2 -Query $sql + Invoke-DbaQuery -WarningAction SilentlyContinue -SqlInstance $TestConfig.instance2 -Query $sql $sql = "ALTER RESOURCE GOVERNOR with (CLASSIFIER_FUNCTION = dbo.dbatoolsci_fnRG); ALTER RESOURCE GOVERNOR RECONFIGURE;" - Invoke-DbaQuery -WarningAction SilentlyContinue -SqlInstance $script:instance2 -Query $sql + Invoke-DbaQuery -WarningAction SilentlyContinue -SqlInstance $TestConfig.instance2 -Query $sql } AfterAll { - Get-DbaProcess -SqlInstance $script:instance2, $script:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue - Invoke-DbaQuery -WarningAction SilentlyContinue -SqlInstance $script:instance2, $script:instance3 -Query "ALTER RESOURCE GOVERNOR WITH (CLASSIFIER_FUNCTION = NULL); ALTER RESOURCE GOVERNOR RECONFIGURE" - Invoke-DbaQuery -WarningAction SilentlyContinue -SqlInstance $script:instance2, $script:instance3 -Query "DROP FUNCTION [dbo].[dbatoolsci_fnRG];ALTER RESOURCE GOVERNOR RECONFIGURE" - Invoke-DbaQuery -WarningAction SilentlyContinue -SqlInstance $script:instance2, $script:instance3 -Query "DROP WORKLOAD GROUP [dbatoolsci_prodprocessing];ALTER RESOURCE GOVERNOR RECONFIGURE" - Invoke-DbaQuery -WarningAction SilentlyContinue -SqlInstance $script:instance2, $script:instance3 -Query "DROP WORKLOAD GROUP [dbatoolsci_goffhoursprocessing];ALTER RESOURCE GOVERNOR RECONFIGURE" - Invoke-DbaQuery -WarningAction SilentlyContinue -SqlInstance $script:instance2, $script:instance3 -Query "DROP RESOURCE POOL [dbatoolsci_offhoursprocessing];ALTER RESOURCE GOVERNOR RECONFIGURE" - Invoke-DbaQuery -WarningAction SilentlyContinue -SqlInstance $script:instance2, $script:instance3 -Query "DROP RESOURCE POOL [dbatoolsci_prod];ALTER RESOURCE GOVERNOR RECONFIGURE" + Get-DbaProcess -SqlInstance $TestConfig.instance2, $TestConfig.instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue + Invoke-DbaQuery -WarningAction SilentlyContinue -SqlInstance $TestConfig.instance2, $TestConfig.instance3 -Query "ALTER RESOURCE GOVERNOR WITH (CLASSIFIER_FUNCTION = NULL); ALTER RESOURCE GOVERNOR RECONFIGURE" + Invoke-DbaQuery -WarningAction SilentlyContinue -SqlInstance $TestConfig.instance2, $TestConfig.instance3 -Query "DROP FUNCTION [dbo].[dbatoolsci_fnRG];ALTER RESOURCE GOVERNOR RECONFIGURE" + Invoke-DbaQuery -WarningAction SilentlyContinue -SqlInstance $TestConfig.instance2, $TestConfig.instance3 -Query "DROP WORKLOAD GROUP [dbatoolsci_prodprocessing];ALTER RESOURCE GOVERNOR RECONFIGURE" + Invoke-DbaQuery -WarningAction SilentlyContinue -SqlInstance $TestConfig.instance2, $TestConfig.instance3 -Query "DROP WORKLOAD GROUP [dbatoolsci_goffhoursprocessing];ALTER RESOURCE GOVERNOR RECONFIGURE" + Invoke-DbaQuery -WarningAction SilentlyContinue -SqlInstance $TestConfig.instance2, $TestConfig.instance3 -Query "DROP RESOURCE POOL [dbatoolsci_offhoursprocessing];ALTER RESOURCE GOVERNOR RECONFIGURE" + Invoke-DbaQuery -WarningAction SilentlyContinue -SqlInstance $TestConfig.instance2, $TestConfig.instance3 -Query "DROP RESOURCE POOL [dbatoolsci_prod];ALTER RESOURCE GOVERNOR RECONFIGURE" } Context "Command works" { It "copies the resource governor successfully" { - $results = Copy-DbaResourceGovernor -Source $script:instance2 -Destination $script:instance3 -Force -WarningAction SilentlyContinue + $results = Copy-DbaResourceGovernor -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -Force -WarningAction SilentlyContinue $results.Status | Select-Object -Unique | Should -Be 'Successful' $results.Status.Count | Should -BeGreaterThan 3 $results.Name | Should -Contain 'dbatoolsci_prod' } It "returns the proper classifier function" { - $results = Get-DbaRgClassifierFunction -SqlInstance $script:instance3 + $results = Get-DbaRgClassifierFunction -SqlInstance $TestConfig.instance3 $results.Name | Should -Be 'dbatoolsci_fnRG' } } -} \ No newline at end of file +} diff --git a/tests/Copy-DbaSpConfigure.Tests.ps1 b/tests/Copy-DbaSpConfigure.Tests.ps1 index 0a319cef8b..fd05be5e72 100644 --- a/tests/Copy-DbaSpConfigure.Tests.ps1 +++ b/tests/Copy-DbaSpConfigure.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,40 +16,40 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Copy config with the same properties." { BeforeAll { - $sourceconfig = (Get-DbaSpConfigure -SqlInstance $script:instance1 -ConfigName RemoteQueryTimeout).ConfiguredValue - $destconfig = (Get-DbaSpConfigure -SqlInstance $script:instance2 -ConfigName RemoteQueryTimeout).ConfiguredValue + $sourceconfig = (Get-DbaSpConfigure -SqlInstance $TestConfig.instance1 -ConfigName RemoteQueryTimeout).ConfiguredValue + $destconfig = (Get-DbaSpConfigure -SqlInstance $TestConfig.instance2 -ConfigName RemoteQueryTimeout).ConfiguredValue # Set it so they don't match if ($sourceconfig -and $destconfig) { $newvalue = $sourceconfig + $destconfig - $null = Set-DbaSpConfigure -SqlInstance $script:instance2 -ConfigName RemoteQueryTimeout -Value $newvalue + $null = Set-DbaSpConfigure -SqlInstance $TestConfig.instance2 -ConfigName RemoteQueryTimeout -Value $newvalue } } AfterAll { if ($destconfig -and $destconfig -ne $sourceconfig) { - $null = Set-DbaSpConfigure -SqlInstance $script:instance2 -ConfigName RemoteQueryTimeout -Value $destconfig + $null = Set-DbaSpConfigure -SqlInstance $TestConfig.instance2 -ConfigName RemoteQueryTimeout -Value $destconfig } } It "starts with different values" { - $config1 = Get-DbaSpConfigure -SqlInstance $script:instance1 -ConfigName RemoteQueryTimeout - $config2 = Get-DbaSpConfigure -SqlInstance $script:instance2 -ConfigName RemoteQueryTimeout + $config1 = Get-DbaSpConfigure -SqlInstance $TestConfig.instance1 -ConfigName RemoteQueryTimeout + $config2 = Get-DbaSpConfigure -SqlInstance $TestConfig.instance2 -ConfigName RemoteQueryTimeout $config1.ConfiguredValue -ne $config2.ConfiguredValue | Should be $true } It "copied successfully" { - $results = Copy-DbaSpConfigure -Source $script:instance1 -Destination $script:instance2 -ConfigName RemoteQueryTimeout + $results = Copy-DbaSpConfigure -Source $TestConfig.instance1 -Destination $TestConfig.instance2 -ConfigName RemoteQueryTimeout $results.Status | Should Be "Successful" } It "retains the same properties" { - $config1 = Get-DbaSpConfigure -SqlInstance $script:instance1 -ConfigName RemoteQueryTimeout - $config2 = Get-DbaSpConfigure -SqlInstance $script:instance2 -ConfigName RemoteQueryTimeout + $config1 = Get-DbaSpConfigure -SqlInstance $TestConfig.instance1 -ConfigName RemoteQueryTimeout + $config2 = Get-DbaSpConfigure -SqlInstance $TestConfig.instance2 -ConfigName RemoteQueryTimeout $config1.ConfiguredValue | Should be $config2.ConfiguredValue } It "didn't modify the source" { - $newconfig = (Get-DbaSpConfigure -SqlInstance $script:instance1 -ConfigName RemoteQueryTimeout).ConfiguredValue + $newconfig = (Get-DbaSpConfigure -SqlInstance $TestConfig.instance1 -ConfigName RemoteQueryTimeout).ConfiguredValue $newconfig -eq $sourceconfig | Should Be $true } } -} \ No newline at end of file +} diff --git a/tests/Copy-DbaSsisCatalog.Tests.ps1 b/tests/Copy-DbaSsisCatalog.Tests.ps1 index 55a02b0416..ee4287596b 100644 --- a/tests/Copy-DbaSsisCatalog.Tests.ps1 +++ b/tests/Copy-DbaSsisCatalog.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Copy-DbaStartupProcedure.Tests.ps1 b/tests/Copy-DbaStartupProcedure.Tests.ps1 index baf79491ae..adec8ddbb6 100644 --- a/tests/Copy-DbaStartupProcedure.Tests.ps1 +++ b/tests/Copy-DbaStartupProcedure.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -20,7 +20,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $procName = "dbatoolsci_test_startup" $server.Query("CREATE OR ALTER PROCEDURE $procName AS @@ -32,11 +32,11 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } AfterAll { - Invoke-DbaQuery -SqlInstance $script:instance2, $script:instance3 -Database "master" -Query "DROP PROCEDURE dbatoolsci_test_startup" + Invoke-DbaQuery -SqlInstance $TestConfig.instance2, $TestConfig.instance3 -Database "master" -Query "DROP PROCEDURE dbatoolsci_test_startup" } Context "Command actually works" { - $results = Copy-DbaStartupProcedure -Source $script:instance2 -Destination $script:instance3 + $results = Copy-DbaStartupProcedure -Source $TestConfig.instance2 -Destination $TestConfig.instance3 It "Should include test procedure: $procName" { ($results | Where-Object Name -eq $procName).Name | Should -Be $procName } @@ -44,4 +44,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { ($results | Where-Object Name -eq $procName).Status | Should -Be 'Successful' } } -} \ No newline at end of file +} diff --git a/tests/Copy-DbaSystemDbUserObject.Tests.ps1 b/tests/Copy-DbaSystemDbUserObject.Tests.ps1 index 148284ae82..91cc69a1d0 100644 --- a/tests/Copy-DbaSystemDbUserObject.Tests.ps1 +++ b/tests/Copy-DbaSystemDbUserObject.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -55,30 +55,30 @@ CREATE RULE dbo.dbatoolsci_range_rule AS @range>= $1000 AND @range <$20000; "@ - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Query $Function - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Query $TableFunction - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Query $Rule + $null = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Query $Function + $null = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Query $TableFunction + $null = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Query $Rule } AfterAll { - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Query "DROP FUNCTION dbo.dbatoolscs_ISOweek;" - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Query "DROP FUNCTION dbo.dbatoolsci_TableFunction;" - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Query "DROP RULE dbo.dbatoolsci_range_rule;" + $null = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Query "DROP FUNCTION dbo.dbatoolscs_ISOweek;" + $null = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Query "DROP FUNCTION dbo.dbatoolsci_TableFunction;" + $null = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Query "DROP RULE dbo.dbatoolsci_range_rule;" } Context "Should Copy Objects to the same instance" { - $results = Copy-DbaSystemDbUserObject -Source $script:instance2 -Destination $script:instance2 + $results = Copy-DbaSystemDbUserObject -Source $TestConfig.instance2 -Destination $TestConfig.instance2 It "Should execute with default parameters" { $results | Should Not Be Null } - $results = Copy-DbaSystemDbUserObject -Source $script:instance2 -Destination $script:instance2 -Classic + $results = Copy-DbaSystemDbUserObject -Source $TestConfig.instance2 -Destination $TestConfig.instance2 -Classic It "Should execute with -Classic parameter" { $results | Should Not Be Null } - $results = Copy-DbaSystemDbUserObject -Source $script:instance2 -Destination $script:instance2 -Force + $results = Copy-DbaSystemDbUserObject -Source $TestConfig.instance2 -Destination $TestConfig.instance2 -Force It "Should execute with -Classic parameter" { $results | Should Not Be Null } } -} \ No newline at end of file +} diff --git a/tests/Copy-DbaXESession.Tests.ps1 b/tests/Copy-DbaXESession.Tests.ps1 index ec94e654a3..01d8545deb 100644 --- a/tests/Copy-DbaXESession.Tests.ps1 +++ b/tests/Copy-DbaXESession.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Copy-DbaXESessionTemplate.Tests.ps1 b/tests/Copy-DbaXESessionTemplate.Tests.ps1 index 23d8d6a8e5..d9b07a268d 100644 --- a/tests/Copy-DbaXESessionTemplate.Tests.ps1 +++ b/tests/Copy-DbaXESessionTemplate.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Disable-DbaAgHadr.Tests.ps1 b/tests/Disable-DbaAgHadr.Tests.ps1 index 4c7792042f..d9a4fbb9ea 100644 --- a/tests/Disable-DbaAgHadr.Tests.ps1 +++ b/tests/Disable-DbaAgHadr.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag "UnitTests" { Context "Validate parameters" { @@ -13,16 +13,16 @@ Describe "$CommandName Unit Tests" -Tag "UnitTests" { } } -# $script:instance3 is used for Availability Group tests and needs Hadr service setting enabled +# $TestConfig.instance3 is used for Availability Group tests and needs Hadr service setting enabled Describe "$commandname Integration Tests" -Tag "IntegrationTests" { AfterAll { - Enable-DbaAgHadr -SqlInstance $script:instance3 -Confirm:$false -Force + Enable-DbaAgHadr -SqlInstance $TestConfig.instance3 -Confirm:$false -Force } - $results = Disable-DbaAgHadr -SqlInstance $script:instance3 -Confirm:$false -Force + $results = Disable-DbaAgHadr -SqlInstance $TestConfig.instance3 -Confirm:$false -Force It "disables hadr" { $results.IsHadrEnabled | Should -Be $false } -} \ No newline at end of file +} diff --git a/tests/Disable-DbaDbEncryption.Tests.ps1 b/tests/Disable-DbaDbEncryption.Tests.ps1 index 79af457ac8..120a74adec 100644 --- a/tests/Disable-DbaDbEncryption.Tests.ps1 +++ b/tests/Disable-DbaDbEncryption.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Validate parameters" { @@ -17,18 +17,18 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { $PSDefaultParameterValues["*:Confirm"] = $false $passwd = ConvertTo-SecureString "dbatools.IO" -AsPlainText -Force - $masterkey = Get-DbaDbMasterKey -SqlInstance $script:instance2 -Database master + $masterkey = Get-DbaDbMasterKey -SqlInstance $TestConfig.instance2 -Database master if (-not $masterkey) { $delmasterkey = $true - $masterkey = New-DbaServiceMasterKey -SqlInstance $script:instance2 -SecurePassword $passwd + $masterkey = New-DbaServiceMasterKey -SqlInstance $TestConfig.instance2 -SecurePassword $passwd } - $mastercert = Get-DbaDbCertificate -SqlInstance $script:instance2 -Database master | Where-Object Name -notmatch "##" | Select-Object -First 1 + $mastercert = Get-DbaDbCertificate -SqlInstance $TestConfig.instance2 -Database master | Where-Object Name -notmatch "##" | Select-Object -First 1 if (-not $mastercert) { $delmastercert = $true - $mastercert = New-DbaDbCertificate -SqlInstance $script:instance2 + $mastercert = New-DbaDbCertificate -SqlInstance $TestConfig.instance2 } - $db = New-DbaDatabase -SqlInstance $script:instance2 + $db = New-DbaDatabase -SqlInstance $TestConfig.instance2 $db | New-DbaDbMasterKey -SecurePassword $passwd $db | New-DbaDbCertificate $db | New-DbaDbEncryptionKey -Force @@ -59,9 +59,9 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $null = $db | Enable-DbaDbEncryption -EncryptorName $mastercert.Name -Force # Give it time to finish encrypting or it'll error Start-Sleep 10 - $results = Disable-DbaDbEncryption -SqlInstance $script:instance2 -Database $db.Name -WarningVariable warn 3> $null + $results = Disable-DbaDbEncryption -SqlInstance $TestConfig.instance2 -Database $db.Name -WarningVariable warn 3> $null $warn | Should -Be $null $results.EncryptionEnabled | Should -Be $false } } -} \ No newline at end of file +} diff --git a/tests/Disable-DbaFilestream.Tests.ps1 b/tests/Disable-DbaFilestream.Tests.ps1 index 826b132f1d..bfd631eda3 100644 --- a/tests/Disable-DbaFilestream.Tests.ps1 +++ b/tests/Disable-DbaFilestream.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,18 +16,18 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { <# Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $OriginalFileStream = Get-DbaFilestream -SqlInstance $script:instance1 + $OriginalFileStream = Get-DbaFilestream -SqlInstance $TestConfig.instance1 } AfterAll { - Set-DbaFilestream -SqlInstance $script:instance1 -FileStreamLevel $OriginalFileStream.InstanceAccessLevel -force + Set-DbaFilestream -SqlInstance $TestConfig.instance1 -FileStreamLevel $OriginalFileStream.InstanceAccessLevel -force } Context "Changing FileStream Level" { $NewLevel = ($OriginalFileStream.FileStreamStateId + 1) % 3 #Move it on one, but keep it less than 4 with modulo division - $results = Set-DbaFilestream -SqlInstance $script:instance1 -FileStreamLevel $NewLevel -Force -WarningAction silentlyContinue -ErrorVariable errvar -Erroraction silentlyContinue + $results = Set-DbaFilestream -SqlInstance $TestConfig.instance1 -FileStreamLevel $NewLevel -Force -WarningAction silentlyContinue -ErrorVariable errvar -Erroraction silentlyContinue It "Should have changed the FileStream Level" { $results.InstanceAccessLevel | Should be $NewLevel } } } -#> \ No newline at end of file +#> diff --git a/tests/Disable-DbaForceNetworkEncryption.Tests.ps1 b/tests/Disable-DbaForceNetworkEncryption.Tests.ps1 index 10d1162dd3..14b3172bf2 100644 --- a/tests/Disable-DbaForceNetworkEncryption.Tests.ps1 +++ b/tests/Disable-DbaForceNetworkEncryption.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -14,9 +14,9 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { } Describe "$commandname Integration Tests" -Tags "IntegrationTests" { - $results = Disable-DbaForceNetworkEncryption $script:instance1 -EnableException + $results = Disable-DbaForceNetworkEncryption $TestConfig.instance1 -EnableException It "returns false" { $results.ForceEncryption -eq $false } -} \ No newline at end of file +} diff --git a/tests/Disable-DbaHideInstance.Tests.ps1 b/tests/Disable-DbaHideInstance.Tests.ps1 index 4eb753cc23..2aa85769dc 100644 --- a/tests/Disable-DbaHideInstance.Tests.ps1 +++ b/tests/Disable-DbaHideInstance.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -14,9 +14,9 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { } Describe "$commandname Integration Tests" -Tags "IntegrationTests" { - $results = Disable-DbaHideInstance $script:instance1 -EnableException + $results = Disable-DbaHideInstance $TestConfig.instance1 -EnableException It "returns false" { $results.HideInstance -eq $false } -} \ No newline at end of file +} diff --git a/tests/Disable-DbaReplDistributor.Tests.ps1 b/tests/Disable-DbaReplDistributor.Tests.ps1 index 8707c37e5a..a72c49deeb 100644 --- a/tests/Disable-DbaReplDistributor.Tests.ps1 +++ b/tests/Disable-DbaReplDistributor.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Add-ReplicationLibrary diff --git a/tests/Disable-DbaReplPublishing.Tests.ps1 b/tests/Disable-DbaReplPublishing.Tests.ps1 index db1d3ce2fd..d867b82ef1 100644 --- a/tests/Disable-DbaReplPublishing.Tests.ps1 +++ b/tests/Disable-DbaReplPublishing.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Add-ReplicationLibrary diff --git a/tests/Disable-DbaStartupProcedure.Tests.ps1 b/tests/Disable-DbaStartupProcedure.Tests.ps1 index 50a5c00302..d654d9d562 100644 --- a/tests/Disable-DbaStartupProcedure.Tests.ps1 +++ b/tests/Disable-DbaStartupProcedure.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,7 +16,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Test" -Tag "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $random = Get-Random $startupProcName = "StartUpProc$random" $startupProc = "dbo.$startupProcName" @@ -30,7 +30,7 @@ Describe "$commandname Integration Test" -Tag "IntegrationTests" { } Context "Validate returns correct output for disable" { - $result = Disable-DbaStartupProcedure -SqlInstance $script:instance2 -StartupProcedure $startupProc -Confirm:$false + $result = Disable-DbaStartupProcedure -SqlInstance $TestConfig.instance2 -StartupProcedure $startupProc -Confirm:$false It "returns correct results" { $result.Schema -eq "dbo" | Should Be $true @@ -42,7 +42,7 @@ Describe "$commandname Integration Test" -Tag "IntegrationTests" { } Context "Validate returns correct output for already existing state" { - $result = Disable-DbaStartupProcedure -SqlInstance $script:instance2 -StartupProcedure $startupProc -Confirm:$false + $result = Disable-DbaStartupProcedure -SqlInstance $TestConfig.instance2 -StartupProcedure $startupProc -Confirm:$false It "returns correct results" { $result.Schema -eq "dbo" | Should Be $true @@ -54,8 +54,8 @@ Describe "$commandname Integration Test" -Tag "IntegrationTests" { } Context "Validate returns correct results for piped input" { - $null = Enable-DbaStartupProcedure -SqlInstance $script:instance2 -StartupProcedure $startupProc -Confirm:$false - $result = Get-DbaStartupProcedure -SqlInstance $script:instance2 | Disable-DbaStartupProcedure -Confirm:$false + $null = Enable-DbaStartupProcedure -SqlInstance $TestConfig.instance2 -StartupProcedure $startupProc -Confirm:$false + $result = Get-DbaStartupProcedure -SqlInstance $TestConfig.instance2 | Disable-DbaStartupProcedure -Confirm:$false It "returns correct results" { $result.Schema -eq "dbo" | Should Be $true @@ -65,4 +65,4 @@ Describe "$commandname Integration Test" -Tag "IntegrationTests" { $result.Note -eq "Disable succeded" | Should Be $true } } -} \ No newline at end of file +} diff --git a/tests/Disable-DbaTraceFlag.Tests.ps1 b/tests/Disable-DbaTraceFlag.Tests.ps1 index dad0ec2542..07c9eb2818 100644 --- a/tests/Disable-DbaTraceFlag.Tests.ps1 +++ b/tests/Disable-DbaTraceFlag.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,7 +16,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Verifying TraceFlag output" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance1 $startingtfs = Get-DbaTraceFlag -SqlInstance $server $safetraceflag = 3226 @@ -37,4 +37,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $results.TraceFlag -contains $safetraceflag | Should Be $true } } -} \ No newline at end of file +} diff --git a/tests/Disconnect-DbaInstance.Tests.ps1 b/tests/Disconnect-DbaInstance.Tests.ps1 index d3c36415b7..d0c6044ed6 100644 --- a/tests/Disconnect-DbaInstance.Tests.ps1 +++ b/tests/Disconnect-DbaInstance.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag "UnitTests" { Context "Validate parameters" { @@ -15,7 +15,7 @@ Describe "$CommandName Unit Tests" -Tag "UnitTests" { Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $null = Connect-DbaInstance -SqlInstance $script:instance1 + $null = Connect-DbaInstance -SqlInstance $TestConfig.instance1 } Context "disconnets a server" { It "disconnects and returns some results" { @@ -23,4 +23,4 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { $results | Should -Not -BeNullOrEmpty } } -} \ No newline at end of file +} diff --git a/tests/Dismount-DbaDatabase.Tests.ps1 b/tests/Dismount-DbaDatabase.Tests.ps1 index 8c17a1f281..2c20751ccf 100644 --- a/tests/Dismount-DbaDatabase.Tests.ps1 +++ b/tests/Dismount-DbaDatabase.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -18,18 +18,18 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { # Setting up the environment we need to test the cmdlet BeforeAll { # Everything in here gets executed before anything else in this context - Get-DbaProcess -SqlInstance $script:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue + Get-DbaProcess -SqlInstance $TestConfig.instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue # Setting up variables names. If you want them to persist between all of the pester blocks, they can be moved outside $dbname = "dbatoolsci_detachattach" # making room in the remote case a db with the same name exists - $null = Get-DbaDatabase -SqlInstance $script:instance3 -Database $dbname | Remove-DbaDatabase -Confirm:$false + $null = Get-DbaDatabase -SqlInstance $TestConfig.instance3 -Database $dbname | Remove-DbaDatabase -Confirm:$false - $db1 = New-DbaDatabase -SqlInstance $script:instance3 -Name $dbname + $db1 = New-DbaDatabase -SqlInstance $TestConfig.instance3 -Name $dbname # memorizing $fileStructure for a later test $fileStructure = New-Object System.Collections.Specialized.StringCollection - foreach ($file in (Get-DbaDbFile -SqlInstance $script:instance3 -Database $dbname).PhysicalName) { + foreach ($file in (Get-DbaDbFile -SqlInstance $TestConfig.instance3 -Database $dbname).PhysicalName) { $null = $fileStructure.Add($file) } } @@ -37,13 +37,13 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { # Everything we create/touch/mess with should be reverted to a "clean" state whenever possible AfterAll { # this gets executed always (think "finally" in try/catch/finally) and it's the best place for final cleanups - $null = Mount-DbaDatabase -SqlInstance $script:instance3 -Database $dbname -FileStructure $script:fileStructure - $null = Get-DbaDatabase -SqlInstance $script:instance3 -Database $dbname | Remove-DbaDatabase -Confirm:$false + $null = Mount-DbaDatabase -SqlInstance $TestConfig.instance3 -Database $dbname -FileStructure $TestConfig.fileStructure + $null = Get-DbaDatabase -SqlInstance $TestConfig.instance3 -Database $dbname | Remove-DbaDatabase -Confirm:$false } # Actual tests Context "Detaches a single database and tests to ensure the alias still exists" { - $results = Dismount-DbaDatabase -SqlInstance $script:instance3 -Database $dbname -Force + $results = Dismount-DbaDatabase -SqlInstance $TestConfig.instance3 -Database $dbname -Force It "was successfull" { $results.DetachResult | Should Be "Success" @@ -61,41 +61,41 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { } Context "Database Detachment" { BeforeAll { - Get-DbaProcess -SqlInstance $script:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue - $server = Connect-DbaInstance -SqlInstance $script:instance3 + Get-DbaProcess -SqlInstance $TestConfig.instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance3 $db1 = "dbatoolsci_dbsetstate_detached" $server.Query("CREATE DATABASE $db1") - Get-DbaProcess -SqlInstance $script:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue - $server = Connect-DbaInstance -SqlInstance $script:instance3 + Get-DbaProcess -SqlInstance $TestConfig.instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance3 $db2 = "dbatoolsci_dbsetstate_detached_withSnap" $server.Query("CREATE DATABASE $db2") - $null = New-DbaDbSnapshot -SqlInstance $script:instance3 -Database $db2 + $null = New-DbaDbSnapshot -SqlInstance $TestConfig.instance3 -Database $db2 $fileStructure = New-Object System.Collections.Specialized.StringCollection - foreach ($file in (Get-DbaDbFile -SqlInstance $script:instance3 -Database $db1).PhysicalName) { + foreach ($file in (Get-DbaDbFile -SqlInstance $TestConfig.instance3 -Database $db1).PhysicalName) { $null = $fileStructure.Add($file) } - Stop-DbaProcess -SqlInstance $script:instance3 -Database $db1 + Stop-DbaProcess -SqlInstance $TestConfig.instance3 -Database $db1 } AfterAll { - $null = Remove-DbaDbSnapshot -SqlInstance $script:instance3 -Database $db2 -Force - $null = Mount-DbaDatabase -SqlInstance $script:instance3 -Database $db1 -FileStructure $fileStructure - $null = Get-DbaDatabase -SqlInstance $script:instance3 -Database $db1, $db2 | Remove-DbaDatabase -Confirm:$false + $null = Remove-DbaDbSnapshot -SqlInstance $TestConfig.instance3 -Database $db2 -Force + $null = Mount-DbaDatabase -SqlInstance $TestConfig.instance3 -Database $db1 -FileStructure $fileStructure + $null = Get-DbaDatabase -SqlInstance $TestConfig.instance3 -Database $db1, $db2 | Remove-DbaDatabase -Confirm:$false } It "Skips detachment if database is snapshotted" { - $result = Dismount-DbaDatabase -SqlInstance $script:instance3 -Database $db2 -Force -WarningAction SilentlyContinue -WarningVariable warn 3> $null + $result = Dismount-DbaDatabase -SqlInstance $TestConfig.instance3 -Database $db2 -Force -WarningAction SilentlyContinue -WarningVariable warn 3> $null $result | Should Be $null $warn -match "snapshot" | Should Be $true - $result = Get-DbaDatabase -SqlInstance $script:instance3 -Database $db2 + $result = Get-DbaDatabase -SqlInstance $TestConfig.instance3 -Database $db2 $result | Should Not Be $null } - $null = Stop-DbaProcess -SqlInstance $script:instance3 -Database $db1 - $result = Dismount-DbaDatabase -SqlInstance $script:instance3 -Database $db1 + $null = Stop-DbaProcess -SqlInstance $TestConfig.instance3 -Database $db1 + $result = Dismount-DbaDatabase -SqlInstance $TestConfig.instance3 -Database $db1 It "Detaches the database correctly" { - $result = Get-DbaDatabase -SqlInstance $script:instance3 -Database $db1 + $result = Get-DbaDatabase -SqlInstance $TestConfig.instance3 -Database $db1 $result | Should Be $null } } } -#$script:instance2 - to make it show up in appveyor, long story \ No newline at end of file +#$TestConfig.instance2 - to make it show up in appveyor, long story diff --git a/tests/Enable-DbaAgHadr.Tests.ps1 b/tests/Enable-DbaAgHadr.Tests.ps1 index aa6e266d56..b5f0675403 100644 --- a/tests/Enable-DbaAgHadr.Tests.ps1 +++ b/tests/Enable-DbaAgHadr.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag "UnitTests" { Context "Validate parameters" { @@ -15,12 +15,12 @@ Describe "$CommandName Unit Tests" -Tag "UnitTests" { Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { - Disable-DbaAgHadr -SqlInstance $script:instance3 -Confirm:$false -Force + Disable-DbaAgHadr -SqlInstance $TestConfig.instance3 -Confirm:$false -Force } - $results = Enable-DbaAgHadr -SqlInstance $script:instance3 -Confirm:$false -Force + $results = Enable-DbaAgHadr -SqlInstance $TestConfig.instance3 -Confirm:$false -Force It "enables hadr" { $results.IsHadrEnabled | Should -Be $true } -} \ No newline at end of file +} diff --git a/tests/Enable-DbaDbEncryption.Tests.ps1 b/tests/Enable-DbaDbEncryption.Tests.ps1 index 15a7749ce2..009c014f6d 100644 --- a/tests/Enable-DbaDbEncryption.Tests.ps1 +++ b/tests/Enable-DbaDbEncryption.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Validate parameters" { @@ -18,18 +18,18 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { $PSDefaultParameterValues["*:Confirm"] = $false $passwd = ConvertTo-SecureString "dbatools.IO" -AsPlainText -Force - $masterkey = Get-DbaDbMasterKey -SqlInstance $script:instance2 -Database master + $masterkey = Get-DbaDbMasterKey -SqlInstance $TestConfig.instance2 -Database master if (-not $masterkey) { $delmasterkey = $true - $masterkey = New-DbaServiceMasterKey -SqlInstance $script:instance2 -SecurePassword $passwd + $masterkey = New-DbaServiceMasterKey -SqlInstance $TestConfig.instance2 -SecurePassword $passwd } - $mastercert = Get-DbaDbCertificate -SqlInstance $script:instance2 -Database master | Where-Object Name -notmatch "##" | Select-Object -First 1 + $mastercert = Get-DbaDbCertificate -SqlInstance $TestConfig.instance2 -Database master | Where-Object Name -notmatch "##" | Select-Object -First 1 if (-not $mastercert) { $delmastercert = $true - $mastercert = New-DbaDbCertificate -SqlInstance $script:instance2 + $mastercert = New-DbaDbCertificate -SqlInstance $TestConfig.instance2 } - $db = New-DbaDatabase -SqlInstance $script:instance2 + $db = New-DbaDatabase -SqlInstance $TestConfig.instance2 $db | New-DbaDbMasterKey -SecurePassword $passwd $db | New-DbaDbCertificate $db | New-DbaDbEncryptionKey -Force @@ -53,9 +53,9 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $results.EncryptionEnabled | Should -Be $true } It "should enable encryption on a database" { - $null = Disable-DbaDbEncryption -SqlInstance $script:instance2 -Database $db.Name - $results = Enable-DbaDbEncryption -SqlInstance $script:instance2 -EncryptorName $mastercert.Name -Database $db.Name -Force + $null = Disable-DbaDbEncryption -SqlInstance $TestConfig.instance2 -Database $db.Name + $results = Enable-DbaDbEncryption -SqlInstance $TestConfig.instance2 -EncryptorName $mastercert.Name -Database $db.Name -Force $results.EncryptionEnabled | Should -Be $true } } -} \ No newline at end of file +} diff --git a/tests/Enable-DbaFilestream.Tests.ps1 b/tests/Enable-DbaFilestream.Tests.ps1 index 4675b00944..7b4d52747e 100644 --- a/tests/Enable-DbaFilestream.Tests.ps1 +++ b/tests/Enable-DbaFilestream.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,22 +16,22 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { <# Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $OriginalFileStream = Get-DbaFilestream -SqlInstance $script:instance1 + $OriginalFileStream = Get-DbaFilestream -SqlInstance $TestConfig.instance1 } AfterAll { if ($OriginalFileStream.InstanceAccessLevel -eq 0) { - Disable-DbaFilestream -SqlInstance $script:instance1 -Confirm:$false + Disable-DbaFilestream -SqlInstance $TestConfig.instance1 -Confirm:$false } else { - Enable-DbaFilestream -SqlInstance $script:instance1 -FileStreamLevel $OriginalFileStream.InstanceAccessLevel -Confirm:$false + Enable-DbaFilestream -SqlInstance $TestConfig.instance1 -FileStreamLevel $OriginalFileStream.InstanceAccessLevel -Confirm:$false } } Context "Changing FileStream Level" { $NewLevel = ($OriginalFileStream.FileStreamStateId + 1) % 3 #Move it on one, but keep it less than 4 with modulo division - $results = Enable-DbaFilestream -SqlInstance $script:instance1 -FileStreamLevel $NewLevel -Confirm:$false + $results = Enable-DbaFilestream -SqlInstance $TestConfig.instance1 -FileStreamLevel $NewLevel -Confirm:$false It "Should have changed the FileStream Level" { $results.InstanceAccessLevel | Should be $NewLevel } } } -#> \ No newline at end of file +#> diff --git a/tests/Enable-DbaForceNetworkEncryption.Tests.ps1 b/tests/Enable-DbaForceNetworkEncryption.Tests.ps1 index 7e0125746c..aa4dd9a6c4 100644 --- a/tests/Enable-DbaForceNetworkEncryption.Tests.ps1 +++ b/tests/Enable-DbaForceNetworkEncryption.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -14,9 +14,9 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { } Describe "$commandname Integration Tests" -Tags "IntegrationTests" { - $results = Enable-DbaForceNetworkEncryption $script:instance1 -EnableException + $results = Enable-DbaForceNetworkEncryption $TestConfig.instance1 -EnableException It "returns true" { $results.ForceEncryption -eq $true } -} \ No newline at end of file +} diff --git a/tests/Enable-DbaHideInstance.Tests.ps1 b/tests/Enable-DbaHideInstance.Tests.ps1 index 6804dbe0c2..db6cbf16ae 100644 --- a/tests/Enable-DbaHideInstance.Tests.ps1 +++ b/tests/Enable-DbaHideInstance.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -14,9 +14,13 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { } Describe "$commandname Integration Tests" -Tags "IntegrationTests" { - $results = Enable-DbaHideInstance $script:instance1 -EnableException + AfterAll { + $null = Disable-DbaHideInstance $TestConfig.instance1 + } + + $results = Enable-DbaHideInstance $TestConfig.instance1 -EnableException It "returns true" { $results.HideInstance -eq $true } -} \ No newline at end of file +} diff --git a/tests/Enable-DbaReplDistributor.Tests.ps1 b/tests/Enable-DbaReplDistributor.Tests.ps1 index c1f08019a0..ecec1f8b34 100644 --- a/tests/Enable-DbaReplDistributor.Tests.ps1 +++ b/tests/Enable-DbaReplDistributor.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Add-ReplicationLibrary diff --git a/tests/Enable-DbaReplPublishing.Tests.ps1 b/tests/Enable-DbaReplPublishing.Tests.ps1 index 08143c6619..e0c51d1827 100644 --- a/tests/Enable-DbaReplPublishing.Tests.ps1 +++ b/tests/Enable-DbaReplPublishing.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Add-ReplicationLibrary diff --git a/tests/Enable-DbaStartupProcedure.Tests.ps1 b/tests/Enable-DbaStartupProcedure.Tests.ps1 index 40bafadd4f..59cc961b04 100644 --- a/tests/Enable-DbaStartupProcedure.Tests.ps1 +++ b/tests/Enable-DbaStartupProcedure.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,7 +15,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { } Describe "$commandname Integration Test" -Tag "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $random = Get-Random $startupProcName = "StartUpProc$random" $startupProc = "dbo.$startupProcName" @@ -28,7 +28,7 @@ Describe "$commandname Integration Test" -Tag "IntegrationTests" { } Context "Validate returns correct output for enable" { - $result = Enable-DbaStartupProcedure -SqlInstance $script:instance2 -StartupProcedure $startupProc -Confirm:$false + $result = Enable-DbaStartupProcedure -SqlInstance $TestConfig.instance2 -StartupProcedure $startupProc -Confirm:$false It "returns correct results" { $result.Schema -eq "dbo" | Should Be $true @@ -40,7 +40,7 @@ Describe "$commandname Integration Test" -Tag "IntegrationTests" { } Context "Validate returns correct output for already existing state" { - $result = Enable-DbaStartupProcedure -SqlInstance $script:instance2 -StartupProcedure $startupProc -Confirm:$false + $result = Enable-DbaStartupProcedure -SqlInstance $TestConfig.instance2 -StartupProcedure $startupProc -Confirm:$false It "returns correct results" { $result.Schema -eq "dbo" | Should Be $true @@ -52,7 +52,7 @@ Describe "$commandname Integration Test" -Tag "IntegrationTests" { } Context "Validate returns correct output for missing procedures" { - $result = Enable-DbaStartupProcedure -SqlInstance $script:instance2 -StartupProcedure "Unknown.NotHere" -Confirm:$false + $result = Enable-DbaStartupProcedure -SqlInstance $TestConfig.instance2 -StartupProcedure "Unknown.NotHere" -Confirm:$false It "returns correct results" { $null -eq $result | Should Be $true @@ -60,10 +60,10 @@ Describe "$commandname Integration Test" -Tag "IntegrationTests" { } Context "Validate returns correct output for incorrectly formed procedures" { - $result = Enable-DbaStartupProcedure -SqlInstance $script:instance2 -StartupProcedure "Four.Part.Schema.Name" -Confirm:$false + $result = Enable-DbaStartupProcedure -SqlInstance $TestConfig.instance2 -StartupProcedure "Four.Part.Schema.Name" -Confirm:$false It "returns correct results" { $null -eq $result | Should Be $true } } -} \ No newline at end of file +} diff --git a/tests/Enable-DbaTraceFlag.Tests.ps1 b/tests/Enable-DbaTraceFlag.Tests.ps1 index 58950b47b9..9b27794711 100644 --- a/tests/Enable-DbaTraceFlag.Tests.ps1 +++ b/tests/Enable-DbaTraceFlag.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,8 +16,8 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Verifying TraceFlag output" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 - $startingtfs = Get-DbaTraceFlag -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 + $startingtfs = Get-DbaTraceFlag -SqlInstance $TestConfig.instance2 $safetraceflag = 3226 if ($startingtfs.TraceFlag -contains $safetraceflag) { @@ -36,4 +36,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $results.TraceFlag -contains $safetraceflag | Should Be $true } } -} \ No newline at end of file +} diff --git a/tests/Expand-DbaDbLogFile.Tests.ps1 b/tests/Expand-DbaDbLogFile.Tests.ps1 index f27b05a28a..ce7c93b64f 100644 --- a/tests/Expand-DbaDbLogFile.Tests.ps1 +++ b/tests/Expand-DbaDbLogFile.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,15 +16,15 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { $db1Name = "dbatoolsci_expand" - $db1 = New-DbaDatabase -SqlInstance $script:instance1 -Name $db1Name + $db1 = New-DbaDatabase -SqlInstance $TestConfig.instance1 -Name $db1Name } AfterAll { - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance1 -Database $db1Name + Remove-DbaDatabase -Confirm:$false -SqlInstance $TestConfig.instance1 -Database $db1Name } Context "Ensure command functionality" { - $results = Expand-DbaDbLogFile -SqlInstance $script:instance1 -Database $db1 -TargetLogSize 128 + $results = Expand-DbaDbLogFile -SqlInstance $TestConfig.instance1 -Database $db1 -TargetLogSize 128 It -Skip "Should have correct properties" { $ExpectedProps = 'ComputerName,InstanceName,SqlInstance,Database,ID,Name,LogFileCount,InitialSize,CurrentSize,InitialVLFCount,CurrentVLFCount'.Split(',') @@ -44,4 +44,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } } } -} \ No newline at end of file +} diff --git a/tests/Export-DbaBinaryFile.Tests.ps1 b/tests/Export-DbaBinaryFile.Tests.ps1 index 0150b54102..44d5b21331 100644 --- a/tests/Export-DbaBinaryFile.Tests.ps1 +++ b/tests/Export-DbaBinaryFile.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,10 +15,10 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { BeforeEach { - $db = Get-DbaDatabase -SqlInstance $script:instance2 -Database tempdb + $db = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database tempdb $null = $db.Query("CREATE TABLE [dbo].[BunchOFilezz]([FileName123] [nvarchar](50) NULL, [TheFile123] [image] NULL)") - $null = Import-DbaBinaryFile -SqlInstance $script:instance2 -Database tempdb -Table BunchOFilezz -FilePath $script:appveyorlabrepo\azure\adalsql.msi - $null = Get-ChildItem $script:appveyorlabrepo\certificates | Import-DbaBinaryFile -SqlInstance $script:instance2 -Database tempdb -Table BunchOFilezz + $null = Import-DbaBinaryFile -SqlInstance $TestConfig.instance2 -Database tempdb -Table BunchOFilezz -FilePath "$($TestConfig.appveyorlabrepo)\azure\adalsql.msi" + $null = Get-ChildItem "$($TestConfig.appveyorlabrepo)\certificates" | Import-DbaBinaryFile -SqlInstance $TestConfig.instance2 -Database tempdb -Table BunchOFilezz } AfterEach { try { @@ -30,14 +30,14 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } It "exports the table data to file" { - $results = Export-DbaBinaryFile -SqlInstance $script:instance2 -Database tempdb -Path C:\temp\exports + $results = Export-DbaBinaryFile -SqlInstance $TestConfig.instance2 -Database tempdb -Path C:\temp\exports $results.Name.Count | Should -Be 3 $results.Name | Should -Be @('adalsql.msi', 'localhost.crt', 'localhost.pfx') } It "exports the table data to file" { - $results = Get-DbaBinaryFileTable -SqlInstance $script:instance2 -Database tempdb | Export-DbaBinaryFile -Path C:\temp\exports + $results = Get-DbaBinaryFileTable -SqlInstance $TestConfig.instance2 -Database tempdb | Export-DbaBinaryFile -Path C:\temp\exports $results.Name.Count | Should -Be 3 $results.Name | Should -Be @('adalsql.msi', 'localhost.crt', 'localhost.pfx') } -} \ No newline at end of file +} diff --git a/tests/Export-DbaCredential.Tests.ps1 b/tests/Export-DbaCredential.Tests.ps1 index 34e6cf6dd9..e31d3801c7 100644 --- a/tests/Export-DbaCredential.Tests.ps1 +++ b/tests/Export-DbaCredential.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -18,19 +18,19 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { BeforeAll { $plaintext = "ReallyT3rrible!" $password = ConvertTo-SecureString $plaintext -AsPlainText -Force - $null = New-DbaCredential -SqlInstance $script:instance2 -Name dbatoolsci_CaptainAcred -Identity dbatoolsci_CaptainAcredId -Password $password - $null = New-DbaCredential -SqlInstance $script:instance2 -Identity dbatoolsci_Hulk -Password $password + $null = New-DbaCredential -SqlInstance $TestConfig.instance2 -Name dbatoolsci_CaptainAcred -Identity dbatoolsci_CaptainAcredId -Password $password + $null = New-DbaCredential -SqlInstance $TestConfig.instance2 -Identity dbatoolsci_Hulk -Password $password $allfiles = @() } AfterAll { try { - (Get-DbaCredential -SqlInstance $script:instance2 -Identity dbatoolsci_CaptainAcred, dbatoolsci_Hulk -ErrorAction Stop -WarningAction SilentlyContinue).Drop() + (Get-DbaCredential -SqlInstance $TestConfig.instance2 -Identity dbatoolsci_CaptainAcred, dbatoolsci_Hulk -ErrorAction Stop -WarningAction SilentlyContinue).Drop() } catch { } $null = $allfiles | Remove-Item -ErrorAction Ignore } Context "Should export all credentails" { - $file = Export-DbaCredential -SqlInstance $script:instance2 + $file = Export-DbaCredential -SqlInstance $TestConfig.instance2 $results = Get-Content -Path $file -Raw $allfiles += $file It "Should have information" { @@ -46,7 +46,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Should export a specific credential" { $filepath = "$env:USERPROFILE\Documents\dbatoolsci_credential.sql" - $null = Export-DbaCredential -SqlInstance $script:instance2 -Identity 'dbatoolsci_CaptainAcredId' -FilePath $filepath + $null = Export-DbaCredential -SqlInstance $TestConfig.instance2 -Identity 'dbatoolsci_CaptainAcredId' -FilePath $filepath $results = Get-Content -Path $filepath $allfiles += $filepath @@ -65,7 +65,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Should export a specific credential and append it to exisiting export" { $filepath = "$env:USERPROFILE\Documents\dbatoolsci_credential.sql" - $null = Export-DbaCredential -SqlInstance $script:instance2 -Identity 'dbatoolsci_Hulk' -FilePath $filepath -Append + $null = Export-DbaCredential -SqlInstance $TestConfig.instance2 -Identity 'dbatoolsci_Hulk' -FilePath $filepath -Append $results = Get-Content -Path $filepath It "Should have information" { @@ -83,7 +83,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Should export a specific credential excluding the password" { $filepath = "$env:USERPROFILE\Documents\temp-credential.sql" - $null = Export-DbaCredential -SqlInstance $script:instance2 -Identity 'dbatoolsci_CaptainAcredId' -FilePath $filepath -ExcludePassword + $null = Export-DbaCredential -SqlInstance $TestConfig.instance2 -Identity 'dbatoolsci_CaptainAcredId' -FilePath $filepath -ExcludePassword $results = Get-Content -Path $filepath $allfiles += $filepath @@ -99,4 +99,4 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $results | Should Not Match 'ReallyT3rrible!' } } -} \ No newline at end of file +} diff --git a/tests/Export-DbaDacPackage.Tests.ps1 b/tests/Export-DbaDacPackage.Tests.ps1 index f32783844a..4bef8bd248 100644 --- a/tests/Export-DbaDacPackage.Tests.ps1 +++ b/tests/Export-DbaDacPackage.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -18,9 +18,9 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $random = Get-Random $dbname = "dbatoolsci_exportdacpac_$random" try { - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance1 $null = $server.Query("Create Database [$dbname]") - $db = Get-DbaDatabase -SqlInstance $script:instance1 -Database $dbname + $db = Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $dbname $null = $db.Query("CREATE TABLE dbo.example (id int, PRIMARY KEY (id)); INSERT dbo.example SELECT top 100 object_id @@ -32,21 +32,21 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $dbName2 = "dbatoolsci:2_$random" $dbName2Escaped = "dbatoolsci`$2_$random" - $null = New-DbaDatabase -SqlInstance $script:instance1 -Name $dbName2 + $null = New-DbaDatabase -SqlInstance $TestConfig.instance1 -Name $dbName2 } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance1 -Database $dbname, $dbName2 -Confirm:$false + Remove-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $dbname, $dbName2 -Confirm:$false } # See https://github.com/dataplat/dbatools/issues/7038 Context "Ensure the database name is part of the generated filename" { It "Database name is included in the output filename" { - $result = Export-DbaDacPackage -SqlInstance $script:instance1 -Database $dbname + $result = Export-DbaDacPackage -SqlInstance $TestConfig.instance1 -Database $dbname $result.Path | Should -BeLike "*$($dbName)*" } It "Database names with invalid filesystem chars are successfully exported" { - $result = Export-DbaDacPackage -SqlInstance $script:instance1 -Database $dbname, $dbName2 + $result = Export-DbaDacPackage -SqlInstance $TestConfig.instance1 -Database $dbname, $dbName2 $result.Path.Count | Should -Be 2 $result.Path[0] | Should -BeLike "*$($dbName)*" $result.Path[1] | Should -BeLike "*$($dbName2Escaped)*" @@ -61,10 +61,10 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Pop-Location Remove-Item $testFolder -Force -Recurse } - if ((Get-DbaDbTable -SqlInstance $script:instance1 -Database $dbname -Table example)) { + if ((Get-DbaDbTable -SqlInstance $TestConfig.instance1 -Database $dbname -Table example)) { # Sometimes appveyor bombs It "exports a dacpac" { - $results = Export-DbaDacPackage -SqlInstance $script:instance1 -Database $dbname + $results = Export-DbaDacPackage -SqlInstance $TestConfig.instance1 -Database $dbname $results.Path | Should -Not -BeNullOrEmpty Test-Path $results.Path | Should -Be $true if (($results).Path) { @@ -74,14 +74,14 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { It "exports to the correct directory" { $relativePath = '.\' $expectedPath = (Resolve-Path $relativePath).Path - $results = Export-DbaDacPackage -SqlInstance $script:instance1 -Database $dbname -Path $relativePath + $results = Export-DbaDacPackage -SqlInstance $TestConfig.instance1 -Database $dbname -Path $relativePath $results.Path | Split-Path | Should -Be $expectedPath Test-Path $results.Path | Should -Be $true } It "exports dacpac with a table list" { $relativePath = '.\extract.dacpac' $expectedPath = Join-Path (Get-Item .) 'extract.dacpac' - $results = Export-DbaDacPackage -SqlInstance $script:instance1 -Database $dbname -FilePath $relativePath -Table example + $results = Export-DbaDacPackage -SqlInstance $TestConfig.instance1 -Database $dbname -FilePath $relativePath -Table example $results.Path | Should -Be $expectedPath Test-Path $results.Path | Should -Be $true if (($results).Path) { @@ -90,7 +90,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } It "uses EXE to extract dacpac" { $exportProperties = "/p:ExtractAllTableData=True" - $results = Export-DbaDacPackage -SqlInstance $script:instance1 -Database $dbname -ExtendedProperties $exportProperties + $results = Export-DbaDacPackage -SqlInstance $TestConfig.instance1 -Database $dbname -ExtendedProperties $exportProperties $results.Path | Should -Not -BeNullOrEmpty Test-Path $results.Path | Should -Be $true if (($results).Path) { @@ -108,10 +108,10 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Pop-Location Remove-Item $testFolder -Force -Recurse } - if ((Get-DbaDbTable -SqlInstance $script:instance1 -Database $dbname -Table example)) { + if ((Get-DbaDbTable -SqlInstance $TestConfig.instance1 -Database $dbname -Table example)) { # Sometimes appveyor bombs It "exports a bacpac" { - $results = Export-DbaDacPackage -SqlInstance $script:instance1 -Database $dbname -Type Bacpac + $results = Export-DbaDacPackage -SqlInstance $TestConfig.instance1 -Database $dbname -Type Bacpac $results.Path | Should -Not -BeNullOrEmpty Test-Path $results.Path | Should -Be $true if (($results).Path) { @@ -121,7 +121,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { It "exports bacpac with a table list" { $relativePath = '.\extract.bacpac' $expectedPath = Join-Path (Get-Item .) 'extract.bacpac' - $results = Export-DbaDacPackage -SqlInstance $script:instance1 -Database $dbname -FilePath $relativePath -Table example -Type Bacpac + $results = Export-DbaDacPackage -SqlInstance $TestConfig.instance1 -Database $dbname -FilePath $relativePath -Table example -Type Bacpac $results.Path | Should -Be $expectedPath Test-Path $results.Path | Should -Be $true if (($results).Path) { @@ -130,7 +130,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } It "uses EXE to extract bacpac" { $exportProperties = "/p:TargetEngineVersion=Default" - $results = Export-DbaDacPackage -SqlInstance $script:instance1 -Database $dbname -ExtendedProperties $exportProperties -Type Bacpac + $results = Export-DbaDacPackage -SqlInstance $TestConfig.instance1 -Database $dbname -ExtendedProperties $exportProperties -Type Bacpac $results.Path | Should -Not -BeNullOrEmpty Test-Path $results.Path | Should -Be $true if (($results).Path) { @@ -139,4 +139,4 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } } -} \ No newline at end of file +} diff --git a/tests/Export-DbaDbRole.Tests.ps1 b/tests/Export-DbaDbRole.Tests.ps1 index 452016eafb..e70895f771 100644 --- a/tests/Export-DbaDbRole.Tests.ps1 +++ b/tests/Export-DbaDbRole.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -24,7 +24,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $user1 = "dbatoolsci_exportdbadbrole_user1$random" $dbRole = "dbatoolsci_SpExecute$random" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $null = $server.Query("CREATE DATABASE [$dbname1]") $null = $server.Query("CREATE LOGIN [$login1] WITH PASSWORD = 'GoodPass1234!'") $server.Databases[$dbname1].ExecuteNonQuery("CREATE USER [$user1] FOR LOGIN [$login1]") @@ -37,15 +37,15 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } AfterAll { try { - Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbname1 -Confirm:$false - Remove-DbaLogin -SqlInstance $script:instance2 -Login $login1 -Confirm:$false + Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname1 -Confirm:$false + Remove-DbaLogin -SqlInstance $TestConfig.instance2 -Login $login1 -Confirm:$false } catch { } (Get-ChildItem $outputFile1 -ErrorAction SilentlyContinue) | Remove-Item -ErrorAction SilentlyContinue } Context "Check if output file was created" { - $null = Export-DbaDbRole -SqlInstance $script:instance2 -Database msdb -FilePath $outputFile1 + $null = Export-DbaDbRole -SqlInstance $TestConfig.instance2 -Database msdb -FilePath $outputFile1 It "Exports results to one sql file" { (Get-ChildItem $outputFile1).Count | Should Be 1 } @@ -56,7 +56,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Check piping support" { - $role = Get-DbaDbRole -SqlInstance $script:instance2 -Database $dbname1 -Role $dbRole + $role = Get-DbaDbRole -SqlInstance $TestConfig.instance2 -Database $dbname1 -Role $dbRole $null = $role | Export-DbaDbRole -FilePath $outputFile1 It "Exports results to one sql file" { (Get-ChildItem $outputFile1).Count | Should Be 1 @@ -85,4 +85,4 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $script:results -match "ALTER ROLE [$dbRole] ADD MEMBER [$user1];" } } -} \ No newline at end of file +} diff --git a/tests/Export-DbaDbTableData.Tests.ps1 b/tests/Export-DbaDbTableData.Tests.ps1 index 63a1545243..67ebc1b3f3 100644 --- a/tests/Export-DbaDbTableData.Tests.ps1 +++ b/tests/Export-DbaDbTableData.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,7 +15,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $db = Get-DbaDatabase -SqlInstance $script:instance1 -Database tempdb + $db = Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database tempdb $null = $db.Query("CREATE TABLE dbo.dbatoolsci_example (id int); INSERT dbo.dbatoolsci_example SELECT top 10 1 @@ -34,17 +34,17 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { It "exports the table data" { $escaped = [regex]::escape('INSERT [dbo].[dbatoolsci_example] ([id]) VALUES (1)') $secondescaped = [regex]::escape('INSERT [dbo].[dbatoolsci_temp] ([name], [database_id],') - $results = Get-DbaDbTable -SqlInstance $script:instance1 -Database tempdb -Table dbatoolsci_example | Export-DbaDbTableData -Passthru + $results = Get-DbaDbTable -SqlInstance $TestConfig.instance1 -Database tempdb -Table dbatoolsci_example | Export-DbaDbTableData -Passthru "$results" | Should -match $escaped - $results = Get-DbaDbTable -SqlInstance $script:instance1 -Database tempdb -Table dbatoolsci_temp | Export-DbaDbTableData -Passthru + $results = Get-DbaDbTable -SqlInstance $TestConfig.instance1 -Database tempdb -Table dbatoolsci_temp | Export-DbaDbTableData -Passthru "$results" | Should -Match $secondescaped } It "supports piping more than one table" { $escaped = [regex]::escape('INSERT [dbo].[dbatoolsci_example] ([id]) VALUES (1)') $secondescaped = [regex]::escape('INSERT [dbo].[dbatoolsci_temp] ([name], [database_id],') - $results = Get-DbaDbTable -SqlInstance $script:instance1 -Database tempdb -Table dbatoolsci_example, dbatoolsci_temp | Export-DbaDbTableData -Passthru + $results = Get-DbaDbTable -SqlInstance $TestConfig.instance1 -Database tempdb -Table dbatoolsci_example, dbatoolsci_temp | Export-DbaDbTableData -Passthru "$results" | Should -match $escaped "$results" | Should -match $secondescaped } -} \ No newline at end of file +} diff --git a/tests/Export-DbaDiagnosticQuery.Tests.ps1 b/tests/Export-DbaDiagnosticQuery.Tests.ps1 index fedbbcc148..3c4090a86a 100644 --- a/tests/Export-DbaDiagnosticQuery.Tests.ps1 +++ b/tests/Export-DbaDiagnosticQuery.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -20,8 +20,8 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } Context "Verifying output" { It "exports results to one file and creates directory if required" { - $null = Invoke-DbaDiagnosticQuery -SqlInstance $script:instance2 -QueryName 'Memory Clerk Usage' | Export-DbaDiagnosticQuery -Path "C:\temp\dbatoolsci" + $null = Invoke-DbaDiagnosticQuery -SqlInstance $TestConfig.instance2 -QueryName 'Memory Clerk Usage' | Export-DbaDiagnosticQuery -Path "C:\temp\dbatoolsci" (Get-ChildItem "C:\temp\dbatoolsci").Count | Should Be 1 } } -} \ No newline at end of file +} diff --git a/tests/Export-DbaExecutionPlan.Tests.ps1 b/tests/Export-DbaExecutionPlan.Tests.ps1 index 9a79ed7c94..89a15f6f96 100644 --- a/tests/Export-DbaExecutionPlan.Tests.ps1 +++ b/tests/Export-DbaExecutionPlan.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Export-DbaInstance.Tests.ps1 b/tests/Export-DbaInstance.Tests.ps1 index ab16368b10..8223f7ee81 100644 --- a/tests/Export-DbaInstance.Tests.ps1 +++ b/tests/Export-DbaInstance.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -40,7 +40,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } # registered server and group - $testServer = $script:instance2 + $testServer = $TestConfig.instance2 $server = Connect-DbaInstance -SqlInstance $testServer $srvName = "dbatoolsci-server1" $group = "dbatoolsci-group1" @@ -358,4 +358,4 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { # placeholder for a future test with availability groups It -Skip "Export availability groups" { } -} \ No newline at end of file +} diff --git a/tests/Export-DbaLinkedServer.Tests.ps1 b/tests/Export-DbaLinkedServer.Tests.ps1 index ab3c37b882..dd29fdec44 100644 --- a/tests/Export-DbaLinkedServer.Tests.ps1 +++ b/tests/Export-DbaLinkedServer.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Export-DbaLogin.Tests.ps1 b/tests/Export-DbaLogin.Tests.ps1 index d648a2bbe5..e1ce21f4ef 100644 --- a/tests/Export-DbaLogin.Tests.ps1 +++ b/tests/Export-DbaLogin.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -26,7 +26,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $login2 = "dbatoolsci_exportdbalogin_login2$random" $user2 = "dbatoolsci_exportdbalogin_user2$random" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $db1 = New-DbaDatabase -SqlInstance $server -Name $dbname1 $null = $server.Query("CREATE LOGIN [$login1] WITH PASSWORD = 'GoodPass1234!'") $db1.Query("CREATE USER [$user1] FOR LOGIN [$login1]") @@ -50,35 +50,35 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $db1.Query("CREATE USER [$login3] WITHOUT LOGIN") } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbname1 -Confirm:$false - Remove-DbaLogin -SqlInstance $script:instance2 -Login $login1 -Confirm:$false + Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname1 -Confirm:$false + Remove-DbaLogin -SqlInstance $TestConfig.instance2 -Login $login1 -Confirm:$false - Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbname2 -Confirm:$false - Remove-DbaLogin -SqlInstance $script:instance2 -Login $login2 -Confirm:$false + Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname2 -Confirm:$false + Remove-DbaLogin -SqlInstance $TestConfig.instance2 -Login $login2 -Confirm:$false $timenow = (Get-Date -uformat "%m%d%Y%H") $ExportedCredential = Get-ChildItem $DefaultExportPath, $AltExportPath | Where-Object { $_.Name -match "$timenow\d{4}-login.sql|Dbatoolsci_login_CustomFile.sql" } if ($ExportedCredential) { $null = Remove-Item -Path $($ExportedCredential.FullName) -ErrorAction SilentlyContinue } - Remove-DbaLogin -SqlInstance $script:instance2 -Login $login3 -Confirm:$false + Remove-DbaLogin -SqlInstance $TestConfig.instance2 -Login $login3 -Confirm:$false } Context "Executes with Exclude Parameters" { It "Should exclude databases when exporting" { - $file = Export-DbaLogin -SqlInstance $script:instance2 -ExcludeDatabase -WarningAction SilentlyContinue + $file = Export-DbaLogin -SqlInstance $TestConfig.instance2 -ExcludeDatabase -WarningAction SilentlyContinue $results = Get-Content -Path $file -Raw $allfiles += $file.FullName $results | Should Match '\nGo\r' } It "Should exclude Jobs when exporting" { - $file = Export-DbaLogin -SqlInstance $script:instance2 -ExcludeJobs -WarningAction SilentlyContinue + $file = Export-DbaLogin -SqlInstance $TestConfig.instance2 -ExcludeJobs -WarningAction SilentlyContinue $results = Get-Content -Path $file -Raw $allfiles += $file.FullName $results | Should Not Match 'Job' } It "Should exclude Go when exporting" { - $file = Export-DbaLogin -SqlInstance $script:instance2 -BatchSeparator '' -ObjectLevel -WarningAction SilentlyContinue + $file = Export-DbaLogin -SqlInstance $TestConfig.instance2 -BatchSeparator '' -ObjectLevel -WarningAction SilentlyContinue $results = Get-Content -Path $file -Raw $allfiles += $file.FullName $results | Should Not Match 'GO' @@ -88,13 +88,13 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $results | Should Match "USE \[$dbname2\]" } It "Should exclude a specific login" { - $file = Export-DbaLogin -SqlInstance $script:instance2 -ExcludeLogin $login1 -WarningAction SilentlyContinue + $file = Export-DbaLogin -SqlInstance $TestConfig.instance2 -ExcludeLogin $login1 -WarningAction SilentlyContinue $results = Get-Content -Path $file -Raw $allfiles += $file.FullName $results | Should Not Match "$login1" } It "Should exclude passwords" { - $file = Export-DbaLogin -SqlInstance $script:instance2 -ExcludeLogin $login1 -WarningAction SilentlyContinue -ExcludePassword + $file = Export-DbaLogin -SqlInstance $TestConfig.instance2 -ExcludeLogin $login1 -WarningAction SilentlyContinue -ExcludePassword $results = Get-Content -Path $file -Raw $allfiles += $file.FullName $results | Should Not Match '(?<=PASSWORD =\s0x)(\w+)' @@ -102,7 +102,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } Context "Executes for various users, databases, and environments" { It "Should Export a specific user" { - $file = Export-DbaLogin -SqlInstance $script:instance2 -Login $login1 -Database $dbname1 -DefaultDatabase master -WarningAction SilentlyContinue + $file = Export-DbaLogin -SqlInstance $TestConfig.instance2 -Login $login1 -Database $dbname1 -DefaultDatabase master -WarningAction SilentlyContinue $results = Get-Content -Path $file -Raw $allfiles += $file.FullName $results | Should Not Match "$login2|$dbname2" @@ -110,7 +110,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $results | Should -Match ([regex]::Escape("IF NOT EXISTS (SELECT * FROM sys.database_principals WHERE name = N'$user1')")) } It "Should Export with object level permissions" { - $results = Export-DbaLogin -SqlInstance $script:instance2 -Login $login2 -ObjectLevel -PassThru -WarningAction SilentlyContinue + $results = Export-DbaLogin -SqlInstance $TestConfig.instance2 -Login $login2 -ObjectLevel -PassThru -WarningAction SilentlyContinue $results | Should Not Match "$login1|$dbname1" $results | Should Match "GRANT SELECT ON OBJECT::\[sys\]\.\[tables\] TO \[$user2\] WITH GRANT OPTION" $results | Should Match "CREATE USER \[$user2\] FOR LOGIN \[$login2\]" @@ -119,7 +119,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } foreach ($version in $((Get-Command $CommandName).Parameters.DestinationVersion.attributes.validvalues)) { It "Should Export for the SQLVersion $version" { - $file = Export-DbaLogin -SqlInstance $script:instance2 -Login $login2 -Database $dbname2 -DestinationVersion $version -WarningAction SilentlyContinue + $file = Export-DbaLogin -SqlInstance $TestConfig.instance2 -Login $login2 -Database $dbname2 -DestinationVersion $version -WarningAction SilentlyContinue $results = Get-Content -Path $file -Raw $allfiles += $file.FullName $results | Should Match "$login2|$dbname2" @@ -136,30 +136,30 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } Context "Exports file to random and specified paths" { It "Should export file to the configured path" { - $file = Export-DbaLogin -SqlInstance $script:instance2 -ExcludeDatabase -WarningAction SilentlyContinue + $file = Export-DbaLogin -SqlInstance $TestConfig.instance2 -ExcludeDatabase -WarningAction SilentlyContinue $results = $file.DirectoryName $allfiles += $file.FullName $results | Should Be $DefaultExportPath } It "Should export file to custom folder path" { - $file = Export-DbaLogin -SqlInstance $script:instance2 -Path $AltExportPath -ExcludeDatabase -WarningAction SilentlyContinue + $file = Export-DbaLogin -SqlInstance $TestConfig.instance2 -Path $AltExportPath -ExcludeDatabase -WarningAction SilentlyContinue $results = $file.DirectoryName $allfiles += $file.FullName $results | Should Be $AltExportPath } It "Should export file to custom file path" { - $file = Export-DbaLogin -SqlInstance $script:instance2 -FilePath "$AltExportPath\Dbatoolsci_login_CustomFile.sql" -ExcludeDatabase -WarningAction SilentlyContinue + $file = Export-DbaLogin -SqlInstance $TestConfig.instance2 -FilePath "$AltExportPath\Dbatoolsci_login_CustomFile.sql" -ExcludeDatabase -WarningAction SilentlyContinue $results = $file.Name $allfiles += $file.FullName $results | Should Be "Dbatoolsci_login_CustomFile.sql" } It "Should export file to custom file path and Append" { - $file = Export-DbaLogin -SqlInstance $script:instance2 -FilePath "$AltExportPath\Dbatoolsci_login_CustomFile.sql" -Append -ExcludeDatabase -WarningAction SilentlyContinue + $file = Export-DbaLogin -SqlInstance $TestConfig.instance2 -FilePath "$AltExportPath\Dbatoolsci_login_CustomFile.sql" -Append -ExcludeDatabase -WarningAction SilentlyContinue $allfiles += $file.FullName $file.CreationTimeUtc.Ticks | Should BeLessThan $file.LastWriteTimeUtc.Ticks } It "Should not export file to custom file path with NoClobber" { - { Export-DbaLogin -SqlInstance $script:instance2 -FilePath "$AltExportPath\Dbatoolsci_login_CustomFile.sql" -NoClobber -WarningAction SilentlyContinue } | Should Throw + { Export-DbaLogin -SqlInstance $TestConfig.instance2 -FilePath "$AltExportPath\Dbatoolsci_login_CustomFile.sql" -NoClobber -WarningAction SilentlyContinue } | Should Throw } } -} \ No newline at end of file +} diff --git a/tests/Export-DbaPfDataCollectorSetTemplate.Tests.ps1 b/tests/Export-DbaPfDataCollectorSetTemplate.Tests.ps1 index 871c448aff..23ff591bae 100644 --- a/tests/Export-DbaPfDataCollectorSetTemplate.Tests.ps1 +++ b/tests/Export-DbaPfDataCollectorSetTemplate.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Export-DbaRegServer.Tests.ps1 b/tests/Export-DbaRegServer.Tests.ps1 index b3f13679be..82062be11b 100644 --- a/tests/Export-DbaRegServer.Tests.ps1 +++ b/tests/Export-DbaRegServer.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Validate parameters" { @@ -20,29 +20,29 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $regSrvName = "dbatoolsci-server12" $regSrvDesc = "dbatoolsci-server123" - $newGroup = Add-DbaRegServerGroup -SqlInstance $script:instance2 -Name $group - $newServer = Add-DbaRegServer -SqlInstance $script:instance2 -ServerName $srvName -Name $regSrvName -Description $regSrvDesc + $newGroup = Add-DbaRegServerGroup -SqlInstance $TestConfig.instance2 -Name $group + $newServer = Add-DbaRegServer -SqlInstance $TestConfig.instance2 -ServerName $srvName -Name $regSrvName -Description $regSrvDesc $srvName2 = "dbatoolsci-server2" $group2 = "dbatoolsci-group2" $regSrvName2 = "dbatoolsci-server21" $regSrvDesc2 = "dbatoolsci-server321" - $newGroup2 = Add-DbaRegServerGroup -SqlInstance $script:instance2 -Name $group2 - $newServer2 = Add-DbaRegServer -SqlInstance $script:instance2 -ServerName $srvName2 -Name $regSrvName2 -Description $regSrvDesc2 + $newGroup2 = Add-DbaRegServerGroup -SqlInstance $TestConfig.instance2 -Name $group2 + $newServer2 = Add-DbaRegServer -SqlInstance $TestConfig.instance2 -ServerName $srvName2 -Name $regSrvName2 -Description $regSrvDesc2 $regSrvName3 = "dbatoolsci-server3" $srvName3 = "dbatoolsci-server3" $regSrvDesc3 = "dbatoolsci-server3desc" - $newServer3 = Add-DbaRegServer -SqlInstance $script:instance2 -ServerName $srvName3 -Name $regSrvName3 -Description $regSrvDesc3 + $newServer3 = Add-DbaRegServer -SqlInstance $TestConfig.instance2 -ServerName $srvName3 -Name $regSrvName3 -Description $regSrvDesc3 $random = Get-Random $newDirectory = "C:\temp-$random" } AfterEach { - Get-DbaRegServer -SqlInstance $script:instance2 | Where-Object Name -Match dbatoolsci | Remove-DbaRegServer -Confirm:$false - Get-DbaRegServerGroup -SqlInstance $script:instance2 | Where-Object Name -Match dbatoolsci | Remove-DbaRegServerGroup -Confirm:$false + Get-DbaRegServer -SqlInstance $TestConfig.instance2 | Where-Object Name -Match dbatoolsci | Remove-DbaRegServer -Confirm:$false + Get-DbaRegServerGroup -SqlInstance $TestConfig.instance2 | Where-Object Name -Match dbatoolsci | Remove-DbaRegServerGroup -Confirm:$false $results, $results2, $results3 | Remove-Item -ErrorAction Ignore Remove-Item $newDirectory -ErrorAction Ignore -Recurse -Force @@ -63,59 +63,59 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { It "creates an importable xml file" { $results3 = $newServer3 | Export-DbaRegServer -Path C:\temp - Get-DbaRegServer -SqlInstance $script:instance2 | Where-Object Name -Match dbatoolsci | Remove-DbaRegServer -Confirm:$false - Get-DbaRegServerGroup -SqlInstance $script:instance2 | Where-Object Name -Match dbatoolsci | Remove-DbaRegServerGroup -Confirm:$false - $results4 = Import-DbaRegServer -SqlInstance $script:instance2 -Path $results3 + Get-DbaRegServer -SqlInstance $TestConfig.instance2 | Where-Object Name -Match dbatoolsci | Remove-DbaRegServer -Confirm:$false + Get-DbaRegServerGroup -SqlInstance $TestConfig.instance2 | Where-Object Name -Match dbatoolsci | Remove-DbaRegServerGroup -Confirm:$false + $results4 = Import-DbaRegServer -SqlInstance $TestConfig.instance2 -Path $results3 $newServer3.ServerName | Should -BeIn $results4.ServerName $newServer3.Description | Should -BeIn $results4.Description } It "Create an xml file using FilePath" { $outputFileName = "C:\temp\dbatoolsci-regsrvr-export-$random.xml" - $results = Export-DbaRegServer -SqlInstance $script:instance2 -FilePath $outputFileName + $results = Export-DbaRegServer -SqlInstance $TestConfig.instance2 -FilePath $outputFileName $results -is [System.IO.FileInfo] | Should -Be $true $results.FullName | Should -Be $outputFileName } It "Create a regsrvr file using the FilePath alias OutFile" { $outputFileName = "C:\temp\dbatoolsci-regsrvr-export-$random.regsrvr" - $results = Export-DbaRegServer -SqlInstance $script:instance2 -OutFile $outputFileName + $results = Export-DbaRegServer -SqlInstance $TestConfig.instance2 -OutFile $outputFileName $results -is [System.IO.FileInfo] | Should -Be $true $results.FullName | Should -Be $outputFileName } It "Try to create an invalid file using FilePath" { $outputFileName = "C:\temp\dbatoolsci-regsrvr-export-$random.txt" - $results = Export-DbaRegServer -SqlInstance $script:instance2 -FilePath $outputFileName + $results = Export-DbaRegServer -SqlInstance $TestConfig.instance2 -FilePath $outputFileName $results.length | Should -Be 0 } It "Create an xml file using the FilePath alias FileName in a directory that does not yet exist" { $outputFileName = "$newDirectory\dbatoolsci-regsrvr-export-$random.xml" - $results = Export-DbaRegServer -SqlInstance $script:instance2 -FileName $outputFileName + $results = Export-DbaRegServer -SqlInstance $TestConfig.instance2 -FileName $outputFileName $results -is [System.IO.FileInfo] | Should -Be $true $results.FullName | Should -Be $outputFileName } It "Ensure the Overwrite param is working" { $outputFileName = "C:\temp\dbatoolsci-regsrvr-export-$random.xml" - $results = Export-DbaRegServer -SqlInstance $script:instance2 -FilePath $outputFileName + $results = Export-DbaRegServer -SqlInstance $TestConfig.instance2 -FilePath $outputFileName $results -is [System.IO.FileInfo] | Should -Be $true $results.FullName | Should -Be $outputFileName # test without -Overwrite - $invalidResults = Export-DbaRegServer -SqlInstance $script:instance2 -FilePath $outputFileName + $invalidResults = Export-DbaRegServer -SqlInstance $TestConfig.instance2 -FilePath $outputFileName $invalidResults.length | Should -Be 0 # test with -Overwrite - $resultsOverwrite = Export-DbaRegServer -SqlInstance $script:instance2 -FilePath $outputFileName -Overwrite + $resultsOverwrite = Export-DbaRegServer -SqlInstance $TestConfig.instance2 -FilePath $outputFileName -Overwrite $resultsOverwrite -is [System.IO.FileInfo] | Should -Be $true $resultsOverwrite.FullName | Should -Be $outputFileName } It "Test with the Group param" { $outputFileName = "C:\temp\dbatoolsci-regsrvr-export-$random.xml" - $results = Export-DbaRegServer -SqlInstance $script:instance2 -FilePath $outputFileName -Group $group + $results = Export-DbaRegServer -SqlInstance $TestConfig.instance2 -FilePath $outputFileName -Group $group $results -is [System.IO.FileInfo] | Should -Be $true $results.FullName | Should -Be $outputFileName @@ -127,7 +127,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { It "Test with the Group param and multiple group names" { $outputFileName = "C:\temp\dbatoolsci-regsrvr-export-$random.xml" - $results = Export-DbaRegServer -SqlInstance $script:instance2 -FilePath $outputFileName -Group @($group, $group2) + $results = Export-DbaRegServer -SqlInstance $TestConfig.instance2 -FilePath $outputFileName -Group @($group, $group2) $results.length | Should -Be 2 $fileText = Get-Content -Path $results[0] -Raw @@ -142,7 +142,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } It "Test with the ExcludeGroup param" { - $results = Export-DbaRegServer -SqlInstance $script:instance2 -ExcludeGroup $group2 + $results = Export-DbaRegServer -SqlInstance $TestConfig.instance2 -ExcludeGroup $group2 $results -is [System.IO.FileInfo] | Should -Be $true $fileText = Get-Content -Path $results -Raw @@ -150,4 +150,4 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $fileText | Should -Match $group $fileText | Should -Not -Match $group2 } -} \ No newline at end of file +} diff --git a/tests/Export-DbaReplServerSetting.Tests.ps1 b/tests/Export-DbaReplServerSetting.Tests.ps1 index 4ff9ddbac7..60263b015a 100644 --- a/tests/Export-DbaReplServerSetting.Tests.ps1 +++ b/tests/Export-DbaReplServerSetting.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Add-ReplicationLibrary diff --git a/tests/Export-DbaScript.Tests.ps1 b/tests/Export-DbaScript.Tests.ps1 index 712cb36138..100a1e0ba1 100644 --- a/tests/Export-DbaScript.Tests.ps1 +++ b/tests/Export-DbaScript.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -17,40 +17,40 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "works as expected" { It "should export some text matching create table" { - $results = Get-DbaDbTable -SqlInstance $script:instance2 -Database msdb | Select-Object -First 1 | Export-DbaScript -Passthru + $results = Get-DbaDbTable -SqlInstance $TestConfig.instance2 -Database msdb | Select-Object -First 1 | Export-DbaScript -Passthru $results -match "CREATE TABLE" } It "should include BatchSeparator based on the Formatting.BatchSeparator configuration" { - $results = Get-DbaDbTable -SqlInstance $script:instance2 -Database msdb | Select-Object -First 1 | Export-DbaScript -Passthru + $results = Get-DbaDbTable -SqlInstance $TestConfig.instance2 -Database msdb | Select-Object -First 1 | Export-DbaScript -Passthru $results -match "(Get-DbatoolsConfigValue -FullName 'Formatting.BatchSeparator')" } It "should include the defined BatchSeparator" { - $results = Get-DbaDbTable -SqlInstance $script:instance2 -Database msdb | Select-Object -First 1 | Export-DbaScript -Passthru -BatchSeparator "MakeItSo" + $results = Get-DbaDbTable -SqlInstance $TestConfig.instance2 -Database msdb | Select-Object -First 1 | Export-DbaScript -Passthru -BatchSeparator "MakeItSo" $results -match "MakeItSo" } It "should not accept non-SMO objects" { - $null = Get-DbaDbTable -SqlInstance $script:instance2 -Database msdb | Select-Object -First 1 | Export-DbaScript -Passthru -BatchSeparator "MakeItSo" + $null = Get-DbaDbTable -SqlInstance $TestConfig.instance2 -Database msdb | Select-Object -First 1 | Export-DbaScript -Passthru -BatchSeparator "MakeItSo" $null = [pscustomobject]@{ Invalid = $true } | Export-DbaScript -WarningVariable invalid -WarningAction Continue $invalid -match "not a SQL Management Object" } It "should not accept non-SMO objects" { - $null = Get-DbaDbTable -SqlInstance $script:instance2 -Database msdb | Select-Object -First 1 | Export-DbaScript -Passthru -BatchSeparator "MakeItSo" + $null = Get-DbaDbTable -SqlInstance $TestConfig.instance2 -Database msdb | Select-Object -First 1 | Export-DbaScript -Passthru -BatchSeparator "MakeItSo" $null = [pscustomobject]@{ Invalid = $true } | Export-DbaScript -WarningVariable invalid -WarningAction Continue $invalid -match "not a SQL Management Object" } It "should not append when using NoPrefix (#7455)" { if (-not (Test-Path C:\temp)) { $null = mkdir C:\temp } - $null = Get-DbaDbTable -SqlInstance $script:instance2 -Database msdb | Select-Object -First 1 | Export-DbaScript -NoPrefix -FilePath C:\temp\msdb.txt + $null = Get-DbaDbTable -SqlInstance $TestConfig.instance2 -Database msdb | Select-Object -First 1 | Export-DbaScript -NoPrefix -FilePath C:\temp\msdb.txt $linecount1 = (Get-Content C:\temp\msdb.txt).Count - $null = Get-DbaDbTable -SqlInstance $script:instance2 -Database msdb | Select-Object -First 1 | Export-DbaScript -NoPrefix -FilePath C:\temp\msdb.txt + $null = Get-DbaDbTable -SqlInstance $TestConfig.instance2 -Database msdb | Select-Object -First 1 | Export-DbaScript -NoPrefix -FilePath C:\temp\msdb.txt $linecount2 = (Get-Content C:\temp\msdb.txt).Count $linecount1 | Should -Be $linecount2 - $null = Get-DbaDbTable -SqlInstance $script:instance2 -Database msdb | Select-Object -First 1 | Export-DbaScript -NoPrefix -FilePath C:\temp\msdb.txt -Append + $null = Get-DbaDbTable -SqlInstance $TestConfig.instance2 -Database msdb | Select-Object -First 1 | Export-DbaScript -NoPrefix -FilePath C:\temp\msdb.txt -Append $linecount3 = (Get-Content C:\temp\msdb.txt).Count $linecount1 | Should -Not -Be $linecount3 } } -} \ No newline at end of file +} diff --git a/tests/Export-DbaServerRole.Tests.ps1 b/tests/Export-DbaServerRole.Tests.ps1 index b6fd57a4b5..174001f17c 100644 --- a/tests/Export-DbaServerRole.Tests.ps1 +++ b/tests/Export-DbaServerRole.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -22,7 +22,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $login1 = "dbatoolsci_exportdbaserverrole_login1$random" $svRole = "dbatoolsci_ScriptPermissions$random" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $null = $server.Query("CREATE LOGIN [$login1] WITH PASSWORD = 'GoodPass1234!'") $null = $server.Query("CREATE SERVER ROLE [$svRole] AUTHORIZATION [$login1]") $null = $server.Query("ALTER SERVER ROLE [dbcreator] ADD MEMBER [$svRole]") @@ -34,8 +34,8 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } AfterAll { try { - Remove-DbaServerRole -SqlInstance $script:instance2 -ServerRole $svRole -Confirm:$false - Remove-DbaLogin -SqlInstance $script:instance2 -Login $login1 -Confirm:$false + Remove-DbaServerRole -SqlInstance $TestConfig.instance2 -ServerRole $svRole -Confirm:$false + Remove-DbaLogin -SqlInstance $TestConfig.instance2 -Login $login1 -Confirm:$false } catch { } (Get-ChildItem $outputFile -ErrorAction SilentlyContinue) | Remove-Item -ErrorAction SilentlyContinue @@ -43,7 +43,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Check if output file was created" { - $null = Export-DbaServerRole -SqlInstance $script:instance2 -FilePath $outputFile + $null = Export-DbaServerRole -SqlInstance $TestConfig.instance2 -FilePath $outputFile It "Exports results to one sql file" { (Get-ChildItem $outputFile).Count | Should Be 1 } @@ -53,7 +53,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } Context "Check using piped input created" { - $role = Get-DbaServerRole -SqlInstance $script:instance2 -ServerRole $svRole + $role = Get-DbaServerRole -SqlInstance $TestConfig.instance2 -ServerRole $svRole $null = $role | Export-DbaServerRole -FilePath $outputFile It "Exports results to one sql file" { (Get-ChildItem $outputFile).Count | Should Be 1 @@ -85,4 +85,4 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $script:results -match "GRANT VIEW ANY DATABASE TO [$svRole];" } } -} \ No newline at end of file +} diff --git a/tests/Export-DbaSpConfigure.Tests.ps1 b/tests/Export-DbaSpConfigure.Tests.ps1 index eb154c8ee6..12427593aa 100644 --- a/tests/Export-DbaSpConfigure.Tests.ps1 +++ b/tests/Export-DbaSpConfigure.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Export-DbaSysDbUserObject.Tests.ps1 b/tests/Export-DbaSysDbUserObject.Tests.ps1 index fcc32b7d20..64fe89a901 100644 --- a/tests/Export-DbaSysDbUserObject.Tests.ps1 +++ b/tests/Export-DbaSysDbUserObject.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -23,7 +23,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $tableFunctionName = "[dbatoolsci_TableFunction_$random]" $scalarFunctionName = "[dbatoolsci_ScalarFunction_$random]" $ruleName = "[dbatoolsci_Rule_$random]" - $server = Connect-DbaInstance -SqlInstance $script:instance2 -SqlCredential $SqlCredential + $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") $server.query("CREATE PROCEDURE dbo.$procName as select 1;", "master") @@ -33,7 +33,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $server.query("CREATE RULE dbo.$ruleName AS @range>= 1 AND @range <10;", "master") } AfterAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 -SqlCredential $SqlCredential + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 -SqlCredential $SqlCredential $server.query("DROP TABLE dbo.$tableName", "master") $server.query("DROP VIEW dbo.$viewName", "master") $server.query("DROP PROCEDURE dbo.$procName", "master") @@ -43,7 +43,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $server.query("DROP RULE dbo.$ruleName", "master") } Context "works as expected with passthru" { - $script = Export-DbaSysDbUserObject -SqlInstance $script:instance2 -PassThru | Out-String + $script = Export-DbaSysDbUserObject -SqlInstance $TestConfig.instance2 -PassThru | Out-String It "should export text matching table name '$tableName'" { $script -match $tableName | Should be $true } @@ -68,7 +68,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } Context "works as expected with filename" { - $null = Export-DbaSysDbUserObject -SqlInstance $script:instance2 -FilePath "C:\Temp\objects_$random.sql" + $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 @@ -92,4 +92,4 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $file -match $ruleName | Should be $true } } -} \ No newline at end of file +} diff --git a/tests/Export-DbaUser.Tests.ps1 b/tests/Export-DbaUser.Tests.ps1 index bbb0562abf..d4d9c71d14 100644 --- a/tests/Export-DbaUser.Tests.ps1 +++ b/tests/Export-DbaUser.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -37,16 +37,16 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $role02 = "dbatoolsci_exportdbauser_role02" $role03 = "dbatoolsci_exportdbauser_role03" - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance1 $null = $server.Query("CREATE DATABASE [$dbname]") $securePassword = $(ConvertTo-SecureString -String "GoodPass1234!" -AsPlainText -Force) - $null = New-DbaLogin -SqlInstance $script:instance1 -Login $login -Password $securePassword - $null = New-DbaLogin -SqlInstance $script:instance1 -Login $login2 -Password $securePassword - $null = New-DbaLogin -SqlInstance $script:instance1 -Login $login01 -Password $securePassword - $null = New-DbaLogin -SqlInstance $script:instance1 -Login $login02 -Password $securePassword + $null = New-DbaLogin -SqlInstance $TestConfig.instance1 -Login $login -Password $securePassword + $null = New-DbaLogin -SqlInstance $TestConfig.instance1 -Login $login2 -Password $securePassword + $null = New-DbaLogin -SqlInstance $TestConfig.instance1 -Login $login01 -Password $securePassword + $null = New-DbaLogin -SqlInstance $TestConfig.instance1 -Login $login02 -Password $securePassword - $db = Get-DbaDatabase -SqlInstance $script:instance1 -Database $dbname + $db = Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $dbname $null = $db.Query("CREATE USER [$user] FOR LOGIN [$login]") $null = $db.Query("CREATE USER [$user2] FOR LOGIN [$login2]") $null = $db.Query("CREATE USER [$user01] FOR LOGIN [$login01]") @@ -67,17 +67,17 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } catch { } # No idea why appveyor can't handle this } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance1 -Database $dbname -Confirm:$false - Remove-DbaLogin -SqlInstance $script:instance1 -Login $login -Confirm:$false - Remove-DbaLogin -SqlInstance $script:instance1 -Login $login2 -Confirm:$false + Remove-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $dbname -Confirm:$false + Remove-DbaLogin -SqlInstance $TestConfig.instance1 -Login $login -Confirm:$false + Remove-DbaLogin -SqlInstance $TestConfig.instance1 -Login $login2 -Confirm:$false (Get-ChildItem $outputFile -ErrorAction SilentlyContinue) | Remove-Item -ErrorAction SilentlyContinue (Get-ChildItem $outputFile2 -ErrorAction SilentlyContinue) | Remove-Item -ErrorAction SilentlyContinue Remove-Item -Path $outputPath -Recurse -ErrorAction SilentlyContinue -Confirm:$false } Context "Check if output file was created" { - if (Get-DbaDbUser -SqlInstance $script:instance1 -Database $dbname | Where-Object Name -eq $user) { - $null = Export-DbaUser -SqlInstance $script:instance1 -Database $dbname -User $user -FilePath $outputFile + if (Get-DbaDbUser -SqlInstance $TestConfig.instance1 -Database $dbname | Where-Object Name -eq $user) { + $null = Export-DbaUser -SqlInstance $TestConfig.instance1 -Database $dbname -User $user -FilePath $outputFile It "Exports results to one sql file" { (Get-ChildItem $outputFile).Count | Should Be 1 } @@ -91,7 +91,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { It 'Excludes database context' { $scriptingOptions = New-DbaScriptingOption $scriptingOptions.IncludeDatabaseContext = $false - $null = Export-DbaUser -SqlInstance $script:instance1 -Database $dbname -ScriptingOptionsObject $scriptingOptions -FilePath $outputFile2 -WarningAction SilentlyContinue + $null = Export-DbaUser -SqlInstance $TestConfig.instance1 -Database $dbname -ScriptingOptionsObject $scriptingOptions -FilePath $outputFile2 -WarningAction SilentlyContinue $results = Get-Content -Path $outputFile2 -Raw $results | Should Not BeLike ('*USE `[' + $dbname + '`]*') (Get-ChildItem $outputFile2 -ErrorAction SilentlyContinue) | Remove-Item -ErrorAction SilentlyContinue @@ -99,19 +99,19 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { It 'Includes database context' { $scriptingOptions = New-DbaScriptingOption $scriptingOptions.IncludeDatabaseContext = $true - $null = Export-DbaUser -SqlInstance $script:instance1 -Database $dbname -ScriptingOptionsObject $scriptingOptions -FilePath $outputFile2 -WarningAction SilentlyContinue + $null = Export-DbaUser -SqlInstance $TestConfig.instance1 -Database $dbname -ScriptingOptionsObject $scriptingOptions -FilePath $outputFile2 -WarningAction SilentlyContinue $results = Get-Content -Path $outputFile2 -Raw $results | Should BeLike ('*USE `[' + $dbname + '`]*') (Get-ChildItem $outputFile2 -ErrorAction SilentlyContinue) | Remove-Item -ErrorAction SilentlyContinue } It 'Defaults to include database context' { - $null = Export-DbaUser -SqlInstance $script:instance1 -Database $dbname -FilePath $outputFile2 -WarningAction SilentlyContinue + $null = Export-DbaUser -SqlInstance $TestConfig.instance1 -Database $dbname -FilePath $outputFile2 -WarningAction SilentlyContinue $results = Get-Content -Path $outputFile2 -Raw $results | Should BeLike ('*USE `[' + $dbname + '`]*') (Get-ChildItem $outputFile2 -ErrorAction SilentlyContinue) | Remove-Item -ErrorAction SilentlyContinue } It 'Exports as template' { - $results = Export-DbaUser -SqlInstance $script:instance1 -Database $dbname -User $user -Template -DestinationVersion SQLServer2016 -WarningAction SilentlyContinue -Passthru + $results = Export-DbaUser -SqlInstance $TestConfig.instance1 -Database $dbname -User $user -Template -DestinationVersion SQLServer2016 -WarningAction SilentlyContinue -Passthru $results | Should BeLike "*CREATE USER ``[{templateUser}``] FOR LOGIN ``[{templateLogin}``]*" $results | Should BeLike "*GRANT SELECT ON OBJECT::``[dbo``].``[$table``] TO ``[{templateUser}``]*" $results | Should BeLike "*ALTER ROLE ``[$role``] ADD MEMBER ``[{templateUser}``]*" @@ -119,9 +119,9 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } Context "Check if one output file per user was created" { - $null = Export-DbaUser -SqlInstance $script:instance1 -Database $dbname -Path $outputPath + $null = Export-DbaUser -SqlInstance $TestConfig.instance1 -Database $dbname -Path $outputPath It "Exports files to the path" { - $userCount = (Get-DbaDbUser -SqlInstance $script:instance1 -Database $dbname | Where-Object { $_.Name -notin @("dbo", "guest", "sys", "INFORMATION_SCHEMA") } | Measure-Object).Count + $userCount = (Get-DbaDbUser -SqlInstance $TestConfig.instance1 -Database $dbname | Where-Object { $_.Name -notin @("dbo", "guest", "sys", "INFORMATION_SCHEMA") } | Measure-Object).Count (Get-ChildItem $outputPath).Count | Should Be $userCount } It "Exported file name contains username '$user'" { @@ -135,7 +135,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Check if the output scripts were self-contained" { # Clean up the output folder Remove-Item -Path $outputPath -Recurse -ErrorAction SilentlyContinue - $null = Export-DbaUser -SqlInstance $script:instance1 -Database $dbname -Path $outputPath + $null = Export-DbaUser -SqlInstance $TestConfig.instance1 -Database $dbname -Path $outputPath It "Contains the CREATE ROLE and ALTER ROLE statements for its own roles" { Get-ChildItem $outputPath | Where-Object Name -like ('*' + $user01 + '*') | ForEach-Object { @@ -161,4 +161,4 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } } -} \ No newline at end of file +} diff --git a/tests/Export-DbaXECsv.Tests.ps1 b/tests/Export-DbaXECsv.Tests.ps1 index 2df7ac894b..ae4e624c8a 100644 --- a/tests/Export-DbaXECsv.Tests.ps1 +++ b/tests/Export-DbaXECsv.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Export-DbaXESession.Tests.ps1 b/tests/Export-DbaXESession.Tests.ps1 index fc567e0153..d8dc05c846 100644 --- a/tests/Export-DbaXESession.Tests.ps1 +++ b/tests/Export-DbaXESession.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -24,7 +24,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } Context "Check if output file was created" { - $null = Export-DbaXESession -SqlInstance $script:instance2 -FilePath $outputFile + $null = Export-DbaXESession -SqlInstance $TestConfig.instance2 -FilePath $outputFile It "Exports results to one sql file" { (Get-ChildItem $outputFile).Count | Should Be 1 } @@ -34,7 +34,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } Context "Check if session parameter is honored" { - $null = Export-DbaXESession -SqlInstance $script:instance2 -FilePath $outputFile -Session system_health + $null = Export-DbaXESession -SqlInstance $TestConfig.instance2 -FilePath $outputFile -Session system_health It "Exports results to one sql file" { (Get-ChildItem $outputFile).Count | Should Be 1 } @@ -44,7 +44,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } Context "Check if supports Pipeline input" { - $null = Get-DbaXESession -SqlInstance $script:instance2 -Session system_health | Export-DbaXESession -FilePath $outputFile + $null = Get-DbaXESession -SqlInstance $TestConfig.instance2 -Session system_health | Export-DbaXESession -FilePath $outputFile It "Exports results to one sql file" { (Get-ChildItem $outputFile).Count | Should Be 1 } @@ -52,4 +52,4 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { (Get-ChildItem $outputFile).Length | Should BeGreaterThan 0 } } -} \ No newline at end of file +} diff --git a/tests/Export-DbaXESessionTemplate.Tests.ps1 b/tests/Export-DbaXESessionTemplate.Tests.ps1 index 1b1ad8d5f9..1dca24d554 100644 --- a/tests/Export-DbaXESessionTemplate.Tests.ps1 +++ b/tests/Export-DbaXESessionTemplate.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,17 +15,17 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $null = Get-DbaXESession -SqlInstance $script:instance2 -Session 'Profiler TSQL Duration' | Remove-DbaXESession + $null = Get-DbaXESession -SqlInstance $TestConfig.instance2 -Session 'Profiler TSQL Duration' | Remove-DbaXESession } AfterAll { - $null = Get-DbaXESession -SqlInstance $script:instance2 -Session 'Profiler TSQL Duration' | Remove-DbaXESession + $null = Get-DbaXESession -SqlInstance $TestConfig.instance2 -Session 'Profiler TSQL Duration' | Remove-DbaXESession Remove-Item -Path 'C:\windows\temp\Profiler TSQL Duration.xml' -ErrorAction SilentlyContinue } Context "Test Importing Session Template" { - $session = Import-DbaXESessionTemplate -SqlInstance $script:instance2 -Template 'Profiler TSQL Duration' + $session = Import-DbaXESessionTemplate -SqlInstance $TestConfig.instance2 -Template 'Profiler TSQL Duration' $results = $session | Export-DbaXESessionTemplate -Path C:\windows\temp It "session exports to disk" { $results.Name | Should Be 'Profiler TSQL Duration.xml' } } -} \ No newline at end of file +} diff --git a/tests/Export-DbatoolsConfig.Tests.ps1 b/tests/Export-DbatoolsConfig.Tests.ps1 index 7f5f8180bd..3d48dfbb1d 100644 --- a/tests/Export-DbatoolsConfig.Tests.ps1 +++ b/tests/Export-DbatoolsConfig.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Find-DbaAgentJob.Tests.ps1 b/tests/Find-DbaAgentJob.Tests.ps1 index 2977d35cc7..730f2b3507 100644 --- a/tests/Find-DbaAgentJob.Tests.ps1 +++ b/tests/Find-DbaAgentJob.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -14,76 +14,76 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { } Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { - + Context "Command finds jobs using all parameters" { BeforeAll { #subsystemServer needs the real underlying name, and it doesn't work if targeting something like localhost\namedinstance # the typical error would be WARNING: [17:19:26][New-DbaAgentJobStep] Something went wrong creating the job step | The specified '@server' is #invalid (valid values are returned by sp_helpserver). - $srvName = Invoke-DbaQuery -SqlInstance $script:instance2 -Query "select @@servername as sn" -as PSObject - $null = New-DbaAgentJob -SqlInstance $script:instance2 -Job 'dbatoolsci_testjob' -OwnerLogin 'sa' - $null = New-DbaAgentJobStep -SqlInstance $script:instance2 -Job 'dbatoolsci_testjob' -StepId 1 -StepName 'dbatoolsci Failed' -Subsystem TransactSql -SubsystemServer $srvName.sn -Command "RAISERROR (15600,-1,-1, 'dbatools_error');" -CmdExecSuccessCode 0 -OnSuccessAction QuitWithSuccess -OnFailAction QuitWithFailure -Database master -RetryAttempts 1 -RetryInterval 2 - $null = Start-DbaAgentJob -SqlInstance $script:instance2 -Job 'dbatoolsci_testjob' - $null = New-DbaAgentJob -SqlInstance $script:instance2 -Job 'dbatoolsci_testjob' -OwnerLogin 'sa' - $null = New-DbaAgentJobStep -SqlInstance $script:instance2 -Job 'dbatoolsci_testjob' -StepId 1 -StepName 'dbatoolsci Failed' -Subsystem TransactSql -SubsystemServer $srvName.sn -Command "RAISERROR (15600,-1,-1, 'dbatools_error');" -CmdExecSuccessCode 0 -OnSuccessAction QuitWithSuccess -OnFailAction QuitWithFailure -Database master -RetryAttempts 1 -RetryInterval 2 - $null = New-DbaAgentJobCategory -SqlInstance $script:instance2 -Category 'dbatoolsci_job_category' -CategoryType LocalJob - $null = New-DbaAgentJob -SqlInstance $script:instance2 -Job 'dbatoolsci_testjob_disabled' -Category 'dbatoolsci_job_category' -Disabled - $null = New-DbaAgentJobStep -SqlInstance $script:instance2 -Job 'dbatoolsci_testjob_disabled' -StepId 1 -StepName 'dbatoolsci Test Step' -Subsystem TransactSql -SubsystemServer $srvName.sn -Command 'SELECT * FROM master.sys.all_columns' -CmdExecSuccessCode 0 -OnSuccessAction QuitWithSuccess -OnFailAction QuitWithFailure -Database master -RetryAttempts 1 -RetryInterval 2 + $srvName = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Query "select @@servername as sn" -as PSObject + $null = New-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job 'dbatoolsci_testjob' -OwnerLogin 'sa' + $null = New-DbaAgentJobStep -SqlInstance $TestConfig.instance2 -Job 'dbatoolsci_testjob' -StepId 1 -StepName 'dbatoolsci Failed' -Subsystem TransactSql -SubsystemServer $srvName.sn -Command "RAISERROR (15600,-1,-1, 'dbatools_error');" -CmdExecSuccessCode 0 -OnSuccessAction QuitWithSuccess -OnFailAction QuitWithFailure -Database master -RetryAttempts 1 -RetryInterval 2 + $null = Start-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job 'dbatoolsci_testjob' + $null = New-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job 'dbatoolsci_testjob' -OwnerLogin 'sa' + $null = New-DbaAgentJobStep -SqlInstance $TestConfig.instance2 -Job 'dbatoolsci_testjob' -StepId 1 -StepName 'dbatoolsci Failed' -Subsystem TransactSql -SubsystemServer $srvName.sn -Command "RAISERROR (15600,-1,-1, 'dbatools_error');" -CmdExecSuccessCode 0 -OnSuccessAction QuitWithSuccess -OnFailAction QuitWithFailure -Database master -RetryAttempts 1 -RetryInterval 2 + $null = New-DbaAgentJobCategory -SqlInstance $TestConfig.instance2 -Category 'dbatoolsci_job_category' -CategoryType LocalJob + $null = New-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job 'dbatoolsci_testjob_disabled' -Category 'dbatoolsci_job_category' -Disabled + $null = New-DbaAgentJobStep -SqlInstance $TestConfig.instance2 -Job 'dbatoolsci_testjob_disabled' -StepId 1 -StepName 'dbatoolsci Test Step' -Subsystem TransactSql -SubsystemServer $srvName.sn -Command 'SELECT * FROM master.sys.all_columns' -CmdExecSuccessCode 0 -OnSuccessAction QuitWithSuccess -OnFailAction QuitWithFailure -Database master -RetryAttempts 1 -RetryInterval 2 } AfterAll { - $null = Remove-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_testjob, dbatoolsci_testjob_disabled -Confirm:$false - $null = Remove-DbaAgentJobCategory -SqlInstance $script:instance2 -Category 'dbatoolsci_job_category' -Confirm:$false + $null = Remove-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job dbatoolsci_testjob, dbatoolsci_testjob_disabled -Confirm:$false + $null = Remove-DbaAgentJobCategory -SqlInstance $TestConfig.instance2 -Category 'dbatoolsci_job_category' -Confirm:$false } - $results = Find-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_testjob + $results = Find-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job dbatoolsci_testjob It "Should find a specific job" { $results.name | Should Be "dbatoolsci_testjob" } - $results = Find-DbaAgentJob -SqlInstance $script:instance2 -Job *dbatoolsci* -Exclude dbatoolsci_testjob_disabled + $results = Find-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job *dbatoolsci* -Exclude dbatoolsci_testjob_disabled It "Should find a specific job but not an excluded job" { $results.name | Should Not Be "dbatoolsci_testjob_disabled" } - $results = Find-DbaAgentJob -SqlInstance $script:instance2 -StepName 'dbatoolsci Test Step' + $results = Find-DbaAgentJob -SqlInstance $TestConfig.instance2 -StepName 'dbatoolsci Test Step' It "Should find a specific job with a specific step" { $results.name | Should Be "dbatoolsci_testjob_disabled" } - $results = Find-DbaAgentJob -SqlInstance $script:instance2 -LastUsed 10 + $results = Find-DbaAgentJob -SqlInstance $TestConfig.instance2 -LastUsed 10 It "Should find jobs not used in the last 10 days" { $results | Should not be null } - $results = Find-DbaAgentJob -SqlInstance $script:instance2 -IsDisabled + $results = Find-DbaAgentJob -SqlInstance $TestConfig.instance2 -IsDisabled It "Should find jobs disabled from running" { $results.name | Should be "dbatoolsci_testjob_disabled" } - $results = Find-DbaAgentJob -SqlInstance $script:instance2 -IsDisabled + $results = Find-DbaAgentJob -SqlInstance $TestConfig.instance2 -IsDisabled It "Should find 1 job disabled from running" { $results.count | Should be 1 } - $results = Find-DbaAgentJob -SqlInstance $script:instance2 -IsNotScheduled + $results = Find-DbaAgentJob -SqlInstance $TestConfig.instance2 -IsNotScheduled It "Should find jobs that have not been scheduled" { $results | Should not be null } - $results = Find-DbaAgentJob -SqlInstance $script:instance2 -IsNotScheduled -Job *dbatoolsci* + $results = Find-DbaAgentJob -SqlInstance $TestConfig.instance2 -IsNotScheduled -Job *dbatoolsci* It "Should find 2 jobs that have no schedule" { $results.count | Should be 2 } - $results = Find-DbaAgentJob -SqlInstance $script:instance2 -IsNoEmailNotification + $results = Find-DbaAgentJob -SqlInstance $TestConfig.instance2 -IsNoEmailNotification It "Should find jobs that have no email notification" { $results | Should not be null } - $results = Find-DbaAgentJob -SqlInstance $script:instance2 -Category 'dbatoolsci_job_category' + $results = Find-DbaAgentJob -SqlInstance $TestConfig.instance2 -Category 'dbatoolsci_job_category' It "Should find jobs that have a category of dbatoolsci_job_category" { $results.name | Should be "dbatoolsci_testjob_disabled" } - $results = Find-DbaAgentJob -SqlInstance $script:instance2 -Owner 'sa' + $results = Find-DbaAgentJob -SqlInstance $TestConfig.instance2 -Owner 'sa' It "Should find jobs that are owned by sa" { $results | Should not be null } - - - $results = Find-DbaAgentJob -SqlInstance $script:instance2 -IsFailed -Since '2016-07-01 10:47:00' + + + $results = Find-DbaAgentJob -SqlInstance $TestConfig.instance2 -IsFailed -Since '2016-07-01 10:47:00' It "Should find jobs that have been failed since July of 2016" { $results | Should not be null } } -} \ No newline at end of file +} diff --git a/tests/Find-DbaBackup.Tests.ps1 b/tests/Find-DbaBackup.Tests.ps1 index 3d9824d9c2..2521874a9f 100644 --- a/tests/Find-DbaBackup.Tests.ps1 +++ b/tests/Find-DbaBackup.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Find-DbaCommand.Tests.ps1 b/tests/Find-DbaCommand.Tests.ps1 index 6de954d52f..6ed8fb02dc 100644 --- a/tests/Find-DbaCommand.Tests.ps1 +++ b/tests/Find-DbaCommand.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Find-DbaDatabase.Tests.ps1 b/tests/Find-DbaDatabase.Tests.ps1 index 939c7c870d..43ee07bca4 100644 --- a/tests/Find-DbaDatabase.Tests.ps1 +++ b/tests/Find-DbaDatabase.Tests.ps1 @@ -3,7 +3,7 @@ #> $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig <# Unit test is required for any command added @@ -20,29 +20,29 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { } Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Command actually works" { - $results = Find-DbaDatabase -SqlInstance $script:instance2 -Pattern Master + $results = Find-DbaDatabase -SqlInstance $TestConfig.instance2 -Pattern Master It "Should return correct properties" { $ExpectedProps = 'ComputerName,InstanceName,SqlInstance,Name,Id,Size,Owner,CreateDate,ServiceBrokerGuid,Tables,StoredProcedures,Views,ExtendedProperties'.Split(',') ($results[0].PsObject.Properties.Name | Sort-Object) | Should Be ($ExpectedProps | Sort-Object) } - $results = Find-DbaDatabase -SqlInstance $script:instance2 -Pattern Master + $results = Find-DbaDatabase -SqlInstance $TestConfig.instance2 -Pattern Master It "Should return true if Database Master is Found" { ($results | Where-Object Name -match 'Master' ) | Should Be $true - $results.Id | Should -Be (Get-DbaDatabase -SqlInstance $script:instance2 -Database Master).Id + $results.Id | Should -Be (Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database Master).Id } It "Should return true if Creation Date of Master is '4/8/2003 9:13:36 AM'" { $($results.CreateDate.ToFileTimeutc()[0]) -eq 126942668163900000 | Should Be $true } - $results = Find-DbaDatabase -SqlInstance $script:instance1, $script:instance2 -Pattern Master - It "Should return true if Executed Against 2 instances: $script:instance1 and $script:instance2" { + $results = Find-DbaDatabase -SqlInstance $TestConfig.instance1, $TestConfig.instance2 -Pattern Master + It "Should return true if Executed Against 2 instances: $TestConfig.instance1 and $($TestConfig.instance2)" { ($results.InstanceName | Select-Object -Unique).count -eq 2 | Should Be $true } - $results = Find-DbaDatabase -SqlInstance $script:instance2 -Property ServiceBrokerGuid -Pattern -0000-0000-000000000000 + $results = Find-DbaDatabase -SqlInstance $TestConfig.instance2 -Property ServiceBrokerGuid -Pattern -0000-0000-000000000000 It "Should return true if Database Found via Property Filter" { $results.ServiceBrokerGuid | Should BeLike '*-0000-0000-000000000000' } } -} \ No newline at end of file +} diff --git a/tests/Find-DbaDbDisabledIndex.Tests.ps1 b/tests/Find-DbaDbDisabledIndex.Tests.ps1 index 82c2c90b03..056e32e02b 100644 --- a/tests/Find-DbaDbDisabledIndex.Tests.ps1 +++ b/tests/Find-DbaDbDisabledIndex.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,7 +16,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Command actually works" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance1 $random = Get-Random $databaseName1 = "dbatoolsci1_$random" $databaseName2 = "dbatoolsci2_$random" @@ -35,22 +35,22 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } It "Should find disabled index: $indexName" { - $results = Find-DbaDbDisabledIndex -SqlInstance $script:instance1 + $results = Find-DbaDbDisabledIndex -SqlInstance $TestConfig.instance1 ($results | Where-Object { $_.IndexName -eq $indexName }).Count | Should -Be 2 ($results | Where-Object { $_.DatabaseName -in $databaseName1, $databaseName2 }).Count | Should -Be 2 ($results | Where-Object { $_.DatabaseId -in $db1.Id, $db2.Id }).Count | Should -Be 2 } It "Should find disabled index: $indexName for specific database" { - $results = Find-DbaDbDisabledIndex -SqlInstance $script:instance1 -Database $databaseName1 + $results = Find-DbaDbDisabledIndex -SqlInstance $TestConfig.instance1 -Database $databaseName1 $results.IndexName | Should -Be $indexName $results.DatabaseName | Should -Be $databaseName1 $results.DatabaseId | Should -Be $db1.Id } It "Should exclude specific database" { - $results = Find-DbaDbDisabledIndex -SqlInstance $script:instance1 -ExcludeDatabase $databaseName1 + $results = Find-DbaDbDisabledIndex -SqlInstance $TestConfig.instance1 -ExcludeDatabase $databaseName1 $results.IndexName | Should -Be $indexName $results.DatabaseName | Should -Be $databaseName2 $results.DatabaseId | Should -Be $db2.Id } } -} \ No newline at end of file +} diff --git a/tests/Find-DbaDbDuplicateIndex.Tests.ps1 b/tests/Find-DbaDbDuplicateIndex.Tests.ps1 index 52c5319468..65b58562c5 100644 --- a/tests/Find-DbaDbDuplicateIndex.Tests.ps1 +++ b/tests/Find-DbaDbDuplicateIndex.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,7 +15,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance1 $sql = "create database [dbatools_dupeindex]" $server.Query($sql) $sql = "CREATE TABLE [dbatools_dupeindex].[dbo].[WABehaviorEvent]( @@ -47,13 +47,13 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $server.Query($sql) } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance1 -Database dbatools_dupeindex -Confirm:$false + Remove-DbaDatabase -SqlInstance $TestConfig.instance1 -Database dbatools_dupeindex -Confirm:$false } Context "Gets back some results" { - $results = Find-DbaDbDuplicateIndex -SqlInstance $script:instance1 -Database dbatools_dupeindex + $results = Find-DbaDbDuplicateIndex -SqlInstance $TestConfig.instance1 -Database dbatools_dupeindex It "return at least two results" { $results.Count -ge 2 | Should Be $true } } -} \ No newline at end of file +} diff --git a/tests/Find-DbaDbGrowthEvent.Tests.ps1 b/tests/Find-DbaDbGrowthEvent.Tests.ps1 index e247c5c994..c888c252f9 100644 --- a/tests/Find-DbaDbGrowthEvent.Tests.ps1 +++ b/tests/Find-DbaDbGrowthEvent.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,7 +16,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Command actually works" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance1 $random = Get-Random $databaseName1 = "dbatoolsci1_$random" $db1 = New-DbaDatabase -SqlInstance $server -Name $databaseName1 @@ -61,4 +61,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } #> } -} \ No newline at end of file +} diff --git a/tests/Find-DbaDbUnusedIndex.Tests.ps1 b/tests/Find-DbaDbUnusedIndex.Tests.ps1 index c806ef01de..00585ff7d5 100644 --- a/tests/Find-DbaDbUnusedIndex.Tests.ps1 +++ b/tests/Find-DbaDbUnusedIndex.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -23,17 +23,17 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Verify basics of the Find-DbaDbUnusedIndex command" { BeforeAll { - Write-Message -Level Warning -Message "Find-DbaDbUnusedIndex testing connection to $script:instance2" - Test-DbaConnection -SqlInstance $script:instance2 + Write-Message -Level Warning -Message "Find-DbaDbUnusedIndex testing connection to $($TestConfig.instance2)" + Test-DbaConnection -SqlInstance $TestConfig.instance2 - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $random = Get-Random $dbName = "dbatoolsci_$random" Write-Message -Level Warning -Message "Find-DbaDbUnusedIndex setting up the new database $dbName" - Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbName -Confirm:$false - $newDB = New-DbaDatabase -SqlInstance $script:instance2 -Name $dbName + Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbName -Confirm:$false + $newDB = New-DbaDatabase -SqlInstance $TestConfig.instance2 -Name $dbName $indexName = "dbatoolsci_index_$random" $tableName = "dbatoolsci_table_$random" @@ -49,11 +49,11 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { AfterAll { Write-Message -Level Warning -Message "Find-DbaDbUnusedIndex removing the database $dbName" - Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbName -Confirm:$false + Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbName -Confirm:$false } It "Should find the 'unused' index on each test sql instance" { - $results = Find-DbaDbUnusedIndex -SqlInstance $script:instance2 -Database $dbName -IgnoreUptime -Seeks 10 -Scans 10 -Lookups 10 + $results = Find-DbaDbUnusedIndex -SqlInstance $TestConfig.instance2 -Database $dbName -IgnoreUptime -Seeks 10 -Scans 10 -Lookups 10 $results.Database | Should -Be $dbName $results.DatabaseId | Should -Be $newDB.Id @@ -61,10 +61,10 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { foreach ($row in $results) { if ($row["IndexName"] -eq $indexName) { - Write-Message -Level Debug -Message "$($indexName) was found on $($script:instance2) in database $($dbName)" + Write-Message -Level Debug -Message "$($indexName) was found on $($TestConfig.instance2) in database $($dbName)" $testSQLinstance = $true } else { - Write-Message -Level Warning -Message "$($indexName) was not found on $($script:instance2) in database $($dbName)" + Write-Message -Level Warning -Message "$($indexName) was not found on $($TestConfig.instance2) in database $($dbName)" } } @@ -77,7 +77,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $testSQLinstance = $false - $results = Find-DbaDbUnusedIndex -SqlInstance $script:instance2 -Database $dbName -IgnoreUptime -Seeks 10 -Scans 10 -Lookups 10 + $results = Find-DbaDbUnusedIndex -SqlInstance $TestConfig.instance2 -Database $dbName -IgnoreUptime -Seeks 10 -Scans 10 -Lookups 10 if ( ($null -ne $results) ) { $row = $null @@ -95,10 +95,10 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { [object[]]$columnNamesReturned = @($row | Get-Member -MemberType Property | Select-Object -Property Name | ForEach-Object { $_.Name }) if ( @(Compare-Object -ReferenceObject $expectedColumnArray -DifferenceObject $columnNamesReturned).Count -eq 0 ) { - Write-Message -Level Debug -Message "Columns matched on $($script:instance2)" + Write-Message -Level Debug -Message "Columns matched on $($TestConfig.instance2)" $testSQLinstance = $true } else { - Write-Message -Level Warning -Message "The columns specified in the expectedColumnList variable do not match these returned columns from $($script:instance2): $($columnNamesReturned)" + Write-Message -Level Warning -Message "The columns specified in the expectedColumnList variable do not match these returned columns from $($TestConfig.instance2): $($columnNamesReturned)" } } } @@ -106,4 +106,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $testSQLinstance | Should -Be $true } } -} \ No newline at end of file +} diff --git a/tests/Find-DbaInstance.Tests.ps1 b/tests/Find-DbaInstance.Tests.ps1 index c48ab6b324..869a8392f2 100644 --- a/tests/Find-DbaInstance.Tests.ps1 +++ b/tests/Find-DbaInstance.Tests.ps1 @@ -5,7 +5,7 @@ param( $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -23,7 +23,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Context "Command finds SQL Server instances" { BeforeAll { - $results = Find-DbaInstance -ComputerName $script:instance3 -ScanType Browser, SqlConnect | Select-Object -First 1 + $results = Find-DbaInstance -ComputerName $TestConfig.instance3 -ScanType Browser, SqlConnect | Select-Object -First 1 } It "Returns an object type of [Dataplat.Dbatools.Discovery.DbaInstanceReport]" { $results | Should -BeOfType [Dataplat.Dbatools.Discovery.DbaInstanceReport] @@ -31,7 +31,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { It "FullName is populated" { $results.FullName | Should -Not -BeNullOrEmpty } - if (([DbaInstanceParameter]$script:instance3).IsLocalHost -eq $false) { + if (([DbaInstanceParameter]$TestConfig.instance3).IsLocalHost -eq $false) { It "TcpConnected is true" { $results.TcpConnected | Should -Be $true } @@ -41,3 +41,4 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } } } + diff --git a/tests/Find-DbaLoginInGroup.Tests.ps1 b/tests/Find-DbaLoginInGroup.Tests.ps1 index ad0b6af6be..a29fdef91f 100644 --- a/tests/Find-DbaLoginInGroup.Tests.ps1 +++ b/tests/Find-DbaLoginInGroup.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Find-DbaOrphanedFile.Tests.ps1 b/tests/Find-DbaOrphanedFile.Tests.ps1 index fd5372daa6..0f1fee7d79 100644 --- a/tests/Find-DbaOrphanedFile.Tests.ps1 +++ b/tests/Find-DbaOrphanedFile.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -17,7 +17,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Orphaned files are correctly identified" { BeforeAll { $dbname = "dbatoolsci_orphanedfile_$(Get-Random)" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $db1 = New-DbaDatabase -SqlInstance $server -Name $dbname $dbname2 = "dbatoolsci_orphanedfile_$(Get-Random)" @@ -41,7 +41,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $tmpBackupPath2 = Join-Path $tmpdirInner2 "backup" $null = New-Item -Path $tmpBackupPath2 -type Container - $result = Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbname + $result = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname if ($result.count -eq 0) { It "has failed setup" { Set-TestInconclusive -message "Setup failed" @@ -49,23 +49,23 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { throw "has failed setup" } - $backupFile = Backup-DbaDatabase -SqlInstance $script:instance2 -Database $dbname -Path $tmpBackupPath -Type Full - $backupFile2 = Backup-DbaDatabase -SqlInstance $script:instance2 -Database $dbname2 -Path $tmpBackupPath2 -Type Full + $backupFile = Backup-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname -Path $tmpBackupPath -Type Full + $backupFile2 = Backup-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname2 -Path $tmpBackupPath2 -Type Full Copy-Item -Path $backupFile.BackupPath -Destination "C:\" -Confirm:$false $tmpBackupPath3 = Join-Path (Get-SqlDefaultPaths $server data) "dbatoolsci_$(Get-Random)" $null = New-Item -Path $tmpBackupPath3 -type Container } AfterAll { - Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbname, $dbname2 | Remove-DbaDatabase -Confirm:$false + Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname, $dbname2 | Remove-DbaDatabase -Confirm:$false Remove-Item $tmpdir -Recurse -Force -ErrorAction SilentlyContinue Remove-Item $tmpdir2 -Recurse -Force -ErrorAction SilentlyContinue Remove-Item "C:\$($backupFile.BackupFile)" -Force -ErrorAction SilentlyContinue Remove-Item $tmpBackupPath3 -Recurse -Force -ErrorAction SilentlyContinue } It "Has the correct properties" { - $null = Detach-DbaDatabase -SqlInstance $script:instance2 -Database $dbname -Force - $results = Find-DbaOrphanedFile -SqlInstance $script:instance2 + $null = Detach-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname -Force + $results = Find-DbaOrphanedFile -SqlInstance $TestConfig.instance2 $ExpectedStdProps = 'ComputerName,InstanceName,SqlInstance,Filename,RemoteFilename'.Split(',') ($results[0].PSStandardMembers.DefaultDisplayPropertySet.ReferencedPropertyNames | Sort-Object) | Should -Be ($ExpectedStdProps | Sort-Object) $ExpectedProps = 'ComputerName,InstanceName,SqlInstance,Filename,RemoteFilename,Server'.Split(',') @@ -74,41 +74,41 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { It "Finds two files" { - $results = Find-DbaOrphanedFile -SqlInstance $script:instance2 + $results = Find-DbaOrphanedFile -SqlInstance $TestConfig.instance2 $results.Filename.Count | Should -Be 2 } It "Finds zero files after cleaning up" { - $results = Find-DbaOrphanedFile -SqlInstance $script:instance2 + $results = Find-DbaOrphanedFile -SqlInstance $TestConfig.instance2 $results.FileName | Remove-Item - $results = Find-DbaOrphanedFile -SqlInstance $script:instance2 + $results = Find-DbaOrphanedFile -SqlInstance $TestConfig.instance2 $results.Filename.Count | Should -Be 0 } It "works with -Recurse" { "a" | Out-File (Join-Path $tmpdir "out.mdf") - $results = Find-DbaOrphanedFile -SqlInstance $script:instance2 -Path $tmpdir + $results = Find-DbaOrphanedFile -SqlInstance $TestConfig.instance2 -Path $tmpdir $results.Filename.Count | Should -Be 1 Move-Item "$tmpdir\out.mdf" -destination $tmpdirInner - $results = Find-DbaOrphanedFile -SqlInstance $script:instance2 -Path $tmpdir + $results = Find-DbaOrphanedFile -SqlInstance $TestConfig.instance2 -Path $tmpdir $results.Filename.Count | Should -Be 0 - $results = Find-DbaOrphanedFile -SqlInstance $script:instance2 -Path $tmpdir -Recurse + $results = Find-DbaOrphanedFile -SqlInstance $TestConfig.instance2 -Path $tmpdir -Recurse $results.Filename.Count | Should -Be 1 Copy-Item -Path "$tmpdirInner\out.mdf" -Destination $tmpBackupPath3 -Confirm:$false - $results = Find-DbaOrphanedFile -SqlInstance $script:instance2 -Path $tmpdir, $tmpdir2 -Recurse -FileType bak + $results = Find-DbaOrphanedFile -SqlInstance $TestConfig.instance2 -Path $tmpdir, $tmpdir2 -Recurse -FileType bak $results.Filename | Should -Contain $backupFile.BackupPath $results.Filename | Should -Contain $backupFile2.BackupPath $results.Filename | Should -Contain "$tmpdirInner\out.mdf" $results.Filename | Should -Contain "$tmpBackupPath3\out.mdf" $results.Count | Should -Be 4 - $results = Find-DbaOrphanedFile -SqlInstance $script:instance2 -Recurse + $results = Find-DbaOrphanedFile -SqlInstance $TestConfig.instance2 -Recurse $results.Filename | Should -Be "$tmpBackupPath3\out.mdf" } It "works with -Path" { - $results = Find-DbaOrphanedFile -SqlInstance $script:instance2 -Path "C:" -FileType bak + $results = Find-DbaOrphanedFile -SqlInstance $TestConfig.instance2 -Path "C:" -FileType bak $results.Filename | Should -Contain "C:\$($backupFile.BackupFile)" } } -} \ No newline at end of file +} diff --git a/tests/Find-DbaSimilarTable.Tests.ps1 b/tests/Find-DbaSimilarTable.Tests.ps1 index 6d91a64aa1..50c226b368 100644 --- a/tests/Find-DbaSimilarTable.Tests.ps1 +++ b/tests/Find-DbaSimilarTable.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,7 +16,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Testing if similar tables are discovered" { BeforeAll { - $db = Get-DbaDatabase -SqlInstance $script:instance1 -Database tempdb + $db = Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database tempdb $db.Query("CREATE TABLE dbatoolsci_table1 (id int identity, fname varchar(20), lname char(5), lol bigint, whatever datetime)") $db.Query("CREATE TABLE dbatoolsci_table2 (id int identity, fname varchar(20), lname char(5), lol bigint, whatever datetime)") } @@ -25,7 +25,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $db.Query("DROP TABLE dbatoolsci_table2") } - $results = Find-DbaSimilarTable -SqlInstance $script:instance1 -Database tempdb | Where-Object Table -Match dbatoolsci + $results = Find-DbaSimilarTable -SqlInstance $TestConfig.instance1 -Database tempdb | Where-Object Table -Match dbatoolsci It "returns at least two rows" { # not an exact count because who knows $results.Count -ge 2 | Should Be $true @@ -39,4 +39,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } } } -} \ No newline at end of file +} diff --git a/tests/Find-DbaStoredProcedure.Tests.ps1 b/tests/Find-DbaStoredProcedure.Tests.ps1 index e61dda563b..b6cf365576 100644 --- a/tests/Find-DbaStoredProcedure.Tests.ps1 +++ b/tests/Find-DbaStoredProcedure.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -23,43 +23,43 @@ AS SELECT [sid],[loginname],[sysadmin] FROM [master].[sys].[syslogins]; "@ - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Database 'Master' -Query $ServerProcedure + $null = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database 'Master' -Query $ServerProcedure } AfterAll { $DropProcedure = "DROP PROCEDURE dbo.cp_dbatoolsci_sysadmin;" - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Database 'Master' -Query $DropProcedure + $null = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database 'Master' -Query $DropProcedure } - $results = Find-DbaStoredProcedure -SqlInstance $script:instance2 -Pattern dbatools* -IncludeSystemDatabases + $results = Find-DbaStoredProcedure -SqlInstance $TestConfig.instance2 -Pattern dbatools* -IncludeSystemDatabases It "Should find a specific StoredProcedure named cp_dbatoolsci_sysadmin" { $results.Name | Should Contain "cp_dbatoolsci_sysadmin" - $results.DatabaseId | Should -Be (Get-DbaDatabase -SqlInstance $script:instance2 -Database master).ID + $results.DatabaseId | Should -Be (Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database master).ID } } Context "Command finds Procedures in a User Database" { BeforeAll { - $null = New-DbaDatabase -SqlInstance $script:instance2 -Name 'dbatoolsci_storedproceduredb' + $null = New-DbaDatabase -SqlInstance $TestConfig.instance2 -Name 'dbatoolsci_storedproceduredb' $StoredProcedure = @" CREATE PROCEDURE dbo.sp_dbatoolsci_custom AS SET NOCOUNT ON; PRINT 'Dbatools Rocks'; "@ - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Database 'dbatoolsci_storedproceduredb' -Query $StoredProcedure + $null = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database 'dbatoolsci_storedproceduredb' -Query $StoredProcedure } AfterAll { - $null = Remove-DbaDatabase -SqlInstance $script:instance2 -Database 'dbatoolsci_storedproceduredb' -Confirm:$false + $null = Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database 'dbatoolsci_storedproceduredb' -Confirm:$false } - $results = Find-DbaStoredProcedure -SqlInstance $script:instance2 -Pattern dbatools* -Database 'dbatoolsci_storedproceduredb' + $results = Find-DbaStoredProcedure -SqlInstance $TestConfig.instance2 -Pattern dbatools* -Database 'dbatoolsci_storedproceduredb' It "Should find a specific StoredProcedure named sp_dbatoolsci_custom" { $results.Name | Should Contain "sp_dbatoolsci_custom" - $results.DatabaseId | Should -Be (Get-DbaDatabase -SqlInstance $script:instance2 -Database dbatoolsci_storedproceduredb).ID + $results.DatabaseId | Should -Be (Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database dbatoolsci_storedproceduredb).ID } It "Should find sp_dbatoolsci_custom in dbatoolsci_storedproceduredb" { $results.Database | Should Contain "dbatoolsci_storedproceduredb" } - $results = Find-DbaStoredProcedure -SqlInstance $script:instance2 -Pattern dbatools* -ExcludeDatabase 'dbatoolsci_storedproceduredb' + $results = Find-DbaStoredProcedure -SqlInstance $TestConfig.instance2 -Pattern dbatools* -ExcludeDatabase 'dbatoolsci_storedproceduredb' It "Should find no results when Excluding dbatoolsci_storedproceduredb" { $results | Should Be $null } } -} \ No newline at end of file +} diff --git a/tests/Find-DbaTrigger.Tests.ps1 b/tests/Find-DbaTrigger.Tests.ps1 index 523f245e77..724046f1e2 100644 --- a/tests/Find-DbaTrigger.Tests.ps1 +++ b/tests/Find-DbaTrigger.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -27,17 +27,17 @@ AS PRINT 'dbatoolsci Database Created.' SELECT EVENTDATA().value('(/EVENT_INSTANCE/TSQLCommand/CommandText)[1]','nvarchar(max)') "@ - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Query $ServerTrigger + $null = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Query $ServerTrigger } AfterAll { $DropTrigger = @" DROP TRIGGER dbatoolsci_ddl_trig_database ON ALL SERVER; "@ - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Database 'Master' -Query $DropTrigger + $null = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database 'Master' -Query $DropTrigger } - $results = Find-DbaTrigger -SqlInstance $script:instance2 -Pattern dbatoolsci* -IncludeSystemDatabases -IncludeSystemObjects -TriggerLevel Server + $results = Find-DbaTrigger -SqlInstance $TestConfig.instance2 -Pattern dbatoolsci* -IncludeSystemDatabases -IncludeSystemObjects -TriggerLevel Server It "Should find a specific Trigger at the Server Level" { $results.TriggerLevel | Should Be "Server" $results.DatabaseId | Should -BeNullOrEmpty @@ -45,7 +45,7 @@ ON ALL SERVER; It "Should find a specific Trigger named dbatoolsci_ddl_trig_database" { $results.Name | Should Be "dbatoolsci_ddl_trig_database" } - $results = Find-DbaTrigger -SqlInstance $script:instance2 -Pattern dbatoolsci* -TriggerLevel All + $results = Find-DbaTrigger -SqlInstance $TestConfig.instance2 -Pattern dbatoolsci* -TriggerLevel All It "Should find a specific Trigger when TriggerLevel is All" { $results.Name | Should Be "dbatoolsci_ddl_trig_database" } @@ -55,7 +55,7 @@ ON ALL SERVER; ## All Triggers adapted from examples on: ## https://docs.microsoft.com/en-us/sql/t-sql/statements/create-trigger-transact-sql?view=sql-server-2017 - $dbatoolsci_triggerdb = New-DbaDatabase -SqlInstance $script:instance2 -Name 'dbatoolsci_triggerdb' + $dbatoolsci_triggerdb = New-DbaDatabase -SqlInstance $TestConfig.instance2 -Name 'dbatoolsci_triggerdb' $DatabaseTrigger = @" CREATE TRIGGER dbatoolsci_safety ON DATABASE @@ -66,7 +66,7 @@ RETURN; RAISERROR ('You must disable Trigger "safety" to drop synonyms!',10, 1) ROLLBACK "@ - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Database 'dbatoolsci_triggerdb' -Query $DatabaseTrigger + $null = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database 'dbatoolsci_triggerdb' -Query $DatabaseTrigger $TableTrigger = @" CREATE TABLE dbo.Customer (id int, PRIMARY KEY (id)); GO @@ -76,13 +76,13 @@ AFTER INSERT, UPDATE AS RAISERROR ('Notify Customer Relations', 16, 10); GO "@ - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Database 'dbatoolsci_triggerdb' -Query $TableTrigger + $null = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database 'dbatoolsci_triggerdb' -Query $TableTrigger } AfterAll { - $null = Remove-DbaDatabase -SqlInstance $script:instance2 -Database 'dbatoolsci_triggerdb' -Confirm:$false + $null = Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database 'dbatoolsci_triggerdb' -Confirm:$false } - $results = Find-DbaTrigger -SqlInstance $script:instance2 -Pattern dbatoolsci* -Database 'dbatoolsci_triggerdb' -TriggerLevel Database + $results = Find-DbaTrigger -SqlInstance $TestConfig.instance2 -Pattern dbatoolsci* -Database 'dbatoolsci_triggerdb' -TriggerLevel Database It "Should find a specific Trigger at the Database Level" { $results.TriggerLevel | Should Be "Database" $results.DatabaseId | Should -Be $dbatoolsci_triggerdb.ID @@ -91,7 +91,7 @@ GO $results.Name | Should Be "dbatoolsci_safety" } - $results = Find-DbaTrigger -SqlInstance $script:instance2 -Pattern dbatoolsci* -Database 'dbatoolsci_triggerdb' -ExcludeDatabase Master -TriggerLevel Object + $results = Find-DbaTrigger -SqlInstance $TestConfig.instance2 -Pattern dbatoolsci* -Database 'dbatoolsci_triggerdb' -ExcludeDatabase Master -TriggerLevel Object It "Should find a specific Trigger at the Object Level" { $results.TriggerLevel | Should Be "Object" $results.DatabaseId | Should -Be $dbatoolsci_triggerdb.ID @@ -102,10 +102,10 @@ GO It "Should find a specific Trigger on the Table [dbo].[Customer]" { $results.Object | Should Be "[dbo].[Customer]" } - $results = Find-DbaTrigger -SqlInstance $script:instance2 -Pattern dbatoolsci* -TriggerLevel All + $results = Find-DbaTrigger -SqlInstance $TestConfig.instance2 -Pattern dbatoolsci* -TriggerLevel All It "Should find 2 Triggers when TriggerLevel is All" { $results.name | Should Be @('dbatoolsci_safety', 'dbatoolsci_reminder1') $results.DatabaseId | Should -Be $dbatoolsci_triggerdb.ID, $dbatoolsci_triggerdb.ID } } -} \ No newline at end of file +} diff --git a/tests/Find-DbaUserObject.Tests.ps1 b/tests/Find-DbaUserObject.Tests.ps1 index 626fccbc05..81c8741f00 100644 --- a/tests/Find-DbaUserObject.Tests.ps1 +++ b/tests/Find-DbaUserObject.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,13 +16,13 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Command finds User Objects for SA" { BeforeAll { - $null = New-DbaDatabase -SqlInstance $script:instance2 -Name 'dbatoolsci_userObject' -Owner 'sa' + $null = New-DbaDatabase -SqlInstance $TestConfig.instance2 -Name 'dbatoolsci_userObject' -Owner 'sa' } AfterAll { - $null = Remove-DbaDatabase -SqlInstance $script:instance2 -Database 'dbatoolsci_userObject' -Confirm:$false + $null = Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database 'dbatoolsci_userObject' -Confirm:$false } - $results = Find-DbaUserObject -SqlInstance $script:instance2 -Pattern sa + $results = Find-DbaUserObject -SqlInstance $TestConfig.instance2 -Pattern sa It "Should find a specific Database Owned by sa" { $results.Where( {$_.name -eq 'dbatoolsci_userobject'}).Type | Should Be "Database" } @@ -31,9 +31,9 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } Context "Command finds User Objects" { - $results = Find-DbaUserObject -SqlInstance $script:instance2 + $results = Find-DbaUserObject -SqlInstance $TestConfig.instance2 It "Should find resutls" { $results | Should Not Be Null } } -} \ No newline at end of file +} diff --git a/tests/Find-DbaView.Tests.ps1 b/tests/Find-DbaView.Tests.ps1 index 21e20cd56b..e9cb17fe49 100644 --- a/tests/Find-DbaView.Tests.ps1 +++ b/tests/Find-DbaView.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -23,48 +23,48 @@ AS SELECT [sid],[loginname],[sysadmin] FROM [master].[sys].[syslogins]; "@ - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Database 'Master' -Query $ServerView + $null = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database 'Master' -Query $ServerView } AfterAll { $DropView = "DROP VIEW dbo.v_dbatoolsci_sysadmin;" - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Database 'Master' -Query $DropView + $null = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database 'Master' -Query $DropView } - $results = Find-DbaView -SqlInstance $script:instance2 -Pattern dbatools* -IncludeSystemDatabases + $results = Find-DbaView -SqlInstance $TestConfig.instance2 -Pattern dbatools* -IncludeSystemDatabases It "Should find a specific View named v_dbatoolsci_sysadmin" { $results.Name | Should Be "v_dbatoolsci_sysadmin" } It "Should find v_dbatoolsci_sysadmin in Master" { $results.Database | Should Be "Master" - $results.DatabaseId | Should -Be (Get-DbaDatabase -SqlInstance $script:instance2 -Database Master).ID + $results.DatabaseId | Should -Be (Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database Master).ID } } Context "Command finds View in a User Database" { BeforeAll { - $null = New-DbaDatabase -SqlInstance $script:instance2 -Name 'dbatoolsci_viewdb' + $null = New-DbaDatabase -SqlInstance $TestConfig.instance2 -Name 'dbatoolsci_viewdb' $DatabaseView = @" CREATE VIEW dbo.v_dbatoolsci_sysadmin AS SELECT [sid],[loginname],[sysadmin] FROM [master].[sys].[syslogins]; "@ - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Database 'dbatoolsci_viewdb' -Query $DatabaseView + $null = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database 'dbatoolsci_viewdb' -Query $DatabaseView } AfterAll { - $null = Remove-DbaDatabase -SqlInstance $script:instance2 -Database 'dbatoolsci_viewdb' -Confirm:$false + $null = Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database 'dbatoolsci_viewdb' -Confirm:$false } - $results = Find-DbaView -SqlInstance $script:instance2 -Pattern dbatools* -Database 'dbatoolsci_viewdb' + $results = Find-DbaView -SqlInstance $TestConfig.instance2 -Pattern dbatools* -Database 'dbatoolsci_viewdb' It "Should find a specific view named v_dbatoolsci_sysadmin" { $results.Name | Should Be "v_dbatoolsci_sysadmin" } It "Should find v_dbatoolsci_sysadmin in dbatoolsci_viewdb Database" { $results.Database | Should Be "dbatoolsci_viewdb" - $results.DatabaseId | Should -Be (Get-DbaDatabase -SqlInstance $script:instance2 -Database dbatoolsci_viewdb).ID + $results.DatabaseId | Should -Be (Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database dbatoolsci_viewdb).ID } - $results = Find-DbaView -SqlInstance $script:instance2 -Pattern dbatools* -ExcludeDatabase 'dbatoolsci_viewdb' + $results = Find-DbaView -SqlInstance $TestConfig.instance2 -Pattern dbatools* -ExcludeDatabase 'dbatoolsci_viewdb' It "Should find no results when Excluding dbatoolsci_viewdb" { $results | Should Be $null } } -} \ No newline at end of file +} diff --git a/tests/Format-DbaBackupInformation.Tests.ps1 b/tests/Format-DbaBackupInformation.Tests.ps1 index 2b71de3f1c..824d703e99 100644 --- a/tests/Format-DbaBackupInformation.Tests.ps1 +++ b/tests/Format-DbaBackupInformation.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaAgBackupHistory.Tests.ps1 b/tests/Get-DbaAgBackupHistory.Tests.ps1 index 74f2174e64..7ecc2b608b 100644 --- a/tests/Get-DbaAgBackupHistory.Tests.ps1 +++ b/tests/Get-DbaAgBackupHistory.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaAgDatabase.Tests.ps1 b/tests/Get-DbaAgDatabase.Tests.ps1 index a4fb6eb79c..b4a54d3d2f 100644 --- a/tests/Get-DbaAgDatabase.Tests.ps1 +++ b/tests/Get-DbaAgDatabase.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,14 +15,14 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $null = Get-DbaProcess -SqlInstance $script:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue - $server = Connect-DbaInstance -SqlInstance $script:instance3 + $null = Get-DbaProcess -SqlInstance $TestConfig.instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance3 $agname = "dbatoolsci_getagdb_agroup" $dbname = "dbatoolsci_getagdb_agroupdb" $server.Query("create database $dbname") - $null = Get-DbaDatabase -SqlInstance $script:instance3 -Database $dbname | Backup-DbaDatabase - $null = Get-DbaDatabase -SqlInstance $script:instance3 -Database $dbname | Backup-DbaDatabase -Type Log - $ag = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Database $dbname -Confirm:$false -Certificate dbatoolsci_AGCert -UseLastBackup + $null = Get-DbaDatabase -SqlInstance $TestConfig.instance3 -Database $dbname | Backup-DbaDatabase + $null = Get-DbaDatabase -SqlInstance $TestConfig.instance3 -Database $dbname | Backup-DbaDatabase -Type Log + $ag = New-DbaAvailabilityGroup -Primary $TestConfig.instance3 -Name $agname -ClusterType None -FailoverMode Manual -Database $dbname -Confirm:$false -Certificate dbatoolsci_AGCert -UseLastBackup } AfterAll { $null = Remove-DbaAvailabilityGroup -SqlInstance $server -AvailabilityGroup $agname -Confirm:$false @@ -30,10 +30,10 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { } Context "gets ag db" { It "returns results" { - $results = Get-DbaAgDatabase -SqlInstance $script:instance3 -Database $dbname + $results = Get-DbaAgDatabase -SqlInstance $TestConfig.instance3 -Database $dbname $results.AvailabilityGroup | Should -Be $agname $results.Name | Should -Be $dbname $results.LocalReplicaRole | Should -Not -Be $null } } -} #$script:instance2 for appveyor \ No newline at end of file +} #$TestConfig.instance2 for appveyor diff --git a/tests/Get-DbaAgHadr.Tests.ps1 b/tests/Get-DbaAgHadr.Tests.ps1 index d946621db5..ecd586d652 100644 --- a/tests/Get-DbaAgHadr.Tests.ps1 +++ b/tests/Get-DbaAgHadr.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag "UnitTests" { Context "Validate parameters" { @@ -13,13 +13,13 @@ Describe "$CommandName Unit Tests" -Tag "UnitTests" { } } -# $script:instance3 is used for Availability Group tests and needs Hadr service setting enabled +# $TestConfig.instance3 is used for Availability Group tests and needs Hadr service setting enabled Describe "$CommandName Integration Test" -Tag "IntegrationTests" { - $results = Get-DbaAgHadr -SqlInstance $script:instance3 + $results = Get-DbaAgHadr -SqlInstance $TestConfig.instance3 Context "Validate output" { It "returns the correct properties" { $results.IsHadrEnabled | Should -Be $true } } -} #$script:instance2 for appveyor \ No newline at end of file +} #$TestConfig.instance2 for appveyor diff --git a/tests/Get-DbaAgListener.Tests.ps1 b/tests/Get-DbaAgListener.Tests.ps1 index 25573e372e..8fa95c2d48 100644 --- a/tests/Get-DbaAgListener.Tests.ps1 +++ b/tests/Get-DbaAgListener.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,16 +16,16 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { $agname = "dbatoolsci_ag_listener" - $ag = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Certificate dbatoolsci_AGCert -Confirm:$false + $ag = New-DbaAvailabilityGroup -Primary $TestConfig.instance3 -Name $agname -ClusterType None -FailoverMode Manual -Certificate dbatoolsci_AGCert -Confirm:$false $ag | Add-DbaAgListener -IPAddress 127.0.20.1 -Port 14330 -Confirm:$false } AfterAll { - $null = Remove-DbaAvailabilityGroup -SqlInstance $script:instance3 -AvailabilityGroup $agname -Confirm:$false + $null = Remove-DbaAvailabilityGroup -SqlInstance $TestConfig.instance3 -AvailabilityGroup $agname -Confirm:$false } Context "gets ags" { It "returns results with proper data" { - $results = Get-DbaAgListener -SqlInstance $script:instance3 + $results = Get-DbaAgListener -SqlInstance $TestConfig.instance3 $results.PortNumber | Should -Contain 14330 } } -} #$script:instance2 for appveyor \ No newline at end of file +} #$TestConfig.instance2 for appveyor diff --git a/tests/Get-DbaAgReplica.Tests.ps1 b/tests/Get-DbaAgReplica.Tests.ps1 index 92b9a5bb56..8658988957 100644 --- a/tests/Get-DbaAgReplica.Tests.ps1 +++ b/tests/Get-DbaAgReplica.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$commandname Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,21 +16,21 @@ Describe "$commandname Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { $agname = "dbatoolsci_agroup" - $ag = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Certificate dbatoolsci_AGCert -Confirm:$false + $ag = New-DbaAvailabilityGroup -Primary $TestConfig.instance3 -Name $agname -ClusterType None -FailoverMode Manual -Certificate dbatoolsci_AGCert -Confirm:$false $replicaName = $ag.PrimaryReplica } AfterAll { - $null = Remove-DbaAvailabilityGroup -SqlInstance $script:instance3 -AvailabilityGroup $agname -Confirm:$false + $null = Remove-DbaAvailabilityGroup -SqlInstance $TestConfig.instance3 -AvailabilityGroup $agname -Confirm:$false } Context "gets ag replicas" { It "returns results with proper data" { - $results = Get-DbaAgReplica -SqlInstance $script:instance3 + $results = Get-DbaAgReplica -SqlInstance $TestConfig.instance3 $results.AvailabilityGroup | Should -Contain $agname $results.Role | Should -Contain 'Primary' $results.AvailabilityMode | Should -Contain 'SynchronousCommit' } It "returns just one result" { - $results = Get-DbaAgReplica -SqlInstance $script:instance3 -Replica $replicaName -AvailabilityGroup $agname + $results = Get-DbaAgReplica -SqlInstance $TestConfig.instance3 -Replica $replicaName -AvailabilityGroup $agname $results.AvailabilityGroup | Should -Be $agname $results.Role | Should -Be 'Primary' $results.AvailabilityMode | Should -Be 'SynchronousCommit' @@ -45,4 +45,4 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { { Get-DbaAgReplica -SqlInstance invalidSQLHostName -EnableException } | Should -Throw } } -} #$script:instance2 for appveyor \ No newline at end of file +} #$TestConfig.instance2 for appveyor diff --git a/tests/Get-DbaAgentAlert.Tests.ps1 b/tests/Get-DbaAgentAlert.Tests.ps1 index 422ac1d129..2f09279558 100644 --- a/tests/Get-DbaAgentAlert.Tests.ps1 +++ b/tests/Get-DbaAgentAlert.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,16 +15,17 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 -Database master + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 -Database master $server.Query("EXEC msdb.dbo.sp_add_alert @name=N'dbatoolsci test alert',@message_id=0,@severity=6,@enabled=1,@delay_between_responses=0,@include_event_description_in=0,@category_name=N'[Uncategorized]',@job_id=N'00000000-0000-0000-0000-000000000000'") } AfterAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 -Database master + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 -Database master $server.Query("EXEC msdb.dbo.sp_delete_alert @name=N'dbatoolsci test alert'") } - $results = Get-DbaAgentAlert -SqlInstance $script:instance2 + $results = Get-DbaAgentAlert -SqlInstance $TestConfig.instance2 It "gets the newly created alert" { $results.Name -contains 'dbatoolsci test alert' } } + diff --git a/tests/Get-DbaAgentAlertCategory.Tests.ps1 b/tests/Get-DbaAgentAlertCategory.Tests.ps1 index 565ad9ff6f..ad6425b182 100644 --- a/tests/Get-DbaAgentAlertCategory.Tests.ps1 +++ b/tests/Get-DbaAgentAlertCategory.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,18 +16,18 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Command gets alert categories" { BeforeAll { - $null = New-DbaAgentAlertCategory -SqlInstance $script:instance2 -Category dbatoolsci_testcategory, dbatoolsci_testcategory2 + $null = New-DbaAgentAlertCategory -SqlInstance $TestConfig.instance2 -Category dbatoolsci_testcategory, dbatoolsci_testcategory2 } AfterAll { - $null = Remove-DbaAgentAlertCategory -SqlInstance $script:instance2 -Category dbatoolsci_testcategory, dbatoolsci_testcategory2 -Confirm:$false + $null = Remove-DbaAgentAlertCategory -SqlInstance $TestConfig.instance2 -Category dbatoolsci_testcategory, dbatoolsci_testcategory2 -Confirm:$false } - $results = Get-DbaAgentAlertCategory -SqlInstance $script:instance2 | Where-Object {$_.Name -match "dbatoolsci"} + $results = Get-DbaAgentAlertCategory -SqlInstance $TestConfig.instance2 | Where-Object {$_.Name -match "dbatoolsci"} It "Should get at least 2 categories" { $results.count | Should BeGreaterThan 1 } - $results = Get-DbaAgentAlertCategory -SqlInstance $script:instance2 -Category dbatoolsci_testcategory | Where-Object {$_.Name -match "dbatoolsci"} + $results = Get-DbaAgentAlertCategory -SqlInstance $TestConfig.instance2 -Category dbatoolsci_testcategory | Where-Object {$_.Name -match "dbatoolsci"} It "Should get the dbatoolsci_testcategory category" { $results.count | Should Be 1 } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaAgentJob.Tests.ps1 b/tests/Get-DbaAgentJob.Tests.ps1 index 7b2bc868b1..d5c41b23cc 100644 --- a/tests/Get-DbaAgentJob.Tests.ps1 +++ b/tests/Get-DbaAgentJob.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,17 +16,17 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Command gets jobs" { BeforeAll { - $null = New-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_testjob - $null = New-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_testjob_disabled -Disabled + $null = New-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job dbatoolsci_testjob + $null = New-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job dbatoolsci_testjob_disabled -Disabled } AfterAll { - $null = Remove-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_testjob, dbatoolsci_testjob_disabled -Confirm:$false + $null = Remove-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job dbatoolsci_testjob, dbatoolsci_testjob_disabled -Confirm:$false } - $results = Get-DbaAgentJob -SqlInstance $script:instance2 | Where-Object { $_.Name -match "dbatoolsci_testjob" } + $results = Get-DbaAgentJob -SqlInstance $TestConfig.instance2 | Where-Object { $_.Name -match "dbatoolsci_testjob" } It "Should get 2 dbatoolsci jobs" { $results.count | Should Be 2 } - $results = Get-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_testjob + $results = Get-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job dbatoolsci_testjob It "Should get a specific job" { $results.name | Should Be "dbatoolsci_testjob" } @@ -34,44 +34,44 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } Context "Command gets no disabled jobs" { BeforeAll { - $null = New-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_testjob - $null = New-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_testjob_disabled -Disabled + $null = New-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job dbatoolsci_testjob + $null = New-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job dbatoolsci_testjob_disabled -Disabled } AfterAll { - $null = Remove-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_testjob, dbatoolsci_testjob_disabled -Confirm:$false + $null = Remove-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job dbatoolsci_testjob, dbatoolsci_testjob_disabled -Confirm:$false } - $results = Get-DbaAgentJob -SqlInstance $script:instance2 -ExcludeDisabledJobs | Where-Object { $_.Name -match "dbatoolsci_testjob" } + $results = Get-DbaAgentJob -SqlInstance $TestConfig.instance2 -ExcludeDisabledJobs | Where-Object { $_.Name -match "dbatoolsci_testjob" } It "Should return only enabled jobs" { $results.enabled -contains $False | Should Be $False } } Context "Command doesn't get excluded job" { BeforeAll { - $null = New-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_testjob - $null = New-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_testjob_disabled -Disabled + $null = New-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job dbatoolsci_testjob + $null = New-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job dbatoolsci_testjob_disabled -Disabled } AfterAll { - $null = Remove-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_testjob, dbatoolsci_testjob_disabled -Confirm:$false + $null = Remove-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job dbatoolsci_testjob, dbatoolsci_testjob_disabled -Confirm:$false } - $results = Get-DbaAgentJob -SqlInstance $script:instance2 -ExcludeJob dbatoolsci_testjob | Where-Object { $_.Name -match "dbatoolsci_testjob" } + $results = Get-DbaAgentJob -SqlInstance $TestConfig.instance2 -ExcludeJob dbatoolsci_testjob | Where-Object { $_.Name -match "dbatoolsci_testjob" } It "Should not return excluded job" { $results.name -contains "dbatoolsci_testjob" | Should Be $False } } Context "Command doesn't get excluded category" { BeforeAll { - $null = New-DbaAgentJobCategory -SqlInstance $script:instance2 -Category 'Cat1' - $null = New-DbaAgentJobCategory -SqlInstance $script:instance2 -Category 'Cat2' + $null = New-DbaAgentJobCategory -SqlInstance $TestConfig.instance2 -Category 'Cat1' + $null = New-DbaAgentJobCategory -SqlInstance $TestConfig.instance2 -Category 'Cat2' - $null = New-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_testjob_cat1 -Category 'Cat1' - $null = New-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_testjob_cat2 -Category 'Cat2' + $null = New-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job dbatoolsci_testjob_cat1 -Category 'Cat1' + $null = New-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job dbatoolsci_testjob_cat2 -Category 'Cat2' } AfterAll { - $null = Remove-DbaAgentJobCategory -SqlInstance $script:instance2 -Category 'Cat1', 'Cat2' -Confirm:$false + $null = Remove-DbaAgentJobCategory -SqlInstance $TestConfig.instance2 -Category 'Cat1', 'Cat2' -Confirm:$false - $null = Remove-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_testjob_cat1, dbatoolsci_testjob_cat2 -Confirm:$false + $null = Remove-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job dbatoolsci_testjob_cat1, dbatoolsci_testjob_cat2 -Confirm:$false } - $results = Get-DbaAgentJob -SqlInstance $script:instance2 -ExcludeCategory 'Cat2' | Where-Object { $_.Name -match "dbatoolsci_testjob" } + $results = Get-DbaAgentJob -SqlInstance $TestConfig.instance2 -ExcludeCategory 'Cat2' | Where-Object { $_.Name -match "dbatoolsci_testjob" } It "Should not return excluded job" { $results.name -contains "dbatoolsci_testjob_cat2" | Should Be $False } @@ -80,20 +80,20 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { BeforeAll { $jobName1 = "dbatoolsci_dbfilter_$(Get-Random)" $jobName2 = "dbatoolsci_dbfilter_$(Get-Random)" - $null = New-DbaAgentJob -SqlInstance $script:instance2 -Job $jobName1 -Disabled - $null = New-DbaAgentJobStep -SqlInstance $script:instance2 -Job $jobName1 -StepName "TSQL-x" -Subsystem TransactSql -Database "msdb" - $null = New-DbaAgentJobStep -SqlInstance $script:instance2 -Job $jobName1 -StepName "TSQL-y" -Subsystem TransactSql -Database "tempdb" - $null = New-DbaAgentJobStep -SqlInstance $script:instance2 -Job $jobName1 -StepName "TSQL-z" -Subsystem TransactSql -Database "master" + $null = New-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job $jobName1 -Disabled + $null = New-DbaAgentJobStep -SqlInstance $TestConfig.instance2 -Job $jobName1 -StepName "TSQL-x" -Subsystem TransactSql -Database "msdb" + $null = New-DbaAgentJobStep -SqlInstance $TestConfig.instance2 -Job $jobName1 -StepName "TSQL-y" -Subsystem TransactSql -Database "tempdb" + $null = New-DbaAgentJobStep -SqlInstance $TestConfig.instance2 -Job $jobName1 -StepName "TSQL-z" -Subsystem TransactSql -Database "master" - $null = New-DbaAgentJob -SqlInstance $script:instance2 -Job $jobName2 -Disabled - $null = New-DbaAgentJobStep -SqlInstance $script:instance2 -Job $jobName2 -StepName "TSQL-x" -Subsystem TransactSql -Database "msdb" - $null = New-DbaAgentJobStep -SqlInstance $script:instance2 -Job $jobName2 -StepName "TSQL-y" -Subsystem TransactSql -Database "model" - $null = New-DbaAgentJobStep -SqlInstance $script:instance2 -Job $jobName2 -StepName "TSQL-z" -Subsystem TransactSql -Database "master" + $null = New-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job $jobName2 -Disabled + $null = New-DbaAgentJobStep -SqlInstance $TestConfig.instance2 -Job $jobName2 -StepName "TSQL-x" -Subsystem TransactSql -Database "msdb" + $null = New-DbaAgentJobStep -SqlInstance $TestConfig.instance2 -Job $jobName2 -StepName "TSQL-y" -Subsystem TransactSql -Database "model" + $null = New-DbaAgentJobStep -SqlInstance $TestConfig.instance2 -Job $jobName2 -StepName "TSQL-z" -Subsystem TransactSql -Database "master" } AfterAll { - $null = Remove-DbaAgentJob -SqlInstance $script:instance2 -Job $jobName1, $jobName2 -Confirm:$false + $null = Remove-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job $jobName1, $jobName2 -Confirm:$false } - $resultSingleDatabase = Get-DbaAgentJob -SqlInstance $script:instance2 -Database tempdb + $resultSingleDatabase = Get-DbaAgentJob -SqlInstance $TestConfig.instance2 -Database tempdb It "Returns result with single database" { $resultSingleDatabase.Count | Should -BeGreaterOrEqual 1 } @@ -101,7 +101,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $resultSingleDatabase.name -contains $jobName1 | Should -BeTrue } - $resultMultipleDatabases = Get-DbaAgentJob -SqlInstance $script:instance2 -Database tempdb, model + $resultMultipleDatabases = Get-DbaAgentJob -SqlInstance $TestConfig.instance2 -Database tempdb, model It "Returns both jobs with double database" { $resultMultipleDatabases.Count | Should -BeGreaterOrEqual 2 } @@ -109,4 +109,4 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $resultMultipleDatabases.name -contains $jobName2 | Should -BeTrue } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaAgentJobCategory.Tests.ps1 b/tests/Get-DbaAgentJobCategory.Tests.ps1 index 2edf4b21b0..3344a55e11 100644 --- a/tests/Get-DbaAgentJobCategory.Tests.ps1 +++ b/tests/Get-DbaAgentJobCategory.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,22 +16,22 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Command gets job categories" { BeforeAll { - $null = New-DbaAgentJobCategory -SqlInstance $script:instance2 -Category dbatoolsci_testcategory, dbatoolsci_testcategory2 + $null = New-DbaAgentJobCategory -SqlInstance $TestConfig.instance2 -Category dbatoolsci_testcategory, dbatoolsci_testcategory2 } AfterAll { - $null = Remove-DbaAgentJobCategory -SqlInstance $script:instance2 -Category dbatoolsci_testcategory, dbatoolsci_testcategory2 -Confirm:$false + $null = Remove-DbaAgentJobCategory -SqlInstance $TestConfig.instance2 -Category dbatoolsci_testcategory, dbatoolsci_testcategory2 -Confirm:$false } - $results = Get-DbaAgentJobCategory -SqlInstance $script:instance2 | Where-Object {$_.Name -match "dbatoolsci"} + $results = Get-DbaAgentJobCategory -SqlInstance $TestConfig.instance2 | Where-Object {$_.Name -match "dbatoolsci"} It "Should get at least 2 categories" { $results.count | Should BeGreaterThan 1 } - $results = Get-DbaAgentJobCategory -SqlInstance $script:instance2 -Category dbatoolsci_testcategory | Where-Object {$_.Name -match "dbatoolsci"} + $results = Get-DbaAgentJobCategory -SqlInstance $TestConfig.instance2 -Category dbatoolsci_testcategory | Where-Object {$_.Name -match "dbatoolsci"} It "Should get the dbatoolsci_testcategory category" { $results.count | Should Be 1 } - $results = Get-DbaAgentJobCategory -SqlInstance $script:instance2 -CategoryType LocalJob | Where-Object {$_.Name -match "dbatoolsci"} + $results = Get-DbaAgentJobCategory -SqlInstance $TestConfig.instance2 -CategoryType LocalJob | Where-Object {$_.Name -match "dbatoolsci"} It "Should get at least 1 LocalJob" { $results.count | Should BeGreaterThan 1 } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaAgentJobHistory.Tests.ps1 b/tests/Get-DbaAgentJobHistory.Tests.ps1 index be3780942b..862a38dc0f 100644 --- a/tests/Get-DbaAgentJobHistory.Tests.ps1 +++ b/tests/Get-DbaAgentJobHistory.Tests.ps1 @@ -1,6 +1,6 @@ $commandname = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaAgentJobOutputFile.Tests.ps1 b/tests/Get-DbaAgentJobOutputFile.Tests.ps1 index 78868ca151..ea63f48ded 100644 --- a/tests/Get-DbaAgentJobOutputFile.Tests.ps1 +++ b/tests/Get-DbaAgentJobOutputFile.Tests.ps1 @@ -1,6 +1,6 @@ $commandname = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaAgentJobStep.Tests.ps1 b/tests/Get-DbaAgentJobStep.Tests.ps1 index 9937fe05f6..b32e782770 100644 --- a/tests/Get-DbaAgentJobStep.Tests.ps1 +++ b/tests/Get-DbaAgentJobStep.Tests.ps1 @@ -1,6 +1,6 @@ $commandname = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -17,30 +17,30 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Gets a job step" { BeforeAll { $jobName = "dbatoolsci_job_$(get-random)" - $null = New-DbaAgentJob -SqlInstance $script:instance2 -Job $jobName - $null = New-DbaAgentJobStep -SqlInstance $script:instance2 -Job $jobName -StepName dbatoolsci_jobstep1 -Subsystem TransactSql -Command 'select 1' + $null = New-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job $jobName + $null = New-DbaAgentJobStep -SqlInstance $TestConfig.instance2 -Job $jobName -StepName dbatoolsci_jobstep1 -Subsystem TransactSql -Command 'select 1' } AfterAll { - $null = Remove-DbaAgentJob -SqlInstance $script:instance2 -Job $jobName -Confirm:$false + $null = Remove-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job $jobName -Confirm:$false } It "Successfully gets job when not using Job param" { - $results = Get-DbaAgentJobStep -SqlInstance $script:instance2 + $results = Get-DbaAgentJobStep -SqlInstance $TestConfig.instance2 $results.Name | should contain 'dbatoolsci_jobstep1' } It "Successfully gets job when using Job param" { - $results = Get-DbaAgentJobStep -SqlInstance $script:instance2 -Job $jobName + $results = Get-DbaAgentJobStep -SqlInstance $TestConfig.instance2 -Job $jobName $results.Name | should contain 'dbatoolsci_jobstep1' } It "Successfully gets job when excluding some jobs" { - $results = Get-DbaAgentJobStep -SqlInstance $script:instance2 -ExcludeJob 'syspolicy_purge_history' + $results = Get-DbaAgentJobStep -SqlInstance $TestConfig.instance2 -ExcludeJob 'syspolicy_purge_history' $results.Name | should contain 'dbatoolsci_jobstep1' } It "Successfully excludes disabled jobs" { - $null = Set-DbaAgentJob -SqlInstance $script:instance2 -Job $jobName -Disabled - $results = Get-DbaAgentJobStep -SqlInstance $script:instance2 -ExcludeDisabledJobs + $null = Set-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job $jobName -Disabled + $results = Get-DbaAgentJobStep -SqlInstance $TestConfig.instance2 -ExcludeDisabledJobs $results.Name | should not contain 'dbatoolsci_jobstep1' } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaAgentLog.Tests.ps1 b/tests/Get-DbaAgentLog.Tests.ps1 index 92f2a495b9..1445215a9d 100644 --- a/tests/Get-DbaAgentLog.Tests.ps1 +++ b/tests/Get-DbaAgentLog.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,7 +15,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Command gets agent log" { - $results = Get-DbaAgentLog -SqlInstance $script:instance2 + $results = Get-DbaAgentLog -SqlInstance $TestConfig.instance2 It "Results are not empty" { $results | Should Not Be $Null } @@ -27,9 +27,9 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } Context "Command gets current agent log using LogNumber parameter" { - $results = Get-DbaAgentLog -SqlInstance $script:instance2 -LogNumber 0 + $results = Get-DbaAgentLog -SqlInstance $TestConfig.instance2 -LogNumber 0 It "Results are not empty" { $results | Should Not Be $Null } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaAgentOperator.Tests.ps1 b/tests/Get-DbaAgentOperator.Tests.ps1 index 19b24cbe7c..9cc587ebbc 100644 --- a/tests/Get-DbaAgentOperator.Tests.ps1 +++ b/tests/Get-DbaAgentOperator.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,7 +15,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $sql = "EXEC msdb.dbo.sp_add_operator @name=N'dbatoolsci_operator', @enabled=1, @pager_days=0" $server.Query($sql) $sql = "EXEC msdb.dbo.sp_add_operator @name=N'dbatoolsci_operator2', @enabled=1, @pager_days=0" @@ -28,13 +28,13 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $server.Query($sql) } Context "Get back some operators" { - $results = Get-DbaAgentOperator -SqlInstance $script:instance2 + $results = Get-DbaAgentOperator -SqlInstance $TestConfig.instance2 It "return at least two results" { $results.Count -ge 2 | Should Be $true } - $results = Get-DbaAgentOperator -SqlInstance $script:instance2 -Operator dbatoolsci_operator + $results = Get-DbaAgentOperator -SqlInstance $TestConfig.instance2 -Operator dbatoolsci_operator It "return one result" { $results.Count | Should Be 1 } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaAgentProxy.Tests.ps1 b/tests/Get-DbaAgentProxy.Tests.ps1 index d65f54f3ea..55d5ff43ec 100644 --- a/tests/Get-DbaAgentProxy.Tests.ps1 +++ b/tests/Get-DbaAgentProxy.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -18,21 +18,21 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $tPassword = ConvertTo-SecureString "ThisIsThePassword1" -AsPlainText -Force $tUserName = "dbatoolsci_proxytest" New-LocalUser -Name $tUserName -Password $tPassword -Disabled:$false - New-DbaCredential -SqlInstance $script:instance2 -Name "$tUserName" -Identity "$env:COMPUTERNAME\$tUserName" -Password $tPassword - New-DbaAgentProxy -SqlInstance $script:instance2 -Name STIG -ProxyCredential "$tUserName" - New-DbaAgentProxy -SqlInstance $script:instance2 -Name STIGX -ProxyCredential "$tUserName" + New-DbaCredential -SqlInstance $TestConfig.instance2 -Name "$tUserName" -Identity "$env:COMPUTERNAME\$tUserName" -Password $tPassword + New-DbaAgentProxy -SqlInstance $TestConfig.instance2 -Name STIG -ProxyCredential "$tUserName" + New-DbaAgentProxy -SqlInstance $TestConfig.instance2 -Name STIGX -ProxyCredential "$tUserName" } Afterall { $tUserName = "dbatoolsci_proxytest" Remove-LocalUser -Name $tUserName - $credential = Get-DbaCredential -SqlInstance $script:instance2 -Name $tUserName + $credential = Get-DbaCredential -SqlInstance $TestConfig.instance2 -Name $tUserName $credential.DROP() - $proxy = Get-DbaAgentProxy -SqlInstance $script:instance2 -Proxy "STIG", "STIGX" + $proxy = Get-DbaAgentProxy -SqlInstance $TestConfig.instance2 -Proxy "STIG", "STIGX" $proxy.DROP() } Context "Gets the list of Proxy" { - $results = Get-DbaAgentProxy -SqlInstance $script:instance2 + $results = Get-DbaAgentProxy -SqlInstance $TestConfig.instance2 It "Results are not empty" { $results | Should Not Be $Null } @@ -44,7 +44,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } Context "Gets a single Proxy" { - $results = Get-DbaAgentProxy -SqlInstance $script:instance2 -Proxy "STIG" + $results = Get-DbaAgentProxy -SqlInstance $TestConfig.instance2 -Proxy "STIG" It "Results are not empty" { $results | Should Not Be $Null } @@ -56,7 +56,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } Context "Gets the list of Proxy without excluded" { - $results = Get-DbaAgentProxy -SqlInstance $script:instance2 -ExcludeProxy "STIG" + $results = Get-DbaAgentProxy -SqlInstance $TestConfig.instance2 -ExcludeProxy "STIG" It "Results are not empty" { $results | Should Not Be $Null } @@ -67,4 +67,4 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $results.isenabled | Should Be $true } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaAgentSchedule.Tests.ps1 b/tests/Get-DbaAgentSchedule.Tests.ps1 index c1302a3651..846e56cc5a 100644 --- a/tests/Get-DbaAgentSchedule.Tests.ps1 +++ b/tests/Get-DbaAgentSchedule.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,9 +15,9 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "UnitTests" { BeforeAll { - Write-Message -Level Warning -Message "BeforeAll start: Get-DbaAgentSchedule.Tests.ps1 testing with instance3=$($script:instance3) and instance2=$($script:instance2)" - $server3 = Connect-DbaInstance -SqlInstance $script:instance3 - $server2 = Connect-DbaInstance -SqlInstance $script:instance2 + Write-Message -Level Warning -Message "BeforeAll start: Get-DbaAgentSchedule.Tests.ps1 testing with instance3=$($TestConfig.instance3) and instance2=$($TestConfig.instance2)" + $server3 = Connect-DbaInstance -SqlInstance $TestConfig.instance3 + $server2 = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $sqlAgentServer3 = Get-DbaService -ComputerName $server3.ComputerName -InstanceName $server3.DbaInstanceName -Type Agent Write-Message -Level Warning -Message "The SQL Agent service for instance3 has state=$($sqlAgentServer3.State) and start mode=$($sqlAgentServer3.StartMode)" @@ -25,11 +25,11 @@ Describe "$commandname Integration Tests" -Tags "UnitTests" { $sqlAgentServer2 = Get-DbaService -ComputerName $server2.ComputerName -InstanceName $server2.DbaInstanceName -Type Agent Write-Message -Level Warning -Message "The SQL Agent service for instance2 has state=$($sqlAgentServer2.State) and start mode=$($sqlAgentServer2.StartMode)" - $null = New-DbaAgentSchedule -SqlInstance $script:instance2 -Schedule dbatoolsci_MonthlyTest -FrequencyType Monthly -FrequencyInterval 10 -FrequencyRecurrenceFactor 1 -Force - $null = New-DbaAgentSchedule -SqlInstance $script:instance2 -Schedule dbatoolsci_WeeklyTest -FrequencyType Weekly -FrequencyInterval 2 -FrequencyRecurrenceFactor 1 -StartTime 020000 -Force - $null = New-DbaAgentSchedule -SqlInstance $script:instance3 -Schedule dbatoolsci_MonthlyTest -FrequencyType Monthly -FrequencyInterval 10 -FrequencyRecurrenceFactor 1 -Force + $null = New-DbaAgentSchedule -SqlInstance $TestConfig.instance2 -Schedule dbatoolsci_MonthlyTest -FrequencyType Monthly -FrequencyInterval 10 -FrequencyRecurrenceFactor 1 -Force + $null = New-DbaAgentSchedule -SqlInstance $TestConfig.instance2 -Schedule dbatoolsci_WeeklyTest -FrequencyType Weekly -FrequencyInterval 2 -FrequencyRecurrenceFactor 1 -StartTime 020000 -Force + $null = New-DbaAgentSchedule -SqlInstance $TestConfig.instance3 -Schedule dbatoolsci_MonthlyTest -FrequencyType Monthly -FrequencyInterval 10 -FrequencyRecurrenceFactor 1 -Force $scheduleParams = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 Schedule = 'Issue_6636_Once' FrequencyInterval = 1 FrequencyRecurrenceFactor = 0 @@ -42,7 +42,7 @@ Describe "$commandname Integration Tests" -Tags "UnitTests" { $null = New-DbaAgentSchedule @ScheduleParams -Force $scheduleParams = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 Schedule = 'Issue_6636_Hour' FrequencyInterval = 1 FrequencyRecurrenceFactor = 0 @@ -55,7 +55,7 @@ Describe "$commandname Integration Tests" -Tags "UnitTests" { $null = New-DbaAgentSchedule @ScheduleParams -Force $scheduleParams = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 Schedule = 'Issue_6636_Minute' FrequencyInterval = 1 FrequencyRecurrenceFactor = 0 @@ -68,7 +68,7 @@ Describe "$commandname Integration Tests" -Tags "UnitTests" { $null = New-DbaAgentSchedule @ScheduleParams -Force $scheduleParams = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 Schedule = 'Issue_6636_Second' FrequencyInterval = 1 FrequencyRecurrenceFactor = 0 @@ -82,7 +82,7 @@ Describe "$commandname Integration Tests" -Tags "UnitTests" { # frequency type additions for issue 6636 $scheduleParams = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 Schedule = "Issue_6636_OneTime" FrequencyType = "OneTime" } @@ -90,7 +90,7 @@ Describe "$commandname Integration Tests" -Tags "UnitTests" { $null = New-DbaAgentSchedule @ScheduleParams -Force $scheduleParams = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 Schedule = "Issue_6636_AutoStart" FrequencyType = "AutoStart" } @@ -98,54 +98,54 @@ Describe "$commandname Integration Tests" -Tags "UnitTests" { $null = New-DbaAgentSchedule @ScheduleParams -Force $scheduleParams = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 Schedule = "Issue_6636_OnIdle" FrequencyType = "OnIdle" } $null = New-DbaAgentSchedule @ScheduleParams -Force - Write-Message -Level Warning -Message "BeforeAll end: Get-DbaAgentSchedule.Tests.ps1 testing with instance3=$($script:instance3) and instance2=$($script:instance2)" + Write-Message -Level Warning -Message "BeforeAll end: Get-DbaAgentSchedule.Tests.ps1 testing with instance3=$($TestConfig.instance3) and instance2=$($TestConfig.instance2)" } AfterAll { - Write-Message -Level Warning -Message "AfterAll start: Get-DbaAgentSchedule.Tests.ps1 testing with instance3=$($script:instance3) and instance2=$($script:instance2)" + Write-Message -Level Warning -Message "AfterAll start: Get-DbaAgentSchedule.Tests.ps1 testing with instance3=$($TestConfig.instance3) and instance2=$($TestConfig.instance2)" - $schedules = Get-DbaAgentSchedule -SqlInstance $script:instance2 -Schedule dbatoolsci_WeeklyTest, dbatoolsci_MonthlyTest, Issue_6636_Once, Issue_6636_Once_Copy, Issue_6636_Hour, Issue_6636_Hour_Copy, Issue_6636_Minute, Issue_6636_Minute_Copy, Issue_6636_Second, Issue_6636_Second_Copy, Issue_6636_OneTime, Issue_6636_OneTime_Copy, Issue_6636_AutoStart, Issue_6636_AutoStart_Copy, Issue_6636_OnIdle, Issue_6636_OnIdle_Copy + $schedules = Get-DbaAgentSchedule -SqlInstance $TestConfig.instance2 -Schedule dbatoolsci_WeeklyTest, dbatoolsci_MonthlyTest, Issue_6636_Once, Issue_6636_Once_Copy, Issue_6636_Hour, Issue_6636_Hour_Copy, Issue_6636_Minute, Issue_6636_Minute_Copy, Issue_6636_Second, Issue_6636_Second_Copy, Issue_6636_OneTime, Issue_6636_OneTime_Copy, Issue_6636_AutoStart, Issue_6636_AutoStart_Copy, Issue_6636_OnIdle, Issue_6636_OnIdle_Copy if ($null -ne $schedules) { $schedules.DROP() } else { - Write-Message -Level Warning -Message "The schedules from $script:instance2 were returned as null" + Write-Message -Level Warning -Message "The schedules from $TestConfig.instance2 were returned as null" } - $schedules = Get-DbaAgentSchedule -SqlInstance $script:instance3 -Schedule dbatoolsci_MonthlyTest + $schedules = Get-DbaAgentSchedule -SqlInstance $TestConfig.instance3 -Schedule dbatoolsci_MonthlyTest if ($null -ne $schedules) { $schedules.DROP() } else { - Write-Message -Level Warning -Message "The schedules from $script:instance3 were returned as null" + Write-Message -Level Warning -Message "The schedules from $TestConfig.instance3 were returned as null" } - Write-Message -Level Warning -Message "AfterAll end: Get-DbaAgentSchedule.Tests.ps1 testing with instance3=$($script:instance3) and instance2=$($script:instance2)" + Write-Message -Level Warning -Message "AfterAll end: Get-DbaAgentSchedule.Tests.ps1 testing with instance3=$($TestConfig.instance3) and instance2=$($TestConfig.instance2)" } Context "Gets the list of Schedules" { It "Results are not empty" { - $results = Get-DbaAgentSchedule -SqlInstance $script:instance2 -Schedule dbatoolsci_WeeklyTest, dbatoolsci_MonthlyTest + $results = Get-DbaAgentSchedule -SqlInstance $TestConfig.instance2 -Schedule dbatoolsci_WeeklyTest, dbatoolsci_MonthlyTest $results.Count | Should -Be 2 } } Context "Handles multiple instances" { It "Results contain two instances" { - $results = Get-DbaAgentSchedule -SqlInstance $script:instance2, $script:instance3 + $results = Get-DbaAgentSchedule -SqlInstance $TestConfig.instance2, $TestConfig.instance3 ($results | Select-Object SqlInstance -Unique).Count | Should -Be 2 } } Context "Monthly schedule is correct" { It "verify schedule components" { - $results = Get-DbaAgentSchedule -SqlInstance $script:instance2 -Schedule dbatoolsci_MonthlyTest + $results = Get-DbaAgentSchedule -SqlInstance $TestConfig.instance2 -Schedule dbatoolsci_MonthlyTest $results.count | Should -Be 1 $results | Should -Not -BeNullOrEmpty @@ -162,10 +162,10 @@ Describe "$commandname Integration Tests" -Tags "UnitTests" { Context "Issue 6636 - provide flexibility in the FrequencySubdayType and FrequencyType input params based on the return values from the SMO object JobServer.SharedSchedules" { It "Ensure frequency subday type of 'Once' is usable" { - $result = Get-DbaAgentSchedule -SqlInstance $script:instance2 -Schedule Issue_6636_Once + $result = Get-DbaAgentSchedule -SqlInstance $TestConfig.instance2 -Schedule Issue_6636_Once $scheduleParams = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 Schedule = 'Issue_6636_Once_Copy' FrequencyInterval = $result.FrequencyInterval FrequencyRecurrenceFactor = $result.FrequencyRecurrenceFactor @@ -177,17 +177,17 @@ Describe "$commandname Integration Tests" -Tags "UnitTests" { $newSchedule = New-DbaAgentSchedule @ScheduleParams -Force - $result = Get-DbaAgentSchedule -SqlInstance $script:instance2 -Schedule Issue_6636_Once_Copy + $result = Get-DbaAgentSchedule -SqlInstance $TestConfig.instance2 -Schedule Issue_6636_Once_Copy $result.ScheduleName | Should -Be "Issue_6636_Once_Copy" $result.FrequencySubdayTypes | Should -Be "Once" } It "Ensure frequency subday type of 'Hour' is usable" { - $result = Get-DbaAgentSchedule -SqlInstance $script:instance2 -Schedule Issue_6636_Hour + $result = Get-DbaAgentSchedule -SqlInstance $TestConfig.instance2 -Schedule Issue_6636_Hour $scheduleParams = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 Schedule = 'Issue_6636_Hour_Copy' FrequencyInterval = $result.FrequencyInterval FrequencyRecurrenceFactor = $result.FrequencyRecurrenceFactor @@ -199,17 +199,17 @@ Describe "$commandname Integration Tests" -Tags "UnitTests" { $newSchedule = New-DbaAgentSchedule @ScheduleParams -Force - $result = Get-DbaAgentSchedule -SqlInstance $script:instance2 -Schedule Issue_6636_Hour_Copy + $result = Get-DbaAgentSchedule -SqlInstance $TestConfig.instance2 -Schedule Issue_6636_Hour_Copy $result.ScheduleName | Should -Be "Issue_6636_Hour_Copy" $result.FrequencySubdayTypes | Should -Be "Hour" } It "Ensure frequency subday type of 'Minute' is usable" { - $result = Get-DbaAgentSchedule -SqlInstance $script:instance2 -Schedule Issue_6636_Minute + $result = Get-DbaAgentSchedule -SqlInstance $TestConfig.instance2 -Schedule Issue_6636_Minute $scheduleParams = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 Schedule = 'Issue_6636_Minute_Copy' FrequencyInterval = $result.FrequencyInterval FrequencyRecurrenceFactor = $result.FrequencyRecurrenceFactor @@ -221,17 +221,17 @@ Describe "$commandname Integration Tests" -Tags "UnitTests" { $newSchedule = New-DbaAgentSchedule @ScheduleParams -Force - $result = Get-DbaAgentSchedule -SqlInstance $script:instance2 -Schedule Issue_6636_Minute_Copy + $result = Get-DbaAgentSchedule -SqlInstance $TestConfig.instance2 -Schedule Issue_6636_Minute_Copy $result.ScheduleName | Should -Be "Issue_6636_Minute_Copy" $result.FrequencySubdayTypes | Should -Be "Minute" } It "Ensure frequency subday type of 'Second' is usable" { - $result = Get-DbaAgentSchedule -SqlInstance $script:instance2 -Schedule Issue_6636_Second + $result = Get-DbaAgentSchedule -SqlInstance $TestConfig.instance2 -Schedule Issue_6636_Second $scheduleParams = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 Schedule = 'Issue_6636_Second_Copy' FrequencyInterval = $result.FrequencyInterval FrequencyRecurrenceFactor = $result.FrequencyRecurrenceFactor @@ -243,17 +243,17 @@ Describe "$commandname Integration Tests" -Tags "UnitTests" { $newSchedule = New-DbaAgentSchedule @ScheduleParams -Force - $result = Get-DbaAgentSchedule -SqlInstance $script:instance2 -Schedule Issue_6636_Second_Copy + $result = Get-DbaAgentSchedule -SqlInstance $TestConfig.instance2 -Schedule Issue_6636_Second_Copy $result.ScheduleName | Should -Be "Issue_6636_Second_Copy" $result.FrequencySubdayTypes | Should -Be "Second" } It "Ensure frequency type of 'OneTime' is usable" { - $result = Get-DbaAgentSchedule -SqlInstance $script:instance2 -Schedule Issue_6636_OneTime + $result = Get-DbaAgentSchedule -SqlInstance $TestConfig.instance2 -Schedule Issue_6636_OneTime $scheduleParams = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 Schedule = 'Issue_6636_OneTime_Copy' FrequencyType = $result.FrequencyTypes # OneTime StartTime = $result.ActiveStartTimeOfDay.ToString().Replace(":", "") @@ -261,17 +261,17 @@ Describe "$commandname Integration Tests" -Tags "UnitTests" { $newSchedule = New-DbaAgentSchedule @ScheduleParams -Force - $result = Get-DbaAgentSchedule -SqlInstance $script:instance2 -Schedule Issue_6636_OneTime_Copy + $result = Get-DbaAgentSchedule -SqlInstance $TestConfig.instance2 -Schedule Issue_6636_OneTime_Copy $result.ScheduleName | Should -Be "Issue_6636_OneTime_Copy" $result.FrequencyTypes | Should -Be "OneTime" } It "Ensure frequency type of 'AutoStart' is usable" { - $result = Get-DbaAgentSchedule -SqlInstance $script:instance2 -Schedule Issue_6636_AutoStart + $result = Get-DbaAgentSchedule -SqlInstance $TestConfig.instance2 -Schedule Issue_6636_AutoStart $scheduleParams = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 Schedule = 'Issue_6636_AutoStart_Copy' FrequencyType = $result.FrequencyTypes # AutoStart StartTime = $result.ActiveStartTimeOfDay.ToString().Replace(":", "") @@ -279,27 +279,27 @@ Describe "$commandname Integration Tests" -Tags "UnitTests" { $newSchedule = New-DbaAgentSchedule @ScheduleParams -Force - $result = Get-DbaAgentSchedule -SqlInstance $script:instance2 -Schedule Issue_6636_AutoStart_Copy + $result = Get-DbaAgentSchedule -SqlInstance $TestConfig.instance2 -Schedule Issue_6636_AutoStart_Copy $result.ScheduleName | Should -Be "Issue_6636_AutoStart_Copy" $result.FrequencyTypes | Should -Be "AutoStart" } It "Ensure frequency type of 'OnIdle' is usable" { - $result = Get-DbaAgentSchedule -SqlInstance $script:instance2 -Schedule Issue_6636_OnIdle + $result = Get-DbaAgentSchedule -SqlInstance $TestConfig.instance2 -Schedule Issue_6636_OnIdle $scheduleParams = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 Schedule = 'Issue_6636_OnIdle_Copy' FrequencyType = $result.FrequencyTypes # OnIdle } $newSchedule = New-DbaAgentSchedule @ScheduleParams -Force - $result = Get-DbaAgentSchedule -SqlInstance $script:instance2 -Schedule Issue_6636_OnIdle_Copy + $result = Get-DbaAgentSchedule -SqlInstance $TestConfig.instance2 -Schedule Issue_6636_OnIdle_Copy $result.ScheduleName | Should -Be "Issue_6636_OnIdle_Copy" $result.FrequencyTypes | Should -Be "OnIdle" } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaAgentServer.Tests.ps1 b/tests/Get-DbaAgentServer.Tests.ps1 index 971cf0bbf5..0a843e4fcd 100644 --- a/tests/Get-DbaAgentServer.Tests.ps1 +++ b/tests/Get-DbaAgentServer.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,9 +15,9 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Command gets server agent" { - $results = Get-DbaAgentServer -SqlInstance $script:instance2 + $results = Get-DbaAgentServer -SqlInstance $TestConfig.instance2 It "Should get 1 agent server" { $results.count | Should Be 1 } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaAvailabilityGroup.Tests.ps1 b/tests/Get-DbaAvailabilityGroup.Tests.ps1 index 8ee6c94b5e..720e73fcc2 100644 --- a/tests/Get-DbaAvailabilityGroup.Tests.ps1 +++ b/tests/Get-DbaAvailabilityGroup.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$commandname Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,20 +16,20 @@ Describe "$commandname Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { $agname = "dbatoolsci_agroup" - $null = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Confirm:$false -Certificate dbatoolsci_AGCert + $null = New-DbaAvailabilityGroup -Primary $TestConfig.instance3 -Name $agname -ClusterType None -FailoverMode Manual -Confirm:$false -Certificate dbatoolsci_AGCert } AfterAll { - Remove-DbaAvailabilityGroup -SqlInstance $script:instance3 -AvailabilityGroup $agname -Confirm:$false + Remove-DbaAvailabilityGroup -SqlInstance $TestConfig.instance3 -AvailabilityGroup $agname -Confirm:$false } Context "gets ags" { It "returns results with proper data" { - $results = Get-DbaAvailabilityGroup -SqlInstance $script:instance3 + $results = Get-DbaAvailabilityGroup -SqlInstance $TestConfig.instance3 $results.AvailabilityGroup | Should -Contain $agname } It "returns a single result" { - $results = Get-DbaAvailabilityGroup -SqlInstance $script:instance3 -AvailabilityGroup $agname + $results = Get-DbaAvailabilityGroup -SqlInstance $TestConfig.instance3 -AvailabilityGroup $agname $results.AvailabilityGroup | Should -Be $agname } } -} #$script:instance2 for appveyor \ No newline at end of file +} #$TestConfig.instance2 for appveyor diff --git a/tests/Get-DbaAvailableCollation.Tests.ps1 b/tests/Get-DbaAvailableCollation.Tests.ps1 index 2b35c5f82c..908ecc0f10 100644 --- a/tests/Get-DbaAvailableCollation.Tests.ps1 +++ b/tests/Get-DbaAvailableCollation.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,9 +15,9 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Available Collations" { - $results = Get-DbaAvailableCollation -SqlInstance $script:instance2 + $results = Get-DbaAvailableCollation -SqlInstance $TestConfig.instance2 It "finds a collation that matches Slovenian" { ($results.Name -match 'Slovenian').Count -gt 10 | Should Be $true } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaBackupDevice.Tests.ps1 b/tests/Get-DbaBackupDevice.Tests.ps1 index 8b26296ba9..bb169b6d26 100644 --- a/tests/Get-DbaBackupDevice.Tests.ps1 +++ b/tests/Get-DbaBackupDevice.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,18 +15,18 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $sql = "EXEC sp_addumpdevice 'tape', 'dbatoolsci_tape', '\\.\tape0';" $server.Query($sql) } Afterall { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $sql = "EXEC sp_dropdevice 'dbatoolsci_tape';" $server.Query($sql) } Context "Gets the backup devices" { - $results = Get-DbaBackupDevice -SqlInstance $script:instance2 + $results = Get-DbaBackupDevice -SqlInstance $TestConfig.instance2 It "Results are not empty" { $results | Should Not Be $Null } @@ -40,4 +40,4 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $results.PhysicalLocation | Should Be "\\.\Tape0" } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaBackupInformation.Tests.ps1 b/tests/Get-DbaBackupInformation.Tests.ps1 index 42f271320f..2ee7aaaf85 100644 --- a/tests/Get-DbaBackupInformation.Tests.ps1 +++ b/tests/Get-DbaBackupInformation.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -24,17 +24,17 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } $random = Get-Random $dbname = "dbatoolsci_Backuphistory_$random" - $null = Get-DbaDatabase -SqlInstance $script:instance1 -Database $dbname | Remove-DbaDatabase -Confirm:$false - $null = Restore-DbaDatabase -SqlInstance $script:instance1 -Path $script:appveyorlabrepo\singlerestore\singlerestore.bak -DatabaseName $dbname -DestinationFilePrefix $dbname - $db = Get-DbaDatabase -SqlInstance $script:instance1 -Database $dbname + $null = Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $dbname | Remove-DbaDatabase -Confirm:$false + $null = Restore-DbaDatabase -SqlInstance $TestConfig.instance1 -Path "$($TestConfig.appveyorlabrepo)\singlerestore\singlerestore.bak" -DatabaseName $dbname -DestinationFilePrefix $dbname + $db = Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $dbname $db | Backup-DbaDatabase -Type Full -BackupDirectory $DestBackupDir $db | Backup-DbaDatabase -Type Differential -BackupDirectory $DestBackupDir $db | Backup-DbaDatabase -Type Log -BackupDirectory $DestBackupDir $dbname2 = "dbatoolsci_Backuphistory2_$random" - $null = Get-DbaDatabase -SqlInstance $script:instance1 -Database $dbname2 | Remove-DbaDatabase -Confirm:$false - $null = Restore-DbaDatabase -SqlInstance $script:instance1 -Path $script:appveyorlabrepo\singlerestore\singlerestore.bak -DatabaseName $dbname2 -DestinationFilePrefix $dbname2 - $db2 = Get-DbaDatabase -SqlInstance $script:instance1 -Database $dbname2 + $null = Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $dbname2 | Remove-DbaDatabase -Confirm:$false + $null = Restore-DbaDatabase -SqlInstance $TestConfig.instance1 -Path "$($TestConfig.appveyorlabrepo)\singlerestore\singlerestore.bak" -DatabaseName $dbname2 -DestinationFilePrefix $dbname2 + $db2 = Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $dbname2 $db2 | Backup-DbaDatabase -Type Full -BackupDirectory $DestBackupDir $db2 | Backup-DbaDatabase -Type Differential -BackupDirectory $DestBackupDir $db2 | Backup-DbaDatabase -Type Log -BackupDirectory $DestBackupDir @@ -52,20 +52,20 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } $dbname3 = "dbatoolsci_BackuphistoryOla_$random" - $null = Get-DbaDatabase -SqlInstance $script:instance1 -Database $dbname3 | Remove-DbaDatabase -Confirm:$false - $null = Restore-DbaDatabase -SqlInstance $script:instance1 -Path $script:appveyorlabrepo\singlerestore\singlerestore.bak -DatabaseName $dbname3 -DestinationFilePrefix $dbname3 - $db3 = Get-DbaDatabase -SqlInstance $script:instance1 -Database $dbname3 + $null = Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $dbname3 | Remove-DbaDatabase -Confirm:$false + $null = Restore-DbaDatabase -SqlInstance $TestConfig.instance1 -Path "$($TestConfig.appveyorlabrepo)\singlerestore\singlerestore.bak" -DatabaseName $dbname3 -DestinationFilePrefix $dbname3 + $db3 = Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $dbname3 $db3 | Backup-DbaDatabase -Type Full -BackupDirectory "$DestBackupDirOla\FULL" $db3 | Backup-DbaDatabase -Type Differential -BackupDirectory "$DestBackupDirOla\Diff" $db3 | Backup-DbaDatabase -Type Log -BackupDirectory "$DestBackupDirOla\LOG" } AfterAll { - $null = Get-DbaDatabase -SqlInstance $script:instance1 -Database $dbname, $dbname2, $dbname3 | Remove-DbaDatabase -Confirm:$false + $null = Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $dbname, $dbname2, $dbname3 | Remove-DbaDatabase -Confirm:$false } Context "Get history for all database" { - $results = Get-DbaBackupInformation -SqlInstance $script:instance1 -Path $DestBackupDir + $results = Get-DbaBackupInformation -SqlInstance $TestConfig.instance1 -Path $DestBackupDir It "Should be 6 backups returned" { $results.count | Should Be 6 } @@ -78,7 +78,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } Context "Get history for one database" { - $results = Get-DbaBackupInformation -SqlInstance $script:instance1 -Path $DestBackupDir -DatabaseName $dbname2 + $results = Get-DbaBackupInformation -SqlInstance $TestConfig.instance1 -Path $DestBackupDir -DatabaseName $dbname2 It "Should be 3 backups returned" { $results.count | Should Be 3 } @@ -95,10 +95,10 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Check the export/import of backup history" { # This one used to cause all sorts of red - $results = Get-DbaBackupInformation -SqlInstance $script:instance1 -Path $DestBackupDir -DatabaseName $dbname2 -ExportPath "$DestBackupDir\history.xml" + $results = Get-DbaBackupInformation -SqlInstance $TestConfig.instance1 -Path $DestBackupDir -DatabaseName $dbname2 -ExportPath "$DestBackupDir\history.xml" # the command below returns just a warning - # Get-DbaBackupInformation -Import -Path "$DestBackupDir\history.xml" | Restore-DbaDatabase -SqlInstance $script:instance1 -DestinationFilePrefix hist -RestoredDatabaseNamePrefix hist -TrustDbBackupHistory + # Get-DbaBackupInformation -Import -Path "$DestBackupDir\history.xml" | Restore-DbaDatabase -SqlInstance $TestConfig.instance1 -DestinationFilePrefix hist -RestoredDatabaseNamePrefix hist -TrustDbBackupHistory It "Should restore cleanly" { ($results | Where-Object {$_.RestoreComplete -eq $false}).count | Should be 0 @@ -106,7 +106,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } Context "Test Maintenance solution options" { - $results = Get-DbaBackupInformation -SqlInstance $script:instance1 -Path $DestBackupDirOla -MaintenanceSolution + $results = Get-DbaBackupInformation -SqlInstance $TestConfig.instance1 -Path $DestBackupDirOla -MaintenanceSolution It "Should be 3 backups returned" { $results.count | Should Be 3 } @@ -119,7 +119,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { It "Should only be backups of $dbname3" { ($results | Where-Object {$_.Database -ne $dbname3 }).count | Should Be 0 } - $ResultsSanLog = Get-DbaBackupInformation -SqlInstance $script:instance1 -Path $DestBackupDirOla -MaintenanceSolution -IgnoreLogBackup + $ResultsSanLog = Get-DbaBackupInformation -SqlInstance $TestConfig.instance1 -Path $DestBackupDirOla -MaintenanceSolution -IgnoreLogBackup It "Should be 2 backups returned" { $ResultsSanLog.count | Should Be 2 } @@ -129,7 +129,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { It "Should be 0 log backups" { ($resultsSanLog | Where-Object {$_.Type -eq 'Transaction Log'}).count | Should be 0 } - $ResultsSanLog = Get-DbaBackupInformation -SqlInstance $script:instance1 -Path $DestBackupDirOla -IgnoreLogBackup -WarningVariable warnvar -WarningAction SilentlyContinue 3> $null + $ResultsSanLog = Get-DbaBackupInformation -SqlInstance $TestConfig.instance1 -Path $DestBackupDirOla -IgnoreLogBackup -WarningVariable warnvar -WarningAction SilentlyContinue 3> $null It "Should Warn if IgnoreLogBackup without MaintenanceSolution" { $warnVar | Should -Match "IgnoreLogBackup can only by used with MaintenanceSolution. Will not be used" } @@ -137,4 +137,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $resultsSanLog.count | Should Be 3 } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaBinaryFileTable.Tests.ps1 b/tests/Get-DbaBinaryFileTable.Tests.ps1 index 8778c5c077..f350d7a7c4 100644 --- a/tests/Get-DbaBinaryFileTable.Tests.ps1 +++ b/tests/Get-DbaBinaryFileTable.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,10 +15,10 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $db = Get-DbaDatabase -SqlInstance $script:instance2 -Database tempdb + $db = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database tempdb $null = $db.Query("CREATE TABLE [dbo].[BunchOFilez]([FileName123] [nvarchar](50) NULL, [TheFile123] [image] NULL)") - $null = Import-DbaBinaryFile -SqlInstance $script:instance2 -Database tempdb -Table BunchOFilez -FilePath $script:appveyorlabrepo\azure\adalsql.msi - $null = Get-ChildItem $script:appveyorlabrepo\certificates | Import-DbaBinaryFile -SqlInstance $script:instance2 -Database tempdb -Table BunchOFilez + $null = Import-DbaBinaryFile -SqlInstance $TestConfig.instance2 -Database tempdb -Table BunchOFilez -FilePath "$($TestConfig.appveyorlabrepo)\azure\adalsql.msi" + $null = Get-ChildItem "$($TestConfig.appveyorlabrepo)\certificates" | Import-DbaBinaryFile -SqlInstance $TestConfig.instance2 -Database tempdb -Table BunchOFilez } AfterAll { try { @@ -29,12 +29,12 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } It "returns a table" { - $results = Get-DbaBinaryFileTable -SqlInstance $script:instance2 -Database tempdb + $results = Get-DbaBinaryFileTable -SqlInstance $TestConfig.instance2 -Database tempdb $results.Name.Count | Should -BeGreaterOrEqual 1 } It "supports piping" { - $results = Get-DbaDbTable -SqlInstance $script:instance2 -Database tempdb | Get-DbaBinaryFileTable + $results = Get-DbaDbTable -SqlInstance $TestConfig.instance2 -Database tempdb | Get-DbaBinaryFileTable $results.Name.Count | Should -BeGreaterOrEqual 1 } -} \ No newline at end of file +} diff --git a/tests/Get-DbaBuild.Tests.ps1 b/tests/Get-DbaBuild.Tests.ps1 index f85cc6e67a..fcdccc90bc 100644 --- a/tests/Get-DbaBuild.Tests.ps1 +++ b/tests/Get-DbaBuild.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -145,7 +145,7 @@ Describe "$CommandName Unit Test" -Tags Unittest { $result.Warning | Should -Be 'This version has been officially retired by Microsoft' } } - + Context "Recognizes version 'aliases', see #8915" { It 'works with versions with the minor being either not 0 or 50' { $result2016 = Get-DbaBuild -Build '13.3.6300' @@ -205,8 +205,8 @@ Describe "$CommandName Unit Test" -Tags Unittest { Describe "$commandname Integration Tests" -Tags 'IntegrationTests' { Context "piping and params" { BeforeAll { - $server1 = Connect-DbaInstance -SqlInstance $script:instance1 - $server2 = Connect-DbaInstance -SqlInstance $script:instance2 + $server1 = Connect-DbaInstance -SqlInstance $TestConfig.instance1 + $server2 = Connect-DbaInstance -SqlInstance $TestConfig.instance2 } It "works when instances are piped" { $res = @($server1, $server2) | Get-DbaBuild @@ -217,7 +217,7 @@ Describe "$commandname Integration Tests" -Tags 'IntegrationTests' { } } Context "Test retrieving version from instances" { - $results = Get-DbaBuild -SqlInstance $script:instance1, $script:instance2 + $results = Get-DbaBuild -SqlInstance $TestConfig.instance1, $TestConfig.instance2 It "Should return an exact match" { $results | Should -Not -BeNullOrEmpty foreach ($r in $results) { @@ -249,4 +249,4 @@ Describe "$commandname Integration Tests" -Tags 'IntegrationTests' { } } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaClientAlias.Tests.ps1 b/tests/Get-DbaClientAlias.Tests.ps1 index c6fd7bc746..551ef15906 100644 --- a/tests/Get-DbaClientAlias.Tests.ps1 +++ b/tests/Get-DbaClientAlias.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaClientProtocol.Tests.ps1 b/tests/Get-DbaClientProtocol.Tests.ps1 index fc1f315a33..967f4fbe6f 100644 --- a/tests/Get-DbaClientProtocol.Tests.ps1 +++ b/tests/Get-DbaClientProtocol.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaCmConnection.Tests.ps1 b/tests/Get-DbaCmConnection.Tests.ps1 index 2404a1162e..5d0b25740d 100644 --- a/tests/Get-DbaCmConnection.Tests.ps1 +++ b/tests/Get-DbaCmConnection.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaCmObject.Tests.ps1 b/tests/Get-DbaCmObject.Tests.ps1 index 01fdeb21aa..23bbd04a63 100644 --- a/tests/Get-DbaCmObject.Tests.ps1 +++ b/tests/Get-DbaCmObject.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaComputerCertificate.Tests.ps1 b/tests/Get-DbaComputerCertificate.Tests.ps1 index 9a9e41a8f4..94918a9910 100644 --- a/tests/Get-DbaComputerCertificate.Tests.ps1 +++ b/tests/Get-DbaComputerCertificate.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,7 +16,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Can get a certificate" { BeforeAll { - $null = Add-DbaComputerCertificate -Path $script:appveyorlabrepo\certificates\localhost.crt -Confirm:$false + $null = Add-DbaComputerCertificate -Path "$($TestConfig.appveyorlabrepo)\certificates\localhost.crt" -Confirm:$false $thumbprint = "29C469578D6C6211076A09CEE5C5797EEA0C2713" } AfterAll { @@ -38,4 +38,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { "$($cert.EnhancedKeyUsageList)" -match '1\.3\.6\.1\.5\.5\.7\.3\.1' | Should Be $true } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaComputerSystem.Tests.ps1 b/tests/Get-DbaComputerSystem.Tests.ps1 index 1af4e1477c..082c04ff63 100644 --- a/tests/Get-DbaComputerSystem.Tests.ps1 +++ b/tests/Get-DbaComputerSystem.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "Get-DbaComputerSystem Unit Tests" -Tag "UnitTests" { Context "Validate parameters" { @@ -19,7 +19,7 @@ Describe "Get-DbaComputerSystem Unit Tests" -Tag "UnitTests" { } } Describe "Get-DbaComputerSystem Integration Test" -Tag "IntegrationTests" { - $result = Get-DbaComputerSystem -ComputerName $script:instance1 + $result = Get-DbaComputerSystem -ComputerName $TestConfig.instance1 $props = 'ComputerName', 'Domain', 'IsDaylightSavingsTime', 'Manufacturer', 'Model', 'NumberLogicalProcessors' , 'NumberProcessors', 'IsHyperThreading', 'SystemFamily', 'SystemSkuNumber', 'SystemType', 'IsSystemManagedPageFile', 'TotalPhysicalMemory' @@ -32,4 +32,4 @@ Describe "Get-DbaComputerSystem Integration Test" -Tag "IntegrationTests" { } } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaConnectedInstance.Tests.ps1 b/tests/Get-DbaConnectedInstance.Tests.ps1 index 97f3a6607e..4246ba145f 100644 --- a/tests/Get-DbaConnectedInstance.Tests.ps1 +++ b/tests/Get-DbaConnectedInstance.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag "UnitTests" { Context "Validate parameters" { @@ -13,7 +13,7 @@ Describe "$CommandName Unit Tests" -Tag "UnitTests" { Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $null = Get-DbaDatabase -SqlInstance $script:instance1 + $null = Get-DbaDatabase -SqlInstance $TestConfig.instance1 } Context "gets connected objects" { It "returns some results" { @@ -21,4 +21,4 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { $results | Should -Not -BeNullOrEmpty } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaConnection.Tests.ps1 b/tests/Get-DbaConnection.Tests.ps1 index 923c925841..ea0d9044e8 100644 --- a/tests/Get-DbaConnection.Tests.ps1 +++ b/tests/Get-DbaConnection.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,11 +15,11 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Context "returns the proper transport" { - $results = Get-DbaConnection -SqlInstance $script:instance1 + $results = Get-DbaConnection -SqlInstance $TestConfig.instance1 foreach ($result in $results) { It "returns an scheme" { $result.AuthScheme -eq 'ntlm' -or $result.AuthScheme -eq 'Kerberos' | Should -Be $true } } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaCpuRingBuffer.Tests.ps1 b/tests/Get-DbaCpuRingBuffer.Tests.ps1 index 45f844a688..420b985963 100644 --- a/tests/Get-DbaCpuRingBuffer.Tests.ps1 +++ b/tests/Get-DbaCpuRingBuffer.Tests.ps1 @@ -1,6 +1,6 @@ $commandname = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Validate parameters" { @@ -15,10 +15,10 @@ Describe "$CommandName Unit Tests" -Tags "UnitTests" { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Command returns proper info" { - $results = Get-DbaCpuRingBuffer -SqlInstance $script:instance2 -CollectionMinutes 100 + $results = Get-DbaCpuRingBuffer -SqlInstance $TestConfig.instance2 -CollectionMinutes 100 It "returns results" { $results.Count -gt 0 | Should Be $true } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaCpuUsage.Tests.ps1 b/tests/Get-DbaCpuUsage.Tests.ps1 index c90e23e034..c723f5f90d 100644 --- a/tests/Get-DbaCpuUsage.Tests.ps1 +++ b/tests/Get-DbaCpuUsage.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,9 +15,9 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Gets the CPU Usage" { - $results = Get-DbaCPUUsage -SqlInstance $script:instance2 + $results = Get-DbaCPUUsage -SqlInstance $TestConfig.instance2 It "Results are not empty" { $results | Should Not Be $Null } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaCredential.Tests.ps1 b/tests/Get-DbaCredential.Tests.ps1 index 342bbf87d2..cf59ec3fbd 100644 --- a/tests/Get-DbaCredential.Tests.ps1 +++ b/tests/Get-DbaCredential.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig . "$PSScriptRoot\..\private\functions\Invoke-Command2.ps1" @@ -23,37 +23,37 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { # Add user foreach ($login in $logins) { - $null = Invoke-Command2 -ScriptBlock { net user $args[0] $args[1] /add *>&1 } -ArgumentList $login, $plaintext -ComputerName $script:instance2 + $null = Invoke-Command2 -ScriptBlock { net user $args[0] $args[1] /add *>&1 } -ArgumentList $login, $plaintext -ComputerName $TestConfig.instance2 } - $results = New-DbaCredential -SqlInstance $script:instance2 -Name dbatoolsci_thorcred -Identity dbatoolsci_thor -Password $password - $results = New-DbaCredential -SqlInstance $script:instance2 -Identity dbatoolsci_thorsmomma -Password $password + $results = New-DbaCredential -SqlInstance $TestConfig.instance2 -Name dbatoolsci_thorcred -Identity dbatoolsci_thor -Password $password + $results = New-DbaCredential -SqlInstance $TestConfig.instance2 -Identity dbatoolsci_thorsmomma -Password $password } AfterAll { try { - (Get-DbaCredential -SqlInstance $script:instance2 -Identity dbatoolsci_thor, dbatoolsci_thorsmomma -ErrorAction Stop -WarningAction SilentlyContinue).Drop() + (Get-DbaCredential -SqlInstance $TestConfig.instance2 -Identity dbatoolsci_thor, dbatoolsci_thorsmomma -ErrorAction Stop -WarningAction SilentlyContinue).Drop() } catch { } foreach ($login in $logins) { - $null = Invoke-Command2 -ScriptBlock { net user $args /delete *>&1 } -ArgumentList $login -ComputerName $script:instance2 - $null = Invoke-Command2 -ScriptBlock { net user $args /delete *>&1 } -ArgumentList $login -ComputerName $script:instance2 + $null = Invoke-Command2 -ScriptBlock { net user $args /delete *>&1 } -ArgumentList $login -ComputerName $TestConfig.instance2 + $null = Invoke-Command2 -ScriptBlock { net user $args /delete *>&1 } -ArgumentList $login -ComputerName $TestConfig.instance2 } } Context "Get credentials" { It "Should get just one credential with the proper properties when using Identity" { - $results = Get-DbaCredential -SqlInstance $script:instance2 -Identity dbatoolsci_thorsmomma + $results = Get-DbaCredential -SqlInstance $TestConfig.instance2 -Identity dbatoolsci_thorsmomma $results.Name | Should Be "dbatoolsci_thorsmomma" $results.Identity | Should Be "dbatoolsci_thorsmomma" } It "Should get just one credential with the proper properties when using Name" { - $results = Get-DbaCredential -SqlInstance $script:instance2 -Name dbatoolsci_thorsmomma + $results = Get-DbaCredential -SqlInstance $TestConfig.instance2 -Name dbatoolsci_thorsmomma $results.Name | Should Be "dbatoolsci_thorsmomma" $results.Identity | Should Be "dbatoolsci_thorsmomma" } It "gets more than one credential" { - $results = Get-DbaCredential -SqlInstance $script:instance2 -Identity dbatoolsci_thor, dbatoolsci_thorsmomma + $results = Get-DbaCredential -SqlInstance $TestConfig.instance2 -Identity dbatoolsci_thor, dbatoolsci_thorsmomma $results.count -gt 1 } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaCustomError.Tests.ps1 b/tests/Get-DbaCustomError.Tests.ps1 index e652e18dec..1c0f84a25a 100644 --- a/tests/Get-DbaCustomError.Tests.ps1 +++ b/tests/Get-DbaCustomError.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,18 +15,18 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance1 $sql = "EXEC msdb.dbo.sp_addmessage 54321, 9, N'Dbatools is Awesome!';" $server.Query($sql) } Afterall { - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance1 $sql = "EXEC msdb.dbo.sp_dropmessage 54321;" $server.Query($sql) } Context "Gets the backup devices" { - $results = Get-DbaCustomError -SqlInstance $script:instance1 + $results = Get-DbaCustomError -SqlInstance $TestConfig.instance1 It "Results are not empty" { $results | Should Not Be $Null } @@ -40,4 +40,4 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $results.ID | Should Be 54321 } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDBFileGroup.Tests.ps1 b/tests/Get-DbaDBFileGroup.Tests.ps1 index 7c28d1be28..6dca8ed26e 100644 --- a/tests/Get-DbaDBFileGroup.Tests.ps1 +++ b/tests/Get-DbaDBFileGroup.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -17,17 +17,17 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { BeforeAll { $random = Get-Random $multifgdb = "dbatoolsci_multifgdb$random" - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance2 -Database $multifgdb + Remove-DbaDatabase -Confirm:$false -SqlInstance $TestConfig.instance2 -Database $multifgdb - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $server.Query("CREATE DATABASE $multifgdb; ALTER DATABASE $multifgdb ADD FILEGROUP [Test1]; ALTER DATABASE $multifgdb ADD FILEGROUP [Test2];") } AfterAll { - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance2 -Database $multifgdb + Remove-DbaDatabase -Confirm:$false -SqlInstance $TestConfig.instance2 -Database $multifgdb } Context "Returns values for Instance" { - $results = Get-DbaDbFileGroup -SqlInstance $script:instance2 + $results = Get-DbaDbFileGroup -SqlInstance $TestConfig.instance2 It "Results are not empty" { $results | Should Not Be $Null } @@ -37,13 +37,13 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } Context "Accepts database and filegroup input" { - $results = Get-DbaDbFileGroup -SqlInstance $script:instance2 -Database $multifgdb + $results = Get-DbaDbFileGroup -SqlInstance $TestConfig.instance2 -Database $multifgdb It "Reports the right number of filegroups" { $results.Count | Should Be 3 } - $results = Get-DbaDbFileGroup -SqlInstance $script:instance2 -Database $multifgdb -FileGroup Test1 + $results = Get-DbaDbFileGroup -SqlInstance $TestConfig.instance2 -Database $multifgdb -FileGroup Test1 It "Reports the right number of filegroups" { $results.Count | Should Be 1 @@ -51,7 +51,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } Context "Accepts piped input" { - $results = Get-DbaDatabase -SqlInstance $script:instance2 -ExcludeUser | Get-DbaDbFileGroup + $results = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -ExcludeUser | Get-DbaDbFileGroup It "Reports the right number of filegroups" { $results.Count | Should Be 4 @@ -62,4 +62,4 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $results.Parent.Name | Should -Contain 'msdb' } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDatabase.Tests.ps1 b/tests/Get-DbaDatabase.Tests.ps1 index a499c05aad..1c2b390ca0 100644 --- a/tests/Get-DbaDatabase.Tests.ps1 +++ b/tests/Get-DbaDatabase.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,21 +16,21 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Count system databases on localhost" { - $results = Get-DbaDatabase -SqlInstance $script:instance1 -ExcludeUser + $results = Get-DbaDatabase -SqlInstance $TestConfig.instance1 -ExcludeUser It "reports the right number of databases" { $results.Count | Should Be 4 } } Context "Check that tempdb database is in Simple recovery mode" { - $results = Get-DbaDatabase -SqlInstance $script:instance1 -Database tempdb + $results = Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database tempdb It "tempdb's recovery mode is Simple" { $results.RecoveryModel | Should Be "Simple" } } Context "Check that master database is accessible" { - $results = Get-DbaDatabase -SqlInstance $script:instance1 -Database master + $results = Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database master It "master is accessible" { $results.IsAccessible | Should Be $true } @@ -44,19 +44,19 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $random = Get-Random $dbname1 = "dbatoolsci_Backup_$random" $dbname2 = "dbatoolsci_NoBackup_$random" - $null = New-DbaDatabase -SqlInstance $script:instance1 -Name $dbname1 , $dbname2 - $null = Backup-DbaDatabase -SqlInstance $script:instance1 -Type Full -FilePath nul -Database $dbname1 + $null = New-DbaDatabase -SqlInstance $TestConfig.instance1 -Name $dbname1 , $dbname2 + $null = Backup-DbaDatabase -SqlInstance $TestConfig.instance1 -Type Full -FilePath nul -Database $dbname1 } AfterAll { - $null = Get-DbaDatabase -SqlInstance $script:instance1 -Database $dbname1, $dbname2 | Remove-DbaDatabase -Confirm:$false + $null = Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $dbname1, $dbname2 | Remove-DbaDatabase -Confirm:$false } Context "Results return if no backup" { - $results = Get-DbaDatabase -SqlInstance $script:instance1 -Database $dbname1 -NoFullBackup + $results = Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $dbname1 -NoFullBackup It "Should not report as database has full backup" { ($results).Count | Should Be 0 } - $results = Get-DbaDatabase -SqlInstance $script:instance1 -Database $dbname2 -NoFullBackup + $results = Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $dbname2 -NoFullBackup It "Should report 1 database with no full backup" { ($results).Count | Should Be 1 } @@ -181,4 +181,4 @@ Describe "$commandname Unit Tests" -Tags "UnitTests", Get-DBADatabase { Assert-MockCalled @assertMockParams } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbAssembly.Tests.ps1 b/tests/Get-DbaDbAssembly.Tests.ps1 index c8a4432669..6da9050598 100644 --- a/tests/Get-DbaDbAssembly.Tests.ps1 +++ b/tests/Get-DbaDbAssembly.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,8 +15,8 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Gets the Db Assembly" { - $results = Get-DbaDbAssembly -SqlInstance $script:instance2 | Where-Object { $_.parent.name -eq 'master' } - $masterDb = Get-DbaDatabase -SqlInstance $script:instance2 -Database master + $results = Get-DbaDbAssembly -SqlInstance $TestConfig.instance2 | Where-Object { $_.parent.name -eq 'master' } + $masterDb = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database master It "Gets results" { $results | Should Not Be $Null $results.DatabaseId | Should -Be $masterDb.Id @@ -31,4 +31,4 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $results.Version | Should -Be $masterDb.assemblies.Version } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbAsymmetricKey.Tests.ps1 b/tests/Get-DbaDbAsymmetricKey.Tests.ps1 index fdbca45985..0b90c4b4f3 100644 --- a/tests/Get-DbaDbAsymmetricKey.Tests.ps1 +++ b/tests/Get-DbaDbAsymmetricKey.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -20,12 +20,12 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $algorithm = 'Rsa4096' $dbuser = 'keyowner' $database = 'GetAsKey' - $newDB = New-DbaDatabase -SqlInstance $script:instance2 -Name $database + $newDB = New-DbaDatabase -SqlInstance $TestConfig.instance2 -Name $database $tPassword = ConvertTo-SecureString "ThisIsThePassword1" -AsPlainText -Force - New-DbaDbMasterKey -SqlInstance $script:instance2 -Database $database -SecurePassword $tPassword -confirm:$false - New-DbaDbUser -SqlInstance $script:instance2 -Database $database -UserName $dbuser - $null = New-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Database $database -Name $keyname -Owner keyowner -Algorithm $algorithm -WarningVariable warnvar - $results = Get-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname -Database $database + New-DbaDbMasterKey -SqlInstance $TestConfig.instance2 -Database $database -SecurePassword $tPassword -confirm:$false + New-DbaDbUser -SqlInstance $TestConfig.instance2 -Database $database -UserName $dbuser + $null = New-DbaDbAsymmetricKey -SqlInstance $TestConfig.instance2 -Database $database -Name $keyname -Owner keyowner -Algorithm $algorithm -WarningVariable warnvar + $results = Get-DbaDbAsymmetricKey -SqlInstance $TestConfig.instance2 -Name $keyname -Database $database It "Should Create new key in $database called $keyname" { $warnvar | Should -BeNullOrEmpty $results.database | Should -Be $database @@ -34,7 +34,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $results.Owner | Should -Be $dbuser $results | Should -HaveCount 1 } - $pipeResults = Get-DbaDatabase -SqlInstance $script:instance2 -Database $database | Get-DbaDbAsymmetricKey + $pipeResults = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $database | Get-DbaDbAsymmetricKey It "Should work with a piped database" { $pipeResults.database | Should -Be $database $pipeResults.name | Should -Be $keyname @@ -42,16 +42,16 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $pipeResults | Should -HaveCount 1 } - $null = New-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Database $database -Name $keyname2 -Owner keyowner -Algorithm $algorithm -WarningVariable warnvar - $multiResults = Get-DbaDatabase -SqlInstance $script:instance2 -Database $database | Get-DbaDbAsymmetricKey + $null = New-DbaDbAsymmetricKey -SqlInstance $TestConfig.instance2 -Database $database -Name $keyname2 -Owner keyowner -Algorithm $algorithm -WarningVariable warnvar + $multiResults = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $database | Get-DbaDbAsymmetricKey It "Should return 2 keys" { $multiResults | Should -HaveCount 2 $multiresults.name | Should -Contain $keyname $multiresults.name | Should -Contain $keyname2 } - $drop = Remove-DbaDatabase -SqlInstance $script:instance2 -Database $database -confirm:$false + $drop = Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $database -confirm:$false It "Should drop database" { $drop.Status | Should -Be 'Dropped' } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbBackupHistory.Tests.ps1 b/tests/Get-DbaDbBackupHistory.Tests.ps1 index 497bcc6e68..7a5e46a427 100644 --- a/tests/Get-DbaDbBackupHistory.Tests.ps1 +++ b/tests/Get-DbaDbBackupHistory.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -22,25 +22,25 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $random = Get-Random $dbname = "dbatoolsci_history_$random" $dbnameForked = "dbatoolsci_history_forked_$random" - $null = Get-DbaDatabase -SqlInstance $script:instance1 -Database $dbname, $dbnameForked | Remove-DbaDatabase -Confirm:$false - $null = Restore-DbaDatabase -SqlInstance $script:instance1 -Path $script:appveyorlabrepo\singlerestore\singlerestore.bak -DatabaseName $dbname -DestinationFilePrefix $dbname - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $null = Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $dbname, $dbnameForked | Remove-DbaDatabase -Confirm:$false + $null = Restore-DbaDatabase -SqlInstance $TestConfig.instance1 -Path "$($TestConfig.appveyorlabrepo)\singlerestore\singlerestore.bak" -DatabaseName $dbname -DestinationFilePrefix $dbname + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance1 $server.Databases['master'].ExecuteNonQuery("CREATE DATABASE $dbnameForked; ALTER DATABASE $dbnameForked SET AUTO_CLOSE OFF WITH ROLLBACK IMMEDIATE") - $db = Get-DbaDatabase -SqlInstance $script:instance1 -Database $dbname + $db = Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $dbname $db | Backup-DbaDatabase -Type Full -BackupDirectory $DestBackupDir $db | Backup-DbaDatabase -Type Differential -BackupDirectory $DestBackupDir $db | Backup-DbaDatabase -Type Log -BackupDirectory $DestBackupDir $db | Backup-DbaDatabase -Type Log -BackupDirectory $DestBackupDir - $null = Get-DbaDatabase -SqlInstance $script:instance1 -Database master | Backup-DbaDatabase -Type Full -BackupDirectory $DestBackupDir + $null = Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database master | Backup-DbaDatabase -Type Full -BackupDirectory $DestBackupDir $db | Backup-DbaDatabase -Type Full -BackupDirectory $DestBackupDir -BackupFileName CopyOnly.bak -CopyOnly } AfterAll { - $null = Get-DbaDatabase -SqlInstance $script:instance1 -Database $dbname, $dbnameForked | Remove-DbaDatabase -Confirm:$false + $null = Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $dbname, $dbnameForked | Remove-DbaDatabase -Confirm:$false } Context "Get last history for single database" { - $results = Get-DbaDbBackupHistory -SqlInstance $script:instance1 -Database $dbname -Last + $results = Get-DbaDbBackupHistory -SqlInstance $TestConfig.instance1 -Database $dbname -Last It "Should be 4 backups returned" { $results.count | Should Be 4 } @@ -60,44 +60,44 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } Context "Get last history for all databases" { - $results = Get-DbaDbBackupHistory -SqlInstance $script:instance1 + $results = Get-DbaDbBackupHistory -SqlInstance $TestConfig.instance1 It "Should be more than one database" { ($results | Where-Object Database -match "master").Count | Should BeGreaterThan 0 } } Context "ExcludeDatabase is honored" { - $results = Get-DbaDbBackupHistory -SqlInstance $script:instance1 -ExcludeDatabase 'master' + $results = Get-DbaDbBackupHistory -SqlInstance $TestConfig.instance1 -ExcludeDatabase 'master' It "Should not report about excluded database master" { ($results | Where-Object Database -match "master").Count | Should Be 0 } - $results = Get-DbaDbBackupHistory -SqlInstance $script:instance1 -ExcludeDatabase 'master' -Type Full + $results = Get-DbaDbBackupHistory -SqlInstance $TestConfig.instance1 -ExcludeDatabase 'master' -Type Full It "Should not report about excluded database master" { ($results | Where-Object Database -match "master").Count | Should Be 0 } - $results = Get-DbaDbBackupHistory -SqlInstance $script:instance1 -ExcludeDatabase 'master' -LastFull + $results = Get-DbaDbBackupHistory -SqlInstance $TestConfig.instance1 -ExcludeDatabase 'master' -LastFull It "Should not report about excluded database master" { ($results | Where-Object Database -match "master").Count | Should Be 0 } } Context "LastFull should work with multiple databases" { - $results = Get-DbaDbBackupHistory -SqlInstance $script:instance1 -Database $dbname, master -lastfull + $results = Get-DbaDbBackupHistory -SqlInstance $TestConfig.instance1 -Database $dbname, master -lastfull It "Should return 2 records" { $results.count | Should Be 2 } } Context "Testing IncludeCopyOnly with LastFull" { - $results = Get-DbaDbBackupHistory -SqlInstance $script:instance1 -LastFull -Database $dbname - $resultsCo = Get-DbaDbBackupHistory -SqlInstance $script:instance1 -LastFull -IncludeCopyOnly -Database $dbname + $results = Get-DbaDbBackupHistory -SqlInstance $TestConfig.instance1 -LastFull -Database $dbname + $resultsCo = Get-DbaDbBackupHistory -SqlInstance $TestConfig.instance1 -LastFull -IncludeCopyOnly -Database $dbname It "Should return the CopyOnly Backup" { ($resultsCo.BackupSetID -ne $Results.BackupSetID) | Should Be $True } } Context "Testing IncludeCopyOnly with Last" { - $resultsCo = Get-DbaDbBackupHistory -SqlInstance $script:instance1 -Last -IncludeCopyOnly -Database $dbname + $resultsCo = Get-DbaDbBackupHistory -SqlInstance $TestConfig.instance1 -Last -IncludeCopyOnly -Database $dbname It "Should return just the CopyOnly Full Backup" { ($resultsCo | Measure-Object).count | Should Be 1 } @@ -106,7 +106,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Context "Testing TotalSize regression test for #3517" { It "supports large numbers" { $historyObject = New-Object Dataplat.Dbatools.Database.BackupHistory - $server = Connect-DbaInstance $script:instance1 + $server = Connect-DbaInstance $TestConfig.instance1 $cast = $server.Query('select cast(1000000000000000 as numeric(20,0)) AS TotalSize') $historyObject.TotalSize = $cast.TotalSize ($historyObject.TotalSize.Byte) | Should -Be 1000000000000000 @@ -150,8 +150,8 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } Context "Testing IgnoreDiff parameter for #6914" { - $noIgnore = Get-DbaDbBackupHistory -SqlInstance $script:instance1 -Database $dbname - $Ignore = Get-DbaDbBackupHistory -SqlInstance $script:instance1 -Database $dbname -IgnoreDiffBackup + $noIgnore = Get-DbaDbBackupHistory -SqlInstance $TestConfig.instance1 -Database $dbname + $Ignore = Get-DbaDbBackupHistory -SqlInstance $TestConfig.instance1 -Database $dbname -IgnoreDiffBackup It "Should return one less backup" { $noIgnore.count - $Ignore.count | Should -Be 1 } @@ -162,19 +162,19 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Context "Testing the Since parameter" { It "DateTime for -Since" { - $results = Get-DbaDbBackupHistory -SqlInstance $script:instance1 -Database $dbname -Since (Get-Date).AddMinutes(-5) + $results = Get-DbaDbBackupHistory -SqlInstance $TestConfig.instance1 -Database $dbname -Since (Get-Date).AddMinutes(-5) $results.count | Should -BeGreaterThan 0 } It "TimeSpan for -Since" { - $results = Get-DbaDbBackupHistory -SqlInstance $script:instance1 -Database $dbname -Since (New-TimeSpan -Minutes -5) + $results = Get-DbaDbBackupHistory -SqlInstance $TestConfig.instance1 -Database $dbname -Since (New-TimeSpan -Minutes -5) $results.count | Should -BeGreaterThan 0 } It "Invalid type for -Since" { - $results = Get-DbaDbBackupHistory -SqlInstance $script:instance1 -Database $dbname -Since "-" -WarningVariable warning 3> $null + $results = Get-DbaDbBackupHistory -SqlInstance $TestConfig.instance1 -Database $dbname -Since "-" -WarningVariable warning 3> $null $results | Should -BeNullOrEmpty $warning | Should -BeLike "*-Since must be either a DateTime or TimeSpan object*" } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbCertificate.Tests.ps1 b/tests/Get-DbaDbCertificate.Tests.ps1 index e5a626a8b6..e6b9ad3634 100644 --- a/tests/Get-DbaDbCertificate.Tests.ps1 +++ b/tests/Get-DbaDbCertificate.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,15 +16,15 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Can get a database certificate" { BeforeAll { - if (-not (Get-DbaDbMasterKey -SqlInstance $script:instance1 -Database master)) { - $masterkey = New-DbaDbMasterKey -SqlInstance $script:instance1 -Database master -Password $(ConvertTo-SecureString -String "GoodPass1234!" -AsPlainText -Force) -Confirm:$false + if (-not (Get-DbaDbMasterKey -SqlInstance $TestConfig.instance1 -Database master)) { + $masterkey = New-DbaDbMasterKey -SqlInstance $TestConfig.instance1 -Database master -Password $(ConvertTo-SecureString -String "GoodPass1234!" -AsPlainText -Force) -Confirm:$false } - $tempdbmasterkey = New-DbaDbMasterKey -SqlInstance $script:instance1 -Database tempdb -Password $(ConvertTo-SecureString -String "GoodPass1234!" -AsPlainText -Force) -Confirm:$false + $tempdbmasterkey = New-DbaDbMasterKey -SqlInstance $TestConfig.instance1 -Database tempdb -Password $(ConvertTo-SecureString -String "GoodPass1234!" -AsPlainText -Force) -Confirm:$false $certificateName1 = "Cert_$(Get-Random)" $certificateName2 = "Cert_$(Get-Random)" - $cert1 = New-DbaDbCertificate -SqlInstance $script:instance1 -Name $certificateName1 -Confirm:$false - $cert2 = New-DbaDbCertificate -SqlInstance $script:instance1 -Name $certificateName2 -Database "tempdb" -Confirm:$false + $cert1 = New-DbaDbCertificate -SqlInstance $TestConfig.instance1 -Name $certificateName1 -Confirm:$false + $cert2 = New-DbaDbCertificate -SqlInstance $TestConfig.instance1 -Name $certificateName2 -Database "tempdb" -Confirm:$false } AfterAll { $null = $cert1 | Remove-DbaDbCertificate -Confirm:$false @@ -33,22 +33,22 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { if ($masterKey) { $masterkey | Remove-DbaDbMasterKey -Confirm:$false } } - $cert = Get-DbaDbCertificate -SqlInstance $script:instance1 -Certificate $certificateName1 + $cert = Get-DbaDbCertificate -SqlInstance $TestConfig.instance1 -Certificate $certificateName1 It "returns database certificate created in default, master database" { "$($cert.Database)" -match 'master' | Should Be $true - $cert.DatabaseId | Should -Be (Get-DbaDatabase -SqlInstance $script:instance1 -Database master).Id + $cert.DatabaseId | Should -Be (Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database master).Id } - $cert = Get-DbaDbCertificate -SqlInstance $script:instance1 -Database tempdb + $cert = Get-DbaDbCertificate -SqlInstance $TestConfig.instance1 -Database tempdb It "returns database certificate created in tempdb database, looked up by certificate name" { "$($cert.Name)" -match $certificateName2 | Should Be $true - $cert.DatabaseId | Should -Be (Get-DbaDatabase -SqlInstance $script:instance1 -Database tempdb).Id + $cert.DatabaseId | Should -Be (Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database tempdb).Id } - $cert = Get-DbaDbCertificate -SqlInstance $script:instance1 -ExcludeDatabase master + $cert = Get-DbaDbCertificate -SqlInstance $TestConfig.instance1 -ExcludeDatabase master It "returns database certificates excluding those in the master database" { "$($cert.Database)" -notmatch 'master' | Should Be $true } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbCheckConstraint.Tests.ps1 b/tests/Get-DbaDbCheckConstraint.Tests.ps1 index 04276ac5fe..e3ee27d70e 100644 --- a/tests/Get-DbaDbCheckConstraint.Tests.ps1 +++ b/tests/Get-DbaDbCheckConstraint.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,7 +15,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $random = Get-Random $tableName = "dbatools_getdbtbl1" $tableName2 = "dbatools_getdbtbl2" @@ -28,26 +28,26 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } AfterAll { - $null = Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbname | Remove-DbaDatabase -Confirm:$false + $null = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname | Remove-DbaDatabase -Confirm:$false } Context "Command actually works" { It "returns no check constraints from excluded DB with -ExcludeDatabase" { - $results = Get-DbaDbCheckConstraint -SqlInstance $script:instance2 -ExcludeDatabase master + $results = Get-DbaDbCheckConstraint -SqlInstance $TestConfig.instance2 -ExcludeDatabase master $results.where( { $_.Database -eq 'master' }).count | Should Be 0 } It "returns only check constraints from selected DB with -Database" { - $results = Get-DbaDbCheckConstraint -SqlInstance $script:instance2 -Database $dbname + $results = Get-DbaDbCheckConstraint -SqlInstance $TestConfig.instance2 -Database $dbname $results.where( { $_.Database -ne 'master' }).count | Should Be 1 - $results.DatabaseId | Get-Unique | Should -Be (Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbname).Id + $results.DatabaseId | Get-Unique | Should -Be (Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname).Id } It "Should include test check constraint: $ckName" { - $results = Get-DbaDbCheckConstraint -SqlInstance $script:instance2 -Database $dbname -ExcludeSystemTable + $results = Get-DbaDbCheckConstraint -SqlInstance $TestConfig.instance2 -Database $dbname -ExcludeSystemTable ($results | Where-Object Name -eq $ckName).Name | Should Be $ckName } It "Should exclude system tables" { - $results = Get-DbaDbCheckConstraint -SqlInstance $script:instance2 -Database master -ExcludeSystemTable + $results = Get-DbaDbCheckConstraint -SqlInstance $TestConfig.instance2 -Database master -ExcludeSystemTable ($results | Where-Object Name -eq 'spt_fallback_db') | Should Be $null } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbCompatibility.Tests.ps1 b/tests/Get-DbaDbCompatibility.Tests.ps1 index 50e7dcabdc..b8520b8692 100644 --- a/tests/Get-DbaDbCompatibility.Tests.ps1 +++ b/tests/Get-DbaDbCompatibility.Tests.ps1 @@ -1,6 +1,6 @@ $commandname = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,11 +15,11 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance1 $compatibilityLevel = $server.Databases['master'].CompatibilityLevel } Context "Gets compatibility for multiple databases" { - $results = Get-DbaDbCompatibility -SqlInstance $script:instance1 + $results = Get-DbaDbCompatibility -SqlInstance $TestConfig.instance1 It "Gets results" { $results | Should Not Be $null } @@ -29,19 +29,19 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { if ($row.DatabaseId -le 4) { $row.Compatibility | Should Be $compatibilityLevel } - $row.DatabaseId | Should -Be (Get-DbaDatabase -SqlInstance $script:instance1 -Database $row.Database).Id + $row.DatabaseId | Should -Be (Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $row.Database).Id } } } Context "Gets compatibility for one database" { - $results = Get-DbaDbCompatibility -SqlInstance $script:instance1 -database master + $results = Get-DbaDbCompatibility -SqlInstance $TestConfig.instance1 -database master It "Gets results" { $results | Should Not Be $null } It "Should return correct compatibility level for $($results.database)" { $results.Compatibility | Should Be $compatibilityLevel - $results.DatabaseId | Should -Be (Get-DbaDatabase -SqlInstance $script:instance1 -Database master).Id + $results.DatabaseId | Should -Be (Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database master).Id } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbCompression.Tests.ps1 b/tests/Get-DbaDbCompression.Tests.ps1 index 5575efe863..e6eb3bb58c 100644 --- a/tests/Get-DbaDbCompression.Tests.ps1 +++ b/tests/Get-DbaDbCompression.Tests.ps1 @@ -1,6 +1,6 @@ $commandname = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,7 +16,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { BeforeAll { $dbname = "dbatoolsci_test_$(Get-Random)" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $null = $server.Query("Create Database [$dbname]") $null = $server.Query("select * into syscols from sys.all_columns select * into sysallparams from sys.all_parameters @@ -24,10 +24,10 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { create nonclustered index NC_syscols on syscols (precision) include (collation_name)", $dbname) } AfterAll { - Get-DbaProcess -SqlInstance $script:instance2 -Database $dbname | Stop-DbaProcess -WarningAction SilentlyContinue - Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbname -Confirm:$false + Get-DbaProcess -SqlInstance $TestConfig.instance2 -Database $dbname | Stop-DbaProcess -WarningAction SilentlyContinue + Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname -Confirm:$false } - $results = Get-DbaDbCompression -SqlInstance $script:instance2 -Database $dbname + $results = Get-DbaDbCompression -SqlInstance $TestConfig.instance2 -Database $dbname Context "Command handles heaps and clustered indexes" { It "Gets results" { @@ -54,7 +54,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Command excludes results for specified database" { It "Shouldn't get any results for $dbname" { - $(Get-DbaDbCompression -SqlInstance $script:instance2 -Database $dbname -ExcludeDatabase $dbname) | Should not Match $dbname + $(Get-DbaDbCompression -SqlInstance $TestConfig.instance2 -Database $dbname -ExcludeDatabase $dbname) | Should not Match $dbname } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbDbccOpenTran.Tests.ps1 b/tests/Get-DbaDbDbccOpenTran.Tests.ps1 index 92b6d61187..1f4fffeb4c 100644 --- a/tests/Get-DbaDbDbccOpenTran.Tests.ps1 +++ b/tests/Get-DbaDbDbccOpenTran.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,7 +15,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Test" -Tag "IntegrationTests" { Context "Gets results for Open Transactions" { $props = 'ComputerName', 'InstanceName', 'SqlInstance', 'Database', 'Cmd', 'Output', 'Field', 'Data' - $result = Get-DbaDbDbccOpenTran -SqlInstance $script:instance1 + $result = Get-DbaDbDbccOpenTran -SqlInstance $TestConfig.instance1 It "returns results for DBCC OPENTRAN" { $result | Should Not Be $null @@ -32,8 +32,8 @@ Describe "$commandname Integration Test" -Tag "IntegrationTests" { } } - $result = Get-DbaDbDbccOpenTran -SqlInstance $script:instance1 -Database tempDB - $tempDB = Get-DbaDatabase -SqlInstance $script:instance1 -Database tempDB + $result = Get-DbaDbDbccOpenTran -SqlInstance $TestConfig.instance1 -Database tempDB + $tempDB = Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database tempDB It "returns results for a database" { $result | Should Not Be $null @@ -41,4 +41,4 @@ Describe "$commandname Integration Test" -Tag "IntegrationTests" { $result.DatabaseId | Get-Unique | Should -Be $tempDB.Id } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbDetachedFileInfo.Tests.ps1 b/tests/Get-DbaDbDetachedFileInfo.Tests.ps1 index a079fc59a7..e0fdbca14c 100644 --- a/tests/Get-DbaDbDetachedFileInfo.Tests.ps1 +++ b/tests/Get-DbaDbDetachedFileInfo.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,24 +15,24 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $versionName = $server.GetSqlServerVersionName() $random = Get-Random $dbname = "dbatoolsci_detatch_$random" $server.Query("CREATE DATABASE $dbname") - $path = (Get-DbaDbFile -SqlInstance $script:instance2 -Database $dbname | Where-object {$_.PhysicalName -like '*.mdf'}).physicalname - Detach-DbaDatabase -SqlInstance $script:instance2 -Database $dbname -Force + $path = (Get-DbaDbFile -SqlInstance $TestConfig.instance2 -Database $dbname | Where-object {$_.PhysicalName -like '*.mdf'}).physicalname + Detach-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname -Force } AfterAll { $server.Query("CREATE DATABASE $dbname ON (FILENAME = '$path') FOR ATTACH") - Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbname -Confirm:$false + Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname -Confirm:$false } Context "Command actually works" { - $results = Get-DbaDbDetachedFileInfo -SqlInstance $script:instance2 -Path $path + $results = Get-DbaDbDetachedFileInfo -SqlInstance $TestConfig.instance2 -Path $path it "Gets Results" { $results | Should Not Be $null } @@ -49,4 +49,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $results.LogFiles | Should Not Be $null } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbEncryption.Tests.ps1 b/tests/Get-DbaDbEncryption.Tests.ps1 index 7aec23ae4a..8644af134a 100644 --- a/tests/Get-DbaDbEncryption.Tests.ps1 +++ b/tests/Get-DbaDbEncryption.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -23,14 +23,14 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $random = Get-Random $cert = "dbatoolsci_getcert$random" $password = ConvertTo-SecureString -String Get-Random -AsPlainText -Force - New-DbaDbCertificate -SqlInstance $script:instance1 -Name $cert -password $password + New-DbaDbCertificate -SqlInstance $TestConfig.instance1 -Name $cert -password $password } AfterAll { - Get-DbaDbCertificate -SqlInstance $script:instance1 -Certificate $cert | Remove-DbaDbCertificate -confirm:$false + Get-DbaDbCertificate -SqlInstance $TestConfig.instance1 -Certificate $cert | Remove-DbaDbCertificate -confirm:$false } - $results = Get-DbaDbEncryption -SqlInstance $script:instance1 + $results = Get-DbaDbEncryption -SqlInstance $TestConfig.instance1 It "Should find a certificate named $cert" { ($results.Name -match 'dbatoolsci').Count -gt 0 | Should Be $true } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbEncryptionKey.Tests.ps1 b/tests/Get-DbaDbEncryptionKey.Tests.ps1 index 5bc16f975a..cc6915dbfe 100644 --- a/tests/Get-DbaDbEncryptionKey.Tests.ps1 +++ b/tests/Get-DbaDbEncryptionKey.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Validate parameters" { @@ -17,18 +17,18 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { $PSDefaultParameterValues["*:Confirm"] = $false $passwd = ConvertTo-SecureString "dbatools.IO" -AsPlainText -Force - $masterkey = Get-DbaDbMasterKey -SqlInstance $script:instance2 -Database master + $masterkey = Get-DbaDbMasterKey -SqlInstance $TestConfig.instance2 -Database master if (-not $masterkey) { $delmasterkey = $true - $masterkey = New-DbaServiceMasterKey -SqlInstance $script:instance2 -SecurePassword $passwd + $masterkey = New-DbaServiceMasterKey -SqlInstance $TestConfig.instance2 -SecurePassword $passwd } - $mastercert = Get-DbaDbCertificate -SqlInstance $script:instance2 -Database master | Where-Object Name -notmatch "##" | Select-Object -First 1 + $mastercert = Get-DbaDbCertificate -SqlInstance $TestConfig.instance2 -Database master | Where-Object Name -notmatch "##" | Select-Object -First 1 if (-not $mastercert) { $delmastercert = $true - $mastercert = New-DbaDbCertificate -SqlInstance $script:instance2 + $mastercert = New-DbaDbCertificate -SqlInstance $TestConfig.instance2 } - $db = New-DbaDatabase -SqlInstance $script:instance2 + $db = New-DbaDatabase -SqlInstance $TestConfig.instance2 $db | New-DbaDbMasterKey -SecurePassword $passwd $db | New-DbaDbCertificate $db | New-DbaDbEncryptionKey -Force @@ -52,8 +52,8 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $results.EncryptionType | Should -Be "ServerCertificate" } It "should get an encryption key on a database" { - $results = Get-DbaDbEncryptionKey -SqlInstance $script:instance2 -Database $db.Name + $results = Get-DbaDbEncryptionKey -SqlInstance $TestConfig.instance2 -Database $db.Name $results.EncryptionType | Should -Be "ServerCertificate" } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbExtentDiff.Tests.ps1 b/tests/Get-DbaDbExtentDiff.Tests.ps1 index e28a4fad10..f0e9e37f16 100644 --- a/tests/Get-DbaDbExtentDiff.Tests.ps1 +++ b/tests/Get-DbaDbExtentDiff.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,15 +16,15 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { BeforeAll { $dbname = "dbatoolsci_test_$(get-random)" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $server.Query("Create Database [$dbname]") } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbname -Confirm:$false + Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname -Confirm:$false } Context "Gets Changed Extents for Multiple Databases" { - $results = Get-DbaDbExtentDiff -SqlInstance $script:instance2 + $results = Get-DbaDbExtentDiff -SqlInstance $TestConfig.instance2 It "Gets results" { $results | Should Not Be $null } @@ -38,7 +38,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } Context "Gets Changed Extents for Single Database" { - $results = Get-DbaDbExtentDiff -SqlInstance $script:instance2 -Database $dbname + $results = Get-DbaDbExtentDiff -SqlInstance $TestConfig.instance2 -Database $dbname It "Gets results" { $results | Should Not Be $null } @@ -49,4 +49,4 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $results.ExtentsChanged | Should BeGreaterOrEqual 0 } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbFeatureUsage.Tests.ps1 b/tests/Get-DbaDbFeatureUsage.Tests.ps1 index 7c03f33fd9..8bedee400c 100644 --- a/tests/Get-DbaDbFeatureUsage.Tests.ps1 +++ b/tests/Get-DbaDbFeatureUsage.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,7 +16,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { BeforeAll { $dbname = "dbatoolsci_test_$(get-random)" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $server.Query("Create Database [$dbname]") $server.Query("Create Table [$dbname].dbo.TestCompression (Column1 nvarchar(10), @@ -28,13 +28,13 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $server.Query("DROP Database [$dbname]") } Context "Gets Feature Usage" { - $results = Get-DbaDbFeatureUsage -SqlInstance $script:instance2 + $results = Get-DbaDbFeatureUsage -SqlInstance $TestConfig.instance2 It "Gets results" { $results | Should Not Be $null } } Context "Gets Feature Usage using -Database" { - $results = Get-DbaDbFeatureUsage -SqlInstance $script:instance2 -Database $dbname + $results = Get-DbaDbFeatureUsage -SqlInstance $TestConfig.instance2 -Database $dbname It "Gets results" { $results | Should Not Be $null } @@ -43,9 +43,9 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } Context "Gets Feature Usage using -ExcludeDatabase" { - $results = Get-DbaDbFeatureUsage -SqlInstance $script:instance2 -ExcludeDatabase $dbname + $results = Get-DbaDbFeatureUsage -SqlInstance $TestConfig.instance2 -ExcludeDatabase $dbname It "Gets results" { $results.database | Should Not Contain $dbname } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbFile.Tests.ps1 b/tests/Get-DbaDbFile.Tests.ps1 index 8c64127465..e2da4da699 100644 --- a/tests/Get-DbaDbFile.Tests.ps1 +++ b/tests/Get-DbaDbFile.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -24,14 +24,14 @@ Describe "$CommandName Unit Tests" -Tag "Unit" { Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Context "Should return file information" { - $results = Get-DbaDbFile -SqlInstance $script:instance1 + $results = Get-DbaDbFile -SqlInstance $TestConfig.instance1 It "returns information about tempdb files" { $results.Database -contains "tempdb" | Should -Be $true } } Context "Should return file information for only tempdb" { - $results = Get-DbaDbFile -SqlInstance $script:instance1 -Database tempdb + $results = Get-DbaDbFile -SqlInstance $TestConfig.instance1 -Database tempdb foreach ($result in $results) { It "returns only tempdb files" { $result.Database | Should -Be "tempdb" @@ -40,7 +40,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } Context "Should return file information for only tempdb primary filegroup" { - $results = Get-DbaDbFile -SqlInstance $script:instance1 -Database tempdb -FileGroup Primary + $results = Get-DbaDbFile -SqlInstance $TestConfig.instance1 -Database tempdb -FileGroup Primary foreach ($result in $results) { It "returns only tempdb files that are in Primary filegroup" { $result.Database | Should -Be "tempdb" @@ -50,7 +50,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } Context "Physical name is populated" { - $results = Get-DbaDbFile -SqlInstance $script:instance1 -Database master + $results = Get-DbaDbFile -SqlInstance $TestConfig.instance1 -Database master It "master returns proper results" { $result = $results | Where-Object LogicalName -eq 'master' $result.PhysicalName -match 'master.mdf' | Should -Be $true @@ -61,13 +61,13 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Context "Database ID is populated" { It "returns proper results for the master db" { - $results = Get-DbaDbFile -SqlInstance $script:instance1 -Database master - $results.DatabaseID | Get-Unique | Should -Be (Get-DbaDatabase -SqlInstance $script:instance1 -Database master).ID + $results = Get-DbaDbFile -SqlInstance $TestConfig.instance1 -Database master + $results.DatabaseID | Get-Unique | Should -Be (Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database master).ID } It "uses a pipeline input and returns proper results for the tempdb" { - $tempDB = Get-DbaDatabase -SqlInstance $script:instance1 -Database tempdb + $tempDB = Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database tempdb $results = $tempDB | Get-DbaDbFile $results.DatabaseID | Get-Unique | Should -Be $tempDB.ID } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbFileGrowth.Tests.ps1 b/tests/Get-DbaDbFileGrowth.Tests.ps1 index f124610890..8ba1fe11cc 100644 --- a/tests/Get-DbaDbFileGrowth.Tests.ps1 +++ b/tests/Get-DbaDbFileGrowth.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,16 +15,16 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Context "Should return file information" { - $result = Get-DbaDbFileGrowth -SqlInstance $script:instance2 + $result = Get-DbaDbFileGrowth -SqlInstance $TestConfig.instance2 It "returns information about msdb files" { $result.Database -contains "msdb" | Should -Be $true } } Context "Should return file information for only msdb" { - $result = Get-DbaDbFileGrowth -SqlInstance $script:instance2 -Database msdb | Select-Object -First 1 + $result = Get-DbaDbFileGrowth -SqlInstance $TestConfig.instance2 -Database msdb | Select-Object -First 1 It "returns only msdb files" { $result.Database | Should -Be "msdb" } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbFileMapping.Tests.ps1 b/tests/Get-DbaDbFileMapping.Tests.ps1 index fd0544decc..b55c969c93 100644 --- a/tests/Get-DbaDbFileMapping.Tests.ps1 +++ b/tests/Get-DbaDbFileMapping.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Context "Validate parameters" { [array]$params = ([Management.Automation.CommandMetaData]$ExecutionContext.SessionState.InvokeCommand.GetCommand($CommandName, 'Function')).Parameters.Keys @@ -13,17 +13,17 @@ Context "Validate parameters" { Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Context "Should return file information" { - $results = Get-DbaDbFileMapping -SqlInstance $script:instance1 + $results = Get-DbaDbFileMapping -SqlInstance $TestConfig.instance1 It "returns information about multiple databases" { $results.Database -contains "tempdb" | Should -Be $true $results.Database -contains "master" | Should -Be $true } } Context "Should return file information for a single database" { - $results = Get-DbaDbFileMapping -SqlInstance $script:instance1 -Database tempdb + $results = Get-DbaDbFileMapping -SqlInstance $TestConfig.instance1 -Database tempdb It "returns information about tempdb" { $results.Database -contains "tempdb" | Should -Be $true $results.Database -contains "master" | Should -Be $false } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbForeignKey.Tests.ps1 b/tests/Get-DbaDbForeignKey.Tests.ps1 index 845aa182c5..03a9f1a095 100644 --- a/tests/Get-DbaDbForeignKey.Tests.ps1 +++ b/tests/Get-DbaDbForeignKey.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,7 +15,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $random = Get-Random $tableName = "dbatools_getdbtbl1" $tableName2 = "dbatools_getdbtbl2" @@ -28,30 +28,30 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } AfterAll { - $null = Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbname | Remove-DbaDatabase -Confirm:$false + $null = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname | Remove-DbaDatabase -Confirm:$false } Context "Command actually works" { It "returns no foreign keys from excluded DB with -ExcludeDatabase" { - $results = Get-DbaDbForeignKey -SqlInstance $script:instance2 -ExcludeDatabase master + $results = Get-DbaDbForeignKey -SqlInstance $TestConfig.instance2 -ExcludeDatabase master $results.where( { $_.Database -eq 'master' }).count | Should Be 0 } It "returns only foreign keys from selected DB with -Database" { - $results = Get-DbaDbForeignKey -SqlInstance $script:instance2 -Database $dbname + $results = Get-DbaDbForeignKey -SqlInstance $TestConfig.instance2 -Database $dbname $results.where( { $_.Database -ne 'master' }).count | Should Be 1 } It "Should include test foreign keys: $ckName" { - $results = Get-DbaDbForeignKey -SqlInstance $script:instance2 -Database $dbname -ExcludeSystemTable + $results = Get-DbaDbForeignKey -SqlInstance $TestConfig.instance2 -Database $dbname -ExcludeSystemTable ($results | Where-Object Name -eq $ckName).Name | Should Be $ckName } It "Should exclude system tables" { - $results = Get-DbaDbForeignKey -SqlInstance $script:instance2 -Database master -ExcludeSystemTable + $results = Get-DbaDbForeignKey -SqlInstance $TestConfig.instance2 -Database master -ExcludeSystemTable ($results | Where-Object Name -eq 'spt_fallback_db') | Should Be $null } } Context "Parameters are returned correctly" { - $results = Get-DbaDbForeignKey -SqlInstance $script:instance2 -ExcludeDatabase master + $results = Get-DbaDbForeignKey -SqlInstance $TestConfig.instance2 -ExcludeDatabase master It "Has the correct default properties" { $expectedStdProps = 'ComputerName,CreateDate,Database,DateLastModified,ID,InstanceName,IsChecked,IsEnabled,Name,NotForReplication,ReferencedKey,ReferencedTable,ReferencedTableSchema,SqlInstance,Table'.split(',') ($results[0].PSStandardMembers.DefaultDisplayPropertySet.ReferencedPropertyNames | Sort-Object) | Should Be ($ExpectedStdProps | Sort-Object) @@ -61,4 +61,4 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { ($results[0].PsObject.Properties.Name | Sort-Object) | Should Be ($ExpectedProps | Sort-Object) } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbIdentity.Tests.ps1 b/tests/Get-DbaDbIdentity.Tests.ps1 index 98ca22755f..3f742cef2a 100644 --- a/tests/Get-DbaDbIdentity.Tests.ps1 +++ b/tests/Get-DbaDbIdentity.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -14,7 +14,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { } Describe "$commandname Integration Test" -Tag "IntegrationTests" { BeforeAll { - $db = Get-DbaDatabase -SqlInstance $script:instance1 -Database tempdb + $db = Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database tempdb $null = $db.Query("CREATE TABLE dbo.dbatoolsci_example (Id int NOT NULL IDENTITY (125, 1), Value varchar(5)); INSERT INTO dbo.dbatoolsci_example(Value) Select 1; CREATE TABLE dbo.dbatoolsci_example2 (Id int NOT NULL IDENTITY (5, 1), Value varchar(5)); @@ -31,7 +31,7 @@ Describe "$commandname Integration Test" -Tag "IntegrationTests" { Context "Validate standard output " { $props = 'ComputerName', 'InstanceName', 'SqlInstance', 'Database', 'Table', 'Cmd', 'IdentityValue', 'ColumnValue', 'Output' - $result = Get-DbaDbIdentity -SqlInstance $script:instance1 -Database tempdb -Table 'dbo.dbatoolsci_example', 'dbo.dbatoolsci_example2' + $result = Get-DbaDbIdentity -SqlInstance $TestConfig.instance1 -Database tempdb -Table 'dbo.dbatoolsci_example', 'dbo.dbatoolsci_example2' foreach ($prop in $props) { $p = $result[0].PSObject.Properties[$prop] @@ -48,4 +48,4 @@ Describe "$commandname Integration Test" -Tag "IntegrationTests" { $result[0].IdentityValue -eq 125 | Should Be $true } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbLogShipError.Tests.ps1 b/tests/Get-DbaDbLogShipError.Tests.ps1 index f5a0b3e075..708174bd27 100644 --- a/tests/Get-DbaDbLogShipError.Tests.ps1 +++ b/tests/Get-DbaDbLogShipError.Tests.ps1 @@ -1,6 +1,6 @@ $commandname = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -17,8 +17,8 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Context "Return values" { It "Get the log shipping errors" { $Results = @() - $Results += Get-DbaDbLogShipError -SqlInstance $script:instance2 + $Results += Get-DbaDbLogShipError -SqlInstance $TestConfig.instance2 $Results.Count | Should Be 0 } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbLogSpace.Tests.ps1 b/tests/Get-DbaDbLogSpace.Tests.ps1 index dce590823b..c238abc19a 100644 --- a/tests/Get-DbaDbLogSpace.Tests.ps1 +++ b/tests/Get-DbaDbLogSpace.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -19,14 +19,14 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $dbCreate = ("CREATE DATABASE [{0}] GO ALTER DATABASE [{0}] MODIFY FILE ( NAME = N'{0}_log', SIZE = 10MB )" -f $db1) - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Database master -Query $dbCreate + $null = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database master -Query $dbCreate } AfterAll { - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance2 -Database $db1 + Remove-DbaDatabase -Confirm:$false -SqlInstance $TestConfig.instance2 -Database $db1 } Context "Command actually works" { - $results = Get-DbaDbLogSpace -SqlInstance $script:instance2 -Database $db1 + $results = Get-DbaDbLogSpace -SqlInstance $TestConfig.instance2 -Database $db1 It "Should have correct properties" { $results | Should Not BeNullOrEmpty } @@ -39,7 +39,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { ($results | Where-Object { $_.Database -eq $db1 }).LogSize.Kilobyte | Should Be 10232 } - if ((Connect-DbaInstance -SqlInstance $script:instance2 -SqlCredential $SqlCredential).versionMajor -lt 11) { + if ((Connect-DbaInstance -SqlInstance $TestConfig.instance2 -SqlCredential $SqlCredential).versionMajor -lt 11) { It "Calculation for space used should work for servers < 2012" { $db1Result = $results | Where-Object { $_.Database -eq $db1 } $db1Result.logspaceused | should be ($db1Result.logsize * ($db1Result.LogSpaceUsedPercent / 100)) @@ -48,7 +48,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } Context "System databases exclusions work" { - $results = Get-DbaDbLogSpace -SqlInstance $script:instance2 -ExcludeSystemDatabase + $results = Get-DbaDbLogSpace -SqlInstance $TestConfig.instance2 -ExcludeSystemDatabase It "Should exclude system databases" { $results.Database | Should Not Bein ('model', 'master', 'tempdb', 'msdb') } @@ -58,7 +58,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } Context "User databases exclusions work" { - $results = Get-DbaDbLogSpace -SqlInstance $script:instance2 -ExcludeDatabase db1 + $results = Get-DbaDbLogSpace -SqlInstance $TestConfig.instance2 -ExcludeDatabase db1 It "Should include system databases" { ('model', 'master', 'tempdb', 'msdb') | Should Bein $results.Database } @@ -68,10 +68,10 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } Context "Piping servers works" { - $results = $script:instance2 | Get-DbaDbLogSpace + $results = $TestConfig.instance2 | Get-DbaDbLogSpace It "Should have database name of $db1" { $results.Database | Should Contain $db1 } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbMail.Tests.ps1 b/tests/Get-DbaDbMail.Tests.ps1 index 3402e8912b..dfc15fd8c8 100644 --- a/tests/Get-DbaDbMail.Tests.ps1 +++ b/tests/Get-DbaDbMail.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,7 +15,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $mailSettings = @{ AccountRetryAttempts = '1' AccountRetryDelay = '60' @@ -31,7 +31,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } Context "Gets DbMail Settings" { - $results = Get-DbaDbMail -SqlInstance $script:instance2 + $results = Get-DbaDbMail -SqlInstance $TestConfig.instance2 It "Gets results" { $results | Should Not Be $null } @@ -44,4 +44,4 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbMailAccount.Tests.ps1 b/tests/Get-DbaDbMailAccount.Tests.ps1 index a80c8ff4bf..dbb6f8a64a 100644 --- a/tests/Get-DbaDbMailAccount.Tests.ps1 +++ b/tests/Get-DbaDbMailAccount.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,7 +16,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { BeforeAll { $accountname = "dbatoolsci_test_$(get-random)" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $mailAccountSettings = "EXEC msdb.dbo.sysmail_add_account_sp @account_name='$accountname', @description='Mail account for email alerts', @@ -27,14 +27,14 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $server.query($mailAccountSettings) } AfterAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $mailAccountSettings = "EXEC msdb.dbo.sysmail_delete_account_sp @account_name = '$accountname';" $server.query($mailAccountSettings) } Context "Gets DbMail Account" { - $results = Get-DbaDbMailAccount -SqlInstance $script:instance2 | Where-Object {$_.Name -eq "$accountname"} + $results = Get-DbaDbMailAccount -SqlInstance $TestConfig.instance2 | Where-Object {$_.Name -eq "$accountname"} It "Gets results" { $results | Should Not Be $null } @@ -55,7 +55,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } Context "Gets DbMail when using -Account" { - $results = Get-DbaDbMailAccount -SqlInstance $script:instance2 -Account $accountname + $results = Get-DbaDbMailAccount -SqlInstance $TestConfig.instance2 -Account $accountname It "Gets results" { $results | Should Not Be $null } @@ -76,9 +76,9 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } Context "Gets no DbMail when using -ExcludeAccount" { - $results = Get-DbaDbMailAccount -SqlInstance $script:instance2 -ExcludeAccount $accountname + $results = Get-DbaDbMailAccount -SqlInstance $TestConfig.instance2 -ExcludeAccount $accountname It "Gets no results" { $results | Should Be $null } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbMailConfig.Tests.ps1 b/tests/Get-DbaDbMailConfig.Tests.ps1 index d6f317ac81..395dc5aa4b 100644 --- a/tests/Get-DbaDbMailConfig.Tests.ps1 +++ b/tests/Get-DbaDbMailConfig.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,7 +15,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $mailSettings = @{ AccountRetryAttempts = '1' AccountRetryDelay = '60' @@ -31,7 +31,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } Context "Gets DbMail Settings" { - $results = Get-DbaDbMailConfig -SqlInstance $script:instance2 + $results = Get-DbaDbMailConfig -SqlInstance $TestConfig.instance2 It "Gets results" { $results | Should Not Be $null } @@ -45,7 +45,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } Context "Gets DbMail Settings when using -Name" { - $results = Get-DbaDbMailConfig -SqlInstance $script:instance2 -Name "ProhibitedExtensions" + $results = Get-DbaDbMailConfig -SqlInstance $TestConfig.instance2 -Name "ProhibitedExtensions" It "Gets results" { $results | Should Not Be $null } @@ -59,4 +59,4 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $results.description | Should Be "Extensions not allowed in outgoing mails" } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbMailHistory.Tests.ps1 b/tests/Get-DbaDbMailHistory.Tests.ps1 index 1eea15e2f2..1a7b1f3846 100644 --- a/tests/Get-DbaDbMailHistory.Tests.ps1 +++ b/tests/Get-DbaDbMailHistory.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,7 +15,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $server.Query("INSERT INTO msdb.[dbo].[sysmail_profile] ([name] ,[description] @@ -66,7 +66,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } Context "Gets Db Mail History" { - $results = Get-DbaDbMailHistory -SqlInstance $script:instance2 | Where-Object {$_.Subject -eq 'Test Job'} + $results = Get-DbaDbMailHistory -SqlInstance $TestConfig.instance2 | Where-Object {$_.Subject -eq 'Test Job'} It "Gets results" { $results | Should Not Be $null } @@ -78,7 +78,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } Context "Gets Db Mail History using -Status" { - $results = Get-DbaDbMailHistory -SqlInstance $script:instance2 -Status Sent + $results = Get-DbaDbMailHistory -SqlInstance $TestConfig.instance2 -Status Sent It "Gets results" { $results | Should Not Be $null } @@ -93,7 +93,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } Context "Gets Db Mail History using -Since" { - $results = Get-DbaDbMailHistory -SqlInstance $script:instance2 -Since '2018-01-01' + $results = Get-DbaDbMailHistory -SqlInstance $TestConfig.instance2 -Since '2018-01-01' It "Gets results" { $results | Should Not Be $null } @@ -104,4 +104,4 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $results.SendRequestDate | Should Begreaterthan '2018-01-01' } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbMailLog.Tests.ps1 b/tests/Get-DbaDbMailLog.Tests.ps1 index c62533b9e8..574d6617ef 100644 --- a/tests/Get-DbaDbMailLog.Tests.ps1 +++ b/tests/Get-DbaDbMailLog.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,7 +15,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $server.Query("INSERT INTO msdb.[dbo].[sysmail_log] ([event_type] ,[log_date] @@ -33,7 +33,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } Context "Gets Db Mail Log" { - $results = Get-DbaDbMailLog -SqlInstance $script:instance2 | Where-Object {$_.Login -eq 'dbatools\dbatoolssci'} + $results = Get-DbaDbMailLog -SqlInstance $TestConfig.instance2 | Where-Object {$_.Login -eq 'dbatools\dbatoolssci'} It "Gets results" { $results | Should Not Be $null } @@ -45,7 +45,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } Context "Gets Db Mail Log using -Type" { - $results = Get-DbaDbMailLog -SqlInstance $script:instance2 -Type Information + $results = Get-DbaDbMailLog -SqlInstance $TestConfig.instance2 -Type Information It "Gets results" { $results | Should Not Be $null } @@ -57,7 +57,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } Context "Gets Db Mail History using -Since" { - $results = Get-DbaDbMailLog -SqlInstance $script:instance2 -Since '2018-01-01' + $results = Get-DbaDbMailLog -SqlInstance $TestConfig.instance2 -Since '2018-01-01' It "Gets results" { $results | Should Not Be $null } @@ -68,4 +68,4 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $results.LastModDate | Should Begreaterthan '2018-01-01' } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbMailProfile.Tests.ps1 b/tests/Get-DbaDbMailProfile.Tests.ps1 index 98a94ce332..7d076b739f 100644 --- a/tests/Get-DbaDbMailProfile.Tests.ps1 +++ b/tests/Get-DbaDbMailProfile.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,21 +16,21 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { BeforeAll { $profilename = "dbatoolsci_test_$(get-random)" - $server = Connect-DbaInstance -SqlInstance $script:instance2, $script:instance3 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2, $TestConfig.instance3 $mailProfile = "EXEC msdb.dbo.sysmail_add_profile_sp @profile_name='$profilename', @description='Profile for system email';" $server.query($mailProfile) } AfterAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2, $script:instance3 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2, $TestConfig.instance3 $mailProfile = "EXEC msdb.dbo.sysmail_delete_profile_sp @profile_name='$profilename';" $server.query($mailProfile) } Context "Gets DbMail Profile" { - $results = Get-DbaDbMailProfile -SqlInstance $script:instance2 | Where-Object {$_.name -eq "$profilename"} + $results = Get-DbaDbMailProfile -SqlInstance $TestConfig.instance2 | Where-Object {$_.name -eq "$profilename"} It "Gets results" { $results | Should Not Be $null } @@ -47,7 +47,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } Context "Gets DbMailProfile when using -Profile" { - $results = Get-DbaDbMailProfile -SqlInstance $script:instance2 -Profile $profilename + $results = Get-DbaDbMailProfile -SqlInstance $TestConfig.instance2 -Profile $profilename It "Gets results" { $results | Should Not Be $null } @@ -59,9 +59,9 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } Context "Gets no DbMailProfile when using -ExcludeProfile" { - $results = Get-DbaDbMailProfile -SqlInstance $script:instance2 -ExcludeProfile $profilename + $results = Get-DbaDbMailProfile -SqlInstance $TestConfig.instance2 -ExcludeProfile $profilename It "Gets no results" { $results | Should -Not -Contain $profilename } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbMailServer.Tests.ps1 b/tests/Get-DbaDbMailServer.Tests.ps1 index 38c097a5d4..7257734cce 100644 --- a/tests/Get-DbaDbMailServer.Tests.ps1 +++ b/tests/Get-DbaDbMailServer.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,7 +16,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { BeforeAll { $accountname = "dbatoolsci_test_$(get-random)" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $mailAccountSettings = "EXEC msdb.dbo.sysmail_add_account_sp @account_name='$accountname', @description='Mail account for email alerts', @@ -27,14 +27,14 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $server.query($mailAccountSettings) } AfterAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $mailAccountSettings = "EXEC msdb.dbo.sysmail_delete_account_sp @account_name = '$accountname';" $server.query($mailAccountSettings) } Context "Gets DbMailServer" { - $results = Get-DbaDbMailServer -SqlInstance $script:instance2 | Where-Object {$_.account -eq "$accountname"} + $results = Get-DbaDbMailServer -SqlInstance $TestConfig.instance2 | Where-Object {$_.account -eq "$accountname"} It "Gets results" { $results | Should Not Be $null } @@ -55,15 +55,15 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } Context "Gets DbMailServer using -Server" { - $results = Get-DbaDbMailServer -SqlInstance $script:instance2 -Server 'smtp.dbatools.io' + $results = Get-DbaDbMailServer -SqlInstance $TestConfig.instance2 -Server 'smtp.dbatools.io' It "Gets results" { $results | Should Not Be $null } } Context "Gets DbMailServer using -Account" { - $results = Get-DbaDbMailServer -SqlInstance $script:instance2 -Account $accounname + $results = Get-DbaDbMailServer -SqlInstance $TestConfig.instance2 -Account $accounname It "Gets results" { $results | Should Not Be $null } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbMasterKey.Tests.ps1 b/tests/Get-DbaDbMasterKey.Tests.ps1 index ffb85e518c..dd697c12a2 100644 --- a/tests/Get-DbaDbMasterKey.Tests.ps1 +++ b/tests/Get-DbaDbMasterKey.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,17 +16,17 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { BeforeAll { $dbname = "dbatoolsci_test_$(get-random)" - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance1 $null = $server.Query("Create Database [$dbname]") - $null = New-DbaDbMasterKey -SqlInstance $script:instance1 -Database $dbname -Password (ConvertTo-SecureString -AsPlainText -Force -String 'ThisIsAPassword!') -Confirm:$false + $null = New-DbaDbMasterKey -SqlInstance $TestConfig.instance1 -Database $dbname -Password (ConvertTo-SecureString -AsPlainText -Force -String 'ThisIsAPassword!') -Confirm:$false } AfterAll { - Remove-DbaDbMasterKey -SqlInstance $script:instance1 -Database $dbname -Confirm:$false - Remove-DbaDatabase -SqlInstance $script:instance1 -Database $dbname -Confirm:$false + Remove-DbaDbMasterKey -SqlInstance $TestConfig.instance1 -Database $dbname -Confirm:$false + Remove-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $dbname -Confirm:$false } Context "Gets DbMasterKey" { - $results = Get-DbaDbMasterKey -SqlInstance $script:instance1 | Where-Object {$_.Database -eq "$dbname"} + $results = Get-DbaDbMasterKey -SqlInstance $TestConfig.instance1 | Where-Object {$_.Database -eq "$dbname"} It "Gets results" { $results | Should Not Be $null } @@ -38,7 +38,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } Context "Gets DbMasterKey when using -database" { - $results = Get-DbaDbMasterKey -SqlInstance $script:instance1 -Database $dbname + $results = Get-DbaDbMasterKey -SqlInstance $TestConfig.instance1 -Database $dbname It "Gets results" { $results | Should Not Be $null } @@ -50,9 +50,9 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } Context "Gets no DbMasterKey when using -ExcludeDatabase" { - $results = Get-DbaDbMasterKey -SqlInstance $script:instance1 -ExcludeDatabase $dbname + $results = Get-DbaDbMasterKey -SqlInstance $TestConfig.instance1 -ExcludeDatabase $dbname It "Gets no results" { $results | Should Be $null } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbMemoryUsage.Tests.ps1 b/tests/Get-DbaDbMemoryUsage.Tests.ps1 index e9f8a8d87e..52f0e48bb9 100644 --- a/tests/Get-DbaDbMemoryUsage.Tests.ps1 +++ b/tests/Get-DbaDbMemoryUsage.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Validate parameters" { @@ -15,7 +15,7 @@ Describe "$CommandName Unit Tests" -Tags "UnitTests" { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $instance = Connect-DbaInstance -SqlInstance $script:instance2 + $instance = Connect-DbaInstance -SqlInstance $TestConfig.instance2 } Context "Functionality" { It 'Returns data' { @@ -38,4 +38,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $uniqueDbs | Should -Contain 'master' } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbMirror.Tests.ps1 b/tests/Get-DbaDbMirror.Tests.ps1 index 127a084b0f..4ff5e8e4dc 100644 --- a/tests/Get-DbaDbMirror.Tests.ps1 +++ b/tests/Get-DbaDbMirror.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,33 +16,33 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $null = Get-DbaProcess -SqlInstance $script:instance2, $script:instance3 | Where-Object Program -Match dbatools | Stop-DbaProcess -Confirm:$false -WarningAction SilentlyContinue - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $null = Get-DbaProcess -SqlInstance $TestConfig.instance2, $TestConfig.instance3 | Where-Object Program -Match dbatools | Stop-DbaProcess -Confirm:$false -WarningAction SilentlyContinue + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $db1 = "dbatoolsci_mirroring" $db2 = "dbatoolsci_mirroring_db2" - Remove-DbaDbMirror -SqlInstance $script:instance2, $script:instance3 -Database $db1, $db2 -Confirm:$false - $null = Get-DbaDatabase -SqlInstance $script:instance2, $script:instance3 -Database $db1, $db2 | Remove-DbaDatabase -Confirm:$false + Remove-DbaDbMirror -SqlInstance $TestConfig.instance2, $TestConfig.instance3 -Database $db1, $db2 -Confirm:$false + $null = Get-DbaDatabase -SqlInstance $TestConfig.instance2, $TestConfig.instance3 -Database $db1, $db2 | Remove-DbaDatabase -Confirm:$false $null = $server.Query("CREATE DATABASE $db1") $null = $server.Query("CREATE DATABASE $db2") } AfterAll { - $null = Get-DbaDatabase -SqlInstance $script:instance2, $script:instance3 -Database $db1, $db2 | Remove-DbaDbMirror -Confirm:$false - $null = Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance2, $script:instance3 -Database $db1, $db2 -ErrorAction SilentlyContinue + $null = Get-DbaDatabase -SqlInstance $TestConfig.instance2, $TestConfig.instance3 -Database $db1, $db2 | Remove-DbaDbMirror -Confirm:$false + $null = Remove-DbaDatabase -Confirm:$false -SqlInstance $TestConfig.instance2, $TestConfig.instance3 -Database $db1, $db2 -ErrorAction SilentlyContinue } It -Skip "returns more than one database" { - $null = Invoke-DbaDbMirroring -Primary $script:instance2 -Mirror $script:instance3 -Database $db1, $db2 -Confirm:$false -Force -SharedPath C:\temp -WarningAction Continue - (Get-DbaDbMirror -SqlInstance $script:instance3).Count | Should -Be 2 + $null = Invoke-DbaDbMirroring -Primary $TestConfig.instance2 -Mirror $TestConfig.instance3 -Database $db1, $db2 -Confirm:$false -Force -SharedPath C:\temp -WarningAction Continue + (Get-DbaDbMirror -SqlInstance $TestConfig.instance3).Count | Should -Be 2 } It -Skip "returns just one database" { - (Get-DbaDbMirror -SqlInstance $script:instance3 -Database $db2).Count | Should -Be 1 + (Get-DbaDbMirror -SqlInstance $TestConfig.instance3 -Database $db2).Count | Should -Be 1 } It -Skip "returns 2x1 database" { - (Get-DbaDbMirror -SqlInstance $script:instance2, $script:instance3 -Database $db2).Count | Should -Be 2 + (Get-DbaDbMirror -SqlInstance $TestConfig.instance2, $TestConfig.instance3 -Database $db2).Count | Should -Be 2 } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbMirrorMonitor.Tests.ps1 b/tests/Get-DbaDbMirrorMonitor.Tests.ps1 index 3259304be4..5b0d06de61 100644 --- a/tests/Get-DbaDbMirrorMonitor.Tests.ps1 +++ b/tests/Get-DbaDbMirrorMonitor.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaDbObjectTrigger.Tests.ps1 b/tests/Get-DbaDbObjectTrigger.Tests.ps1 index 2648ba8f4a..4f51c3e2a0 100644 --- a/tests/Get-DbaDbObjectTrigger.Tests.ps1 +++ b/tests/Get-DbaDbObjectTrigger.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -43,7 +43,7 @@ CREATE TRIGGER $triggerviewname SELECT 'TRIGGER on $viewname view' END "@ - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $server.Query("create database $dbname") $server.Query("CREATE TABLE $tablename (id int);", $dbname) @@ -52,14 +52,14 @@ CREATE TRIGGER $triggerviewname $server.Query("CREATE VIEW $viewname AS SELECT * FROM $tablename;", $dbname) $server.Query("$triggerview", $dbname) - $systemDbs = Get-DbaDatabase -SqlInstance $script:instance2 -ExcludeUser + $systemDbs = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -ExcludeUser } AfterAll { - $null = Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbname | Remove-DbaDatabase -Confirm:$false + $null = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname | Remove-DbaDatabase -Confirm:$false } Context "Gets Table Trigger" { - $results = Get-DbaDbObjectTrigger -SqlInstance $script:instance2 -ExcludeDatabase $systemDbs.Name | Where-Object { $_.name -eq "dbatoolsci_triggerontable" } + $results = Get-DbaDbObjectTrigger -SqlInstance $TestConfig.instance2 -ExcludeDatabase $systemDbs.Name | Where-Object { $_.name -eq "dbatoolsci_triggerontable" } It "Gets results" { $results | Should -Not -Be $null } @@ -71,7 +71,7 @@ CREATE TRIGGER $triggerviewname } } Context "Gets Table Trigger when using -Database" { - $results = Get-DbaDbObjectTrigger -SqlInstance $script:instance2 -Database $dbname | Where-Object { $_.name -eq "dbatoolsci_triggerontable" } + $results = Get-DbaDbObjectTrigger -SqlInstance $TestConfig.instance2 -Database $dbname | Where-Object { $_.name -eq "dbatoolsci_triggerontable" } It "Gets results" { $results | Should -Not -Be $null } @@ -83,7 +83,7 @@ CREATE TRIGGER $triggerviewname } } Context "Gets Table Trigger passing table object using pipeline" { - $results = Get-DbaDbTable -SqlInstance $script:instance2 -Database $dbname -Table "dbatoolsci_trigger" | Get-DbaDbObjectTrigger + $results = Get-DbaDbTable -SqlInstance $TestConfig.instance2 -Database $dbname -Table "dbatoolsci_trigger" | Get-DbaDbObjectTrigger It "Gets results" { $results | Should -Not -Be $null } @@ -95,7 +95,7 @@ CREATE TRIGGER $triggerviewname } } Context "Gets View Trigger" { - $results = Get-DbaDbObjectTrigger -SqlInstance $script:instance2 -ExcludeDatabase $systemDbs.Name | Where-Object { $_.name -eq "dbatoolsci_triggeronview" } + $results = Get-DbaDbObjectTrigger -SqlInstance $TestConfig.instance2 -ExcludeDatabase $systemDbs.Name | Where-Object { $_.name -eq "dbatoolsci_triggeronview" } It "Gets results" { $results | Should -Not -Be $null } @@ -107,7 +107,7 @@ CREATE TRIGGER $triggerviewname } } Context "Gets View Trigger when using -Database" { - $results = Get-DbaDbObjectTrigger -SqlInstance $script:instance2 -Database $dbname | Where-Object { $_.name -eq "dbatoolsci_triggeronview" } + $results = Get-DbaDbObjectTrigger -SqlInstance $TestConfig.instance2 -Database $dbname | Where-Object { $_.name -eq "dbatoolsci_triggeronview" } It "Gets results" { $results | Should -Not -Be $null } @@ -119,7 +119,7 @@ CREATE TRIGGER $triggerviewname } } Context "Gets View Trigger passing table object using pipeline" { - $results = Get-DbaDbView -SqlInstance $script:instance2 -Database $dbname -ExcludeSystemView | Get-DbaDbObjectTrigger + $results = Get-DbaDbView -SqlInstance $TestConfig.instance2 -Database $dbname -ExcludeSystemView | Get-DbaDbObjectTrigger It "Gets results" { $results | Should -Not -Be $null } @@ -131,8 +131,8 @@ CREATE TRIGGER $triggerviewname } } Context "Gets Table and View Trigger passing both objects using pipeline" { - $tableResults = Get-DbaDbTable -SqlInstance $script:instance2 -Database $dbname -Table "dbatoolsci_trigger" - $viewResults = Get-DbaDbView -SqlInstance $script:instance2 -Database $dbname -ExcludeSystemView + $tableResults = Get-DbaDbTable -SqlInstance $TestConfig.instance2 -Database $dbname -Table "dbatoolsci_trigger" + $viewResults = Get-DbaDbView -SqlInstance $TestConfig.instance2 -Database $dbname -ExcludeSystemView $results = $tableResults, $viewResults | Get-DbaDbObjectTrigger It "Gets results" { $results | Should -Not -Be $null @@ -142,7 +142,7 @@ CREATE TRIGGER $triggerviewname } } Context "Gets All types Trigger when using -Type" { - $results = Get-DbaDbObjectTrigger -SqlInstance $script:instance2 -Database $dbname -Type All + $results = Get-DbaDbObjectTrigger -SqlInstance $TestConfig.instance2 -Database $dbname -Type All It "Gets results" { $results | Should -Not -Be $null } @@ -151,7 +151,7 @@ CREATE TRIGGER $triggerviewname } } Context "Gets only Table Trigger when using -Type" { - $results = Get-DbaDbObjectTrigger -SqlInstance $script:instance2 -Database $dbname -Type Table + $results = Get-DbaDbObjectTrigger -SqlInstance $TestConfig.instance2 -Database $dbname -Type Table It "Gets results" { $results | Should -Not -Be $null } @@ -163,7 +163,7 @@ CREATE TRIGGER $triggerviewname } } Context "Gets only View Trigger when using -Type" { - $results = Get-DbaDbObjectTrigger -SqlInstance $script:instance2 -Database $dbname -Type View + $results = Get-DbaDbObjectTrigger -SqlInstance $TestConfig.instance2 -Database $dbname -Type View It "Gets results" { $results | Should -Not -Be $null } @@ -174,4 +174,4 @@ CREATE TRIGGER $triggerviewname $results.Parent.GetType().Name | Should -Be "View" } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbOrphanUser.Tests.ps1 b/tests/Get-DbaDbOrphanUser.Tests.ps1 index 6f16a61c31..0dfdd51190 100644 --- a/tests/Get-DbaDbOrphanUser.Tests.ps1 +++ b/tests/Get-DbaDbOrphanUser.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -22,7 +22,7 @@ CREATE LOGIN [dbatoolsci_orphan2] WITH PASSWORD = N'password2', CHECK_EXPIRATION CREATE LOGIN [dbatoolsci_orphan3] WITH PASSWORD = N'password3', CHECK_EXPIRATION = OFF, CHECK_POLICY = OFF; CREATE DATABASE dbatoolsci_orphan; '@ - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance1 $null = Remove-DbaLogin -SqlInstance $server -Login dbatoolsci_orphan1, dbatoolsci_orphan2, dbatoolsci_orphan3 -Force -Confirm:$false $null = Remove-DbaDatabase -SqlInstance $server -Database dbatoolsci_orphan -Confirm:$false $null = Invoke-DbaQuery -SqlInstance $server -Query $loginsq @@ -36,14 +36,14 @@ CREATE USER [dbatoolsci_orphan3] FROM LOGIN [dbatoolsci_orphan3]; Invoke-DbaQuery -SqlInstance $server -Query $dropOrphan } AfterAll { - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance1 $null = Remove-DbaLogin -SqlInstance $server -Login dbatoolsci_orphan1, dbatoolsci_orphan2, dbatoolsci_orphan3 -Force -Confirm:$false $null = Remove-DbaDatabase -SqlInstance $server -Database dbatoolsci_orphan -Confirm:$false } It "shows time taken for preparation" { 1 | Should -Be 1 } - $results = Get-DbaDbOrphanUser -SqlInstance $script:instance1 -Database dbatoolsci_orphan + $results = Get-DbaDbOrphanUser -SqlInstance $TestConfig.instance1 -Database dbatoolsci_orphan It "Finds two orphans" { $results.Count | Should -Be 2 foreach ($user in $Users) { @@ -56,4 +56,4 @@ CREATE USER [dbatoolsci_orphan3] FROM LOGIN [dbatoolsci_orphan3]; $ExpectedProps = 'ComputerName,InstanceName,SqlInstance,DatabaseName,User,SmoUser'.Split(',') ($result.PsObject.Properties.Name | Sort-Object) | Should Be ($ExpectedProps | Sort-Object) } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbPageInfo.Tests.ps1 b/tests/Get-DbaDbPageInfo.Tests.ps1 index 4c234930b4..f612519117 100644 --- a/tests/Get-DbaDbPageInfo.Tests.ps1 +++ b/tests/Get-DbaDbPageInfo.Tests.ps1 @@ -1,6 +1,6 @@ $commandname = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -17,8 +17,8 @@ Describe "$CommandName Integration Test" -Tag "IntegrationTests" { BeforeAll { $random = Get-Random $dbname = "dbatoolsci_pageinfo_$random" - Get-DbaProcess -SqlInstance $script:instance2 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue - $server = Connect-DbaInstance -SqlInstance $script:instance2 + Get-DbaProcess -SqlInstance $TestConfig.instance2 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $server.Query("CREATE DATABASE $dbname;") $server.Databases[$dbname].Query('CREATE TABLE [dbo].[TestTable](TestText VARCHAR(MAX) NOT NULL)') $query = " @@ -36,14 +36,14 @@ Describe "$CommandName Integration Test" -Tag "IntegrationTests" { $server.Databases[$dbname].Query($query) } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbname -Confirm:$false + Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname -Confirm:$false } Context "Count Pages" { - $result = Get-DbaDbPageInfo -SqlInstance $script:instance2 -Database $dbname + $result = Get-DbaDbPageInfo -SqlInstance $TestConfig.instance2 -Database $dbname It "returns the proper results" { ($result).Count | Should -Be 9 ($result | Where-Object { $_.IsAllocated -eq $false }).Count | Should -Be 5 ($result | Where-Object { $_.IsAllocated -eq $true }).Count | Should -Be 4 } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbPartitionFunction.Tests.ps1 b/tests/Get-DbaDbPartitionFunction.Tests.ps1 index e99847817b..2bd6287299 100644 --- a/tests/Get-DbaDbPartitionFunction.Tests.ps1 +++ b/tests/Get-DbaDbPartitionFunction.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -18,16 +18,16 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $tempguid = [guid]::newguid(); $PFName = "dbatoolssci_$($tempguid.guid)" $CreateTestPartitionFunction = "CREATE PARTITION FUNCTION [$PFName] (int) AS RANGE LEFT FOR VALUES (1, 100, 1000, 10000, 100000);" - Invoke-DbaQuery -SqlInstance $script:instance2 -Query $CreateTestPartitionFunction -Database master + Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Query $CreateTestPartitionFunction -Database master } AfterAll { $DropTestPartitionFunction = "DROP PARTITION FUNCTION [$PFName];" - Invoke-DbaQuery -SqlInstance $script:instance2 -Query $DropTestPartitionFunction -Database master + Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Query $DropTestPartitionFunction -Database master } Context "Partition Functions are correctly located" { - $results1 = Get-DbaDbPartitionFunction -SqlInstance $script:instance2 -Database master | Select-Object * - $results2 = Get-DbaDbPartitionFunction -SqlInstance $script:instance2 + $results1 = Get-DbaDbPartitionFunction -SqlInstance $TestConfig.instance2 -Database master | Select-Object * + $results2 = Get-DbaDbPartitionFunction -SqlInstance $TestConfig.instance2 It "Should execute and return results" { $results2 | Should -Not -Be $null @@ -50,7 +50,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } It "Should not Throw an Error" { - {Get-DbaDbPartitionFunction -SqlInstance $script:instance2 -ExcludeDatabase master } | Should -not -Throw + {Get-DbaDbPartitionFunction -SqlInstance $TestConfig.instance2 -ExcludeDatabase master } | Should -not -Throw } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbPartitionScheme.Tests.ps1 b/tests/Get-DbaDbPartitionScheme.Tests.ps1 index 4601ba568f..2c769ef401 100644 --- a/tests/Get-DbaDbPartitionScheme.Tests.ps1 +++ b/tests/Get-DbaDbPartitionScheme.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -25,7 +25,7 @@ GO CREATE PARTITION SCHEME $PFScheme AS PARTITION [$PFName] ALL TO ( [PRIMARY] ); "@ - Invoke-DbaQuery -SqlInstance $script:instance2 -Query $CreateTestPartitionScheme -Database master + Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Query $CreateTestPartitionScheme -Database master } AfterAll { $DropTestPartitionScheme = @" @@ -33,12 +33,12 @@ DROP PARTITION SCHEME [$PFScheme]; GO DROP PARTITION FUNCTION [$PFName]; "@ - Invoke-DbaQuery -SqlInstance $script:instance2 -Query $DropTestPartitionScheme -Database master + Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Query $DropTestPartitionScheme -Database master } Context "Partition Schemes are correctly located" { - $results1 = Get-DbaDbPartitionScheme -SqlInstance $script:instance2 -Database master | Select-Object * - $results2 = Get-DbaDbPartitionScheme -SqlInstance $script:instance2 + $results1 = Get-DbaDbPartitionScheme -SqlInstance $TestConfig.instance2 -Database master | Select-Object * + $results2 = Get-DbaDbPartitionScheme -SqlInstance $TestConfig.instance2 It "Should execute and return results" { $results2 | Should -Not -Be $null @@ -61,7 +61,7 @@ DROP PARTITION FUNCTION [$PFName]; } It "Should not Throw an Error" { - {Get-DbaDbPartitionScheme -SqlInstance $script:instance2 -ExcludeDatabase master } | Should -not -Throw + {Get-DbaDbPartitionScheme -SqlInstance $TestConfig.instance2 -ExcludeDatabase master } | Should -not -Throw } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbQueryStoreOption.Tests.ps1 b/tests/Get-DbaDbQueryStoreOption.Tests.ps1 index 2ee20b45b2..0e30b0f1fd 100644 --- a/tests/Get-DbaDbQueryStoreOption.Tests.ps1 +++ b/tests/Get-DbaDbQueryStoreOption.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaDbRecoveryModel.Tests.ps1 b/tests/Get-DbaDbRecoveryModel.Tests.ps1 index 883fe4371c..86faedfb9f 100644 --- a/tests/Get-DbaDbRecoveryModel.Tests.ps1 +++ b/tests/Get-DbaDbRecoveryModel.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,7 +15,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Recovery model is correctly identified" { - $results = Get-DbaDbRecoveryModel -SqlInstance $script:instance2 -Database master + $results = Get-DbaDbRecoveryModel -SqlInstance $TestConfig.instance2 -Database master It "returns a single database" { $results.Count | Should Be 1 @@ -25,7 +25,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $results.RecoveryModel -eq 'Simple' | Should Be $true } - $results = Get-DbaDbRecoveryModel -SqlInstance $script:instance2 + $results = Get-DbaDbRecoveryModel -SqlInstance $TestConfig.instance2 It "returns accurate number of results" { $results.Count -ge 4 | Should Be $true @@ -33,22 +33,22 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } Context "RecoveryModel parameter works" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $dbname = "dbatoolsci_getrecoverymodel" Get-DbaDatabase -SqlInstance $server -Database $dbname | Remove-DbaDatabase -Confirm:$false $server.Query("CREATE DATABASE $dbname; ALTER DATABASE $dbname SET RECOVERY BULK_LOGGED WITH NO_WAIT;") } AfterAll { - Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbname | Remove-DbaDatabase -Confirm:$false + Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname | Remove-DbaDatabase -Confirm:$false } It "gets the newly created database with the correct recovery model" { - $results = Get-DbaDbRecoveryModel -SqlInstance $script:instance2 -Database $dbname + $results = Get-DbaDbRecoveryModel -SqlInstance $TestConfig.instance2 -Database $dbname $results.RecoveryModel -eq 'BulkLogged' | Should Be $true } It "honors the RecoveryModel parameter filter" { - $results = Get-DbaDbRecoveryModel -SqlInstance $script:instance2 -RecoveryModel BulkLogged + $results = Get-DbaDbRecoveryModel -SqlInstance $TestConfig.instance2 -RecoveryModel BulkLogged $results.Name -contains $dbname | Should Be $true } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbRestoreHistory.Tests.ps1 b/tests/Get-DbaDbRestoreHistory.Tests.ps1 index 5e845e80a2..521d4d26f8 100644 --- a/tests/Get-DbaDbRestoreHistory.Tests.ps1 +++ b/tests/Get-DbaDbRestoreHistory.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -19,19 +19,19 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $random = Get-Random $dbname1 = "dbatoolsci_restorehistory1_$random" $dbname2 = "dbatoolsci_restorehistory2_$random" - $null = Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbname1, $dbname2 | Remove-DbaDatabase -Confirm:$false - $null = Restore-DbaDatabase -SqlInstance $script:instance2 -Path $script:appveyorlabrepo\singlerestore\singlerestore.bak -DatabaseName $dbname1 -DestinationFilePrefix $dbname1 - $null = Restore-DbaDatabase -SqlInstance $script:instance2 -Path $script:appveyorlabrepo\singlerestore\singlerestore.bak -DatabaseName $dbname2 -DestinationFilePrefix $dbname2 - $null = Restore-DbaDatabase -SqlInstance $script:instance2 -Path $script:appveyorlabrepo\singlerestore\singlerestore.bak -DatabaseName $dbname2 -DestinationFilePrefix "rsh_pre_$dbname2" -WithReplace - $fullBackup = Backup-DbaDatabase -SqlInstance $script:instance2 -Database $dbname1 -Type Full - $diffBackup = Backup-DbaDatabase -SqlInstance $script:instance2 -Database $dbname1 -Type Diff - $logBackup = Backup-DbaDatabase -SqlInstance $script:instance2 -Database $dbname1 -Type Log + $null = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname1, $dbname2 | Remove-DbaDatabase -Confirm:$false + $null = Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -Path "$($TestConfig.appveyorlabrepo)\singlerestore\singlerestore.bak" -DatabaseName $dbname1 -DestinationFilePrefix $dbname1 + $null = Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -Path "$($TestConfig.appveyorlabrepo)\singlerestore\singlerestore.bak" -DatabaseName $dbname2 -DestinationFilePrefix $dbname2 + $null = Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -Path "$($TestConfig.appveyorlabrepo)\singlerestore\singlerestore.bak" -DatabaseName $dbname2 -DestinationFilePrefix "rsh_pre_$dbname2" -WithReplace + $fullBackup = Backup-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname1 -Type Full + $diffBackup = Backup-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname1 -Type Diff + $logBackup = Backup-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname1 -Type Log - $null = Restore-DbaDatabase -SqlInstance $script:instance2 -Path $diffBackup.BackupPath, $logBackup.BackupPath -DatabaseName $dbname1 -WithReplace + $null = Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -Path $diffBackup.BackupPath, $logBackup.BackupPath -DatabaseName $dbname1 -WithReplace } AfterAll { - $null = Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbname1, $dbname2 | Remove-DbaDatabase -Confirm:$false + $null = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname1, $dbname2 | Remove-DbaDatabase -Confirm:$false Remove-Item -Path $fullBackup.BackupPath -Force Remove-Item -Path $logBackup.BackupPath -Force } @@ -41,32 +41,32 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } Context "Get last restore history for single database" { - $results = @(Get-DbaDbRestoreHistory -SqlInstance $script:instance2 -Database $dbname2 -Last) + $results = @(Get-DbaDbRestoreHistory -SqlInstance $TestConfig.instance2 -Database $dbname2 -Last) It "Results holds 1 object" { $results.count | Should -Be 1 } It "Should return the full restore with the correct properties" { $results[0].RestoreType | Should -Be "Database" - $results[0].From | Should -Be $script:appveyorlabrepo\singlerestore\singlerestore.bak + $results[0].From | Should -Be "$($TestConfig.appveyorlabrepo)\singlerestore\singlerestore.bak" $results[0].To | Should -Match "\\rsh_pre_$dbname2" } } Context "Get last restore history for multiple database" { - $results = @(Get-DbaDbRestoreHistory -SqlInstance $script:instance2 -Database $dbname1, $dbname2 -Last) + $results = @(Get-DbaDbRestoreHistory -SqlInstance $TestConfig.instance2 -Database $dbname1, $dbname2 -Last) It "Results holds 2 objects" { $results.count | Should -Be 2 } It "Should return the full restore with the correct properties" { $results[0].RestoreType | Should -Be "Database" $results[1].RestoreType | Should -Be "Log" - $results[0].From | Should -Be $script:appveyorlabrepo\singlerestore\singlerestore.bak + $results[0].From | Should -Be "$($TestConfig.appveyorlabrepo)\singlerestore\singlerestore.bak" $results[1].From | Should -Be $logBackup.BackupPath ($results | Where-Object Database -eq $dbname1).To | Should -Match "\\$dbname1" ($results | Where-Object Database -eq $dbname2).To | Should -Match "\\rsh_pre_$dbname2" } } Context "Get complete restore history for multiple database" { - $results = @(Get-DbaDbRestoreHistory -SqlInstance $script:instance2 -Database $dbname1, $dbname2) + $results = @(Get-DbaDbRestoreHistory -SqlInstance $TestConfig.instance2 -Database $dbname1, $dbname2) It "Results holds correct number of objects" { $results.Count | Should -Be 6 } @@ -77,7 +77,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } Context "return object properties" { It "has the correct properties" { - $results = Get-DbaDbRestoreHistory -SqlInstance $script:instance2 -Database $dbname1, $dbname2 + $results = Get-DbaDbRestoreHistory -SqlInstance $TestConfig.instance2 -Database $dbname1, $dbname2 $result = $results[0] $ExpectedProps = 'ComputerName,InstanceName,SqlInstance,Database,Username,RestoreType,Date,From,To,first_lsn,last_lsn,checkpoint_lsn,database_backup_lsn,backup_finish_date,BackupFinishDate,RowError,RowState,Table,ItemArray,HasErrors'.Split(',') ($result.PsObject.Properties.Name | Sort-Object) | Should Be ($ExpectedProps | Sort-Object) @@ -87,19 +87,19 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } Context "Get restore history by restore type" { It "returns the correct history records for full db restore" { - $results = Get-DbaDbRestoreHistory -SqlInstance $script:instance2 -Database $dbname1, $dbname2 -RestoreType Database + $results = Get-DbaDbRestoreHistory -SqlInstance $TestConfig.instance2 -Database $dbname1, $dbname2 -RestoreType Database $results.count | Should -Be 4 @($results | Where-Object RestoreType -eq Database).Count | Should -Be 4 } It "returns the correct history records for diffential restore" { - $results = Get-DbaDbRestoreHistory -SqlInstance $script:instance2 -Database $dbname1 -RestoreType Differential + $results = Get-DbaDbRestoreHistory -SqlInstance $TestConfig.instance2 -Database $dbname1 -RestoreType Differential $results.Database | Should -Be $dbname1 $results.RestoreType | Should -Be Differential } It "returns the correct history records for log restore" { - $results = Get-DbaDbRestoreHistory -SqlInstance $script:instance2 -Database $dbname1 -RestoreType Log + $results = Get-DbaDbRestoreHistory -SqlInstance $TestConfig.instance2 -Database $dbname1 -RestoreType Log $results.Database | Should -Be $dbname1 $results.RestoreType | Should -Be Log } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbRole.Tests.ps1 b/tests/Get-DbaDbRole.Tests.ps1 index dce5c0ecd2..1eee8780ec 100644 --- a/tests/Get-DbaDbRole.Tests.ps1 +++ b/tests/Get-DbaDbRole.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Validate parameters" { @@ -15,7 +15,7 @@ Describe "$CommandName Unit Tests" -Tags "UnitTests" { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $instance = Connect-DbaInstance -SqlInstance $script:instance2 + $instance = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $allDatabases = $instance.Databases } @@ -72,4 +72,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $result.Name | Select-Object -Unique | Should -Not -Contain 'db_owner' } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbRoleMember.Tests.ps1 b/tests/Get-DbaDbRoleMember.Tests.ps1 index a5e2968414..8cbd3a8ec8 100644 --- a/tests/Get-DbaDbRoleMember.Tests.ps1 +++ b/tests/Get-DbaDbRoleMember.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Validate parameters" { @@ -15,7 +15,7 @@ Describe "$CommandName Unit Tests" -Tags "UnitTests" { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $instance = Connect-DbaInstance -SqlInstance $script:instance2 + $instance = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $allDatabases = $instance.Databases } @@ -71,4 +71,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $result.Role | Select-Object -Unique | Should -Not -Contain 'db_owner' } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbSchema.Tests.ps1 b/tests/Get-DbaDbSchema.Tests.ps1 index 7c5835925f..1159a833b4 100644 --- a/tests/Get-DbaDbSchema.Tests.ps1 +++ b/tests/Get-DbaDbSchema.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,8 +16,8 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BeforeAll { $random = Get-Random - $server1 = Connect-DbaInstance -SqlInstance $script:instance1 - $server2 = Connect-DbaInstance -SqlInstance $script:instance2 + $server1 = Connect-DbaInstance -SqlInstance $TestConfig.instance1 + $server2 = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $null = Get-DbaProcess -SqlInstance $server1, $server2 | Where-Object Program -match dbatools | Stop-DbaProcess -Confirm:$false $newDbName = "dbatoolsci_newdb_$random" $newDbs = New-DbaDatabase -SqlInstance $server1, $server2 -Name $newDbName @@ -136,4 +136,4 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $schemas | Should -BeNullOrEmpty } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbSequence.Tests.ps1 b/tests/Get-DbaDbSequence.Tests.ps1 index b7c206594d..7e3dbaf52b 100644 --- a/tests/Get-DbaDbSequence.Tests.ps1 +++ b/tests/Get-DbaDbSequence.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,7 +16,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BeforeAll { $random = Get-Random - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $newDbName = "dbatoolsci_newdb_$random" $newDbName2 = "dbatoolsci_newdb2_$random" $newDb, $newDb2 = New-DbaDatabase -SqlInstance $server -Name $newDbName, $newDbName2 @@ -86,4 +86,4 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $sequence.Parent.Name | Should -Be $newDbName } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbServiceBrokerQueue.Tests.ps1 b/tests/Get-DbaDbServiceBrokerQueue.Tests.ps1 index dc23adff93..a3a50cec71 100644 --- a/tests/Get-DbaDbServiceBrokerQueue.Tests.ps1 +++ b/tests/Get-DbaDbServiceBrokerQueue.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,7 +15,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $procname = ("dbatools_{0}" -f $(Get-Random)) $server.Query("CREATE PROCEDURE $procname AS SELECT 1", 'tempdb') $queuename = ("dbatools_{0}" -f $(Get-Random)) @@ -27,7 +27,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } Context "Gets the service broker queue" { - $results = Get-DbaDbServiceBrokerQueue -SqlInstance $script:instance2 -database tempdb -ExcludeSystemQueue:$true + $results = Get-DbaDbServiceBrokerQueue -SqlInstance $TestConfig.instance2 -database tempdb -ExcludeSystemQueue:$true It "Gets results" { $results | Should Not Be $Null } @@ -38,4 +38,4 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $results.schema | Should Be "dbo" } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbServiceBrokerService.Tests.ps1 b/tests/Get-DbaDbServiceBrokerService.Tests.ps1 index d3e73ba3b4..4d31c5e84e 100644 --- a/tests/Get-DbaDbServiceBrokerService.Tests.ps1 +++ b/tests/Get-DbaDbServiceBrokerService.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,7 +15,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $procname = ("dbatools_{0}" -f $(Get-Random)) $server.Query("CREATE PROCEDURE $procname AS SELECT 1", 'tempdb') $queuename = ("dbatools_{0}" -f $(Get-Random)) @@ -30,7 +30,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } Context "Gets the service broker service" { - $results = Get-DbaDbServiceBrokerService -SqlInstance $script:instance2 -database tempdb -ExcludeSystemService:$true + $results = Get-DbaDbServiceBrokerService -SqlInstance $TestConfig.instance2 -database tempdb -ExcludeSystemService:$true It "Gets results" { $results | Should Not Be $Null } @@ -44,4 +44,4 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $results.QueueName | Should be "$QueueName" } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbSharePoint.Tests.ps1 b/tests/Get-DbaDbSharePoint.Tests.ps1 index 36b6531631..7ec685f6bc 100644 --- a/tests/Get-DbaDbSharePoint.Tests.ps1 +++ b/tests/Get-DbaDbSharePoint.Tests.ps1 @@ -1,6 +1,6 @@ $commandname = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -17,8 +17,8 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { $skip = $false $spdb = 'SharePoint_Admin_7c0c491d0e6f43858f75afa5399d49ab', 'WSS_Logging', 'SecureStoreService_20e1764876504335a6d8dd0b1937f4bf', 'DefaultWebApplicationDB', 'SharePoint_Config_4c524cb90be44c6f906290fe3e34f2e0', 'DefaultPowerPivotServiceApplicationDB-5b638361-c6fc-4ad9-b8ba-d05e63e48ac6', 'SharePoint_Config_4c524cb90be44c6f906290fe3e34f2e0' - Get-DbaProcess -SqlInstance $script:instance2 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue - $server = Connect-DbaInstance -SqlInstance $script:instance2 + Get-DbaProcess -SqlInstance $TestConfig.instance2 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 foreach ($db in $spdb) { try { $null = $server.Query("Create Database [$db]") @@ -26,7 +26,7 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { } # Andreas Jordan: We should try to get a backup working again or even better just a sql script to set this up. # This takes a long time but I cannot figure out why every backup of this db is malformed - $bacpac = "$script:appveyorlabrepo\bacpac\sharepoint_config.bacpac" + $bacpac = "$($TestConfig.appveyorlabrepo)\bacpac\sharepoint_config.bacpac" if (Test-Path -Path $bacpac) { $sqlpackage = (Get-Command sqlpackage -ErrorAction Ignore).Source if (-not $sqlpackage) { @@ -44,7 +44,7 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { # On PowerShell 7.4.2 on Windows Server 2022, the following line throws: # Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified. # So we don't run the following line but skip the tests - # . $sqlpackage /Action:Import /tsn:$script:instance2 /tdn:Sharepoint_Config /sf:$bacpac /p:Storage=File + # . $sqlpackage /Action:Import /tsn:$TestConfig.instance2 /tdn:Sharepoint_Config /sf:$bacpac /p:Storage=File $skip = $true } else { Write-Warning -Message "No bacpac found in path [$bacpac], skipping tests." @@ -52,14 +52,14 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { } } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance2 -Database $spdb -Confirm:$false + Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $spdb -Confirm:$false } Context "Command gets SharePoint Databases" { - $results = Get-DbaDbSharePoint -SqlInstance $script:instance2 + $results = Get-DbaDbSharePoint -SqlInstance $TestConfig.instance2 foreach ($db in $spdb) { It -Skip:$skip "returns $db from in the SharePoint database list" { $db | Should -BeIn $results.Name } } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbSnapshot.Tests.ps1 b/tests/Get-DbaDbSnapshot.Tests.ps1 index 6b9496d037..6c13aff150 100644 --- a/tests/Get-DbaDbSnapshot.Tests.ps1 +++ b/tests/Get-DbaDbSnapshot.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -17,54 +17,54 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tag "IntegrationTests" { Context "Operations on snapshots" { BeforeAll { - Get-DbaProcess -SqlInstance $script:instance2 | Where-Object Program -match dbatools | Stop-DbaProcess -Confirm:$false -WarningAction SilentlyContinue - $server = Connect-DbaInstance -SqlInstance $script:instance2 + Get-DbaProcess -SqlInstance $TestConfig.instance2 | Where-Object Program -match dbatools | Stop-DbaProcess -Confirm:$false -WarningAction SilentlyContinue + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $db1 = "dbatoolsci_GetSnap" $db1_snap1 = "dbatoolsci_GetSnap_snapshotted1" $db1_snap2 = "dbatoolsci_GetSnap_snapshotted2" $db2 = "dbatoolsci_GetSnap2" $db2_snap1 = "dbatoolsci_GetSnap2_snapshotted" - Remove-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db1, $db2 -Confirm:$false - Get-DbaDatabase -SqlInstance $script:instance2 -Database $db1, $db2 | Remove-DbaDatabase -Confirm:$false + Remove-DbaDbSnapshot -SqlInstance $TestConfig.instance2 -Database $db1, $db2 -Confirm:$false + Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $db1, $db2 | Remove-DbaDatabase -Confirm:$false $server.Query("CREATE DATABASE $db1") $server.Query("CREATE DATABASE $db2") - $null = New-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db1 -Name $db1_snap1 -WarningAction SilentlyContinue - $null = New-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db1 -Name $db1_snap2 -WarningAction SilentlyContinue - $null = New-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db2 -Name $db2_snap1 -WarningAction SilentlyContinue + $null = New-DbaDbSnapshot -SqlInstance $TestConfig.instance2 -Database $db1 -Name $db1_snap1 -WarningAction SilentlyContinue + $null = New-DbaDbSnapshot -SqlInstance $TestConfig.instance2 -Database $db1 -Name $db1_snap2 -WarningAction SilentlyContinue + $null = New-DbaDbSnapshot -SqlInstance $TestConfig.instance2 -Database $db2 -Name $db2_snap1 -WarningAction SilentlyContinue } AfterAll { - Remove-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db1, $db2 -ErrorAction SilentlyContinue -Confirm:$false - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance2 -Database $db1, $db2 -ErrorAction SilentlyContinue + Remove-DbaDbSnapshot -SqlInstance $TestConfig.instance2 -Database $db1, $db2 -ErrorAction SilentlyContinue -Confirm:$false + Remove-DbaDatabase -Confirm:$false -SqlInstance $TestConfig.instance2 -Database $db1, $db2 -ErrorAction SilentlyContinue } It "Gets all snapshots by default" { - $results = Get-DbaDbSnapshot -SqlInstance $script:instance2 + $results = Get-DbaDbSnapshot -SqlInstance $TestConfig.instance2 ($results | Where-Object Name -Like 'dbatoolsci_GetSnap*').Count | Should Be 3 } It "Honors the Database parameter, returning only snapshots of that database" { - $results = Get-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db1 + $results = Get-DbaDbSnapshot -SqlInstance $TestConfig.instance2 -Database $db1 $results.Count | Should Be 2 - $result = Get-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db2 + $result = Get-DbaDbSnapshot -SqlInstance $TestConfig.instance2 -Database $db2 $result.SnapshotOf | Should Be $db2 } It "Honors the ExcludeDatabase parameter, returning relevant snapshots" { - $alldbs = (Get-DbaDatabase -SqlInstance $script:instance2 | Where-Object IsDatabaseSnapShot -eq $false | Where-Object Name -notin @($db1, $db2)).Name - $results = Get-DbaDbSnapshot -SqlInstance $script:instance2 -ExcludeDatabase $alldbs + $alldbs = (Get-DbaDatabase -SqlInstance $TestConfig.instance2 | Where-Object IsDatabaseSnapShot -eq $false | Where-Object Name -notin @($db1, $db2)).Name + $results = Get-DbaDbSnapshot -SqlInstance $TestConfig.instance2 -ExcludeDatabase $alldbs $results.Count | Should Be 3 } It "Honors the Snapshot parameter" { - $result = Get-DbaDbSnapshot -SqlInstance $script:instance2 -Snapshot $db1_snap1 + $result = Get-DbaDbSnapshot -SqlInstance $TestConfig.instance2 -Snapshot $db1_snap1 $result.Name | Should Be $db1_snap1 $result.SnapshotOf | Should Be $db1 } It "Honors the ExcludeSnapshot parameter" { - $result = Get-DbaDbSnapshot -SqlInstance $script:instance2 -ExcludeSnapshot $db1_snap1 -Database $db1 + $result = Get-DbaDbSnapshot -SqlInstance $TestConfig.instance2 -ExcludeSnapshot $db1_snap1 -Database $db1 $result.Name | Should Be $db1_snap2 } It "has the correct default properties" { - $result = Get-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db2 + $result = Get-DbaDbSnapshot -SqlInstance $TestConfig.instance2 -Database $db2 $ExpectedPropsDefault = 'ComputerName', 'CreateDate', 'InstanceName', 'Name', 'SnapshotOf', 'SqlInstance', 'DiskUsage' ($result.PSStandardMembers.DefaultDisplayPropertySet.ReferencedPropertyNames | Sort-Object) | Should Be ($ExpectedPropsDefault | Sort-Object) } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbSpace.Tests.ps1 b/tests/Get-DbaDbSpace.Tests.ps1 index 54a7ea280b..d87417e44e 100644 --- a/tests/Get-DbaDbSpace.Tests.ps1 +++ b/tests/Get-DbaDbSpace.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,15 +16,15 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { BeforeAll { $dbname = "dbatoolsci_test_$(get-random)" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $null = $server.Query("Create Database [$dbname]") } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbname -Confirm:$false + Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname -Confirm:$false } #Skipping these tests as internals of Get-DbaDbSpace seems to be unreliable in CI Context "Gets DbSpace" { - $results = Get-DbaDbSpace -SqlInstance $script:instance2 | Where-Object { $_.Database -eq "$dbname" } + $results = Get-DbaDbSpace -SqlInstance $TestConfig.instance2 | Where-Object { $_.Database -eq "$dbname" } It "Gets results" { $results | Should -Not -BeNullOrEmpty } @@ -40,7 +40,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } #Skipping these tests as internals of Get-DbaDbSpace seems to be unreliable in CI Context "Gets DbSpace when using -Database" { - $results = Get-DbaDbSpace -SqlInstance $script:instance2 -Database $dbname + $results = Get-DbaDbSpace -SqlInstance $TestConfig.instance2 -Database $dbname It "Gets results" { $results | Should Not Be $null } @@ -55,9 +55,9 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } Context "Gets no DbSpace for specific database when using -ExcludeDatabase" { - $results = Get-DbaDbSpace -SqlInstance $script:instance2 -ExcludeDatabase $dbname + $results = Get-DbaDbSpace -SqlInstance $TestConfig.instance2 -ExcludeDatabase $dbname It "Gets no results" { $results.database | Should -Not -Contain $dbname } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbState.Tests.ps1 b/tests/Get-DbaDbState.Tests.ps1 index 513fc8f8e2..77456ed57a 100644 --- a/tests/Get-DbaDbState.Tests.ps1 +++ b/tests/Get-DbaDbState.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,7 +16,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Reading db statuses" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $db1 = "dbatoolsci_dbstate_online" $db2 = "dbatoolsci_dbstate_offline" $db3 = "dbatoolsci_dbstate_emergency" @@ -25,7 +25,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $db6 = "dbatoolsci_dbstate_multi" $db7 = "dbatoolsci_dbstate_rw" $db8 = "dbatoolsci_dbstate_ro" - Get-DbaDatabase -SqlInstance $script:instance2 -Database $db1, $db2, $db3, $db4, $db5, $db6, $db7, $db8 | Remove-DbaDatabase -Confirm:$false + Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $db1, $db2, $db3, $db4, $db5, $db6, $db7, $db8 | Remove-DbaDatabase -Confirm:$false $server.Query("CREATE DATABASE $db1") $server.Query("CREATE DATABASE $db2; ALTER DATABASE $db2 SET OFFLINE WITH ROLLBACK IMMEDIATE") $server.Query("CREATE DATABASE $db3; ALTER DATABASE $db3 SET EMERGENCY WITH ROLLBACK IMMEDIATE") @@ -45,8 +45,8 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } AfterAll { - $null = Set-DbaDbState -Sqlinstance $script:instance2 -Database $db2, $db3, $db4, $db5, $db7 -Online -ReadWrite -MultiUser -Force - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance2 -Database $db1, $db2, $db3, $db4, $db5, $db6, $db7, $db8 + $null = Set-DbaDbState -Sqlinstance $TestConfig.instance2 -Database $db2, $db3, $db4, $db5, $db7 -Online -ReadWrite -MultiUser -Force + Remove-DbaDatabase -Confirm:$false -SqlInstance $TestConfig.instance2 -Database $db1, $db2, $db3, $db4, $db5, $db6, $db7, $db8 } if ($setupright) { # just to have a correct report on how much time BeforeAll takes @@ -54,60 +54,60 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $true | Should Be $true } It "Honors the Database parameter" { - $result = Get-DbaDbState -SqlInstance $script:instance2 -Database $db2 + $result = Get-DbaDbState -SqlInstance $TestConfig.instance2 -Database $db2 $result.DatabaseName | Should be $db2 - $results = Get-DbaDbState -SqlInstance $script:instance2 -Database $db1, $db2 + $results = Get-DbaDbState -SqlInstance $TestConfig.instance2 -Database $db1, $db2 $results.Count | Should be 2 } It "Honors the ExcludeDatabase parameter" { $alldbs_ = $server.Query("select name from sys.databases") $alldbs = ($alldbs_ | Where-Object Name -notin @($db1, $db2, $db3, $db4, $db5, $db6, $db7, $db8)).name - $results = Get-DbaDbState -SqlInstance $script:instance2 -ExcludeDatabase $alldbs + $results = Get-DbaDbState -SqlInstance $TestConfig.instance2 -ExcludeDatabase $alldbs $comparison = Compare-Object -ReferenceObject ($results.DatabaseName) -DifferenceObject (@($db1, $db2, $db3, $db4, $db5, $db6, $db7, $db8)) $comparison.Count | Should Be 0 } It "Identifies online database" { - $result = Get-DbaDbState -SqlInstance $script:instance2 -Database $db1 + $result = Get-DbaDbState -SqlInstance $TestConfig.instance2 -Database $db1 $result.DatabaseName | Should Be $db1 $result.Status | Should Be "ONLINE" } It "Identifies offline database" { - $result = Get-DbaDbState -SqlInstance $script:instance2 -Database $db2 + $result = Get-DbaDbState -SqlInstance $TestConfig.instance2 -Database $db2 $result.DatabaseName | Should Be $db2 $result.Status | Should Be "OFFLINE" } It "Identifies emergency database" { - $result = Get-DbaDbState -SqlInstance $script:instance2 -Database $db3 + $result = Get-DbaDbState -SqlInstance $TestConfig.instance2 -Database $db3 $result.DatabaseName | Should Be $db3 $result.Status | Should Be "EMERGENCY" } It "Identifies single_user database" { - $result = Get-DbaDbState -SqlInstance $script:instance2 -Database $db4 + $result = Get-DbaDbState -SqlInstance $TestConfig.instance2 -Database $db4 $result.DatabaseName | Should Be $db4 $result.Access | Should Be "SINGLE_USER" } It "Identifies restricted_user database" { - $result = Get-DbaDbState -SqlInstance $script:instance2 -Database $db5 + $result = Get-DbaDbState -SqlInstance $TestConfig.instance2 -Database $db5 $result.DatabaseName | Should Be $db5 $result.Access | Should Be "RESTRICTED_USER" } It "Identifies multi_user database" { - $result = Get-DbaDbState -SqlInstance $script:instance2 -Database $db6 + $result = Get-DbaDbState -SqlInstance $TestConfig.instance2 -Database $db6 $result.DatabaseName | Should Be $db6 $result.Access | Should Be "MULTI_USER" } It "Identifies read_write database" { - $result = Get-DbaDbState -SqlInstance $script:instance2 -Database $db7 + $result = Get-DbaDbState -SqlInstance $TestConfig.instance2 -Database $db7 $result.DatabaseName | Should Be $db7 $result.RW | Should Be "READ_WRITE" } It "Identifies read_only database" { - $result = Get-DbaDbState -SqlInstance $script:instance2 -Database $db8 + $result = Get-DbaDbState -SqlInstance $TestConfig.instance2 -Database $db8 $result.DatabaseName | Should Be $db8 $result.RW | Should Be "READ_ONLY" } - $result = Get-DbaDbState -SqlInstance $script:instance2 -Database $db1 + $result = Get-DbaDbState -SqlInstance $TestConfig.instance2 -Database $db1 It "Has the correct properties" { $ExpectedProps = 'SqlInstance,InstanceName,ComputerName,DatabaseName,RW,Status,Access,Database'.Split(',') ($result.PsObject.Properties.Name | Sort-Object) | Should Be ($ExpectedProps | Sort-Object) @@ -119,4 +119,4 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbStoredProcedure.Tests.ps1 b/tests/Get-DbaDbStoredProcedure.Tests.ps1 index 7a4ba13e22..925ae2a6c9 100644 --- a/tests/Get-DbaDbStoredProcedure.Tests.ps1 +++ b/tests/Get-DbaDbStoredProcedure.Tests.ps1 @@ -3,7 +3,7 @@ #> $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig <# Unit test is required for any command added @@ -21,7 +21,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { # Get-DbaNoun Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $random = Get-Random $db1Name = "dbatoolsci_$random" $db1 = New-DbaDatabase -SqlInstance $server -Name $db1Name @@ -38,7 +38,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } Context "Command actually works" { - $results = Get-DbaDbStoredProcedure -SqlInstance $script:instance2 -Database $db1Name + $results = Get-DbaDbStoredProcedure -SqlInstance $TestConfig.instance2 -Database $db1Name It "Should have standard properties" { $ExpectedProps = 'ComputerName,InstanceName,SqlInstance'.Split(',') ($results[0].PsObject.Properties.Name | Where-Object { $_ -in $ExpectedProps } | Sort-Object) | Should Be ($ExpectedProps | Sort-Object) @@ -53,52 +53,52 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Exclusions work correctly" { It "Should contain no procs from master database" { - $results = Get-DbaDbStoredProcedure -SqlInstance $script:instance2 -ExcludeDatabase master + $results = Get-DbaDbStoredProcedure -SqlInstance $TestConfig.instance2 -ExcludeDatabase master $results.Database | Should -Not -Contain 'master' } It "Should exclude system procedures" { - $results = Get-DbaDbStoredProcedure -SqlInstance $script:instance2 -Database $db1Name -ExcludeSystemSp + $results = Get-DbaDbStoredProcedure -SqlInstance $TestConfig.instance2 -Database $db1Name -ExcludeSystemSp $results | Where-Object Name -eq 'sp_helpdb' | Should -BeNullOrEmpty } } Context "Piping works" { It "Should allow piping from string" { - $results = $script:instance2 | Get-DbaDbStoredProcedure -Database $db1Name + $results = $TestConfig.instance2 | Get-DbaDbStoredProcedure -Database $db1Name ($results | Where-Object Name -eq $procName).Name | Should -Not -BeNullOrEmpty } It "Should allow piping from Get-DbaDatabase" { - $results = Get-DbaDatabase -SqlInstance $script:instance2 -Database $db1Name | Get-DbaDbStoredProcedure + $results = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $db1Name | Get-DbaDbStoredProcedure ($results | Where-Object Name -eq $procName).Name | Should -Not -BeNullOrEmpty } } Context "Search by name and schema" { It "Search by name" { - $results = $script:instance2 | Get-DbaDbStoredProcedure -Database $db1Name -Name $procName + $results = $TestConfig.instance2 | Get-DbaDbStoredProcedure -Database $db1Name -Name $procName $results.Name | Should -Be $procName $results.DatabaseId | Should -Be $db1.Id } It "Search by 2 part name" { - $results = $script:instance2 | Get-DbaDbStoredProcedure -Database $db1Name -Name "$schemaName.$procName2" + $results = $TestConfig.instance2 | Get-DbaDbStoredProcedure -Database $db1Name -Name "$schemaName.$procName2" $results.Name | Should -Be $procName2 $results.Schema | Should -Be $schemaName } It "Search by 3 part name and omit the -Database param" { - $results = $script:instance2 | Get-DbaDbStoredProcedure -Name "$db1Name.$schemaName.$procName2" + $results = $TestConfig.instance2 | Get-DbaDbStoredProcedure -Name "$db1Name.$schemaName.$procName2" $results.Name | Should -Be $procName2 $results.Schema | Should -Be $schemaName $results.Database | Should -Be $db1Name } It "Search by name and schema params" { - $results = $script:instance2 | Get-DbaDbStoredProcedure -Database $db1Name -Name $procName2 -Schema $schemaName + $results = $TestConfig.instance2 | Get-DbaDbStoredProcedure -Database $db1Name -Name $procName2 -Schema $schemaName $results.Name | Should -Be $procName2 $results.Schema | Should -Be $schemaName } It "Search by schema name" { - $results = $script:instance2 | Get-DbaDbStoredProcedure -Database $db1Name -Schema $schemaName + $results = $TestConfig.instance2 | Get-DbaDbStoredProcedure -Database $db1Name -Schema $schemaName $results.Name | Should -Be $procName2 $results.Schema | Should -Be $schemaName } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbSynonym.Tests.ps1 b/tests/Get-DbaDbSynonym.Tests.ps1 index 9d4d29b631..ce7493e94d 100644 --- a/tests/Get-DbaDbSynonym.Tests.ps1 +++ b/tests/Get-DbaDbSynonym.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Validate parameters" { @@ -17,27 +17,27 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { $dbname = "dbatoolsscidb_$(Get-Random)" $dbname2 = "dbatoolsscidb2_$(Get-Random)" - $null = New-DbaDatabase -SqlInstance $script:instance2 -Name $dbname - $null = New-DbaDatabase -SqlInstance $script:instance2 -Name $dbname2 - $null = New-DbaDbSchema -SqlInstance $script:instance2 -Database $dbname2 -Schema sch2 - $null = New-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname -Synonym syn1 -BaseObject obj1 - $null = New-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname2 -Synonym syn2 -BaseObject obj2 - $null = New-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname2 -Schema sch2 -Synonym syn3 -BaseObject obj2 + $null = New-DbaDatabase -SqlInstance $TestConfig.instance2 -Name $dbname + $null = New-DbaDatabase -SqlInstance $TestConfig.instance2 -Name $dbname2 + $null = New-DbaDbSchema -SqlInstance $TestConfig.instance2 -Database $dbname2 -Schema sch2 + $null = New-DbaDbSynonym -SqlInstance $TestConfig.instance2 -Database $dbname -Synonym syn1 -BaseObject obj1 + $null = New-DbaDbSynonym -SqlInstance $TestConfig.instance2 -Database $dbname2 -Synonym syn2 -BaseObject obj2 + $null = New-DbaDbSynonym -SqlInstance $TestConfig.instance2 -Database $dbname2 -Schema sch2 -Synonym syn3 -BaseObject obj2 } AfterAll { - $null = Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbname, $dbname2 -Confirm:$false - $null = Remove-DbaDbSynonym -SqlInstance $script:instance2 -Confirm:$false + $null = Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname, $dbname2 -Confirm:$false + $null = Remove-DbaDbSynonym -SqlInstance $TestConfig.instance2 -Confirm:$false } Context "Functionality" { It 'Returns Results' { - $result1 = Get-DbaDbSynonym -SqlInstance $script:instance2 + $result1 = Get-DbaDbSynonym -SqlInstance $TestConfig.instance2 $result1.Count | Should -BeGreaterThan 0 } It 'Returns all synonyms for all databases' { - $result2 = Get-DbaDbSynonym -SqlInstance $script:instance2 + $result2 = Get-DbaDbSynonym -SqlInstance $TestConfig.instance2 $uniqueDatabases = $result2.Database | Select-Object -Unique $uniqueDatabases.Count | Should -BeGreaterThan 1 @@ -45,44 +45,44 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } It 'Accepts a list of databases' { - $result3 = Get-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname, $dbname2 + $result3 = Get-DbaDbSynonym -SqlInstance $TestConfig.instance2 -Database $dbname, $dbname2 $result3.Database | Select-Object -Unique | Should -Be $dbname, $dbname2 } It 'Excludes databases' { - $result4 = Get-DbaDbSynonym -SqlInstance $script:instance2 -ExcludeDatabase $dbname2 + $result4 = Get-DbaDbSynonym -SqlInstance $TestConfig.instance2 -ExcludeDatabase $dbname2 $uniqueDatabases = $result4.Database | Select-Object -Unique $uniqueDatabases | Should -Not -Contain $dbname2 } It 'Accepts a list of synonyms' { - $result5 = Get-DbaDbSynonym -SqlInstance $script:instance2 -Synonym 'syn1', 'syn2' + $result5 = Get-DbaDbSynonym -SqlInstance $TestConfig.instance2 -Synonym 'syn1', 'syn2' $result5.Name | Select-Object -Unique | Should -Be 'syn1', 'syn2' } It 'Excludes synonyms' { - $result6 = Get-DbaDbSynonym -SqlInstance $script:instance2 -ExcludeSynonym 'syn2' + $result6 = Get-DbaDbSynonym -SqlInstance $TestConfig.instance2 -ExcludeSynonym 'syn2' $result6.Name | Select-Object -Unique | Should -Not -Contain 'syn2' } It 'Finds synonyms for specified schema only' { - $result7 = Get-DbaDbSynonym -SqlInstance $script:instance2 -Schema 'sch2' + $result7 = Get-DbaDbSynonym -SqlInstance $TestConfig.instance2 -Schema 'sch2' $result7.Count | Should -Be 1 } It 'Accepts a list of schemas' { - $result8 = Get-DbaDbSynonym -SqlInstance $script:instance2 -Schema 'dbo','sch2' + $result8 = Get-DbaDbSynonym -SqlInstance $TestConfig.instance2 -Schema 'dbo','sch2' $result8.Schema | Select-Object -Unique | Should -Be 'dbo','sch2' } It 'Excludes schemas' { - $result9 = Get-DbaDbSynonym -SqlInstance $script:instance2 -ExcludeSchema 'dbo' + $result9 = Get-DbaDbSynonym -SqlInstance $TestConfig.instance2 -ExcludeSchema 'dbo' $result9.Schema | Select-Object -Unique | Should -Not -Contain 'dbo' } @@ -94,4 +94,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbTable.Tests.ps1 b/tests/Get-DbaDbTable.Tests.ps1 index 577919c7b3..95b2cfe2c3 100644 --- a/tests/Get-DbaDbTable.Tests.ps1 +++ b/tests/Get-DbaDbTable.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,25 +16,25 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BeforeAll { $dbname = "dbatoolsscidb_$(Get-Random)" - $null = New-DbaDatabase -SqlInstance $script:instance1 -Name $dbname -Owner sa + $null = New-DbaDatabase -SqlInstance $TestConfig.instance1 -Name $dbname -Owner sa $tablename = "dbatoolssci_$(Get-Random)" - $null = Invoke-DbaQuery -SqlInstance $script:instance1 -Database $dbname -Query "Create table $tablename (col1 int)" + $null = Invoke-DbaQuery -SqlInstance $TestConfig.instance1 -Database $dbname -Query "Create table $tablename (col1 int)" } AfterAll { - $null = Invoke-DbaQuery -SqlInstance $script:instance1 -Database $dbname -Query "drop table $tablename" - $null = Remove-DbaDatabase -SqlInstance $script:instance1 -Database $dbname -Confirm:$false + $null = Invoke-DbaQuery -SqlInstance $TestConfig.instance1 -Database $dbname -Query "drop table $tablename" + $null = Remove-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $dbname -Confirm:$false } Context "Should get the table" { It "Gets the table" { - (Get-DbaDbTable -SqlInstance $script:instance1).Name | Should Contain $tablename + (Get-DbaDbTable -SqlInstance $TestConfig.instance1).Name | Should Contain $tablename } It "Gets the table when you specify the database" { - (Get-DbaDbTable -SqlInstance $script:instance1 -Database $dbname).Name | Should Contain $tablename + (Get-DbaDbTable -SqlInstance $TestConfig.instance1 -Database $dbname).Name | Should Contain $tablename } } Context "Should not get the table if database is excluded" { It "Doesn't find the table" { - (Get-DbaDbTable -SqlInstance $script:instance1 -ExcludeDatabase $dbname).Name | Should Not Contain $tablename + (Get-DbaDbTable -SqlInstance $TestConfig.instance1 -ExcludeDatabase $dbname).Name | Should Not Contain $tablename } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbTrigger.Tests.ps1 b/tests/Get-DbaDbTrigger.Tests.ps1 index e21d6d7d2b..31b9af58e0 100644 --- a/tests/Get-DbaDbTrigger.Tests.ps1 +++ b/tests/Get-DbaDbTrigger.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -26,17 +26,17 @@ CREATE TRIGGER dbatoolsci_safety RAISERROR ('You must disable Trigger "dbatoolsci_safety" to drop synonyms!',10, 1) ROLLBACK "@ - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $server.Query("$trigger") } AfterAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $trigger = "DROP TRIGGER dbatoolsci_safety ON DATABASE;" $server.Query("$trigger") } Context "Gets Database Trigger" { - $results = Get-DbaDbTrigger -SqlInstance $script:instance2 | Where-Object {$_.name -eq "dbatoolsci_safety"} + $results = Get-DbaDbTrigger -SqlInstance $TestConfig.instance2 | Where-Object {$_.name -eq "dbatoolsci_safety"} It "Gets results" { $results | Should Not Be $null } @@ -48,7 +48,7 @@ CREATE TRIGGER dbatoolsci_safety } } Context "Gets Database Trigger when using -Database" { - $results = Get-DbaDbTrigger -SqlInstance $script:instance2 -Database Master + $results = Get-DbaDbTrigger -SqlInstance $TestConfig.instance2 -Database Master It "Gets results" { $results | Should Not Be $null } @@ -60,9 +60,9 @@ CREATE TRIGGER dbatoolsci_safety } } Context "Gets no Database Trigger when using -ExcludeDatabase" { - $results = Get-DbaDbTrigger -SqlInstance $script:instance2 -ExcludeDatabase Master + $results = Get-DbaDbTrigger -SqlInstance $TestConfig.instance2 -ExcludeDatabase Master It "Gets no results" { $results | Should Be $null } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbUdf.Tests.ps1 b/tests/Get-DbaDbUdf.Tests.ps1 index 85e42c7b7e..b5c739dc96 100644 --- a/tests/Get-DbaDbUdf.Tests.ps1 +++ b/tests/Get-DbaDbUdf.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -37,16 +37,16 @@ BEGIN RETURN(@ISOweek); END; "@ - Invoke-DbaQuery -SqlInstance $script:instance2 -Query $CreateTestUDFunction -Database master + Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Query $CreateTestUDFunction -Database master } AfterAll { $DropTestUDFunction = "DROP FUNCTION dbo.dbatoolssci_ISOweek;" - Invoke-DbaQuery -SqlInstance $script:instance2 -Query $DropTestUDFunction -Database master + Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Query $DropTestUDFunction -Database master } Context "User Functions are correctly located" { - $results1 = Get-DbaDbUdf -SqlInstance $script:instance2 -Database master -Name dbatoolssci_ISOweek | Select-Object * - $results2 = Get-DbaDbUdf -SqlInstance $script:instance2 + $results1 = Get-DbaDbUdf -SqlInstance $TestConfig.instance2 -Database master -Name dbatoolssci_ISOweek | Select-Object * + $results2 = Get-DbaDbUdf -SqlInstance $TestConfig.instance2 It "Should execute and return results" { $results2 | Should -Not -Be $null @@ -70,7 +70,7 @@ END; } It "Should not Throw an Error" { - { Get-DbaDbUdf -SqlInstance $script:instance2 -ExcludeDatabase master -ExcludeSystemUdf } | Should -not -Throw + { Get-DbaDbUdf -SqlInstance $TestConfig.instance2 -ExcludeDatabase master -ExcludeSystemUdf } | Should -not -Throw } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbUser.Tests.ps1 b/tests/Get-DbaDbUser.Tests.ps1 index 1675eb54d2..d426a4bc3a 100644 --- a/tests/Get-DbaDbUser.Tests.ps1 +++ b/tests/Get-DbaDbUser.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -30,7 +30,7 @@ USE Master; CREATE USER [$DBUserName2] FOR LOGIN [$DBUserName2] WITH DEFAULT_SCHEMA = dbo; "@ - Invoke-DbaQuery -SqlInstance $script:instance2 -Query $CreateTestUser -Database master + Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Query $CreateTestUser -Database master } AfterAll { $DropTestUser = @" @@ -39,18 +39,18 @@ DROP USER [$DBUserName2]; DROP LOGIN [$DBUserName]; DROP LOGIN [$DBUserName2]; "@ - Invoke-DbaQuery -SqlInstance $script:instance2 -Query $DropTestUser -Database master + Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Query $DropTestUser -Database master } Context "Users are correctly located" { - $results1 = Get-DbaDbUser -SqlInstance $script:instance2 -Database master | Where-Object { $_.name -eq "$DBUserName" } | Select-Object * - $results2 = Get-DbaDbUser -SqlInstance $script:instance2 + $results1 = Get-DbaDbUser -SqlInstance $TestConfig.instance2 -Database master | Where-Object { $_.name -eq "$DBUserName" } | Select-Object * + $results2 = Get-DbaDbUser -SqlInstance $TestConfig.instance2 - $resultsByUser = Get-DbaDbUser -SqlInstance $script:instance2 -Database master -User $DBUserName2 - $resultsByMultipleUser = Get-DbaDbUser -SqlInstance $script:instance2 -User $DBUserName, $DBUserName2 + $resultsByUser = Get-DbaDbUser -SqlInstance $TestConfig.instance2 -Database master -User $DBUserName2 + $resultsByMultipleUser = Get-DbaDbUser -SqlInstance $TestConfig.instance2 -User $DBUserName, $DBUserName2 - $resultsByLogin = Get-DbaDbUser -SqlInstance $script:instance2 -Database master -Login $DBUserName2 - $resultsByMultipleLogin = Get-DbaDbUser -SqlInstance $script:instance2 -Login $DBUserName, $DBUserName2 + $resultsByLogin = Get-DbaDbUser -SqlInstance $TestConfig.instance2 -Database master -Login $DBUserName2 + $resultsByMultipleLogin = Get-DbaDbUser -SqlInstance $TestConfig.instance2 -Login $DBUserName, $DBUserName2 It "Should execute and return results" { $results2 | Should -Not -Be $null @@ -78,7 +78,7 @@ DROP LOGIN [$DBUserName2]; } It "Should not Throw an Error" { - { Get-DbaDbUser -SqlInstance $script:instance2 -ExcludeDatabase master -ExcludeSystemUser } | Should -not -Throw + { Get-DbaDbUser -SqlInstance $TestConfig.instance2 -ExcludeDatabase master -ExcludeSystemUser } | Should -not -Throw } It "Should return a specific user" { @@ -101,4 +101,4 @@ DROP LOGIN [$DBUserName2]; $resultsByMultipleLogin.Database | Should -Be master, master } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbUserDefinedTableType.Tests.ps1 b/tests/Get-DbaDbUserDefinedTableType.Tests.ps1 index acd5227696..28acae6200 100644 --- a/tests/Get-DbaDbUserDefinedTableType.Tests.ps1 +++ b/tests/Get-DbaDbUserDefinedTableType.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,7 +15,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $tabletypename = ("dbatools_{0}" -f $(Get-Random)) $tabletypename1 = ("dbatools_{0}" -f $(Get-Random)) $server.Query("CREATE TYPE $tabletypename AS TABLE([column1] INT NULL)", 'tempdb') @@ -27,7 +27,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } Context "Gets a Db User Defined Table Type" { - $results = Get-DbaDbUserDefinedTableType -SqlInstance $script:instance2 -database tempdb -Type $tabletypename + $results = Get-DbaDbUserDefinedTableType -SqlInstance $TestConfig.instance2 -database tempdb -Type $tabletypename It "Gets results" { $results | Should Not Be $Null } @@ -43,7 +43,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } Context "Gets all the Db User Defined Table Type" { - $results = Get-DbaDbUserDefinedTableType -SqlInstance $script:instance2 -database tempdb + $results = Get-DbaDbUserDefinedTableType -SqlInstance $TestConfig.instance2 -database tempdb It "Gets results" { $results | Should Not Be $Null } @@ -52,4 +52,4 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbView.Tests.ps1 b/tests/Get-DbaDbView.Tests.ps1 index a7e851c416..f28b2b8a88 100644 --- a/tests/Get-DbaDbView.Tests.ps1 +++ b/tests/Get-DbaDbView.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -14,7 +14,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $viewName = ("dbatoolsci_{0}" -f $(Get-Random)) $viewNameWithSchema = ("dbatoolsci_{0}" -f $(Get-Random)) $server.Query("CREATE VIEW $viewName AS (SELECT 1 as col1)", 'tempdb') @@ -29,7 +29,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Command actually works" { BeforeAll { - $results = Get-DbaDbView -SqlInstance $script:instance2 -Database tempdb + $results = Get-DbaDbView -SqlInstance $TestConfig.instance2 -Database tempdb } It "Should have standard properties" { $ExpectedProps = 'ComputerName,InstanceName,SqlInstance'.Split(',') @@ -45,31 +45,31 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Exclusions work correctly" { It "Should contain no views from master database" { - $results = Get-DbaDbView -SqlInstance $script:instance2 -ExcludeDatabase master + $results = Get-DbaDbView -SqlInstance $TestConfig.instance2 -ExcludeDatabase master 'master' | Should -Not -BeIn $results.Database } It "Should exclude system views" { - $results = Get-DbaDbView -SqlInstance $script:instance2 -Database master -ExcludeSystemView + $results = Get-DbaDbView -SqlInstance $TestConfig.instance2 -Database master -ExcludeSystemView ($results | Where-Object IsSystemObject -eq $true).Count | Should -Be 0 } } Context "Piping workings" { It "Should allow piping from string" { - $results = $script:instance2 | Get-DbaDbView -Database tempdb + $results = $TestConfig.instance2 | Get-DbaDbView -Database tempdb ($results | Where-Object Name -eq $viewName).Name | Should -Be $viewName } It "Should allow piping from Get-DbaDatabase" { - $results = Get-DbaDatabase -SqlInstance $script:instance2 -Database tempdb | Get-DbaDbView + $results = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database tempdb | Get-DbaDbView ($results | Where-Object Name -eq $viewName).Name | Should -Be $viewName } } - + Context "Schema parameter (see #9445)" { It "Should return just one view with schema 'someschema'" { - $results = $script:instance2 | Get-DbaDbView -Database tempdb -Schema 'someschema' + $results = $TestConfig.instance2 | Get-DbaDbView -Database tempdb -Schema 'someschema' ($results | Where-Object Name -eq $viewNameWithSchema).Name | Should -Be $viewNameWithSchema ($results | Where-Object Schema -ne 'someschema').Count | Should -Be 0 } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbVirtualLogFile.Tests.ps1 b/tests/Get-DbaDbVirtualLogFile.Tests.ps1 index 0a86552205..e5a7274841 100644 --- a/tests/Get-DbaDbVirtualLogFile.Tests.ps1 +++ b/tests/Get-DbaDbVirtualLogFile.Tests.ps1 @@ -3,7 +3,7 @@ #> $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig <# Unit test is required for any command added @@ -21,10 +21,10 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { # Get-DbaNoun Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $db1 = "dbatoolsci_getvlf" $server.Query("CREATE DATABASE $db1") - $needed = Get-DbaDatabase -SqlInstance $script:instance2 -Database $db1 + $needed = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $db1 $setupright = $true if ($needed.Count -ne 1) { $setupright = $false @@ -34,10 +34,10 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } } AfterAll { - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance2 -Database $db1 + Remove-DbaDatabase -Confirm:$false -SqlInstance $TestConfig.instance2 -Database $db1 } Context "Command actually works" { - $results = Get-DbaDbVirtualLogFile -SqlInstance $script:instance2 -Database $db1 + $results = Get-DbaDbVirtualLogFile -SqlInstance $TestConfig.instance2 -Database $db1 It "Should have correct properties" { $ExpectedProps = 'ComputerName,InstanceName,SqlInstance,Database,RecoveryUnitId,FileId,FileSize,StartOffset,FSeqNo,Status,Parity,CreateLSN'.Split(',') ($results[0].PsObject.Properties.Name | Sort-Object) | Should Be ($ExpectedProps | Sort-Object) @@ -49,4 +49,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbccHelp.Tests.ps1 b/tests/Get-DbaDbccHelp.Tests.ps1 index dfee44dfdd..dbb0f3bc2d 100644 --- a/tests/Get-DbaDbccHelp.Tests.ps1 +++ b/tests/Get-DbaDbccHelp.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -14,7 +14,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { } Describe "$commandname Integration Test" -Tag "IntegrationTests" { $props = 'Operation', 'Cmd', 'Output' - $result = Get-DbaDbccHelp -SqlInstance $script:instance2 -Statement FREESYSTEMCACHE + $result = Get-DbaDbccHelp -SqlInstance $TestConfig.instance2 -Statement FREESYSTEMCACHE Context "Validate standard output" { foreach ($prop in $props) { @@ -33,10 +33,10 @@ Describe "$commandname Integration Test" -Tag "IntegrationTests" { } It "returns the right results for PAGE" { - $result = Get-DbaDbccHelp -SqlInstance $script:instance2 -Statement PAGE -IncludeUndocumented + $result = Get-DbaDbccHelp -SqlInstance $TestConfig.instance2 -Statement PAGE -IncludeUndocumented $result.Operation | Should Be 'PAGE' $result.Cmd | Should Be 'DBCC HELP(PAGE)' $result.Output | Should Not Be $null } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbccMemoryStatus.Tests.ps1 b/tests/Get-DbaDbccMemoryStatus.Tests.ps1 index 24de7e7964..e93cd51152 100644 --- a/tests/Get-DbaDbccMemoryStatus.Tests.ps1 +++ b/tests/Get-DbaDbccMemoryStatus.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -14,7 +14,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { } Describe "$commandname Integration Test" -Tag "IntegrationTests" { $props = 'ComputerName', 'InstanceName', 'RecordSet', 'RowId', 'RecordSetId', 'Type', 'Name', 'Value', 'ValueType' - $result = Get-DbaDbccMemoryStatus -SqlInstance $script:instance2 + $result = Get-DbaDbccMemoryStatus -SqlInstance $TestConfig.instance2 Context "Validate standard output" { foreach ($prop in $props) { @@ -30,4 +30,4 @@ Describe "$commandname Integration Test" -Tag "IntegrationTests" { $result.Count -gt 0 | Should Be $true } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbccProcCache.Tests.ps1 b/tests/Get-DbaDbccProcCache.Tests.ps1 index 3d08ff5226..4a9a745ad0 100644 --- a/tests/Get-DbaDbccProcCache.Tests.ps1 +++ b/tests/Get-DbaDbccProcCache.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -14,7 +14,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { } Describe "$commandname Integration Test" -Tag "IntegrationTests" { $props = 'ComputerName', 'InstanceName', 'SqlInstance', 'Count', 'Used', 'Active', 'CacheSize', 'CacheUsed', 'CacheActive' - $result = Get-DbaDbccProcCache -SqlInstance $script:instance2 + $result = Get-DbaDbccProcCache -SqlInstance $TestConfig.instance2 Context "Validate standard output" { foreach ($prop in $props) { @@ -30,4 +30,4 @@ Describe "$commandname Integration Test" -Tag "IntegrationTests" { $result | Should NOt Be $null } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbccSessionBuffer.Tests.ps1 b/tests/Get-DbaDbccSessionBuffer.Tests.ps1 index cd6ac00b97..4d2cdb0b9e 100644 --- a/tests/Get-DbaDbccSessionBuffer.Tests.ps1 +++ b/tests/Get-DbaDbccSessionBuffer.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -14,7 +14,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { } Describe "$commandname Integration Test" -Tag "IntegrationTests" { BeforeAll { - $db = Get-DbaDatabase -SqlInstance $script:instance1 -Database tempdb + $db = Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database tempdb $queryResult = $db.Query('SELECT top 10 object_id, @@Spid as MySpid FROM sys.objects') } AfterAll { @@ -22,7 +22,7 @@ Describe "$commandname Integration Test" -Tag "IntegrationTests" { Context "Validate standard output for all databases " { $props = 'ComputerName', 'InstanceName', 'SqlInstance', 'SessionId', 'EventType', 'Parameters', 'EventInfo' - $result = Get-DbaDbccSessionBuffer -SqlInstance $script:instance1 -Operation InputBuffer -All + $result = Get-DbaDbccSessionBuffer -SqlInstance $TestConfig.instance1 -Operation InputBuffer -All It "returns results" { $result.Count -gt 0 | Should Be $true @@ -36,7 +36,7 @@ Describe "$commandname Integration Test" -Tag "IntegrationTests" { } $props = 'ComputerName', 'InstanceName', 'SqlInstance', 'SessionId', 'Buffer', 'HexBuffer' - $result = Get-DbaDbccSessionBuffer -SqlInstance $script:instance1 -Operation OutputBuffer -All + $result = Get-DbaDbccSessionBuffer -SqlInstance $TestConfig.instance1 -Operation OutputBuffer -All It "returns results" { $result.Count -gt 0 | Should Be $true @@ -53,17 +53,17 @@ Describe "$commandname Integration Test" -Tag "IntegrationTests" { Context "Validate returns results for SessionId " { $spid = $queryResult[0].MySpid - $result = Get-DbaDbccSessionBuffer -SqlInstance $script:instance1 -Operation InputBuffer -SessionId $spid + $result = Get-DbaDbccSessionBuffer -SqlInstance $TestConfig.instance1 -Operation InputBuffer -SessionId $spid It "returns results for InputBuffer" { $result.SessionId -eq $spid | Should Be $true } - $result = Get-DbaDbccSessionBuffer -SqlInstance $script:instance1 -Operation OutputBuffer -SessionId $spid + $result = Get-DbaDbccSessionBuffer -SqlInstance $TestConfig.instance1 -Operation OutputBuffer -SessionId $spid It "returns results for OutputBuffer" { $result.SessionId -eq $spid | Should Be $true } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbccStatistic.Tests.ps1 b/tests/Get-DbaDbccStatistic.Tests.ps1 index df4b4f4042..fbae851e1d 100644 --- a/tests/Get-DbaDbccStatistic.Tests.ps1 +++ b/tests/Get-DbaDbccStatistic.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -14,7 +14,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { } Describe "$commandname Integration Test" -Tag "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $random = Get-Random $tableName = "dbatools_getdbtbl1" $tableName2 = "dbatools_getdbtbl2" @@ -32,12 +32,12 @@ Describe "$commandname Integration Test" -Tag "IntegrationTests" { $null = $server.Query("UPDATE STATISTICS $tableName", $dbname) } AfterAll { - $null = Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbname | Remove-DbaDatabase -Confirm:$false + $null = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname | Remove-DbaDatabase -Confirm:$false } Context "Validate standard output for StatHeader option " { $props = 'ComputerName', 'InstanceName', 'SqlInstance', 'Database', 'Object', 'Target', 'Cmd', 'Name', 'Updated', 'Rows', 'RowsSampled', 'Steps', 'Density', 'AverageKeyLength', 'StringIndex', 'FilterExpression', 'UnfilteredRows', 'PersistedSamplePercent' - $result = Get-DbaDbccStatistic -SqlInstance $script:instance2 -Database $dbname -Option StatHeader + $result = Get-DbaDbccStatistic -SqlInstance $TestConfig.instance2 -Database $dbname -Option StatHeader It "returns correct results" { $result.Count -eq 3 | Should Be $true @@ -53,7 +53,7 @@ Describe "$commandname Integration Test" -Tag "IntegrationTests" { Context "Validate standard output for DensityVector option " { $props = 'ComputerName', 'InstanceName', 'SqlInstance', 'Database', 'Object', 'Target', 'Cmd', 'AllDensity', 'AverageLength', 'Columns' - $result = Get-DbaDbccStatistic -SqlInstance $script:instance2 -Database $dbname -Option DensityVector + $result = Get-DbaDbccStatistic -SqlInstance $TestConfig.instance2 -Database $dbname -Option DensityVector It "returns results" { $result.Count -gt 0 | Should Be $true @@ -70,7 +70,7 @@ Describe "$commandname Integration Test" -Tag "IntegrationTests" { Context "Validate standard output for Histogram option " { $props = 'ComputerName', 'InstanceName', 'SqlInstance', 'Database', 'Object', 'Target', 'Cmd', 'RangeHiKey', 'RangeRows', 'EqualRows', 'DistinctRangeRows', 'AverageRangeRows' - $result = Get-DbaDbccStatistic -SqlInstance $script:instance2 -Database $dbname -Option Histogram + $result = Get-DbaDbccStatistic -SqlInstance $TestConfig.instance2 -Database $dbname -Option Histogram It "returns results" { $result.Count -gt 0 | Should Be $true @@ -87,7 +87,7 @@ Describe "$commandname Integration Test" -Tag "IntegrationTests" { Context "Validate standard output for StatsStream option " { $props = 'ComputerName', 'InstanceName', 'SqlInstance', 'Database', 'Object', 'Target', 'Cmd', 'StatsStream', 'Rows', 'DataPages' - $result = Get-DbaDbccStatistic -SqlInstance $script:instance2 -Database $dbname -Option StatsStream + $result = Get-DbaDbccStatistic -SqlInstance $TestConfig.instance2 -Database $dbname -Option StatsStream It "returns results" { $result.Count -gt 0 | Should Be $true @@ -103,7 +103,7 @@ Describe "$commandname Integration Test" -Tag "IntegrationTests" { } Context "Validate returns results for single Object " { - $result = Get-DbaDbccStatistic -SqlInstance $script:instance2 -Database $dbname -Object $tableName2 -Option StatsStream + $result = Get-DbaDbccStatistic -SqlInstance $TestConfig.instance2 -Database $dbname -Object $tableName2 -Option StatsStream It "returns results" { $result.Count -gt 0 | Should Be $true @@ -111,10 +111,10 @@ Describe "$commandname Integration Test" -Tag "IntegrationTests" { } Context "Validate returns results for single Object and Target " { - $result = Get-DbaDbccStatistic -SqlInstance $script:instance2 -Database $dbname -Object $tableName2 -Target 'TestStat2' -Option DensityVector + $result = Get-DbaDbccStatistic -SqlInstance $TestConfig.instance2 -Database $dbname -Object $tableName2 -Target 'TestStat2' -Option DensityVector It "returns results" { $result.Count -gt 0 | Should Be $true } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDbccUserOption.Tests.ps1 b/tests/Get-DbaDbccUserOption.Tests.ps1 index adb559bbe8..a99ef5672f 100644 --- a/tests/Get-DbaDbccUserOption.Tests.ps1 +++ b/tests/Get-DbaDbccUserOption.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -14,7 +14,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { } Describe "$commandname Integration Test" -Tag "IntegrationTests" { $props = 'ComputerName', 'InstanceName', 'SqlInstance', 'Option', 'Value' - $result = Get-DbaDbccUserOption -SqlInstance $script:instance2 + $result = Get-DbaDbccUserOption -SqlInstance $TestConfig.instance2 Context "Validate standard output" { foreach ($prop in $props) { @@ -32,7 +32,7 @@ Describe "$commandname Integration Test" -Tag "IntegrationTests" { } Context "Accepts an Option Value" { - $result = Get-DbaDbccUserOption -SqlInstance $script:instance2 -Option ansi_nulls + $result = Get-DbaDbccUserOption -SqlInstance $TestConfig.instance2 -Option ansi_nulls It "Gets results" { $result | Should Not Be $null } @@ -40,4 +40,4 @@ Describe "$commandname Integration Test" -Tag "IntegrationTests" { $result.Option -eq 'ansi_nulls' | Should Be $true } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDefaultPath.Tests.ps1 b/tests/Get-DbaDefaultPath.Tests.ps1 index a0b4c407cc..c47f3ca853 100644 --- a/tests/Get-DbaDefaultPath.Tests.ps1 +++ b/tests/Get-DbaDefaultPath.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,7 +15,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Context "returns proper information" { - $results = Get-DbaDefaultPath -SqlInstance $script:instance1 + $results = Get-DbaDefaultPath -SqlInstance $TestConfig.instance1 It "Data returns a value that contains :\" { $results.Data -match "\:\\" } @@ -29,4 +29,4 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $results.ErrorLog -match "\:\\" } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDependency.Tests.ps1 b/tests/Get-DbaDependency.Tests.ps1 index 5ff4180d9e..a997d0da82 100644 --- a/tests/Get-DbaDependency.Tests.ps1 +++ b/tests/Get-DbaDependency.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,7 +16,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BeforeAll { $dbname = "dbatoolsscidb_$(Get-Random)" - $null = New-DbaDatabase -SqlInstance $script:instance1 -Name $dbname + $null = New-DbaDatabase -SqlInstance $TestConfig.instance1 -Name $dbname $createTableScript = "IF OBJECT_ID('dbo.dbatoolsci_nodependencies') IS NOT NULL BEGIN @@ -99,33 +99,33 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { " - $null = Invoke-DbaQuery -SqlInstance $script:instance1 -Database $dbname -Query $createTableScript + $null = Invoke-DbaQuery -SqlInstance $TestConfig.instance1 -Database $dbname -Query $createTableScript } AfterAll { - $null = Remove-DbaDatabase -SqlInstance $script:instance1 -Database $dbname -Confirm:$false + $null = Remove-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $dbname -Confirm:$false } It "Test with a table that has no dependencies" { - $results = Get-DbaDbTable -SqlInstance $script:instance1 -Database $dbname -Table dbo.dbatoolsci_nodependencies | Get-DbaDependency -Parents + $results = Get-DbaDbTable -SqlInstance $TestConfig.instance1 -Database $dbname -Table dbo.dbatoolsci_nodependencies | Get-DbaDependency -Parents $results.length | Should -Be 0 } It "Test with a table that has parent dependencies" { - $results = Get-DbaDbTable -SqlInstance $script:instance1 -Database $dbname -Table dbo.dbatoolsci2 | Get-DbaDependency -Parents + $results = Get-DbaDbTable -SqlInstance $TestConfig.instance1 -Database $dbname -Table dbo.dbatoolsci2 | Get-DbaDependency -Parents $results.length | Should -Be 1 $results[0].Dependent | Should -Be "dbatoolsci1" $results[0].Tier | Should -Be -1 } It "Test with a table that has child dependencies" { - $results = Get-DbaDbTable -SqlInstance $script:instance1 -Database $dbname -Table dbo.dbatoolsci2 | Get-DbaDependency -IncludeSelf + $results = Get-DbaDbTable -SqlInstance $TestConfig.instance1 -Database $dbname -Table dbo.dbatoolsci2 | Get-DbaDependency -IncludeSelf $results.length | Should -Be 2 $results[1].Dependent | Should -Be "dbatoolsci3" $results[1].Tier | Should -Be 1 } It "Test with a table that has multiple levels of dependencies and use -IncludeSelf" { - $results = Get-DbaDbTable -SqlInstance $script:instance1 -Database $dbname -Table dbo.dbatoolsci3 | Get-DbaDependency -IncludeSelf -Parents + $results = Get-DbaDbTable -SqlInstance $TestConfig.instance1 -Database $dbname -Table dbo.dbatoolsci3 | Get-DbaDependency -IncludeSelf -Parents $results.length | Should -Be 3 $results[0].Dependent | Should -Be "dbatoolsci1" $results[0].Tier | Should -Be -2 @@ -133,7 +133,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { It "Test with a tables that have circular dependencies" { # this causes infinite loop when circular dependencies exist in dependency tree. - $results = Get-DbaDbTable -SqlInstance $script:instance1 -Database $dbname -Table dbo.dbatoolsci_circrefA | Get-DbaDependency + $results = Get-DbaDbTable -SqlInstance $TestConfig.instance1 -Database $dbname -Table dbo.dbatoolsci_circrefA | Get-DbaDependency $results.length | Should -Be 2 $results[0].Dependent | Should -Be "dbatoolsci_circrefB" $results[0].Tier | Should -Be 1 @@ -143,7 +143,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { It "Test with a tables that have circular dependencies and use -IncludeSelf" { # this causes infinite loop when circular dependencies exist in dependency tree. - $results = Get-DbaDbTable -SqlInstance $script:instance1 -Database $dbname -Table dbo.dbatoolsci_circrefA | Get-DbaDependency -IncludeSelf + $results = Get-DbaDbTable -SqlInstance $TestConfig.instance1 -Database $dbname -Table dbo.dbatoolsci_circrefA | Get-DbaDependency -IncludeSelf $results.length | Should -Be 3 $results[0].Dependent | Should -Be "dbatoolsci_circrefA" $results[0].Tier | Should -Be 0 @@ -154,3 +154,4 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } } + diff --git a/tests/Get-DbaDeprecatedFeature.Tests.ps1 b/tests/Get-DbaDeprecatedFeature.Tests.ps1 index 01488382d5..1f12cb36f1 100644 --- a/tests/Get-DbaDeprecatedFeature.Tests.ps1 +++ b/tests/Get-DbaDeprecatedFeature.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,9 +15,9 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Gets Deprecated Features" { - $results = Get-DbaDeprecatedFeature -SqlInstance $script:instance1 + $results = Get-DbaDeprecatedFeature -SqlInstance $TestConfig.instance1 It "Gets results" { $results | Should Not Be $null } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaDiskSpace.Tests.ps1 b/tests/Get-DbaDiskSpace.Tests.ps1 index 8e83581287..a5c4438ae5 100644 --- a/tests/Get-DbaDiskSpace.Tests.ps1 +++ b/tests/Get-DbaDiskSpace.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaDump.Tests.ps1 b/tests/Get-DbaDump.Tests.ps1 index 1889d37378..5141630148 100644 --- a/tests/Get-DbaDump.Tests.ps1 +++ b/tests/Get-DbaDump.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -18,15 +18,15 @@ if (-not $env:appveyor) { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Testing if memory dump is present" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance1 $server.Query("DBCC STACKDUMP") $server.Query("DBCC STACKDUMP") } - $results = Get-DbaDump -SqlInstance $script:instance1 + $results = Get-DbaDump -SqlInstance $TestConfig.instance1 It "finds least one dump" { ($results).Count -ge 1 | Should Be $true } } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaEndpoint.Tests.ps1 b/tests/Get-DbaEndpoint.Tests.ps1 index 718f0afc81..8cf6033901 100644 --- a/tests/Get-DbaEndpoint.Tests.ps1 +++ b/tests/Get-DbaEndpoint.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,13 +15,13 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { It "gets some endpoints" { - $results = Get-DbaEndpoint -SqlInstance $script:instance2 + $results = Get-DbaEndpoint -SqlInstance $TestConfig.instance2 $results.Count | Should -BeGreaterThan 1 $results.Name | Should -Contain 'TSQL Default TCP' } It "gets one endpoint" { - $results = Get-DbaEndpoint -SqlInstance $script:instance2 -Endpoint 'TSQL Default TCP' + $results = Get-DbaEndpoint -SqlInstance $TestConfig.instance2 -Endpoint 'TSQL Default TCP' $results.Name | Should -Be 'TSQL Default TCP' $results.Count | Should -Be 1 } -} \ No newline at end of file +} diff --git a/tests/Get-DbaErrorLog.Tests.ps1 b/tests/Get-DbaErrorLog.Tests.ps1 index eee559ff2e..b6922b8bca 100644 --- a/tests/Get-DbaErrorLog.Tests.ps1 +++ b/tests/Get-DbaErrorLog.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -19,64 +19,64 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $textFilter = "All rights reserved" BeforeAll { $login = 'DaperDan' - $l = Get-DbaLogin -SqlInstance $script:instance1 -Login $login + $l = Get-DbaLogin -SqlInstance $TestConfig.instance1 -Login $login if ($l) { Get-DbaProcess -SqlInstance $instance -Login $login | Stop-DbaProcess $l.Drop() } # (1) Cycle errorlog message: The error log has been reinitialized $sql = "EXEC sp_cycle_errorlog;" - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance1 $null = $server.Query($sql) # (2) Need a login failure, source would be Logon $pwd = "p0w3rsh3llrules" | ConvertTo-SecureString -Force -AsPlainText $sqlCred = New-Object System.Management.Automation.PSCredential($login, $pwd) try { - Connect-DbaInstance -SqlInstance $script:instance1 -SqlCredential $sqlCred -ErrorVariable $whatever + Connect-DbaInstance -SqlInstance $TestConfig.instance1 -SqlCredential $sqlCred -ErrorVariable $whatever } catch {} } It "Has the correct default properties" { $expectedProps = 'ComputerName,InstanceName,SqlInstance,LogDate,Source,Text'.Split(',') - $results = Get-DbaErrorLog -SqlInstance $script:instance1 -LogNumber 0 + $results = Get-DbaErrorLog -SqlInstance $TestConfig.instance1 -LogNumber 0 ($results[0].PSStandardMembers.DefaultDisplayPropertySet.ReferencedPropertyNames | Sort-Object) | Should Be ($expectedProps | Sort-Object) } It "Returns filtered results for [Source = $sourceFilter]" { - $results = Get-DbaErrorLog -SqlInstance $script:instance1 -Source $sourceFilter + $results = Get-DbaErrorLog -SqlInstance $TestConfig.instance1 -Source $sourceFilter $results[0].Source | Should Be $sourceFilter } It "Returns filtered result for [LogNumber = 0] and [Source = $sourceFilter]" { - $results = Get-DbaErrorLog -SqlInstance $script:instance1 -LogNumber 0 -Source $sourceFilter + $results = Get-DbaErrorLog -SqlInstance $TestConfig.instance1 -LogNumber 0 -Source $sourceFilter $results[0].Source | Should Be $sourceFilter } It "Returns filtered results for [Text = $textFilter]" { - $results = Get-DbaErrorLog -SqlInstance $script:instance1 -Text $textFilter + $results = Get-DbaErrorLog -SqlInstance $TestConfig.instance1 -Text $textFilter {$results[0].Text -like "*$textFilter*"} | Should Be $true } It "Returns filtered result for [LogNumber = 0] and [Text = $textFilter]" { - $results = Get-DbaErrorLog -SqlInstance $script:instance1 -LogNumber 0 -Text $textFilter + $results = Get-DbaErrorLog -SqlInstance $TestConfig.instance1 -LogNumber 0 -Text $textFilter {$results[0].Text -like "*$textFilter"} | Should Be $true } - $after = Get-DbaErrorLog -SqlInstance $script:instance1 -LogNumber 1 | Select-Object -First 1 - $before = Get-DbaErrorLog -SqlInstance $script:instance1 -LogNumber 1 | Select-Object -Last 1 + $after = Get-DbaErrorLog -SqlInstance $TestConfig.instance1 -LogNumber 1 | Select-Object -First 1 + $before = Get-DbaErrorLog -SqlInstance $TestConfig.instance1 -LogNumber 1 | Select-Object -Last 1 $afterFilter = $after.LogDate.AddMinutes(+1) It "Returns filtered results for [After = $afterFilter" { - $results = Get-DbaErrorLog -SqlInstance $script:instance1 -After $afterFilter + $results = Get-DbaErrorLog -SqlInstance $TestConfig.instance1 -After $afterFilter {$results[0].LogDate -ge $afterFilter} | Should Be $true } It "Returns filtered results for [LogNumber = 1] and [After = $afterFilter" { - $results = Get-DbaErrorLog -SqlInstance $script:instance1 -LogNumber 1 -After $afterFilter + $results = Get-DbaErrorLog -SqlInstance $TestConfig.instance1 -LogNumber 1 -After $afterFilter {$results[0].LogDate -ge $afterFilter} | Should Be $true } $beforeFilter = $before.LogDate.AddMinutes(-1) It "Returns filtered result for [Before = $beforeFilter]" { - $results = Get-DbaErrorLog -SqlInstance $script:instance1 -Before $beforeFilter + $results = Get-DbaErrorLog -SqlInstance $TestConfig.instance1 -Before $beforeFilter {$results[-1].LogDate -le $beforeFilter} | Should Be $true } It "Returns filtered result for [LogNumber = 1] and [Before = $beforeFilter]" { - $results = Get-DbaErrorLog -SqlInstance $script:instance1 -LogNumber 1 -Before $beforeFilter + $results = Get-DbaErrorLog -SqlInstance $TestConfig.instance1 -LogNumber 1 -Before $beforeFilter {$results[-1].LogDate -le $beforeFilter} | Should Be $true } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaErrorLogConfig.Tests.ps1 b/tests/Get-DbaErrorLogConfig.Tests.ps1 index a53ffb0bbf..0a071e123b 100644 --- a/tests/Get-DbaErrorLogConfig.Tests.ps1 +++ b/tests/Get-DbaErrorLogConfig.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag "UnitTests" { Context "Validate parameters" { @@ -15,7 +15,7 @@ Describe "$CommandName Unit Tests" -Tag "UnitTests" { Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Context "Get NumberErrorLog for multiple instances" { - $results = Get-DbaErrorLogConfig -SqlInstance $script:instance3, $script:instance2 + $results = Get-DbaErrorLogConfig -SqlInstance $TestConfig.instance3, $TestConfig.instance2 foreach ($result in $results) { It 'returns 3 values' { $result.LogCount | Should -Not -Be $null @@ -24,4 +24,4 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaEstimatedCompletionTime.Tests.ps1 b/tests/Get-DbaEstimatedCompletionTime.Tests.ps1 index f152c616c4..fb8ac78d8f 100644 --- a/tests/Get-DbaEstimatedCompletionTime.Tests.ps1 +++ b/tests/Get-DbaEstimatedCompletionTime.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,57 +16,66 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 - $null = Get-DbaDatabase -SqlInstance $server -Database checkdbTestDatabase | Remove-DbaDatabase -Confirm:$false - $null = Restore-DbaDatabase -SqlInstance $server -Path $script:appveyorlabrepo\sql2008-backups\db1\SQL2008_db1_FULL_20170518_041738.bak -DatabaseName checkdbTestDatabase - $null = New-DbaAgentJob -SqlInstance $server -Job checkdbTestJob - $null = New-DbaAgentJobStep -SqlInstance $server -Job checkdbTestJob -StepName checkdb -Subsystem TransactSql -Command "DBCC CHECKDB('checkdbTestDatabase')" + $skip = $true + if ($TestConfig.bigDatabaseBackup) { + try { + if (-not (Test-Path -Path $TestConfig.bigDatabaseBackup) -and $TestConfig.bigDatabaseBackupSourceUrl) { + Invoke-WebRequest -Uri $TestConfig.bigDatabaseBackupSourceUrl -OutFile $TestConfig.bigDatabaseBackup -ErrorAction Stop + } + $null = Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -Path $TestConfig.bigDatabaseBackup -DatabaseName checkdbTestDatabase -WithReplace -ReplaceDbNameInFile -EnableException + $null = New-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job checkdbTestJob -EnableException + $null = New-DbaAgentJobStep -SqlInstance $TestConfig.instance2 -Job checkdbTestJob -StepName checkdb -Subsystem TransactSql -Command "DBCC CHECKDB('checkdbTestDatabase')" -EnableException + $skip = $false + } catch { + Write-Host -Object "Test for $CommandName failed in BeforeAll because: $_" -ForegroundColor Cyan + } + } } AfterAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 - $null = Remove-DbaAgentJob -SqlInstance $server -Job checkdbTestJob -Confirm:$false - $null = Get-DbaDatabase -SqlInstance $erver -Database checkdbTestDatabase | Remove-DbaDatabase -Confirm:$false + $null = Get-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job checkdbTestJob | Remove-DbaAgentJob -Confirm:$false + $null = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database checkdbTestDatabase | Remove-DbaDatabase -Confirm:$false } - Context "Gets Query Estimated Completion" { - $server = Connect-DbaInstance -SqlInstance $script:instance2 - $null = Start-DbaAgentJob -SqlInstance $server -Job checkdbTestJob - $results = Get-DbaEstimatedCompletionTime -SqlInstance $server - $null = Remove-DbaAgentJob -SqlInstance $server -Job checkdb -Confirm:$false - Start-Sleep -Seconds 5 - It "Gets results" { - $results | Should Not Be $null - } - It "Should be SELECT" { - $results.Command | Should Match 'DBCC' - } - It "Should be login dbo" { - $results.login | Should Be 'dbo' - } - } - Context "Gets Query Estimated Completion when using -Database" { - $server = Connect-DbaInstance -SqlInstance $script:instance2 - $null = Start-DbaAgentJob -SqlInstance $server -Job checkdbTestJob - $results = Get-DbaEstimatedCompletionTime -SqlInstance $server -Database checkdbTestDatabase - Start-Sleep -Seconds 5 - It "Gets results" { - $results | Should Not Be $null - } - It "Should be SELECT" { - $results.Command | Should Match 'DBCC' + Context "Gets correct results" { + It -Skip:$skip "Gets Query Estimated Completion" { + $job = Start-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job checkdbTestJob + Start-Sleep -Seconds 1 + $results = Get-DbaEstimatedCompletionTime -SqlInstance $TestConfig.instance2 + while ($job.CurrentRunStatus -eq 'Executing') { + Start-Sleep -Seconds 1 + $job.Refresh() + } + + $results | Should -Not -BeNullOrEmpty + $results.Command | Should -Match 'DBCC' + $results.Database | Should -Be checkdbTestDatabase } - It "Should be login dbo" { - $results.login | Should Be 'dbo' + + It -Skip:$skip "Gets Query Estimated Completion when using -Database" { + $job = Start-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job checkdbTestJob + Start-Sleep -Seconds 1 + $results = Get-DbaEstimatedCompletionTime -SqlInstance $TestConfig.instance2 -Database checkdbTestDatabase + while ($job.CurrentRunStatus -eq 'Executing') { + Start-Sleep -Seconds 1 + $job.Refresh() + } + + $results | Should -Not -BeNullOrEmpty + $results.Command | Should -Match 'DBCC' + $results.Database | Should -Be checkdbTestDatabase } - } - Context "Gets no Query Estimated Completion when using -ExcludeDatabase" { - $server = Connect-DbaInstance -SqlInstance $script:instance2 - $null = Start-DbaAgentJob -SqlInstance $server -Job checkdbTestJob - $results = Get-DbaEstimatedCompletionTime -SqlInstance $server -ExcludeDatabase checkdbTestDatabase - Start-Sleep -Seconds 5 - It "Gets no results" { - $results | Should Be $null + + It -Skip:$skip "Gets no Query Estimated Completion when using -ExcludeDatabase" { + $job = Start-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job checkdbTestJob + Start-Sleep -Seconds 1 + $results = Get-DbaEstimatedCompletionTime -SqlInstance $TestConfig.instance2 -ExcludeDatabase checkdbTestDatabase + while ($job.CurrentRunStatus -eq 'Executing') { + Start-Sleep -Seconds 1 + $job.Refresh() + } + + $results | Should -BeNullOrEmpty } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaExecutionPlan.Tests.ps1 b/tests/Get-DbaExecutionPlan.Tests.ps1 index c3a23e1500..295084c98b 100644 --- a/tests/Get-DbaExecutionPlan.Tests.ps1 +++ b/tests/Get-DbaExecutionPlan.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,13 +16,13 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Gets Execution Plan" { - $results = Get-DbaExecutionPlan -SqlInstance $script:instance2 | Where-Object {$_.statementtype -eq 'SELECT'} | Select-object -First 1 + $results = Get-DbaExecutionPlan -SqlInstance $TestConfig.instance2 | Where-Object {$_.statementtype -eq 'SELECT'} | Select-object -First 1 It "Gets results" { $results | Should Not Be $null } } Context "Gets Execution Plan when using -Database" { - $results = Get-DbaExecutionPlan -SqlInstance $script:instance2 -Database Master | Select-object -First 1 + $results = Get-DbaExecutionPlan -SqlInstance $TestConfig.instance2 -Database Master | Select-object -First 1 It "Gets results" { $results | Should Not Be $null } @@ -31,7 +31,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } Context "Gets no Execution Plan when using -ExcludeDatabase" { - $results = Get-DbaExecutionPlan -SqlInstance $script:instance2 -ExcludeDatabase Master | Select-object -First 1 + $results = Get-DbaExecutionPlan -SqlInstance $TestConfig.instance2 -ExcludeDatabase Master | Select-object -First 1 It "Gets results" { $results | Should Not Be $null } @@ -40,7 +40,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } Context "Gets Execution Plan when using -SinceCreation" { - $results = Get-DbaExecutionPlan -SqlInstance $script:instance2 -Database Master -SinceCreation '01-01-2000' | Select-object -First 1 + $results = Get-DbaExecutionPlan -SqlInstance $TestConfig.instance2 -Database Master -SinceCreation '01-01-2000' | Select-object -First 1 It "Gets results" { $results | Should Not Be $null } @@ -52,7 +52,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } Context "Gets Execution Plan when using -SinceLastExecution" { - $results = Get-DbaExecutionPlan -SqlInstance $script:instance2 -Database Master -SinceLastExecution '01-01-2000' | Select-object -First 1 + $results = Get-DbaExecutionPlan -SqlInstance $TestConfig.instance2 -Database Master -SinceLastExecution '01-01-2000' | Select-object -First 1 It "Gets results" { $results | Should Not Be $null } @@ -64,9 +64,9 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } Context "Gets Execution Plan when using -ExcludeDatabase" { - $results = Get-DbaExecutionPlan -SqlInstance $script:instance2 -ExcludeEmptyQueryPlan + $results = Get-DbaExecutionPlan -SqlInstance $TestConfig.instance2 -ExcludeEmptyQueryPlan It "Gets no results" { $results | Should Not Be $null } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaExtendedProperty.Tests.ps1 b/tests/Get-DbaExtendedProperty.Tests.ps1 index d9fa10d14f..627cfc5df4 100644 --- a/tests/Get-DbaExtendedProperty.Tests.ps1 +++ b/tests/Get-DbaExtendedProperty.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,12 +16,12 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BeforeAll { $random = Get-Random - $server2 = Connect-DbaInstance -SqlInstance $script:instance2 + $server2 = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $null = Get-DbaProcess -SqlInstance $server2 | Where-Object Program -match dbatools | Stop-DbaProcess -Confirm:$false $newDbName = "dbatoolsci_newdb_$random" $db = New-DbaDatabase -SqlInstance $server2 -Name $newDbName $db.Query("EXEC sys.sp_addextendedproperty @name=N'dbatoolz', @value=N'woo'") - #$tempdb = Get-DbaDatabase -SqlInstance $script:instance2 -Database tempdb + #$tempdb = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database tempdb #$tempdb.Query("EXEC sys.sp_addextendedproperty @name=N'temptoolz', @value=N'woo2'") } @@ -47,4 +47,4 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $ep.Name | Should -Be "dbatoolz" } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaExtendedProtection.Tests.ps1 b/tests/Get-DbaExtendedProtection.Tests.ps1 index 0d4fa328d5..efb8f81fa2 100644 --- a/tests/Get-DbaExtendedProtection.Tests.ps1 +++ b/tests/Get-DbaExtendedProtection.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -14,9 +14,9 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { } Describe "$commandname Integration Tests" -Tags "IntegrationTests" { - $results = Get-DbaExtendedProtection $script:instance1 -EnableException + $results = Get-DbaExtendedProtection $TestConfig.instance1 -EnableException It "returns a value" { $results.ExtendedProtection -ne $null } -} \ No newline at end of file +} diff --git a/tests/Get-DbaExternalProcess.Tests.ps1 b/tests/Get-DbaExternalProcess.Tests.ps1 index 6b183472a6..b67ee7c911 100644 --- a/tests/Get-DbaExternalProcess.Tests.ps1 +++ b/tests/Get-DbaExternalProcess.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,7 +16,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Can get an external process" { BeforeAll { - $null = Invoke-DbaQuery -SqlInstance $script:instance1 -Query " + $null = Invoke-DbaQuery -SqlInstance $TestConfig.instance1 -Query " -- To allow advanced options to be changed. EXECUTE sp_configure 'show advanced options', 1; GO @@ -32,7 +32,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $query = @" xp_cmdshell 'powershell -command ""sleep 20""' "@ - Start-Process -FilePath sqlcmd -ArgumentList "-S $script:instance1 -Q `"$query`"" -NoNewWindow -RedirectStandardOutput null + Start-Process -FilePath sqlcmd -ArgumentList "-S $($TestConfig.instance1) -Q `"$query`"" -NoNewWindow -RedirectStandardOutput null } It "returns a process" { @@ -44,3 +44,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } } } + diff --git a/tests/Get-DbaFeature.Tests.ps1 b/tests/Get-DbaFeature.Tests.ps1 index 87da04c29a..05eeb2cc23 100644 --- a/tests/Get-DbaFeature.Tests.ps1 +++ b/tests/Get-DbaFeature.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaFile.Tests.ps1 b/tests/Get-DbaFile.Tests.ps1 index a01420cf24..e5db9a8e58 100644 --- a/tests/Get-DbaFile.Tests.ps1 +++ b/tests/Get-DbaFile.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,29 +16,29 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Returns some files" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $random = Get-Random $db = "dbatoolsci_getfile$random" $server.Query("CREATE DATABASE $db") } AfterAll { - $null = Get-DbaDatabase -SqlInstance $script:instance2 -Database $db | Remove-DbaDatabase -Confirm:$false + $null = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $db | Remove-DbaDatabase -Confirm:$false } - $results = Get-DbaFile -SqlInstance $script:instance2 + $results = Get-DbaFile -SqlInstance $TestConfig.instance2 It "Should find the new database file" { ($results.Filename -match 'dbatoolsci').Count | Should -BeGreaterThan 0 } - $results = Get-DbaFile -SqlInstance $script:instance2 -Path (Get-DbaDefaultPath -SqlInstance $script:instance2).Log + $results = Get-DbaFile -SqlInstance $TestConfig.instance2 -Path (Get-DbaDefaultPath -SqlInstance $TestConfig.instance2).Log It "Should find the new database log file" { ($results.Filename -like '*dbatoolsci*ldf').Count | Should -BeGreaterThan 0 } $masterpath = $server.MasterDBPath - $results = Get-DbaFile -SqlInstance $script:instance2 -Path $masterpath + $results = Get-DbaFile -SqlInstance $TestConfig.instance2 -Path $masterpath It "Should find the master database file" { ($results.Filename -match 'master.mdf').Count | Should -BeGreaterThan 0 } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaFilestream.Tests.ps1 b/tests/Get-DbaFilestream.Tests.ps1 index 10ff9fa6e1..55c4100e7a 100644 --- a/tests/Get-DbaFilestream.Tests.ps1 +++ b/tests/Get-DbaFilestream.Tests.ps1 @@ -3,7 +3,7 @@ #> $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig <# Unit test is required for any command added @@ -21,9 +21,9 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tag "IntegrationTests" { Context "Getting FileStream Level" { - $results = Get-DbaFilestream -SqlInstance $script:instance2 + $results = Get-DbaFilestream -SqlInstance $TestConfig.instance2 It "Should have changed the FileStream Level" { $results.InstanceAccess | Should -BeIn 'Disabled', 'T-SQL access enabled', 'Full access enabled' } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaFirewallRule.Tests.ps1 b/tests/Get-DbaFirewallRule.Tests.ps1 index 88c5fb3714..880a7cd833 100644 --- a/tests/Get-DbaFirewallRule.Tests.ps1 +++ b/tests/Get-DbaFirewallRule.Tests.ps1 @@ -1,6 +1,6 @@ $commandname = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Validate parameters" { diff --git a/tests/Get-DbaForceNetworkEncryption.Tests.ps1 b/tests/Get-DbaForceNetworkEncryption.Tests.ps1 index 3c4ffe0eda..9c7d427ec9 100644 --- a/tests/Get-DbaForceNetworkEncryption.Tests.ps1 +++ b/tests/Get-DbaForceNetworkEncryption.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,10 +15,10 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { if (-not $env:appveyor) { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { - $results = Get-DbaForceNetworkEncryption $script:instance1 -EnableException + $results = Get-DbaForceNetworkEncryption $TestConfig.instance1 -EnableException It "returns true or false" { $results.ForceEncryption -ne $null } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaHelpIndex.Tests.ps1 b/tests/Get-DbaHelpIndex.Tests.ps1 index f642d4954f..b999f30726 100644 --- a/tests/Get-DbaHelpIndex.Tests.ps1 +++ b/tests/Get-DbaHelpIndex.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Write-host -Object "${script:instance2}" -ForegroundColor Cyan Describe "$CommandName Unit Tests" -Tag 'UnitTests' { @@ -15,7 +15,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { } Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $random = Get-Random $dbname = "dbatoolsci_$random" $server.Query("CREATE DATABASE $dbname") @@ -29,10 +29,10 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $server.Query("create nonclustered index idx_1 on t2(c1,c2) include(c3,c4)", $dbname) } AfterAll { - $null = Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbname | Remove-DbaDatabase -Confirm:$false + $null = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname | Remove-DbaDatabase -Confirm:$false } Context "Command works for indexes" { - $results = Get-DbaHelpIndex -SqlInstance $script:instance2 -Database $dbname -ObjectName Test + $results = Get-DbaHelpIndex -SqlInstance $TestConfig.instance2 -Database $dbname -ObjectName Test It 'Results should be returned' { $results | Should Not BeNullOrEmpty } @@ -47,7 +47,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } } Context "Command works when including statistics" { - $results = Get-DbaHelpIndex -SqlInstance $script:instance2 -Database $dbname -ObjectName Test -IncludeStats | Where-Object { $_.Statistics } + $results = Get-DbaHelpIndex -SqlInstance $TestConfig.instance2 -Database $dbname -ObjectName Test -IncludeStats | Where-Object { $_.Statistics } It 'Results should be returned' { $results | Should Not BeNullOrEmpty } @@ -56,7 +56,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } } Context "Command output includes data types" { - $results = Get-DbaHelpIndex -SqlInstance $script:instance2 -Database $dbname -ObjectName Test -IncludeDataTypes + $results = Get-DbaHelpIndex -SqlInstance $TestConfig.instance2 -Database $dbname -ObjectName Test -IncludeDataTypes It 'Results should be returned' { $results | Should Not BeNullOrEmpty } @@ -65,7 +65,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } } Context "Formatting is correct" { - $results = Get-DbaHelpIndex -SqlInstance $script:instance2 -Database $dbname -ObjectName Test -IncludeFragmentation + $results = Get-DbaHelpIndex -SqlInstance $TestConfig.instance2 -Database $dbname -ObjectName Test -IncludeFragmentation It 'Formatted as strings' { $results.IndexReads | Should BeOfType 'String' $results.IndexUpdates | Should BeOfType 'String' @@ -77,7 +77,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } } Context "Formatting is correct for raw" { - $results = Get-DbaHelpIndex -SqlInstance $script:instance2 -Database $dbname -ObjectName Test -raw -IncludeFragmentation + $results = Get-DbaHelpIndex -SqlInstance $TestConfig.instance2 -Database $dbname -ObjectName Test -raw -IncludeFragmentation It 'Formatted as Long' { $results.IndexReads | Should BeOfType 'Long' $results.IndexUpdates | Should BeOfType 'Long' @@ -90,7 +90,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } } Context "Result is correct for tables having the indexes with the same names" { - $results = Get-DbaHelpIndex -SqlInstance $script:instance2 -Database $dbname + $results = Get-DbaHelpIndex -SqlInstance $TestConfig.instance2 -Database $dbname It 'Table t1 has correct index key columns and included columns' { $results.where({ $_.object -eq '[dbo].[t1]' }).KeyColumns | Should -be 'c1' $results.where({ $_.object -eq '[dbo].[t1]' }).IncludeColumns | Should -be 'c3' @@ -101,4 +101,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaHideInstance.Tests.ps1 b/tests/Get-DbaHideInstance.Tests.ps1 index 4b4678db78..babba16ac8 100644 --- a/tests/Get-DbaHideInstance.Tests.ps1 +++ b/tests/Get-DbaHideInstance.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -14,9 +14,9 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { } Describe "$commandname Integration Tests" -Tags "IntegrationTests" { - $results = Get-DbaHideInstance $script:instance1 -EnableException + $results = Get-DbaHideInstance $TestConfig.instance1 -EnableException It "returns true or false" { $results.HideInstance -ne $null } -} \ No newline at end of file +} diff --git a/tests/Get-DbaInstalledPatch.Tests.ps1 b/tests/Get-DbaInstalledPatch.Tests.ps1 index 8147d58b5a..24b3a1b266 100644 --- a/tests/Get-DbaInstalledPatch.Tests.ps1 +++ b/tests/Get-DbaInstalledPatch.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "Get-DbaComputerSystem Unit Tests" -Tag "UnitTests" { Context "Validate parameters" { @@ -14,9 +14,9 @@ Describe "Get-DbaComputerSystem Unit Tests" -Tag "UnitTests" { } Describe "$CommandName Integration Test" -Tag "IntegrationTests" { Context "Validate output" { - $result = Get-DbaInstalledPatch -ComputerName $script:instance1 + $result = Get-DbaInstalledPatch -ComputerName $TestConfig.instance1 It "has some output" { $result | Should -Not -BeNullOrEmpty } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaInstanceAudit.Tests.ps1 b/tests/Get-DbaInstanceAudit.Tests.ps1 index cf25e27d91..eb55246896 100644 --- a/tests/Get-DbaInstanceAudit.Tests.ps1 +++ b/tests/Get-DbaInstanceAudit.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,7 +15,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $sql = "CREATE SERVER AUDIT LoginAudit TO FILE (FILEPATH = N'C:\temp',MAXSIZE = 10 MB,MAX_ROLLOVER_FILES = 1,RESERVE_DISK_SPACE = OFF) WITH (QUEUE_DELAY = 1000, ON_FAILURE = CONTINUE) @@ -35,13 +35,13 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } Context "Verifying command output" { It "returns some results" { - $results = Get-DbaInstanceAudit -SqlInstance $script:instance2 + $results = Get-DbaInstanceAudit -SqlInstance $TestConfig.instance2 $results | Should -Not -Be $null } It "returns some results" { - $results = Get-DbaInstanceAudit -SqlInstance $script:instance2 -Audit LoginAudit + $results = Get-DbaInstanceAudit -SqlInstance $TestConfig.instance2 -Audit LoginAudit $results.Name | Should -Be 'LoginAudit' $results.Enabled | Should -Be $true } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaInstanceAuditSpecification.Tests.ps1 b/tests/Get-DbaInstanceAuditSpecification.Tests.ps1 index 43b16dc2ce..9ffd814b48 100644 --- a/tests/Get-DbaInstanceAuditSpecification.Tests.ps1 +++ b/tests/Get-DbaInstanceAuditSpecification.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaInstanceInstallDate.Tests.ps1 b/tests/Get-DbaInstanceInstallDate.Tests.ps1 index 60e9931270..22416b9b57 100644 --- a/tests/Get-DbaInstanceInstallDate.Tests.ps1 +++ b/tests/Get-DbaInstanceInstallDate.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,15 +16,15 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Gets SQL Server Install Date" { - $results = Get-DbaInstanceInstallDate -SqlInstance $script:instance2 + $results = Get-DbaInstanceInstallDate -SqlInstance $TestConfig.instance2 It "Gets results" { $results | Should Not Be $null } } Context "Gets SQL Server Install Date and Windows Install Date" { - $results = Get-DbaInstanceInstallDate -SqlInstance $script:instance2 -IncludeWindows + $results = Get-DbaInstanceInstallDate -SqlInstance $TestConfig.instance2 -IncludeWindows It "Gets results" { $results | Should Not Be $null } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaInstanceProperty.Tests.ps1 b/tests/Get-DbaInstanceProperty.Tests.ps1 index bdb7cc9de1..678cacc51a 100644 --- a/tests/Get-DbaInstanceProperty.Tests.ps1 +++ b/tests/Get-DbaInstanceProperty.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,7 +15,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Command actually works" { - $results = Get-DbaInstanceProperty -SqlInstance $script:instance2 + $results = Get-DbaInstanceProperty -SqlInstance $TestConfig.instance2 It "Should have correct properties" { $ExpectedProps = 'ComputerName,InstanceName,PropertyType,SqlInstance'.Split(',') (($results | Get-Member -MemberType NoteProperty).name | Sort-Object) | Should Be ($ExpectedProps | Sort-Object) @@ -27,13 +27,13 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { ($results | Where-Object {$_.name -eq 'DisableDefaultConstraintCheck'}).Value | Should Be $False } It "Should get the correct DefaultFile location" { - $defaultFiles = Get-DbaDefaultPath -SqlInstance $script:instance2 + $defaultFiles = Get-DbaDefaultPath -SqlInstance $TestConfig.instance2 ($results | Where-Object {$_.name -eq 'DefaultFile'}).Value | Should BeLike "$($defaultFiles.Data)*" } } Context "Property filters work" { - $resultInclude = Get-DbaInstanceProperty -SqlInstance $script:instance2 -InstanceProperty DefaultFile - $resultExclude = Get-DbaInstanceProperty -SqlInstance $script:instance2 -ExcludeInstanceProperty DefaultFile + $resultInclude = Get-DbaInstanceProperty -SqlInstance $TestConfig.instance2 -InstanceProperty DefaultFile + $resultExclude = Get-DbaInstanceProperty -SqlInstance $TestConfig.instance2 -ExcludeInstanceProperty DefaultFile It "Should only return DefaultFile property" { $resultInclude.Name | Should Contain 'DefaultFile' } @@ -43,7 +43,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } Context "Command can handle multiple instances" { It "Should have results for 2 instances" { - $(Get-DbaInstanceProperty -SqlInstance $script:instance1, $script:instance2 | Select-Object -unique SqlInstance).count | Should Be 2 + $(Get-DbaInstanceProperty -SqlInstance $TestConfig.instance1, $TestConfig.instance2 | Select-Object -unique SqlInstance).count | Should Be 2 } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaInstanceProtocol.Tests.ps1 b/tests/Get-DbaInstanceProtocol.Tests.ps1 index d303ff1250..ad6e8f42d0 100644 --- a/tests/Get-DbaInstanceProtocol.Tests.ps1 +++ b/tests/Get-DbaInstanceProtocol.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,7 +16,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Command actually works" { - $results = Get-DbaInstanceProtocol -ComputerName $script:instance1, $script:instance2 + $results = Get-DbaInstanceProtocol -ComputerName $TestConfig.instance1, $TestConfig.instance2 It "shows some services" { $results.DisplayName | Should Not Be $null @@ -29,4 +29,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaInstanceTrigger.Tests.ps1 b/tests/Get-DbaInstanceTrigger.Tests.ps1 index 226e599424..079c52cea1 100644 --- a/tests/Get-DbaInstanceTrigger.Tests.ps1 +++ b/tests/Get-DbaInstanceTrigger.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,7 +15,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $instance = Connect-DbaInstance -SqlInstance $script:instance2 + $instance = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $trigger1 = "dbatoolsci_trigger1_$random" $trigger2 = "dbatoolsci_trigger2_$random" $sql1 = "CREATE TRIGGER [$trigger1] ON ALL SERVER FOR CREATE_DATABASE AS PRINT 'Database Created.'" @@ -28,7 +28,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $instance.query($sql) } Context "Command actually works" { - $results = Get-DbaInstanceTrigger -SqlInstance $script:instance2 + $results = Get-DbaInstanceTrigger -SqlInstance $TestConfig.instance2 It "Should return results" { $results.Count | Should Be 2 @@ -39,4 +39,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { ($results[0].PsObject.Properties.Name | Sort-Object) | Should Be ($ExpectedProps | Sort-Object) } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaInstanceUserOption.Tests.ps1 b/tests/Get-DbaInstanceUserOption.Tests.ps1 index 22bc6e3703..de1c9f94d6 100644 --- a/tests/Get-DbaInstanceUserOption.Tests.ps1 +++ b/tests/Get-DbaInstanceUserOption.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,7 +16,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Gets UserOptions for the Instance" { - $results = Get-DbaInstanceUserOption -SqlInstance $script:instance2 | Where-Object {$_.name -eq 'AnsiNullDefaultOff'} + $results = Get-DbaInstanceUserOption -SqlInstance $TestConfig.instance2 | Where-Object {$_.name -eq 'AnsiNullDefaultOff'} It "Gets results" { $results | Should Not Be $null } @@ -27,4 +27,4 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $results.Value | Should Be $false } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaIoLatency.Tests.ps1 b/tests/Get-DbaIoLatency.Tests.ps1 index 36f02f5573..04b282af63 100644 --- a/tests/Get-DbaIoLatency.Tests.ps1 +++ b/tests/Get-DbaIoLatency.Tests.ps1 @@ -1,6 +1,6 @@ $commandname = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Validate parameters" { @@ -15,10 +15,10 @@ Describe "$CommandName Unit Tests" -Tags "UnitTests" { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Command returns proper info" { - $results = Get-DbaIoLatency -SqlInstance $script:instance2 + $results = Get-DbaIoLatency -SqlInstance $TestConfig.instance2 It "returns results" { $results.Count -gt 0 | Should Be $true } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaKbUpdate.Tests.ps1 b/tests/Get-DbaKbUpdate.Tests.ps1 index 1fcb17e22d..1f550272a9 100644 --- a/tests/Get-DbaKbUpdate.Tests.ps1 +++ b/tests/Get-DbaKbUpdate.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaLastBackup.Tests.ps1 b/tests/Get-DbaLastBackup.Tests.ps1 index cf1ffb06a8..33c928a973 100644 --- a/tests/Get-DbaLastBackup.Tests.ps1 +++ b/tests/Get-DbaLastBackup.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -14,7 +14,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $random = Get-Random $dbname = "dbatoolsci_getlastbackup$random" $server.Query("CREATE DATABASE $dbname") @@ -26,13 +26,13 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } AfterAll { - $null = Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbname | Remove-DbaDatabase -Confirm:$false + $null = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname | Remove-DbaDatabase -Confirm:$false Remove-Item -Path $backupdir -Recurse -Force -ErrorAction SilentlyContinue } Context "Get null history for database" { It "doesn't have any values for last backups because none exist yet" { - $results = Get-DbaLastBackup -SqlInstance $script:instance2 -Database $dbname + $results = Get-DbaLastBackup -SqlInstance $TestConfig.instance2 -Database $dbname $results.LastFullBackup | Should -BeNullOrEmpty $results.LastDiffBackup | Should -BeNullOrEmpty $results.LastLogBackup | Should -BeNullOrEmpty @@ -42,10 +42,10 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Get last history for single database" { It "returns a date within the proper range" { $yesterday = (Get-Date).AddDays(-1) - $null = Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbname | Backup-DbaDatabase -BackupDirectory $backupdir - $null = Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbname | Backup-DbaDatabase -BackupDirectory $backupdir -Type Differential - $null = Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbname | Backup-DbaDatabase -BackupDirectory $backupdir -Type Log - $results = Get-DbaLastBackup -SqlInstance $script:instance2 -Database $dbname + $null = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname | Backup-DbaDatabase -BackupDirectory $backupdir + $null = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname | Backup-DbaDatabase -BackupDirectory $backupdir -Type Differential + $null = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname | Backup-DbaDatabase -BackupDirectory $backupdir -Type Log + $results = Get-DbaLastBackup -SqlInstance $TestConfig.instance2 -Database $dbname [datetime]$results.LastFullBackup -gt $yesterday | Should -Be $true [datetime]$results.LastDiffBackup -gt $yesterday | Should -Be $true [datetime]$results.LastLogBackup -gt $yesterday | Should -Be $true @@ -54,7 +54,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Get last history for all databases" { It "returns more than 3 databases" { - $results = Get-DbaLastBackup -SqlInstance $script:instance2 + $results = Get-DbaLastBackup -SqlInstance $TestConfig.instance2 $results.count -gt 3 | Should -Be $true $results.Database -contains $dbname | Should -Be $true } @@ -62,18 +62,18 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Get last history for one split database" { It "supports multi-file backups" { - $null = Backup-DbaDatabase -SqlInstance $script:instance2 -Database $dbname -FileCount 4 - $results = Get-DbaLastBackup -SqlInstance $script:instance2 -Database $dbname | Select-Object -First 1 + $null = Backup-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname -FileCount 4 + $results = Get-DbaLastBackup -SqlInstance $TestConfig.instance2 -Database $dbname | Select-Object -First 1 $results.LastFullBackup.GetType().Name | Should -Be "DbaDateTime" } } Context "Filter backups" { It "by 'is_copy_only'" { - $null = Backup-DbaDatabase -SqlInstance $script:instance2 -Database $dbname -BackupDirectory $backupdir -Type Full -CopyOnly - $null = Backup-DbaDatabase -SqlInstance $script:instance2 -Database $dbname -BackupDirectory $backupdir -Type Log -CopyOnly + $null = Backup-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname -BackupDirectory $backupdir -Type Full -CopyOnly + $null = Backup-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname -BackupDirectory $backupdir -Type Log -CopyOnly - $results = Get-DbaLastBackup -SqlInstance $script:instance2 + $results = Get-DbaLastBackup -SqlInstance $TestConfig.instance2 $copyOnlyFullBackup = ($results | Where-Object { $_.Database -eq $dbname -and $_.LastFullBackupIsCopyOnly -eq $true }) $copyOnlyLogBackup = ($results | Where-Object { $_.Database -eq $dbname -and $_.LastLogBackupIsCopyOnly -eq $true }) @@ -81,13 +81,13 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $copyOnlyLogBackup.Database | Should -Be $dbname - $null = Backup-DbaDatabase -SqlInstance $script:instance2 -Database $dbname -BackupDirectory $backupdir -Type Full - $null = Backup-DbaDatabase -SqlInstance $script:instance2 -Database $dbname -BackupDirectory $backupdir -Type Log + $null = Backup-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname -BackupDirectory $backupdir -Type Full + $null = Backup-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname -BackupDirectory $backupdir -Type Log - $results = Get-DbaLastBackup -SqlInstance $script:instance2 -Database $dbname + $results = Get-DbaLastBackup -SqlInstance $TestConfig.instance2 -Database $dbname $results.LastFullBackupIsCopyOnly | Should -Be $false $results.LastLogBackupIsCopyOnly | Should -Be $false } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaLastGoodCheckDb.Tests.ps1 b/tests/Get-DbaLastGoodCheckDb.Tests.ps1 index 8464a5913f..c4f2741297 100644 --- a/tests/Get-DbaLastGoodCheckDb.Tests.ps1 +++ b/tests/Get-DbaLastGoodCheckDb.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,28 +15,28 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance1 -Database master + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance1 -Database master $server.Query("DBCC CHECKDB") $dbname = "dbatoolsci_]_$(Get-Random)" - $db = New-DbaDatabase -SqlInstance $script:instance1 -Name $dbname -Owner sa + $db = New-DbaDatabase -SqlInstance $TestConfig.instance1 -Name $dbname -Owner sa $db.Query("DBCC CHECKDB") } AfterAll { - $null = Remove-DbaDatabase -SqlInstance $script:instance1 -Database $dbname -confirm:$false + $null = Remove-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $dbname -confirm:$false } Context "Command actually works" { - $results = Get-DbaLastGoodCheckDb -SqlInstance $script:instance1 -Database master + $results = Get-DbaLastGoodCheckDb -SqlInstance $TestConfig.instance1 -Database master It "LastGoodCheckDb is a valid date" { $results.LastGoodCheckDb -ne $null | Should Be $true $results.LastGoodCheckDb -is [datetime] | Should Be $true } - $results = Get-DbaLastGoodCheckDb -SqlInstance $script:instance1 -WarningAction SilentlyContinue + $results = Get-DbaLastGoodCheckDb -SqlInstance $TestConfig.instance1 -WarningAction SilentlyContinue It "returns more than 3 results" { ($results).Count -gt 3 | Should Be $true } - $results = Get-DbaLastGoodCheckDb -SqlInstance $script:instance1 -Database $dbname + $results = Get-DbaLastGoodCheckDb -SqlInstance $TestConfig.instance1 -Database $dbname It "LastGoodCheckDb is a valid date for database with embedded ] characters" { $results.LastGoodCheckDb -ne $null | Should Be $true $results.LastGoodCheckDb -is [datetime] | Should Be $true @@ -44,13 +44,13 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } Context "Piping works" { - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance1 $results = $server | Get-DbaLastGoodCheckDb -Database $dbname, master It "LastGoodCheckDb accepts piped input from Connect-DbaInstance" { ($results).Count -eq 2 | Should Be $true } - $db = Get-DbaDatabase -SqlInstance $script:instance1 -Database $dbname, master + $db = Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $dbname, master $results = $db | Get-DbaLastGoodCheckDb It "LastGoodCheckDb accepts piped input from Get-DbaDatabase" { ($results).Count -eq 2 | Should Be $true @@ -58,9 +58,9 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } Context "Doesn't return duplicate results" { - $results = Get-DbaLastGoodCheckDb -SqlInstance $script:instance1, $script:instance2 -Database $dbname + $results = Get-DbaLastGoodCheckDb -SqlInstance $TestConfig.instance1, $TestConfig.instance2 -Database $dbname It "LastGoodCheckDb doesn't return duplicates when multiple servers are passed in" { ($results | Group-Object SqlInstance, Database | Where-Object Count -gt 1) | Should BeNullOrEmpty } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaLatchStatistic.Tests.ps1 b/tests/Get-DbaLatchStatistic.Tests.ps1 index 38f1ba76e9..5edac6b461 100644 --- a/tests/Get-DbaLatchStatistic.Tests.ps1 +++ b/tests/Get-DbaLatchStatistic.Tests.ps1 @@ -1,6 +1,6 @@ $commandname = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Validate parameters" { @@ -15,7 +15,7 @@ Describe "$CommandName Unit Tests" -Tags "UnitTests" { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Command returns proper info" { - $results = Get-DbaLatchStatistic -SqlInstance $script:instance2 -Threshold 100 + $results = Get-DbaLatchStatistic -SqlInstance $TestConfig.instance2 -Threshold 100 It "returns results" { $results | Should -Not -BeNullOrEmpty @@ -27,4 +27,4 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaLinkedServer.Tests.ps1 b/tests/Get-DbaLinkedServer.Tests.ps1 index 978adfeea3..b1adf595f7 100644 --- a/tests/Get-DbaLinkedServer.Tests.ps1 +++ b/tests/Get-DbaLinkedServer.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,22 +15,22 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $null = $server.Query("EXEC master.dbo.sp_addlinkedserver - @server = N'$script:instance3', + @server = N'$($TestConfig.instance3)', @srvproduct=N'SQL Server' ;") } AfterAll { - $null = $server.Query("EXEC master.dbo.sp_dropserver '$script:instance3', 'droplogins'; ") + $null = $server.Query("EXEC master.dbo.sp_dropserver '$($TestConfig.instance3)', 'droplogins'; ") } Context "Gets Linked Servers" { - $results = Get-DbaLinkedServer -SqlInstance $script:instance2 | Where-Object {$_.name -eq "$script:instance3"} + $results = Get-DbaLinkedServer -SqlInstance $TestConfig.instance2 | Where-Object {$_.name -eq "$($TestConfig.instance3)"} It "Gets results" { $results | Should Not Be $null } - It "Should have Remote Server of $script:instance3" { - $results.RemoteServer | Should Be "$script:instance3" + It "Should have Remote Server of $($TestConfig.instance3)" { + $results.RemoteServer | Should Be $TestConfig.instance3 } It "Should have a product name of SQL Server" { $results.productname | Should Be 'SQL Server' @@ -40,12 +40,12 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } Context "Gets Linked Servers using -LinkedServer" { - $results = Get-DbaLinkedServer -SqlInstance $script:instance2 -LinkedServer "$script:instance3" + $results = Get-DbaLinkedServer -SqlInstance $TestConfig.instance2 -LinkedServer $TestConfig.instance3 It "Gets results" { $results | Should Not Be $null } - It "Should have Remote Server of $script:instance3" { - $results.RemoteServer | Should Be "$script:instance3" + It "Should have Remote Server of $($TestConfig.instance3)" { + $results.RemoteServer | Should Be $TestConfig.instance3 } It "Should have a product name of SQL Server" { $results.productname | Should Be 'SQL Server' @@ -55,9 +55,9 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } Context "Gets Linked Servers using -ExcludeLinkedServer" { - $results = Get-DbaLinkedServer -SqlInstance $script:instance2 -ExcludeLinkedServer "$script:instance3" + $results = Get-DbaLinkedServer -SqlInstance $TestConfig.instance2 -ExcludeLinkedServer $TestConfig.instance3 It "Gets results" { $results | Should Be $null } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaLinkedServerLogin.Tests.ps1 b/tests/Get-DbaLinkedServerLogin.Tests.ps1 index 62abe23774..8ef2b88440 100644 --- a/tests/Get-DbaLinkedServerLogin.Tests.ps1 +++ b/tests/Get-DbaLinkedServerLogin.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,8 +16,8 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { BeforeAll { $random = Get-Random - $server2 = Connect-DbaInstance -SqlInstance $script:instance2 - $server3 = Connect-DbaInstance -SqlInstance $script:instance3 + $server2 = Connect-DbaInstance -SqlInstance $TestConfig.instance2 + $server3 = Connect-DbaInstance -SqlInstance $TestConfig.instance3 $securePassword = ConvertTo-SecureString -String 's3cur3P4ssw0rd?' -AsPlainText -Force $localLogin1Name = "dbatoolscli_localLogin1_$random" @@ -110,4 +110,4 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $results.Name | Should -Be $localLogin1Name, $localLogin1Name } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaLocaleSetting.Tests.ps1 b/tests/Get-DbaLocaleSetting.Tests.ps1 index 394c00a7d4..4ecfa9d1fb 100644 --- a/tests/Get-DbaLocaleSetting.Tests.ps1 +++ b/tests/Get-DbaLocaleSetting.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaLogin.Tests.ps1 b/tests/Get-DbaLogin.Tests.ps1 index 60c61e8d2d..e915700f01 100644 --- a/tests/Get-DbaLogin.Tests.ps1 +++ b/tests/Get-DbaLogin.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -19,30 +19,30 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $random = Get-Random $password = ConvertTo-SecureString -String "password1A@" -AsPlainText -Force - New-DbaLogin -SqlInstance $script:instance1 -Login "testlogin1_$random" -Password $password - New-DbaLogin -SqlInstance $script:instance1 -Login "testlogin2_$random" -Password $password + New-DbaLogin -SqlInstance $TestConfig.instance1 -Login "testlogin1_$random" -Password $password + New-DbaLogin -SqlInstance $TestConfig.instance1 -Login "testlogin2_$random" -Password $password } AfterAll { - Remove-DbaLogin -SqlInstance $script:instance1 -Login "testlogin1_$random", "testlogin2_$random" -Confirm:$false -Force + Remove-DbaLogin -SqlInstance $TestConfig.instance1 -Login "testlogin1_$random", "testlogin2_$random" -Confirm:$false -Force } Context "Does sql instance have a SA account" { - $results = Get-DbaLogin -SqlInstance $script:instance1 -Login sa + $results = Get-DbaLogin -SqlInstance $TestConfig.instance1 -Login sa It "Should report that one account named SA exists" { $results.Count | Should Be 1 } } Context "Check that SA account is enabled" { - $results = Get-DbaLogin -SqlInstance $script:instance1 -Login sa + $results = Get-DbaLogin -SqlInstance $TestConfig.instance1 -Login sa It "Should say the SA account is disabled FALSE" { $results.IsDisabled | Should Be "False" } } Context "Check that SA account is SQL Login" { - $results = Get-DbaLogin -SqlInstance $script:instance1 -Login sa -Type SQL -Detailed + $results = Get-DbaLogin -SqlInstance $TestConfig.instance1 -Login sa -Type SQL -Detailed It "Should report that one SQL Login named SA exists" { $results.Count | Should Be 1 } @@ -55,55 +55,55 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Validate params" { It "Multiple logins" { - $results = Get-DbaLogin -SqlInstance $script:instance1 -Login "testlogin1_$random", "testlogin2_$random" -Type SQL + $results = Get-DbaLogin -SqlInstance $TestConfig.instance1 -Login "testlogin1_$random", "testlogin2_$random" -Type SQL $results.Count | Should -Be 2 $results.Name | Should -Contain "testlogin1_$random" $results.Name | Should -Contain "testlogin2_$random" } It "ExcludeLogin" { - $results = Get-DbaLogin -SqlInstance $script:instance1 -ExcludeLogin "testlogin2_$random" -Type SQL + $results = Get-DbaLogin -SqlInstance $TestConfig.instance1 -ExcludeLogin "testlogin2_$random" -Type SQL $results.Name | Should -Not -Contain "testlogin2_$random" $results.Name | Should -Contain "testlogin1_$random" - $results = Get-DbaLogin -SqlInstance $script:instance1 -ExcludeLogin "testlogin1_$random", "testlogin2_$random" -Type SQL + $results = Get-DbaLogin -SqlInstance $TestConfig.instance1 -ExcludeLogin "testlogin1_$random", "testlogin2_$random" -Type SQL $results.Name | Should -Not -Contain "testlogin2_$random" $results.Name | Should -Not -Contain "testlogin1_$random" } It "IncludeFilter" { - $results = Get-DbaLogin -SqlInstance $script:instance1 -IncludeFilter "*$random" -Type SQL + $results = Get-DbaLogin -SqlInstance $TestConfig.instance1 -IncludeFilter "*$random" -Type SQL $results.Count | Should -Be 2 $results.Name | Should -Contain "testlogin1_$random" $results.Name | Should -Contain "testlogin2_$random" } It "ExcludeFilter" { - $results = Get-DbaLogin -SqlInstance $script:instance1 -ExcludeFilter "*$random" -Type SQL + $results = Get-DbaLogin -SqlInstance $TestConfig.instance1 -ExcludeFilter "*$random" -Type SQL $results.Name | Should -Not -Contain "testlogin1_$random" $results.Name | Should -Not -Contain "testlogin2_$random" } It "ExcludeSystemLogin" { - $results = Get-DbaLogin -SqlInstance $script:instance1 -ExcludeSystemLogin -Type SQL + $results = Get-DbaLogin -SqlInstance $TestConfig.instance1 -ExcludeSystemLogin -Type SQL $results.Name | Should -Not -Contain "sa" } It "HasAccess" { - $results = Get-DbaLogin -SqlInstance $script:instance1 -HasAccess -Type SQL + $results = Get-DbaLogin -SqlInstance $TestConfig.instance1 -HasAccess -Type SQL $results.Name | Should -Contain "testlogin1_$random" $results.Name | Should -Contain "testlogin2_$random" } It "Disabled" { - $null = Set-DbaLogin -SqlInstance $script:instance1 -Login "testlogin1_$random" -Disable - $result = Get-DbaLogin -SqlInstance $script:instance1 -Disabled + $null = Set-DbaLogin -SqlInstance $TestConfig.instance1 -Login "testlogin1_$random" -Disable + $result = Get-DbaLogin -SqlInstance $TestConfig.instance1 -Disabled $result.Name | Should -Contain "testlogin1_$random" - $null = Set-DbaLogin -SqlInstance $script:instance1 -Login "testlogin1_$random" -Enable + $null = Set-DbaLogin -SqlInstance $TestConfig.instance1 -Login "testlogin1_$random" -Enable } It "Detailed" { - $results = Get-DbaLogin -SqlInstance $script:instance1 -Detailed -Type SQL + $results = Get-DbaLogin -SqlInstance $TestConfig.instance1 -Detailed -Type SQL $results.Count | Should -BeGreaterOrEqual 2 @@ -118,7 +118,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } It -Skip:$SkipLocalTest "Locked" { - $results = Set-DbaLogin -SqlInstance $script:instance1 -Login "testlogin1_$random" -PasswordPolicyEnforced -EnableException + $results = Set-DbaLogin -SqlInstance $TestConfig.instance1 -Login "testlogin1_$random" -PasswordPolicyEnforced -EnableException $results.PasswordPolicyEnforced | Should -Be $true # simulate a lockout @@ -128,35 +128,35 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { # exceed the lockout count for (($i = 0); $i -le 4; $i++) { try { - Connect-DbaInstance -SqlInstance $script:instance1 -SqlCredential $invalidSqlCredential + Connect-DbaInstance -SqlInstance $TestConfig.instance1 -SqlCredential $invalidSqlCredential } catch { Write-Message -Level Warning -Message "invalid login credentials used on purpose to lock out account" Start-Sleep -s 5 } } - $results = Get-DbaLogin -SqlInstance $script:instance1 -Locked + $results = Get-DbaLogin -SqlInstance $TestConfig.instance1 -Locked $results.Name | Should -Contain "testlogin1_$random" - $results = Get-DbaLogin -SqlInstance $script:instance1 -Login "testlogin1_$random" -Type SQL + $results = Get-DbaLogin -SqlInstance $TestConfig.instance1 -Login "testlogin1_$random" -Type SQL $results.IsLocked | Should -Be $true - $results = Set-DbaLogin -SqlInstance $script:instance1 -Login "testlogin1_$random" -Unlock -Force + $results = Set-DbaLogin -SqlInstance $TestConfig.instance1 -Login "testlogin1_$random" -Unlock -Force $results.IsLocked | Should -Be $false - $results = Get-DbaLogin -SqlInstance $script:instance1 -Locked + $results = Get-DbaLogin -SqlInstance $TestConfig.instance1 -Locked $results.Name | Should -Not -Contain "testlogin1_$random" - $results = Get-DbaLogin -SqlInstance $script:instance1 -Login "testlogin1_$random" -Type SQL + $results = Get-DbaLogin -SqlInstance $TestConfig.instance1 -Login "testlogin1_$random" -Type SQL $results.IsLocked | Should -Be $false } It "MustChangePassword" { - $changeResult = Set-DbaLogin -SqlInstance $script:instance1 -Login "testlogin1_$random" -MustChange -Password $password -PasswordPolicyEnforced -PasswordExpirationEnabled + $changeResult = Set-DbaLogin -SqlInstance $TestConfig.instance1 -Login "testlogin1_$random" -MustChange -Password $password -PasswordPolicyEnforced -PasswordExpirationEnabled $changeResult.MustChangePassword | Should -Be $true - $result = Get-DbaLogin -SqlInstance $script:instance1 -MustChangePassword + $result = Get-DbaLogin -SqlInstance $TestConfig.instance1 -MustChangePassword $result.Name | Should -Contain "testlogin1_$random" } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaMaintenanceSolutionLog.Tests.ps1 b/tests/Get-DbaMaintenanceSolutionLog.Tests.ps1 index bd5a0c2972..da51e6c796 100644 --- a/tests/Get-DbaMaintenanceSolutionLog.Tests.ps1 +++ b/tests/Get-DbaMaintenanceSolutionLog.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaManagementObject.Tests.ps1 b/tests/Get-DbaManagementObject.Tests.ps1 index 766bf2b33e..0aeb52d529 100644 --- a/tests/Get-DbaManagementObject.Tests.ps1 +++ b/tests/Get-DbaManagementObject.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaMaxMemory.Tests.ps1 b/tests/Get-DbaMaxMemory.Tests.ps1 index 5dfa8355be..bb52222ace 100644 --- a/tests/Get-DbaMaxMemory.Tests.ps1 +++ b/tests/Get-DbaMaxMemory.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -66,13 +66,13 @@ Describe "$commandname Unit Test" -Tags Unittest { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Connects to multiple instances" { It 'Returns multiple objects' { - $results = Get-DbaMaxMemory -SqlInstance $script:instance1, $script:instance2 + $results = Get-DbaMaxMemory -SqlInstance $TestConfig.instance1, $TestConfig.instance2 $results.Count | Should BeGreaterThan 1 # and ultimately not throw an exception } It 'Returns the right amount of ' { - $null = Set-DbaMaxMemory -SqlInstance $script:instance1, $script:instance2 -Max 1024 - $results = Get-DbaMaxMemory -SqlInstance $script:instance1 + $null = Set-DbaMaxMemory -SqlInstance $TestConfig.instance1, $TestConfig.instance2 -Max 1024 + $results = Get-DbaMaxMemory -SqlInstance $TestConfig.instance1 $results.MaxValue | Should Be 1024 } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaMemoryCondition.Tests.ps1 b/tests/Get-DbaMemoryCondition.Tests.ps1 index be6c9ee30e..91066b8bb8 100644 --- a/tests/Get-DbaMemoryCondition.Tests.ps1 +++ b/tests/Get-DbaMemoryCondition.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -20,7 +20,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { #> Describe "Get-DbaMemoryCondition Integration Test" -Tag "IntegrationTests" { Context "Command actually works" { - $results = Get-DbaMemoryCondition -SqlInstance $script:instance1 + $results = Get-DbaMemoryCondition -SqlInstance $TestConfig.instance1 It "returns results" { $($results | Measure-Object).Count -gt 0 | Should Be $true @@ -31,4 +31,4 @@ Describe "Get-DbaMemoryCondition Integration Test" -Tag "IntegrationTests" { ($result.PsObject.Properties.Name | Sort-Object) | Should Be ($ExpectedProps | Sort-Object) } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaMemoryUsage.Tests.ps1 b/tests/Get-DbaMemoryUsage.Tests.ps1 index 8be4bccca7..6cbca6268b 100644 --- a/tests/Get-DbaMemoryUsage.Tests.ps1 +++ b/tests/Get-DbaMemoryUsage.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -19,7 +19,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { #> Describe "Get-DbaMemoryUsage Integration Test" -Tag "IntegrationTests" { Context "Command actually works" { - $results = Get-DbaMemoryUsage -ComputerName $script:instance1 + $results = Get-DbaMemoryUsage -ComputerName $TestConfig.instance1 It "returns results" { $results.Count -gt 0 | Should Be $true @@ -30,9 +30,9 @@ Describe "Get-DbaMemoryUsage Integration Test" -Tag "IntegrationTests" { ($result.PsObject.Properties.Name | Sort-Object) | Should Be ($ExpectedProps | Sort-Object) } - $resultsSimple = Get-DbaMemoryUsage -ComputerName $script:instance1 + $resultsSimple = Get-DbaMemoryUsage -ComputerName $TestConfig.instance1 It "returns results" { $resultsSimple.Count -gt 0 | Should Be $true } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaModule.Tests.ps1 b/tests/Get-DbaModule.Tests.ps1 index 663df62008..89d9acf7ff 100644 --- a/tests/Get-DbaModule.Tests.ps1 +++ b/tests/Get-DbaModule.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -18,12 +18,12 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { # SQL2008R2SP2 returns around 600 of these in freshly installed instance. 100 is a good enough number. It "Should have a high count" { - $results = Get-DbaModule -SqlInstance $script:instance1 | Select-Object -First 101 + $results = Get-DbaModule -SqlInstance $TestConfig.instance1 | Select-Object -First 101 $results.Count | Should BeGreaterThan 100 } # SQL2008R2SP2 will return a number of modules from the msdb database so it is a good candidate to test - $results = Get-DbaModule -SqlInstance $script:instance1 -Type View -Database msdb + $results = Get-DbaModule -SqlInstance $TestConfig.instance1 -Type View -Database msdb It "Should only have one type of object" { ($results | Select-Object -Unique Type | Measure-Object).Count | Should Be 1 } @@ -34,7 +34,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } Context "Accepts Piped Input" { - $db = Get-DbaDatabase -SqlInstance $script:instance1 -Database msdb, master + $db = Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database msdb, master # SQL2008R2SP2 returns around 600 of these in freshly installed instance. 100 is a good enough number. $results = $db | Get-DbaModule It "Should have a high count" { @@ -44,7 +44,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { ($results | Select-Object -Unique Database | Measure-Object).Count | Should Be 2 } - $db = Get-DbaDatabase -SqlInstance $script:instance1 -Database msdb + $db = Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database msdb $results = $db | Get-DbaModule -Type View It "Should only have one type of object" { ($results | Select-Object -Unique Type | Measure-Object).Count | Should Be 1 @@ -54,4 +54,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { ($results | Select-Object -Unique Database | Measure-Object).Count | Should Be 1 } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaMsdtc.Tests.ps1 b/tests/Get-DbaMsdtc.Tests.ps1 index 30bd5ed78e..50f9d59fdb 100644 --- a/tests/Get-DbaMsdtc.Tests.ps1 +++ b/tests/Get-DbaMsdtc.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaNetworkActivity.Tests.ps1 b/tests/Get-DbaNetworkActivity.Tests.ps1 index d9b9d45e6c..fc6b1150af 100644 --- a/tests/Get-DbaNetworkActivity.Tests.ps1 +++ b/tests/Get-DbaNetworkActivity.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaNetworkCertificate.Tests.ps1 b/tests/Get-DbaNetworkCertificate.Tests.ps1 index 0cc59ab5b5..230663743f 100644 --- a/tests/Get-DbaNetworkCertificate.Tests.ps1 +++ b/tests/Get-DbaNetworkCertificate.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaNetworkConfiguration.Tests.ps1 b/tests/Get-DbaNetworkConfiguration.Tests.ps1 index 91bec3cdfc..fd0383dff8 100644 --- a/tests/Get-DbaNetworkConfiguration.Tests.ps1 +++ b/tests/Get-DbaNetworkConfiguration.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -14,8 +14,8 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { } Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Command actually works" { - $resultsFull = Get-DbaNetworkConfiguration -SqlInstance $script:instance2 - $resultsTcpIpProperties = Get-DbaNetworkConfiguration -SqlInstance $script:instance2 -OutputType TcpIpProperties + $resultsFull = Get-DbaNetworkConfiguration -SqlInstance $TestConfig.instance2 + $resultsTcpIpProperties = Get-DbaNetworkConfiguration -SqlInstance $TestConfig.instance2 -OutputType TcpIpProperties It "Should Return a Result" { $resultsFull | Should -Not -Be $null @@ -29,4 +29,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { ($resultsTcpIpProperties.PsObject.Properties.Name | Sort-Object) | Should Be ($ExpectedPropsTcpIpProperties | Sort-Object) } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaOleDbProvider.Tests.ps1 b/tests/Get-DbaOleDbProvider.Tests.ps1 index e55193479f..abd1798dcc 100644 --- a/tests/Get-DbaOleDbProvider.Tests.ps1 +++ b/tests/Get-DbaOleDbProvider.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "Get-DbaComputerSystem Unit Tests" -Tag "UnitTests" { Context "Validate parameters" { @@ -14,9 +14,9 @@ Describe "Get-DbaComputerSystem Unit Tests" -Tag "UnitTests" { } Describe "$CommandName Integration Test" -Tag "IntegrationTests" { Context "Validate output" { - $result = Get-DbaOleDbProvider -SqlInstance $script:instance1 + $result = Get-DbaOleDbProvider -SqlInstance $TestConfig.instance1 It "has some output" { $result | Should -Not -BeNullOrEmpty } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaOpenTransaction.Tests.ps1 b/tests/Get-DbaOpenTransaction.Tests.ps1 index b7e2a80da8..bf2b923765 100644 --- a/tests/Get-DbaOpenTransaction.Tests.ps1 +++ b/tests/Get-DbaOpenTransaction.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,6 +15,6 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { It "doesn't throw" { - { Get-DbaOpenTransaction -SqlInstance $script:instance1 } | Should Not Throw + { Get-DbaOpenTransaction -SqlInstance $TestConfig.instance1 } | Should Not Throw } -} \ No newline at end of file +} diff --git a/tests/Get-DbaOperatingSystem.Tests.ps1 b/tests/Get-DbaOperatingSystem.Tests.ps1 index 94bfc97ce1..8d87b52f2f 100644 --- a/tests/Get-DbaOperatingSystem.Tests.ps1 +++ b/tests/Get-DbaOperatingSystem.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -19,7 +19,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { } } Describe "Get-DbaOperatingSystem Integration Test" -Tag "IntegrationTests" { - $result = Get-DbaOperatingSystem -ComputerName $script:instance1 + $result = Get-DbaOperatingSystem -ComputerName $TestConfig.instance1 $props = 'ComputerName', 'Manufacturer', 'Organization', 'Architecture', 'Build', 'Version', 'InstallDate', 'LastBootTime', 'LocalDateTime', @@ -44,4 +44,4 @@ Describe "Get-DbaOperatingSystem Integration Test" -Tag "IntegrationTests" { } } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaPageFileSetting.Tests.ps1 b/tests/Get-DbaPageFileSetting.Tests.ps1 index 3cfc36b8fc..3345ce642a 100644 --- a/tests/Get-DbaPageFileSetting.Tests.ps1 +++ b/tests/Get-DbaPageFileSetting.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaPbmCategory.Tests.ps1 b/tests/Get-DbaPbmCategory.Tests.ps1 index cd02a13453..91db349a45 100644 --- a/tests/Get-DbaPbmCategory.Tests.ps1 +++ b/tests/Get-DbaPbmCategory.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,21 +15,21 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Command actually works" { - $results = Get-DbaPbmCategory -SqlInstance $script:instance2 + $results = Get-DbaPbmCategory -SqlInstance $TestConfig.instance2 it "Gets Results" { $results | Should Not Be $null } } Context "Command actually works using -Category" { - $results = Get-DbaPbmCategory -SqlInstance $script:instance2 -Category 'Availability database errors' + $results = Get-DbaPbmCategory -SqlInstance $TestConfig.instance2 -Category 'Availability database errors' it "Gets Results" { $results | Should Not Be $null } } Context "Command actually works using -ExcludeSystemObject" { - $results = Get-DbaPbmCategory -SqlInstance $script:instance2 -ExcludeSystemObject + $results = Get-DbaPbmCategory -SqlInstance $TestConfig.instance2 -ExcludeSystemObject it "Gets Results" { $results | Should Not Be $null } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaPbmCategorySubscription.Tests.ps1 b/tests/Get-DbaPbmCategorySubscription.Tests.ps1 index e25fc9adc3..f4938dffae 100644 --- a/tests/Get-DbaPbmCategorySubscription.Tests.ps1 +++ b/tests/Get-DbaPbmCategorySubscription.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaPbmCondition.Tests.ps1 b/tests/Get-DbaPbmCondition.Tests.ps1 index d5148e9313..7a3c8e6c23 100644 --- a/tests/Get-DbaPbmCondition.Tests.ps1 +++ b/tests/Get-DbaPbmCondition.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -39,7 +39,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { ', @is_name_condition=1, @obj_name=N'test', @condition_id=@condition_id OUTPUT Select @condition_id as conditionId" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $conditionId = $server.Query($conditionQuery) | Select-Object -expand conditionId } AfterAll { @@ -48,7 +48,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } Context "Command returns results" { - $results = Get-DbaPbmCondition -SqlInstance $script:instance2 + $results = Get-DbaPbmCondition -SqlInstance $TestConfig.instance2 It "Should get results" { $results | Should Not Be $null } @@ -59,7 +59,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } Context "Command actually works by condition name" { - $results = Get-DbaPbmCondition -SqlInstance $script:instance2 -Condition $conditionName + $results = Get-DbaPbmCondition -SqlInstance $TestConfig.instance2 -Condition $conditionName It "Should get results" { $results | Should Not Be $null } @@ -68,4 +68,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $results.Name | Should Be $conditionName } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaPbmObjectSet.Tests.ps1 b/tests/Get-DbaPbmObjectSet.Tests.ps1 index 501b9099d5..3b118b207c 100644 --- a/tests/Get-DbaPbmObjectSet.Tests.ps1 +++ b/tests/Get-DbaPbmObjectSet.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaPbmPolicy.Tests.ps1 b/tests/Get-DbaPbmPolicy.Tests.ps1 index 58841b6fc4..6c1fb7199b 100644 --- a/tests/Get-DbaPbmPolicy.Tests.ps1 +++ b/tests/Get-DbaPbmPolicy.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -47,7 +47,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { EXEC msdb.dbo.sp_syspolicy_add_policy @name=N'dbatoolsci_TestPolicy', @condition_name=N'dbatoolsci_Condition', @policy_category=N'', @description=N'', @help_text=N'', @help_link=N'', @schedule_uid=N'00000000-0000-0000-0000-000000000000', @execution_mode=2, @is_enabled=True, @policy_id=@policy_id OUTPUT, @root_condition_name=N'', @object_set=N'dbatoolsci_TestPolicy_ObjectSet' SELECT @policy_id" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $conditionid = $server.ConnectionContext.ExecuteScalar($sqlconditionid) $objectsetid = $server.ConnectionContext.ExecuteScalar($sqlobjectsetid) $policyid = $server.ConnectionContext.ExecuteScalar($sqlpolicyid) @@ -59,13 +59,13 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $server.Query("EXEC msdb.dbo.sp_syspolicy_delete_condition @condition_id=$conditionid") } - $results = Get-DbaPbmPolicy -SqlInstance $script:instance2 + $results = Get-DbaPbmPolicy -SqlInstance $TestConfig.instance2 It "returns the test policy" { $results.Name -contains 'dbatoolsci_TestPolicy' | Should Be $true } - $results = Get-DbaPbmPolicy -SqlInstance $script:instance2 -Policy dbatoolsci_TestPolicy + $results = Get-DbaPbmPolicy -SqlInstance $TestConfig.instance2 -Policy dbatoolsci_TestPolicy It "returns only the test policy named dbatoolsci_TestPolicy" { $results.Name -eq 'dbatoolsci_TestPolicy' | Should Be $true @@ -75,4 +75,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $results.Condition -eq 'dbatoolsci_Condition' | Should Be $true } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaPbmStore.Tests.ps1 b/tests/Get-DbaPbmStore.Tests.ps1 index 43b16dc2ce..9ffd814b48 100644 --- a/tests/Get-DbaPbmStore.Tests.ps1 +++ b/tests/Get-DbaPbmStore.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaPermission.Tests.ps1 b/tests/Get-DbaPermission.Tests.ps1 index 013455502f..c67d813627 100644 --- a/tests/Get-DbaPermission.Tests.ps1 +++ b/tests/Get-DbaPermission.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,7 +15,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $server = $script:instance1 + $server = $TestConfig.instance1 $random = Get-Random $password = 'MyV3ry$ecur3P@ssw0rd' $securePassword = ConvertTo-SecureString $password -AsPlainText -Force @@ -116,4 +116,4 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaPfAvailableCounter.Tests.ps1 b/tests/Get-DbaPfAvailableCounter.Tests.ps1 index aab3b788c3..dae0b4b774 100644 --- a/tests/Get-DbaPfAvailableCounter.Tests.ps1 +++ b/tests/Get-DbaPfAvailableCounter.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaPfDataCollector.Tests.ps1 b/tests/Get-DbaPfDataCollector.Tests.ps1 index 593d549707..9725a36f81 100644 --- a/tests/Get-DbaPfDataCollector.Tests.ps1 +++ b/tests/Get-DbaPfDataCollector.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaPfDataCollectorCounter.Tests.ps1 b/tests/Get-DbaPfDataCollectorCounter.Tests.ps1 index 8f84c3677f..85c5629bdd 100644 --- a/tests/Get-DbaPfDataCollectorCounter.Tests.ps1 +++ b/tests/Get-DbaPfDataCollectorCounter.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaPfDataCollectorCounterSample.Tests.ps1 b/tests/Get-DbaPfDataCollectorCounterSample.Tests.ps1 index d3fa5dcda6..6988ade708 100644 --- a/tests/Get-DbaPfDataCollectorCounterSample.Tests.ps1 +++ b/tests/Get-DbaPfDataCollectorCounterSample.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaPfDataCollectorSet.Tests.ps1 b/tests/Get-DbaPfDataCollectorSet.Tests.ps1 index 740777acf1..33a94efca4 100644 --- a/tests/Get-DbaPfDataCollectorSet.Tests.ps1 +++ b/tests/Get-DbaPfDataCollectorSet.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaPfDataCollectorSetTemplate.Tests.ps1 b/tests/Get-DbaPfDataCollectorSetTemplate.Tests.ps1 index 07378d25af..dd8366e9b9 100644 --- a/tests/Get-DbaPfDataCollectorSetTemplate.Tests.ps1 +++ b/tests/Get-DbaPfDataCollectorSetTemplate.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaPlanCache.Tests.ps1 b/tests/Get-DbaPlanCache.Tests.ps1 index e5622b8157..681cec80cd 100644 --- a/tests/Get-DbaPlanCache.Tests.ps1 +++ b/tests/Get-DbaPlanCache.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,8 +16,8 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Context "returns proper information" { It "returns correct datatypes" { - $results = Get-DbaPlanCache -SqlInstance $script:instance1 | Clear-DbaPlanCache -Threshold 1024 + $results = Get-DbaPlanCache -SqlInstance $TestConfig.instance1 | Clear-DbaPlanCache -Threshold 1024 $results.Size -is [dbasize] | Should -Be $true } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaPowerPlan.Tests.ps1 b/tests/Get-DbaPowerPlan.Tests.ps1 index c3c4f3db49..effc00cf1c 100644 --- a/tests/Get-DbaPowerPlan.Tests.ps1 +++ b/tests/Get-DbaPowerPlan.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,8 +16,8 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Context "Command actually works" { It "Should return result for the server" { - $results = Get-DbaPowerPlan -ComputerName $script:instance2 + $results = Get-DbaPowerPlan -ComputerName $TestConfig.instance2 $results | Should Not Be Null } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaPrivilege.Tests.ps1 b/tests/Get-DbaPrivilege.Tests.ps1 index 86edc86304..1c929bfd02 100644 --- a/tests/Get-DbaPrivilege.Tests.ps1 +++ b/tests/Get-DbaPrivilege.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaProcess.Tests.ps1 b/tests/Get-DbaProcess.Tests.ps1 index 5c76cb3e5c..345cad22fd 100644 --- a/tests/Get-DbaProcess.Tests.ps1 +++ b/tests/Get-DbaProcess.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,14 +15,14 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Testing Get-DbaProcess results" { - $results = Get-DbaProcess -SqlInstance $script:instance1 + $results = Get-DbaProcess -SqlInstance $TestConfig.instance1 It "matches self as a login at least once" { $matching = $results | Where-Object Login -match $env:username $matching.Length | Should BeGreaterThan 0 } - $results = Get-DbaProcess -SqlInstance $script:instance1 -Program 'dbatools PowerShell module - dbatools.io' + $results = Get-DbaProcess -SqlInstance $TestConfig.instance1 -Program 'dbatools PowerShell module - dbatools.io' foreach ($result in $results) { It "returns only dbatools processes" { @@ -30,7 +30,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } } - $results = Get-DbaProcess -SqlInstance $script:instance1 -Database master + $results = Get-DbaProcess -SqlInstance $TestConfig.instance1 -Database master foreach ($result in $results) { It "returns only processes from master database" { @@ -38,4 +38,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaProductKey.Tests.ps1 b/tests/Get-DbaProductKey.Tests.ps1 index 45d69b1cc8..f00dc9623b 100644 --- a/tests/Get-DbaProductKey.Tests.ps1 +++ b/tests/Get-DbaProductKey.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaQueryExecutionTime.Tests.ps1 b/tests/Get-DbaQueryExecutionTime.Tests.ps1 index ab0b99a170..d9b1689a9e 100644 --- a/tests/Get-DbaQueryExecutionTime.Tests.ps1 +++ b/tests/Get-DbaQueryExecutionTime.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaRandomizedDataset.Tests.ps1 b/tests/Get-DbaRandomizedDataset.Tests.ps1 index 7074ca92da..3a95151191 100644 --- a/tests/Get-DbaRandomizedDataset.Tests.ps1 +++ b/tests/Get-DbaRandomizedDataset.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaRandomizedDatasetTemplate.Tests.ps1 b/tests/Get-DbaRandomizedDatasetTemplate.Tests.ps1 index 40c8ea7f63..1498bf5341 100644 --- a/tests/Get-DbaRandomizedDatasetTemplate.Tests.ps1 +++ b/tests/Get-DbaRandomizedDatasetTemplate.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaRandomizedType.Tests.ps1 b/tests/Get-DbaRandomizedType.Tests.ps1 index 200c0d622f..0650d73227 100644 --- a/tests/Get-DbaRandomizedType.Tests.ps1 +++ b/tests/Get-DbaRandomizedType.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaRandomizedValue.Tests.ps1 b/tests/Get-DbaRandomizedValue.Tests.ps1 index d30ca11498..e0bb4a1ab1 100644 --- a/tests/Get-DbaRandomizedValue.Tests.ps1 +++ b/tests/Get-DbaRandomizedValue.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaRegServer.Tests.ps1 b/tests/Get-DbaRegServer.Tests.ps1 index 38ed054906..f5daf92ce5 100644 --- a/tests/Get-DbaRegServer.Tests.ps1 +++ b/tests/Get-DbaRegServer.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Validate parameters" { @@ -16,7 +16,7 @@ Describe "$CommandName Unit Tests" -Tags "UnitTests" { Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Context "Setup" { BeforeAll { - $server = Connect-DbaInstance $script:instance1 + $server = Connect-DbaInstance $TestConfig.instance1 $regStore = New-Object Microsoft.SqlServer.Management.RegisteredServers.RegisteredServersStore($server.ConnectionContext.SqlConnectionObject) $dbStore = $regStore.DatabaseEngineServerGroup @@ -61,12 +61,12 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $newServer3.Create() } AfterAll { - Get-DbaRegServer -SqlInstance $script:instance1 | Where-Object Name -match dbatoolsci | Remove-DbaRegServer -Confirm:$false - Get-DbaRegServerGroup -SqlInstance $script:instance1 | Where-Object Name -match dbatoolsci | Remove-DbaRegServerGroup -Confirm:$false + Get-DbaRegServer -SqlInstance $TestConfig.instance1 | Where-Object Name -match dbatoolsci | Remove-DbaRegServer -Confirm:$false + Get-DbaRegServerGroup -SqlInstance $TestConfig.instance1 | Where-Object Name -match dbatoolsci | Remove-DbaRegServerGroup -Confirm:$false } It "Should return multiple objects" { - $results = Get-DbaRegServer -SqlInstance $script:instance1 -Group $group + $results = Get-DbaRegServer -SqlInstance $TestConfig.instance1 -Group $group $results.Count | Should Be 2 $results[0].ParentServer | Should -Not -BeNullOrEmpty $results[0].ComputerName | Should -Not -BeNullOrEmpty @@ -78,19 +78,19 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $results[1].SqlInstance | Should -Not -BeNullOrEmpty } It "Should allow searching subgroups" { - $results = Get-DbaRegServer -SqlInstance $script:instance1 -Group "$group\$group2" + $results = Get-DbaRegServer -SqlInstance $TestConfig.instance1 -Group "$group\$group2" $results.Count | Should Be 1 } It "Should return the root server when excluding (see #3529)" { - $results = Get-DbaRegServer -SqlInstance $script:instance1 -ExcludeGroup "$group\$group2" + $results = Get-DbaRegServer -SqlInstance $TestConfig.instance1 -ExcludeGroup "$group\$group2" @($results | Where-Object Name -eq $srvName3).Count | Should -Be 1 } It "Should filter subgroups" { - $results = Get-DbaRegServer -SqlInstance $script:instance1 -Group $group -ExcludeGroup "$group\$group2" + $results = Get-DbaRegServer -SqlInstance $TestConfig.instance1 -Group $group -ExcludeGroup "$group\$group2" $results.Count | Should Be 1 $results.Group | Should Be $group } # Property Comparisons will come later when we have the commands } -} \ No newline at end of file +} diff --git a/tests/Get-DbaRegServerGroup.Tests.ps1 b/tests/Get-DbaRegServerGroup.Tests.ps1 index 7ad932acf0..f5c6b94ae7 100644 --- a/tests/Get-DbaRegServerGroup.Tests.ps1 +++ b/tests/Get-DbaRegServerGroup.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Validate parameters" { @@ -16,7 +16,7 @@ Describe "$CommandName Unit Tests" -Tags "UnitTests" { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Setup" { BeforeAll { - $server = Connect-DbaInstance $script:instance1 + $server = Connect-DbaInstance $TestConfig.instance1 $regStore = New-Object Microsoft.SqlServer.Management.RegisteredServers.RegisteredServersStore($server.ConnectionContext.SqlConnectionObject) $dbStore = $regStore.DatabaseEngineServerGroup @@ -85,34 +85,34 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $subGroupServer.Create() } AfterAll { - Get-DbaRegServer -SqlInstance $script:instance1 | Where-Object Name -Match dbatoolsci | Remove-DbaRegServer -Confirm:$false - Get-DbaRegServerGroup -SqlInstance $script:instance1 | Where-Object Name -Match dbatoolsci | Remove-DbaRegServerGroup -Confirm:$false + Get-DbaRegServer -SqlInstance $TestConfig.instance1 | Where-Object Name -Match dbatoolsci | Remove-DbaRegServer -Confirm:$false + Get-DbaRegServerGroup -SqlInstance $TestConfig.instance1 | Where-Object Name -Match dbatoolsci | Remove-DbaRegServerGroup -Confirm:$false } It "Should return one group" { - $results = Get-DbaRegServerGroup -SqlInstance $script:instance1 -Group $group + $results = Get-DbaRegServerGroup -SqlInstance $TestConfig.instance1 -Group $group $results.Count | Should -Be 1 } It "Should allow searching subgroups" { - $results = Get-DbaRegServerGroup -SqlInstance $script:instance1 -Group "$group\$subGroup" + $results = Get-DbaRegServerGroup -SqlInstance $TestConfig.instance1 -Group "$group\$subGroup" $results.Count | Should -Be 1 } It "Should return two groups" { - $results = Get-DbaRegServerGroup -SqlInstance $script:instance1 -Group @($group, "$group\$subGroup") + $results = Get-DbaRegServerGroup -SqlInstance $TestConfig.instance1 -Group @($group, "$group\$subGroup") $results.Count | Should -Be 2 } It "Verify the ExcludeGroup param is working" { - $results = Get-DbaRegServerGroup -SqlInstance $script:instance1 -Group @($group, $group2) -ExcludeGroup $group + $results = Get-DbaRegServerGroup -SqlInstance $TestConfig.instance1 -Group @($group, $group2) -ExcludeGroup $group $results.Count | Should -Be 1 $results.Name | Should -Be $group2 - $results = Get-DbaRegServerGroup -SqlInstance $script:instance1 -ExcludeGroup $group + $results = Get-DbaRegServerGroup -SqlInstance $TestConfig.instance1 -ExcludeGroup $group $results.Count | Should -Be 2 (($results.Name -contains $group2) -and ($results.Name -contains $group3)) | Should -Be $true } # Property Comparisons will come later when we have the commands } -} \ No newline at end of file +} diff --git a/tests/Get-DbaRegServerStore.Tests.ps1 b/tests/Get-DbaRegServerStore.Tests.ps1 index 512c93b915..b365fcbfeb 100644 --- a/tests/Get-DbaRegServerStore.Tests.ps1 +++ b/tests/Get-DbaRegServerStore.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Validate parameters" { @@ -16,9 +16,9 @@ Describe "$CommandName Unit Tests" -Tags "UnitTests" { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Components are properly retreived" { It "Should return the right values" { - $results = Get-DbaRegServerStore -SqlInstance $script:instance2 + $results = Get-DbaRegServerStore -SqlInstance $TestConfig.instance2 $results.InstanceName | Should -Not -Be $null $results.DisplayName | Should -Be "Central Management Servers" } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaRegistryRoot.Tests.ps1 b/tests/Get-DbaRegistryRoot.Tests.ps1 index 8ff79268f0..1ab5c3c4f2 100644 --- a/tests/Get-DbaRegistryRoot.Tests.ps1 +++ b/tests/Get-DbaRegistryRoot.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaReplArticle.Tests.ps1 b/tests/Get-DbaReplArticle.Tests.ps1 index 11bdb49fd2..d403aa862d 100644 --- a/tests/Get-DbaReplArticle.Tests.ps1 +++ b/tests/Get-DbaReplArticle.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Add-ReplicationLibrary diff --git a/tests/Get-DbaReplArticleColumn.Tests.ps1 b/tests/Get-DbaReplArticleColumn.Tests.ps1 index 3a5f07cf69..5313ffb31f 100644 --- a/tests/Get-DbaReplArticleColumn.Tests.ps1 +++ b/tests/Get-DbaReplArticleColumn.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Add-ReplicationLibrary diff --git a/tests/Get-DbaReplDistributor.Tests.ps1 b/tests/Get-DbaReplDistributor.Tests.ps1 index dded7c7e9d..ad61c770a3 100644 --- a/tests/Get-DbaReplDistributor.Tests.ps1 +++ b/tests/Get-DbaReplDistributor.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,9 +15,9 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "ensuring accuracy of results" { - $results = Get-DbaReplDistributor -SqlInstance $script:instance1 + $results = Get-DbaReplDistributor -SqlInstance $TestConfig.instance1 It "accurately reports that the distributor is not installed" { $results.DistributorInstalled | Should Be $false } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaReplPublication.Tests.ps1 b/tests/Get-DbaReplPublication.Tests.ps1 index fc06284fa7..330d2852b9 100644 --- a/tests/Get-DbaReplPublication.Tests.ps1 +++ b/tests/Get-DbaReplPublication.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$commandname Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaReplPublisher.Tests.ps1 b/tests/Get-DbaReplPublisher.Tests.ps1 index dde5fa4f51..5ff1410789 100644 --- a/tests/Get-DbaReplPublisher.Tests.ps1 +++ b/tests/Get-DbaReplPublisher.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Add-ReplicationLibrary diff --git a/tests/Get-DbaReplServer.Tests.ps1 b/tests/Get-DbaReplServer.Tests.ps1 index 43b16dc2ce..9ffd814b48 100644 --- a/tests/Get-DbaReplServer.Tests.ps1 +++ b/tests/Get-DbaReplServer.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaReplSubscription.Tests.ps1 b/tests/Get-DbaReplSubscription.Tests.ps1 index bee78c532f..f3565c3975 100644 --- a/tests/Get-DbaReplSubscription.Tests.ps1 +++ b/tests/Get-DbaReplSubscription.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Add-ReplicationLibrary diff --git a/tests/Get-DbaResourceGovernor.Tests.ps1 b/tests/Get-DbaResourceGovernor.Tests.ps1 index 43b16dc2ce..9ffd814b48 100644 --- a/tests/Get-DbaResourceGovernor.Tests.ps1 +++ b/tests/Get-DbaResourceGovernor.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaRgClassifierFunction.Tests.ps1 b/tests/Get-DbaRgClassifierFunction.Tests.ps1 index 68ea723eb0..7bd218c451 100644 --- a/tests/Get-DbaRgClassifierFunction.Tests.ps1 +++ b/tests/Get-DbaRgClassifierFunction.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -23,18 +23,18 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { RETURN N'gOffHoursProcessing' END" - Invoke-DbaQuery -SqlInstance $script:instance2 -Query $sql - Invoke-DbaQuery -SqlInstance $script:instance2 -Query "ALTER RESOURCE GOVERNOR with (CLASSIFIER_FUNCTION = dbo.dbatoolsci_fnRG); ALTER RESOURCE GOVERNOR RECONFIGURE" + Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Query $sql + Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Query "ALTER RESOURCE GOVERNOR with (CLASSIFIER_FUNCTION = dbo.dbatoolsci_fnRG); ALTER RESOURCE GOVERNOR RECONFIGURE" } AfterAll { - Invoke-DbaQuery -SqlInstance $script:instance2 -Query "ALTER RESOURCE GOVERNOR WITH (CLASSIFIER_FUNCTION = NULL); ALTER RESOURCE GOVERNOR RECONFIGURE" - Invoke-DbaQuery -SqlInstance $script:instance2 -Query "DROP FUNCTION [dbo].[dbatoolsci_fnRG]" + Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Query "ALTER RESOURCE GOVERNOR WITH (CLASSIFIER_FUNCTION = NULL); ALTER RESOURCE GOVERNOR RECONFIGURE" + Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Query "DROP FUNCTION [dbo].[dbatoolsci_fnRG]" } Context "Command works" { It "returns the proper classifier function" { - $results = Get-DbaRgClassifierFunction -SqlInstance $script:instance2 + $results = Get-DbaRgClassifierFunction -SqlInstance $TestConfig.instance2 $results.Name | Should -Be 'dbatoolsci_fnRG' } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaRgResourcePool.Tests.ps1 b/tests/Get-DbaRgResourcePool.Tests.ps1 index 9ca33e5ef9..cd86ecdf27 100644 --- a/tests/Get-DbaRgResourcePool.Tests.ps1 +++ b/tests/Get-DbaRgResourcePool.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,15 +15,15 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Command actually works" { - $results = Get-DbaRgResourcePool -SqlInstance $script:instance2 + $results = Get-DbaRgResourcePool -SqlInstance $TestConfig.instance2 it "Gets Results" { $results | Should Not Be $null } } Context "Command actually works using -Type" { - $results = Get-DbaRgResourcePool -SqlInstance $script:instance2 -Type Internal + $results = Get-DbaRgResourcePool -SqlInstance $TestConfig.instance2 -Type Internal it "Gets Results" { $results | Should Not Be $null } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaRgWorkloadGroup.Tests.ps1 b/tests/Get-DbaRgWorkloadGroup.Tests.ps1 index e25fc9adc3..f4938dffae 100644 --- a/tests/Get-DbaRgWorkloadGroup.Tests.ps1 +++ b/tests/Get-DbaRgWorkloadGroup.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaRunningJob.Tests.ps1 b/tests/Get-DbaRunningJob.Tests.ps1 index 84a33bb1dd..1ba578890c 100644 --- a/tests/Get-DbaRunningJob.Tests.ps1 +++ b/tests/Get-DbaRunningJob.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaSchemaChangeHistory.Tests.ps1 b/tests/Get-DbaSchemaChangeHistory.Tests.ps1 index 38de23948a..d2e65d6bc7 100644 --- a/tests/Get-DbaSchemaChangeHistory.Tests.ps1 +++ b/tests/Get-DbaSchemaChangeHistory.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,7 +16,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Testing if schema changes are discovered" { BeforeAll { - $db = Get-DbaDatabase -SqlInstance $script:instance1 -Database tempdb + $db = Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database tempdb $db.Query("CREATE TABLE dbatoolsci_schemachange (id int identity)") $db.Query("EXEC sp_rename 'dbatoolsci_schemachange', 'dbatoolsci_schemachange1'") } @@ -24,10 +24,10 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $db.Query("DROP TABLE dbo.dbatoolsci_schemachange1") } - $results = Get-DbaSchemaChangeHistory -SqlInstance $script:instance1 -Database tempdb + $results = Get-DbaSchemaChangeHistory -SqlInstance $TestConfig.instance1 -Database tempdb It "notices dbatoolsci_schemachange changed" { $results.Object -match 'dbatoolsci_schemachange' | Should Be $true } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaServerRole.Tests.ps1 b/tests/Get-DbaServerRole.Tests.ps1 index f35b16eead..eac82a5151 100644 --- a/tests/Get-DbaServerRole.Tests.ps1 +++ b/tests/Get-DbaServerRole.Tests.ps1 @@ -3,7 +3,7 @@ #> $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig <# Unit test is required for any command added @@ -21,26 +21,26 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Command actually works" { - $results = Get-DbaServerRole -SqlInstance $script:instance2 + $results = Get-DbaServerRole -SqlInstance $TestConfig.instance2 It "Should have correct properties" { $ExpectedProps = 'ComputerName,DatabaseEngineEdition,DatabaseEngineType,DateCreated,DateModified,Events,ExecutionManager,ID,InstanceName,IsFixedRole,Login,Name,Owner,Parent,ParentCollection,Properties,Role,ServerRole,ServerVersion,SqlInstance,State,Urn,UserData'.Split(',') ($results[0].PsObject.Properties.Name | Sort-Object) | Should Be ($ExpectedProps | Sort-Object) } It "Shows only one value with ServerRole parameter" { - $results = Get-DbaServerRole -SqlInstance $script:instance2 -ServerRole sysadmin + $results = Get-DbaServerRole -SqlInstance $TestConfig.instance2 -ServerRole sysadmin $results[0].Role | Should Be "sysadmin" } It "Should exclude sysadmin from output" { - $results = Get-DbaServerRole -SqlInstance $script:instance2 -ExcludeServerRole sysadmin + $results = Get-DbaServerRole -SqlInstance $TestConfig.instance2 -ExcludeServerRole sysadmin 'sysadmin' -NotIn $results.Role | Should Be $true } It "Should exclude fixed server-level roles" { - $results = Get-DbaServerRole -SqlInstance $script:instance2 -ExcludeFixedRole + $results = Get-DbaServerRole -SqlInstance $TestConfig.instance2 -ExcludeFixedRole 'sysadmin' -NotIn $results.Role | Should Be $true } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaServerRoleMember.Tests.ps1 b/tests/Get-DbaServerRoleMember.Tests.ps1 index 0f35bd6178..6703a702c1 100644 --- a/tests/Get-DbaServerRoleMember.Tests.ps1 +++ b/tests/Get-DbaServerRoleMember.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Validate parameters" { @@ -15,14 +15,14 @@ Describe "$CommandName Unit Tests" -Tags "UnitTests" { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $server2 = Connect-DbaInstance -SqlInstance $script:instance2 + $server2 = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $password1 = ConvertTo-SecureString 'password1' -AsPlainText -Force $testLogin = 'getDbaInstanceRoleMemberLogin' $null = New-DbaLogin -SqlInstance $server2 -Login $testLogin -Password $password1 $null = Set-DbaLogin -SqlInstance $server2 -Login $testLogin -AddRole 'dbcreator' - $server1 = Connect-DbaInstance -SqlInstance $script:instance1 + $server1 = Connect-DbaInstance -SqlInstance $TestConfig.instance1 $null = New-DbaLogin -SqlInstance $server1 -Login $testLogin -Password $password1 $null = Set-DbaLogin -SqlInstance $server1 -Login $testLogin -AddRole 'dbcreator' } @@ -76,4 +76,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Remove-DbaLogin -SqlInstance $server2 -Login $testLogin -Force -Confirm:$false Remove-DbaLogin -SqlInstance $server1 -Login $testLogin -Force -Confirm:$false } -} \ No newline at end of file +} diff --git a/tests/Get-DbaService.Tests.ps1 b/tests/Get-DbaService.Tests.ps1 index cbc811c09c..0ff4eab8d1 100644 --- a/tests/Get-DbaService.Tests.ps1 +++ b/tests/Get-DbaService.Tests.ps1 @@ -1,6 +1,6 @@ $commandname = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -23,15 +23,15 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Command actually works" { - $instanceName = (Connect-DbaInstance -SqlInstance $script:instance2).ServiceName + $instanceName = (Connect-DbaInstance -SqlInstance $TestConfig.instance2).ServiceName - $results = Get-DbaService -ComputerName $script:instance2 + $results = Get-DbaService -ComputerName $TestConfig.instance2 It "shows some services" { $results.DisplayName | Should Not Be $null } - $results = Get-DbaService -ComputerName $script:instance2 -Type Agent + $results = Get-DbaService -ComputerName $TestConfig.instance2 -Type Agent It "shows only one service type" { foreach ($result in $results) { @@ -39,7 +39,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } - $results = Get-DbaService -ComputerName $script:instance2 -InstanceName $instanceName -Type Agent -AdvancedProperties + $results = Get-DbaService -ComputerName $TestConfig.instance2 -InstanceName $instanceName -Type Agent -AdvancedProperties It "shows a service from a specific instance" { $results.ServiceType| Should Be "Agent" @@ -49,25 +49,25 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $results.Clustered | Should Not Be $null } - $service = Get-DbaService -ComputerName $script:instance2 -Type Agent -InstanceName $instanceName + $service = Get-DbaService -ComputerName $TestConfig.instance2 -Type Agent -InstanceName $instanceName It "sets startup mode of the service to 'Manual'" { { $service.ChangeStartMode('Manual') } | Should Not Throw } - $results = Get-DbaService -ComputerName $script:instance2 -Type Agent -InstanceName $instanceName + $results = Get-DbaService -ComputerName $TestConfig.instance2 -Type Agent -InstanceName $instanceName It "verifies that startup mode of the service is 'Manual'" { $results.StartMode | Should Be 'Manual' } - $service = Get-DbaService -ComputerName $script:instance2 -Type Agent -InstanceName $instanceName + $service = Get-DbaService -ComputerName $TestConfig.instance2 -Type Agent -InstanceName $instanceName It "sets startup mode of the service to 'Automatic'" { { $service.ChangeStartMode('Automatic') } | Should Not Throw } - $results = Get-DbaService -ComputerName $script:instance2 -Type Agent -InstanceName $instanceName + $results = Get-DbaService -ComputerName $TestConfig.instance2 -Type Agent -InstanceName $instanceName It "verifies that startup mode of the service is 'Automatic'" { $results.StartMode | Should Be 'Automatic' @@ -75,10 +75,10 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } Context "Command actually works with SqlInstance" { $results = @( ) - $results += Get-DbaService -SqlInstance $script:instance2 -Type Engine + $results += Get-DbaService -SqlInstance $TestConfig.instance2 -Type Engine It "shows exactly one service" { $results.Count | Should Be 1 } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaSpConfigure.Tests.ps1 b/tests/Get-DbaSpConfigure.Tests.ps1 index 35f93d8d69..88ed48116a 100644 --- a/tests/Get-DbaSpConfigure.Tests.ps1 +++ b/tests/Get-DbaSpConfigure.Tests.ps1 @@ -1,6 +1,6 @@ $commandname = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,29 +15,29 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Get configuration" { - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance1 $configs = $server.Query("sp_configure") $remotequerytimeout = $configs | Where-Object name -match 'remote query timeout' It "returns equal to results of the straight T-SQL query" { - $results = Get-DbaSpConfigure -SqlInstance $script:instance1 + $results = Get-DbaSpConfigure -SqlInstance $TestConfig.instance1 $results.count -eq $configs.count } It "returns two results" { - $results = Get-DbaSpConfigure -SqlInstance $script:instance1 -Name RemoteQueryTimeout, AllowUpdates + $results = Get-DbaSpConfigure -SqlInstance $TestConfig.instance1 -Name RemoteQueryTimeout, AllowUpdates $results.Count | Should Be 2 } It "returns two results less than all data" { - $results = Get-DbaSpConfigure -SqlInstance $script:instance1 -ExcludeName "remote query timeout (s)", AllowUpdates + $results = Get-DbaSpConfigure -SqlInstance $TestConfig.instance1 -ExcludeName "remote query timeout (s)", AllowUpdates $results.Count -eq $configs.count - 2 } It "matches the output of sp_configure " { - $results = Get-DbaSpConfigure -SqlInstance $script:instance1 -Name RemoteQueryTimeout + $results = Get-DbaSpConfigure -SqlInstance $TestConfig.instance1 -Name RemoteQueryTimeout $results.ConfiguredValue -eq $remotequerytimeout.config_value | Should Be $true $results.RunningValue -eq $remotequerytimeout.run_value | Should Be $true } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaSpinLockStatistic.Tests.ps1 b/tests/Get-DbaSpinLockStatistic.Tests.ps1 index 1ce9c92be1..e276011f2c 100644 --- a/tests/Get-DbaSpinLockStatistic.Tests.ps1 +++ b/tests/Get-DbaSpinLockStatistic.Tests.ps1 @@ -1,6 +1,6 @@ $commandname = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Validate parameters" { @@ -15,10 +15,10 @@ Describe "$CommandName Unit Tests" -Tags "UnitTests" { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Command returns proper info" { - $results = Get-DbaSpinLockStatistic -SqlInstance $script:instance2 + $results = Get-DbaSpinLockStatistic -SqlInstance $TestConfig.instance2 It "returns results" { $results.Count -gt 0 | Should Be $true } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaSpn.Tests.ps1 b/tests/Get-DbaSpn.Tests.ps1 index 10aab1a8bb..80462cd0a8 100644 --- a/tests/Get-DbaSpn.Tests.ps1 +++ b/tests/Get-DbaSpn.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaSsisEnvironmentVariable.Tests.ps1 b/tests/Get-DbaSsisEnvironmentVariable.Tests.ps1 index be039b5bcb..c378c430d6 100644 --- a/tests/Get-DbaSsisEnvironmentVariable.Tests.ps1 +++ b/tests/Get-DbaSsisEnvironmentVariable.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaSsisExecutionHistory.Tests.ps1 b/tests/Get-DbaSsisExecutionHistory.Tests.ps1 index 48fa36bd2e..34ed920a70 100644 --- a/tests/Get-DbaSsisExecutionHistory.Tests.ps1 +++ b/tests/Get-DbaSsisExecutionHistory.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaStartupParameter.Tests.ps1 b/tests/Get-DbaStartupParameter.Tests.ps1 index e2b52a3ceb..e7a3fcedf0 100644 --- a/tests/Get-DbaStartupParameter.Tests.ps1 +++ b/tests/Get-DbaStartupParameter.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,9 +15,9 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Command actually works" { - $results = Get-DbaStartupParameter -SqlInstance $script:instance2 + $results = Get-DbaStartupParameter -SqlInstance $TestConfig.instance2 it "Gets Results" { $results | Should Not Be $null } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaStartupProcedure.Tests.ps1 b/tests/Get-DbaStartupProcedure.Tests.ps1 index dd1c1b56b7..54c75c69fc 100644 --- a/tests/Get-DbaStartupProcedure.Tests.ps1 +++ b/tests/Get-DbaStartupProcedure.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -14,7 +14,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { } Describe "$commandname Integration Test" -Tag "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $random = Get-Random $startupProc = "dbo.StartUpProc$random" $dbname = 'master' @@ -27,7 +27,7 @@ Describe "$commandname Integration Test" -Tag "IntegrationTests" { } Context "Validate returns correct output" { - $result = Get-DbaStartupProcedure -SqlInstance $script:instance2 + $result = Get-DbaStartupProcedure -SqlInstance $TestConfig.instance2 It "returns correct results" { $result.Schema -eq 'dbo' | Should Be $true $result.Name -eq "StartUpProc$random" | Should Be $true @@ -35,7 +35,7 @@ Describe "$commandname Integration Test" -Tag "IntegrationTests" { } Context "Validate returns correct output for StartupProcedure parameter " { - $result = Get-DbaStartupProcedure -SqlInstance $script:instance2 -StartupProcedure $startupProc + $result = Get-DbaStartupProcedure -SqlInstance $TestConfig.instance2 -StartupProcedure $startupProc It "returns correct results" { $result.Schema -eq 'dbo' | Should Be $true $result.Name -eq "StartUpProc$random" | Should Be $true @@ -43,9 +43,9 @@ Describe "$commandname Integration Test" -Tag "IntegrationTests" { } Context "Validate returns correct output for incorrect StartupProcedure parameter " { - $result = Get-DbaStartupProcedure -SqlInstance $script:instance2 -StartupProcedure 'Not.Here' + $result = Get-DbaStartupProcedure -SqlInstance $TestConfig.instance2 -StartupProcedure 'Not.Here' It "returns correct results" { $null -eq $result | Should Be $true } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaSuspectPage.Tests.ps1 b/tests/Get-DbaSuspectPage.Tests.ps1 index 528d1a11d9..a652d5e9c1 100644 --- a/tests/Get-DbaSuspectPage.Tests.ps1 +++ b/tests/Get-DbaSuspectPage.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -17,7 +17,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Testing if suspect pages are present" { BeforeAll { $dbname = "dbatoolsci_GetSuspectPage" - $Server = Connect-DbaInstance -SqlInstance $script:instance2 + $Server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $null = $Server.Query("Create Database [$dbname]") $db = Get-DbaDatabase -SqlInstance $Server -Database $dbname } @@ -33,14 +33,14 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { # make darn sure suspect pages show up, run twice try { - $null = Invoke-DbaDbCorruption -SqlInstance $script:instance2 -Database $dbname -Confirm:$false + $null = Invoke-DbaDbCorruption -SqlInstance $TestConfig.instance2 -Database $dbname -Confirm:$false $null = $db.Query("select top 100 from example") $null = $server.Query("ALTER DATABASE $dbname SET PAGE_VERIFY CHECKSUM WITH NO_WAIT") $null = Start-DbccCheck -Server $Server -dbname $dbname -WarningAction SilentlyContinue } catch {} # should fail try { - $null = Invoke-DbaDbCorruption -SqlInstance $script:instance2 -Database $dbname -Confirm:$false + $null = Invoke-DbaDbCorruption -SqlInstance $TestConfig.instance2 -Database $dbname -Confirm:$false $null = $db.Query("select top 100 from example") $null = $server.Query("ALTER DATABASE $dbname SET PAGE_VERIFY CHECKSUM WITH NO_WAIT") $null = Start-DbccCheck -Server $Server -dbname $dbname -WarningAction SilentlyContinue @@ -51,4 +51,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $results.Database -contains $dbname | Should Be $true } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaTcpPort.Tests.ps1 b/tests/Get-DbaTcpPort.Tests.ps1 index 7e22e6a667..c4468d1fc1 100644 --- a/tests/Get-DbaTcpPort.Tests.ps1 +++ b/tests/Get-DbaTcpPort.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -14,9 +14,9 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { } Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Command actually works" { - $results = Get-DbaTcpPort -SqlInstance $script:instance2 - $resultsIpv6 = Get-DbaTcpPort -SqlInstance $script:instance2 -All -ExcludeIpv6 - $resultsAll = Get-DbaTcpPort -SqlInstance $script:instance2 -All + $results = Get-DbaTcpPort -SqlInstance $TestConfig.instance2 + $resultsIpv6 = Get-DbaTcpPort -SqlInstance $TestConfig.instance2 -All -ExcludeIpv6 + $resultsAll = Get-DbaTcpPort -SqlInstance $TestConfig.instance2 -All It "Should Return a Result" { $results | Should -Not -Be $null @@ -36,4 +36,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $resultsAll.Count - $resultsIpv6.Count | Should -BeGreaterThan 0 } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaTempdbUsage.Tests.ps1 b/tests/Get-DbaTempdbUsage.Tests.ps1 index 43b16dc2ce..9ffd814b48 100644 --- a/tests/Get-DbaTempdbUsage.Tests.ps1 +++ b/tests/Get-DbaTempdbUsage.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaTopResourceUsage.Tests.ps1 b/tests/Get-DbaTopResourceUsage.Tests.ps1 index 79a61b5627..590ddfbc7e 100644 --- a/tests/Get-DbaTopResourceUsage.Tests.ps1 +++ b/tests/Get-DbaTopResourceUsage.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -14,8 +14,8 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { } Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { - $results = Get-DbaTopResourceUsage -SqlInstance $instances -Type Duration -Database master - $resultsExcluded = Get-DbaTopResourceUsage -SqlInstance $instances -Type Duration -ExcludeDatabase master + $results = Get-DbaTopResourceUsage -SqlInstance $TestConfig.instances -Type Duration -Database master + $resultsExcluded = Get-DbaTopResourceUsage -SqlInstance $TestConfig.instances -Type Duration -ExcludeDatabase master Context "Command returns proper info" { It "returns results" { $results.Count -gt 0 | Should Be $true diff --git a/tests/Get-DbaTrace.Tests.ps1 b/tests/Get-DbaTrace.Tests.ps1 index 4c9e464cb1..59b8e29636 100644 --- a/tests/Get-DbaTrace.Tests.ps1 +++ b/tests/Get-DbaTrace.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,10 +15,10 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $traceconfig = Get-DbaSpConfigure -SqlInstance $script:instance2 -ConfigName DefaultTraceEnabled + $traceconfig = Get-DbaSpConfigure -SqlInstance $TestConfig.instance2 -ConfigName DefaultTraceEnabled if ($traceconfig.RunningValue -eq $false) { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $server.Query("EXEC sp_configure 'show advanced options', 1;") $server.Query("RECONFIGURE WITH OVERRIDE") $server.Query("EXEC sp_configure 'default trace enabled', 1;") @@ -36,13 +36,13 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $server.Query("RECONFIGURE WITH OVERRIDE") $server.Query("EXEC sp_configure 'show advanced options', 0;") $server.Query("RECONFIGURE WITH OVERRIDE") - #$null = Set-DbaSpConfigure -SqlInstance $script:instance2 -ConfigName DefaultTraceEnabled -Value $false + #$null = Set-DbaSpConfigure -SqlInstance $TestConfig.instance2 -ConfigName DefaultTraceEnabled -Value $false } } Context "Test Check Default Trace" { - $results = Get-DbaTrace -SqlInstance $script:instance2 + $results = Get-DbaTrace -SqlInstance $TestConfig.instance2 It "Should find at least one trace file" { $results.Id.Count -gt 0 | Should Be $true } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaTraceFlag.Tests.ps1 b/tests/Get-DbaTraceFlag.Tests.ps1 index 05a698ef16..a38342ec38 100644 --- a/tests/Get-DbaTraceFlag.Tests.ps1 +++ b/tests/Get-DbaTraceFlag.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,7 +16,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Verifying TraceFlag output" { BeforeAll { $safetraceflag = 3226 - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $startingtfs = $server.Query("DBCC TRACESTATUS(-1)") $startingtfscount = $startingtfs.Count @@ -33,17 +33,17 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { It "Has the right default properties" { $expectedProps = 'ComputerName,InstanceName,SqlInstance,TraceFlag,Global,Status'.Split(',') - $results = Get-DbaTraceFlag -SqlInstance $script:instance2 + $results = Get-DbaTraceFlag -SqlInstance $TestConfig.instance2 ($results[0].PSStandardMembers.DefaultDisplayPropertySet.ReferencedPropertyNames | Sort-Object) | Should Be ($expectedProps | Sort-Object) } It "Returns filtered results" { - $results = Get-DbaTraceFlag -SqlInstance $script:instance2 -TraceFlag $safetraceflag + $results = Get-DbaTraceFlag -SqlInstance $TestConfig.instance2 -TraceFlag $safetraceflag $results.TraceFlag.Count | Should Be 1 } It "Returns following number of TFs: $startingtfscount" { - $results = Get-DbaTraceFlag -SqlInstance $script:instance2 + $results = Get-DbaTraceFlag -SqlInstance $TestConfig.instance2 $results.TraceFlag.Count | Should Be $startingtfscount } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaUpTime.Tests.ps1 b/tests/Get-DbaUpTime.Tests.ps1 index e8e96bc625..9ee60afb0b 100644 --- a/tests/Get-DbaUpTime.Tests.ps1 +++ b/tests/Get-DbaUpTime.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,14 +15,14 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Command actually works" { - $results = Get-DbaUptime -SqlInstance $script:instance1 + $results = Get-DbaUptime -SqlInstance $TestConfig.instance1 It "Should have correct properties" { $ExpectedProps = 'ComputerName,InstanceName,SqlServer,SqlUptime,WindowsUptime,SqlStartTime,WindowsBootTime,SinceSqlStart,SinceWindowsBoot'.Split(',') ($results.PsObject.Properties.Name | Sort-Object) | Should Be ($ExpectedProps | Sort-Object) } } Context "Command can handle multiple SqlInstances" { - $results = Get-DbaUptime -SqlInstance $script:instance1, $script:instance2 + $results = Get-DbaUptime -SqlInstance $TestConfig.instance1, $TestConfig.instance2 It "Command resultset could contain 2 results" { $results.count | Should Be 2 } @@ -33,7 +33,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } } Context "Properties should return expected types" { - $results = Get-DbaUptime -SqlInstance $script:instance1 + $results = Get-DbaUptime -SqlInstance $TestConfig.instance1 foreach ($result in $results) { It "SqlStartTime should be a DbaDateTime" { $result.SqlStartTime | Should BeOfType DbaDateTime @@ -43,4 +43,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaUserPermission.Tests.ps1 b/tests/Get-DbaUserPermission.Tests.ps1 index d538a993a4..9bdd0d7b82 100644 --- a/tests/Get-DbaUserPermission.Tests.ps1 +++ b/tests/Get-DbaUserPermission.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -24,12 +24,12 @@ exec sp_addrolemember 'userrole','alice'; exec sp_addrolemember 'userrole','bob'; '@ - $db = New-DbaDatabase -SqlInstance $script:instance1 -Name $dbName + $db = New-DbaDatabase -SqlInstance $TestConfig.instance1 -Name $dbName $db.ExecuteNonQuery($sql) - $results = Get-DbaUserPermission -SqlInstance $script:instance1 -Database $dbName + $results = Get-DbaUserPermission -SqlInstance $TestConfig.instance1 -Database $dbName - $null = Remove-DbaDatabase -SqlInstance $script:instance1 -Database $dbName -Confirm:$false + $null = Remove-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $dbName -Confirm:$false It "returns results" { $results.Count -gt 0 | Should Be $true @@ -51,9 +51,9 @@ exec sp_addrolemember 'userrole','bob'; $dbName = "dbatoolsci_UserPermissionDiffCollation" $dbCollation = "Latin1_General_CI_AI" - $null = New-DbaDatabase -SqlInstance $script:instance1 -Name $dbName -Collation $dbCollation + $null = New-DbaDatabase -SqlInstance $TestConfig.instance1 -Name $dbName -Collation $dbCollation - $results = Get-DbaUserPermission -SqlInstance $script:instance1 -Database $dbName -WarningVariable warnvar 3> $null + $results = Get-DbaUserPermission -SqlInstance $TestConfig.instance1 -Database $dbName -WarningVariable warnvar 3> $null It "Should not warn about collation conflict" { $warnvar | Should -Be $null } @@ -61,6 +61,6 @@ exec sp_addrolemember 'userrole','bob'; $results.Count -gt 0 | Should Be $true } - $null = Remove-DbaDatabase -SqlInstance $script:instance1 -Database $dbName -Confirm:$false + $null = Remove-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $dbName -Confirm:$false } -} \ No newline at end of file +} diff --git a/tests/Get-DbaWaitResource.Tests.ps1 b/tests/Get-DbaWaitResource.Tests.ps1 index ae38834963..489003df71 100644 --- a/tests/Get-DbaWaitResource.Tests.ps1 +++ b/tests/Get-DbaWaitResource.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -18,7 +18,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $random = Get-Random $WaitResourceDB = "WaitResource$random" - Restore-DbaDatabase -SqlInstance $script:instance1 -DatabaseName $WaitResourceDB -ReplaceDbNameInFile -Path $script:appveyorlabrepo\singlerestore\singlerestore.bak + Restore-DbaDatabase -SqlInstance $TestConfig.instance1 -DatabaseName $WaitResourceDB -ReplaceDbNameInFile -Path "$($TestConfig.appveyorlabrepo)\singlerestore\singlerestore.bak" $sql = " create table waittest ( col1 int, @@ -29,10 +29,10 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { go " - Invoke-DbaQuery -SqlInstance $script:instance1 -Database $WaitResourceDB -Query $sql + Invoke-DbaQuery -SqlInstance $TestConfig.instance1 -Database $WaitResourceDB -Query $sql } AfterAll { - Get-DbaDatabase -SqlInstance $script:instance1 -Database $WaitResourceDB | Remove-DbaDatabase -Confirm:$false + Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $WaitResourceDB | Remove-DbaDatabase -Confirm:$false } @@ -62,9 +62,9 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { select @pageid=PagePid from #TmpIndex where PageType=10 select 'PAGE: '+convert(varchar(3),DB_ID())+':1:'+convert(varchar(15),@pageid) " - $page = (Invoke-DbaQuery -SqlInstance $script:instance1 -Database $WaitResourceDB -Query $Pagesql).Column1 - $file = Get-DbaDbFile -SqlInstance $script:instance1 -Database $WaitResourceDB | Where-Object TypeDescription -eq 'ROWS' - $results = Get-DbaWaitResource -SqlInstance $script:instance1 -WaitResource $page + $page = (Invoke-DbaQuery -SqlInstance $TestConfig.instance1 -Database $WaitResourceDB -Query $Pagesql).Column1 + $file = Get-DbaDbFile -SqlInstance $TestConfig.instance1 -Database $WaitResourceDB | Where-Object TypeDescription -eq 'ROWS' + $results = Get-DbaWaitResource -SqlInstance $TestConfig.instance1 -WaitResource $page It "Should return databasename $WaitResourceDB" { $results.DatabaseName | Should Be $WaitResourceDB } @@ -99,8 +99,8 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { select 'KEY: '+convert(varchar(3),db_id())+':'+convert(varchar(30),@hobt_id)+' '+ %%lockres%% from keytest where col1=1 " - $key = (Invoke-DbaQuery -SqlInstance $script:instance1 -Database $WaitResourceDB -Query $SqlKey).Column1 - $resultskey = Get-DbaWaitResource -SqlInstance $script:instance1 -WaitResource $key -row + $key = (Invoke-DbaQuery -SqlInstance $TestConfig.instance1 -Database $WaitResourceDB -Query $SqlKey).Column1 + $resultskey = Get-DbaWaitResource -SqlInstance $TestConfig.instance1 -WaitResource $key -row It "Should Return DatabaseName $WaitResourceDB" { $results } @@ -123,4 +123,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $resultskey.ObjectData.col2 | Should Be 'bilbo' } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaWaitStatistic.Tests.ps1 b/tests/Get-DbaWaitStatistic.Tests.ps1 index 196e8dc262..b7b38075f5 100644 --- a/tests/Get-DbaWaitStatistic.Tests.ps1 +++ b/tests/Get-DbaWaitStatistic.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,7 +15,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Command returns proper info" { - $results = Get-DbaWaitStatistic -SqlInstance $script:instance2 -Threshold 100 + $results = Get-DbaWaitStatistic -SqlInstance $TestConfig.instance2 -Threshold 100 It "returns results" { $results.Count -gt 0 | Should Be $true @@ -30,7 +30,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Command returns proper info when using parameter IncludeIgnorable" { $ignoredWaits = 'REQUEST_FOR_DEADLOCK_SEARCH', 'SLEEP_MASTERDBREADY', 'SLEEP_TASK', 'LAZYWRITER_SLEEP' - $results = Get-DbaWaitStatistic -SqlInstance $script:instance2 -Threshold 100 -IncludeIgnorable | Where-Object { + $results = Get-DbaWaitStatistic -SqlInstance $TestConfig.instance2 -Threshold 100 -IncludeIgnorable | Where-Object { $ignoredWaits -contains $_.WaitType } @@ -48,4 +48,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaWaitingTask.Tests.ps1 b/tests/Get-DbaWaitingTask.Tests.ps1 index 7690c24c81..0fb4024dfa 100644 --- a/tests/Get-DbaWaitingTask.Tests.ps1 +++ b/tests/Get-DbaWaitingTask.Tests.ps1 @@ -3,7 +3,7 @@ #> $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig <# Unit test is required for any command added @@ -32,7 +32,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $flag = "dbatools_$(Get-Random)" $time = '00:15:00' $sql = "SELECT '$flag'; WAITFOR DELAY '$time'" - $instance = $script:instance2 + $instance = $TestConfig.instance2 $modulePath = 'C:\Github\dbatools\dbatools.psm1' $job = 'YouHaveBeenFoundWaiting' @@ -76,4 +76,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } Get-Job -Name $job | Remove-Job -Force -ErrorAction SilentlyContinue } -} \ No newline at end of file +} diff --git a/tests/Get-DbaWindowsLog.Tests.ps1 b/tests/Get-DbaWindowsLog.Tests.ps1 index dc4f1cdeaa..de55919d2e 100644 --- a/tests/Get-DbaWindowsLog.Tests.ps1 +++ b/tests/Get-DbaWindowsLog.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,10 +15,10 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Command returns proper info" { - $results = Get-DbaWindowsLog -SqlInstance $script:instance2 + $results = Get-DbaWindowsLog -SqlInstance $TestConfig.instance2 It "returns results" { $results.Count -gt 0 | Should Be $true } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaWsfcAvailableDisk.Tests.ps1 b/tests/Get-DbaWsfcAvailableDisk.Tests.ps1 index 85c098d12b..722c2924fb 100644 --- a/tests/Get-DbaWsfcAvailableDisk.Tests.ps1 +++ b/tests/Get-DbaWsfcAvailableDisk.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaWsfcCluster.Tests.ps1 b/tests/Get-DbaWsfcCluster.Tests.ps1 index 85c098d12b..722c2924fb 100644 --- a/tests/Get-DbaWsfcCluster.Tests.ps1 +++ b/tests/Get-DbaWsfcCluster.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaWsfcDisk.Tests.ps1 b/tests/Get-DbaWsfcDisk.Tests.ps1 index 85c098d12b..722c2924fb 100644 --- a/tests/Get-DbaWsfcDisk.Tests.ps1 +++ b/tests/Get-DbaWsfcDisk.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaWsfcNetwork.Tests.ps1 b/tests/Get-DbaWsfcNetwork.Tests.ps1 index 85c098d12b..722c2924fb 100644 --- a/tests/Get-DbaWsfcNetwork.Tests.ps1 +++ b/tests/Get-DbaWsfcNetwork.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaWsfcNetworkInterface.Tests.ps1 b/tests/Get-DbaWsfcNetworkInterface.Tests.ps1 index 85c098d12b..722c2924fb 100644 --- a/tests/Get-DbaWsfcNetworkInterface.Tests.ps1 +++ b/tests/Get-DbaWsfcNetworkInterface.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaWsfcNode.Tests.ps1 b/tests/Get-DbaWsfcNode.Tests.ps1 index 85c098d12b..722c2924fb 100644 --- a/tests/Get-DbaWsfcNode.Tests.ps1 +++ b/tests/Get-DbaWsfcNode.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaWsfcResource.Tests.ps1 b/tests/Get-DbaWsfcResource.Tests.ps1 index 85c098d12b..722c2924fb 100644 --- a/tests/Get-DbaWsfcResource.Tests.ps1 +++ b/tests/Get-DbaWsfcResource.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaWsfcResourceGroup.Tests.ps1 b/tests/Get-DbaWsfcResourceGroup.Tests.ps1 index 91c69f1b10..832bd3f516 100644 --- a/tests/Get-DbaWsfcResourceGroup.Tests.ps1 +++ b/tests/Get-DbaWsfcResourceGroup.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaWsfcResourceType.Tests.ps1 b/tests/Get-DbaWsfcResourceType.Tests.ps1 index 85c098d12b..722c2924fb 100644 --- a/tests/Get-DbaWsfcResourceType.Tests.ps1 +++ b/tests/Get-DbaWsfcResourceType.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaWsfcRole.Tests.ps1 b/tests/Get-DbaWsfcRole.Tests.ps1 index 85c098d12b..722c2924fb 100644 --- a/tests/Get-DbaWsfcRole.Tests.ps1 +++ b/tests/Get-DbaWsfcRole.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaWsfcSharedVolume.Tests.ps1 b/tests/Get-DbaWsfcSharedVolume.Tests.ps1 index 85c098d12b..722c2924fb 100644 --- a/tests/Get-DbaWsfcSharedVolume.Tests.ps1 +++ b/tests/Get-DbaWsfcSharedVolume.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaXEObject.Tests.ps1 b/tests/Get-DbaXEObject.Tests.ps1 index aaed250e70..ee16856a41 100644 --- a/tests/Get-DbaXEObject.Tests.ps1 +++ b/tests/Get-DbaXEObject.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaXESession.Tests.ps1 b/tests/Get-DbaXESession.Tests.ps1 index a36fb8ed31..31445a7cd4 100644 --- a/tests/Get-DbaXESession.Tests.ps1 +++ b/tests/Get-DbaXESession.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,13 +16,13 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Verifying command output" { It "returns some results" { - $results = Get-DbaXESession -SqlInstance $script:instance2 + $results = Get-DbaXESession -SqlInstance $TestConfig.instance2 $results.Count -gt 1 | Should Be $true } It "returns only the system_health session" { - $results = Get-DbaXESession -SqlInstance $script:instance2 -Session system_health + $results = Get-DbaXESession -SqlInstance $TestConfig.instance2 -Session system_health $results.Name -eq 'system_health' | Should Be $true } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaXESessionTarget.Tests.ps1 b/tests/Get-DbaXESessionTarget.Tests.ps1 index 4ef49d7a3f..c52aae924f 100644 --- a/tests/Get-DbaXESessionTarget.Tests.ps1 +++ b/tests/Get-DbaXESessionTarget.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -17,15 +17,15 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Verifying command output" { It "returns only the system_health session" { - $results = Get-DbaXESessionTarget -SqlInstance $script:instance2 -Target package0.event_file + $results = Get-DbaXESessionTarget -SqlInstance $TestConfig.instance2 -Target package0.event_file foreach ($result in $results) { $result.Name -eq 'package0.event_file' | Should Be $true } } It "supports the pipeline" { - $results = Get-DbaXESession -SqlInstance $script:instance2 -Session system_health | Get-DbaXESessionTarget -Target package0.event_file + $results = Get-DbaXESession -SqlInstance $TestConfig.instance2 -Session system_health | Get-DbaXESessionTarget -Target package0.event_file $results.Count -gt 0 | Should Be $true } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaXESessionTargetFile.Tests.ps1 b/tests/Get-DbaXESessionTargetFile.Tests.ps1 index 3594f19e35..57197a8b3f 100644 --- a/tests/Get-DbaXESessionTargetFile.Tests.ps1 +++ b/tests/Get-DbaXESessionTargetFile.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig #Loading this function is needed since it is currently not in the manifest . "$PSScriptRoot\..\public\Get-DbaXESessionTargetFile.ps1" diff --git a/tests/Get-DbaXESessionTemplate.Tests.ps1 b/tests/Get-DbaXESessionTemplate.Tests.ps1 index 9a683eeda2..4e66733292 100644 --- a/tests/Get-DbaXESessionTemplate.Tests.ps1 +++ b/tests/Get-DbaXESessionTemplate.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaXESmartTarget.Tests.ps1 b/tests/Get-DbaXESmartTarget.Tests.ps1 index 15d96ac866..34e08142c1 100644 --- a/tests/Get-DbaXESmartTarget.Tests.ps1 +++ b/tests/Get-DbaXESmartTarget.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbaXEStore.Tests.ps1 b/tests/Get-DbaXEStore.Tests.ps1 index 43b16dc2ce..9ffd814b48 100644 --- a/tests/Get-DbaXEStore.Tests.ps1 +++ b/tests/Get-DbaXEStore.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbatoolsChangeLog.Tests.ps1 b/tests/Get-DbatoolsChangeLog.Tests.ps1 index 7c69b05e39..b73e1a12a0 100644 --- a/tests/Get-DbatoolsChangeLog.Tests.ps1 +++ b/tests/Get-DbatoolsChangeLog.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbatoolsConfig.Tests.ps1 b/tests/Get-DbatoolsConfig.Tests.ps1 index ede17ebaa3..d20c5f025f 100644 --- a/tests/Get-DbatoolsConfig.Tests.ps1 +++ b/tests/Get-DbatoolsConfig.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbatoolsConfigValue.Tests.ps1 b/tests/Get-DbatoolsConfigValue.Tests.ps1 index 31398bcfc8..1e9d6904b0 100644 --- a/tests/Get-DbatoolsConfigValue.Tests.ps1 +++ b/tests/Get-DbatoolsConfigValue.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbatoolsError.Tests.ps1 b/tests/Get-DbatoolsError.Tests.ps1 index 87105f1194..165a822460 100644 --- a/tests/Get-DbatoolsError.Tests.ps1 +++ b/tests/Get-DbatoolsError.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbatoolsLog.Tests.ps1 b/tests/Get-DbatoolsLog.Tests.ps1 index 97295eb3cc..ee7e54bdaa 100644 --- a/tests/Get-DbatoolsLog.Tests.ps1 +++ b/tests/Get-DbatoolsLog.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DbatoolsPath.Tests.ps1 b/tests/Get-DbatoolsPath.Tests.ps1 index a94dd36f96..aedbe47d24 100644 --- a/tests/Get-DbatoolsPath.Tests.ps1 +++ b/tests/Get-DbatoolsPath.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Get-DirectoryRestoreFile.Tests.ps1 b/tests/Get-DirectoryRestoreFile.Tests.ps1 index f9d77a6f23..755daffc22 100644 --- a/tests/Get-DirectoryRestoreFile.Tests.ps1 +++ b/tests/Get-DirectoryRestoreFile.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig . "$PSScriptRoot\..\private\functions\Get-DirectoryRestoreFile.ps1" Describe "$CommandName Unit Tests" -Tag 'UnitTests' { diff --git a/tests/Get-ObjectNameParts.Tests.ps1 b/tests/Get-ObjectNameParts.Tests.ps1 index 03b1ae6a4f..ee7b52cd14 100644 --- a/tests/Get-ObjectNameParts.Tests.ps1 +++ b/tests/Get-ObjectNameParts.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig . "$PSScriptRoot\..\private\functions\Get-DirectoryRestoreFile.ps1" Describe "$CommandName Unit Tests" -Tag 'UnitTests' { diff --git a/tests/Get-SqlDefaultSpConfigure.Tests.ps1 b/tests/Get-SqlDefaultSpConfigure.Tests.ps1 index d84e9bfa09..7c8011cded 100644 --- a/tests/Get-SqlDefaultSpConfigure.Tests.ps1 +++ b/tests/Get-SqlDefaultSpConfigure.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig . "$PSScriptRoot\..\private\functions\Get-SqlDefaultSPConfigure.ps1" Describe "$CommandName Unit Tests" -Tag 'UnitTests' { diff --git a/tests/Get-XpDirTreeRestoreFile.Tests.ps1 b/tests/Get-XpDirTreeRestoreFile.Tests.ps1 index 5411649eed..dfc75d735d 100644 --- a/tests/Get-XpDirTreeRestoreFile.Tests.ps1 +++ b/tests/Get-XpDirTreeRestoreFile.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$commandname Unit Tests" -Tag 'UnitTests' { InModuleScope dbatools { diff --git a/tests/Grant-DbaAgPermission.Tests.ps1 b/tests/Grant-DbaAgPermission.Tests.ps1 index 582563d620..14aaddf3d7 100644 --- a/tests/Grant-DbaAgPermission.Tests.ps1 +++ b/tests/Grant-DbaAgPermission.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,17 +15,17 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $null = Invoke-DbaQuery -SqlInstance $script:instance3 -InputFile $script:appveyorlabrepo\sql2008-scripts\logins.sql -ErrorAction SilentlyContinue + $null = Invoke-DbaQuery -SqlInstance $TestConfig.instance3 -InputFile "$($TestConfig.appveyorlabrepo)\sql2008-scripts\logins.sql" -ErrorAction SilentlyContinue $agname = "dbatoolsci_ag_grant" - $null = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Confirm:$false -Certificate dbatoolsci_AGCert + $null = New-DbaAvailabilityGroup -Primary $TestConfig.instance3 -Name $agname -ClusterType None -FailoverMode Manual -Confirm:$false -Certificate dbatoolsci_AGCert } AfterAll { - $null = Remove-DbaAvailabilityGroup -SqlInstance $script:instance3 -AvailabilityGroup $agname -Confirm:$false + $null = Remove-DbaAvailabilityGroup -SqlInstance $TestConfig.instance3 -AvailabilityGroup $agname -Confirm:$false } Context "grants big perms" { It "returns results with proper data" { - $results = Get-DbaLogin -SqlInstance $script:instance3 -Login tester | Grant-DbaAgPermission -Type EndPoint + $results = Get-DbaLogin -SqlInstance $TestConfig.instance3 -Login tester | Grant-DbaAgPermission -Type EndPoint $results.Status | Should -Be 'Success' } } -} #$script:instance2 for appveyor \ No newline at end of file +} #$TestConfig.instance2 for appveyor diff --git a/tests/Import-DbaBinaryFile.Tests.ps1 b/tests/Import-DbaBinaryFile.Tests.ps1 index 36965c2711..c035bb9c49 100644 --- a/tests/Import-DbaBinaryFile.Tests.ps1 +++ b/tests/Import-DbaBinaryFile.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,7 +15,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $db = Get-DbaDatabase -SqlInstance $script:instance2 -Database tempdb + $db = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database tempdb $null = $db.Query("CREATE TABLE [dbo].[BunchOFiles]([FileName123] [nvarchar](50) NULL, [TheFile123] [image] NULL)") } AfterAll { @@ -27,19 +27,19 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } It "imports files into table data" { - $results = Import-DbaBinaryFile -SqlInstance $script:instance2 -Database tempdb -Table BunchOFiles -FilePath $script:appveyorlabrepo\azure\adalsql.msi -WarningAction Continue -ErrorAction Stop -EnableException + $results = Import-DbaBinaryFile -SqlInstance $TestConfig.instance2 -Database tempdb -Table BunchOFiles -FilePath "$($TestConfig.appveyorlabrepo)\azure\adalsql.msi" -WarningAction Continue -ErrorAction Stop -EnableException $results.Database | Should -Be "tempdb" $results.FilePath | Should -match "adalsql.msi" } It "imports files into table data from piped" { - $results = Get-ChildItem -Path $script:appveyorlabrepo\certificates | Import-DbaBinaryFile -SqlInstance $script:instance2 -Database tempdb -Table BunchOFiles -WarningAction Continue -ErrorAction Stop -EnableException + $results = Get-ChildItem -Path "$($TestConfig.appveyorlabrepo)\certificates" | Import-DbaBinaryFile -SqlInstance $TestConfig.instance2 -Database tempdb -Table BunchOFiles -WarningAction Continue -ErrorAction Stop -EnableException $results.Database | Should -Be @("tempdb", "tempdb") Split-Path -Path $results.FilePath -Leaf | Should -Be @("localhost.crt", "localhost.pfx") } It "piping from Get-DbaBinaryFileTable works" { - $results = Get-DbaBinaryFileTable -SqlInstance $script:instance2 -Database tempdb -Table BunchOFiles | Import-DbaBinaryFile -WarningAction Continue -ErrorAction Stop -EnableException -Path $script:appveyorlabrepo\certificates + $results = Get-DbaBinaryFileTable -SqlInstance $TestConfig.instance2 -Database tempdb -Table BunchOFiles | Import-DbaBinaryFile -WarningAction Continue -ErrorAction Stop -EnableException -Path "$($TestConfig.appveyorlabrepo)\certificates" $results.Database | Should -Be @("tempdb", "tempdb") Split-Path -Path $results.FilePath -Leaf | Should -Be @("localhost.crt", "localhost.pfx") } -} \ No newline at end of file +} diff --git a/tests/Import-DbaCsv.Tests.ps1 b/tests/Import-DbaCsv.Tests.ps1 index 16795b9b03..eb76dbb6e8 100644 --- a/tests/Import-DbaCsv.Tests.ps1 +++ b/tests/Import-DbaCsv.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,36 +15,36 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { AfterAll { - Invoke-DbaQuery -SqlInstance $script:instance1, $script:instance2 -Database tempdb -Query "drop table SuperSmall; drop table CommaSeparatedWithHeader" + Invoke-DbaQuery -SqlInstance $TestConfig.instance1, $TestConfig.instance2 -Database tempdb -Query "drop table SuperSmall; drop table CommaSeparatedWithHeader" } - $path = "$script:appveyorlabrepo\csv\SuperSmall.csv" - $CommaSeparatedWithHeader = "$script:appveyorlabrepo\csv\CommaSeparatedWithHeader.csv" - $col1 = "$script:appveyorlabrepo\csv\cols.csv" - $col2 = "$script:appveyorlabrepo\csv\col2.csv" - $pipe3 = "$script:appveyorlabrepo\csv\pipe3.psv" + $path = "$($TestConfig.appveyorlabrepo)\csv\SuperSmall.csv" + $CommaSeparatedWithHeader = "$($TestConfig.appveyorlabrepo)\csv\CommaSeparatedWithHeader.csv" + $col1 = "$($TestConfig.appveyorlabrepo)\csv\cols.csv" + $col2 = "$($TestConfig.appveyorlabrepo)\csv\col2.csv" + $pipe3 = "$($TestConfig.appveyorlabrepo)\csv\pipe3.psv" Context "Works as expected" { - $results = $path | Import-DbaCsv -SqlInstance $script:instance1 -Database tempdb -Delimiter `t -NotifyAfter 50000 -WarningVariable warn + $results = $path | Import-DbaCsv -SqlInstance $TestConfig.instance1 -Database tempdb -Delimiter `t -NotifyAfter 50000 -WarningVariable warn It "accepts piped input and doesn't add rows if the table does not exist" { $results | Should -Be $null } It "creates the right columnmap (#7630), handles pipe delimiters (#7806)" { - $null = Import-DbaCsv -SqlInstance $script:instance1 -Path $col1 -Database tempdb -AutoCreateTable -Table cols - $null = Import-DbaCsv -SqlInstance $script:instance1 -Path $col2 -Database tempdb -Table cols - $null = Import-DbaCsv -SqlInstance $script:instance1 -Path $pipe3 -Database tempdb -Table cols2 -Delimiter "|" -AutoCreateTable - $results = Invoke-DbaQuery -SqlInstance $script:instance1 -Database tempdb -Query "select * from cols" + $null = Import-DbaCsv -SqlInstance $TestConfig.instance1 -Path $col1 -Database tempdb -AutoCreateTable -Table cols + $null = Import-DbaCsv -SqlInstance $TestConfig.instance1 -Path $col2 -Database tempdb -Table cols + $null = Import-DbaCsv -SqlInstance $TestConfig.instance1 -Path $pipe3 -Database tempdb -Table cols2 -Delimiter "|" -AutoCreateTable + $results = Invoke-DbaQuery -SqlInstance $TestConfig.instance1 -Database tempdb -Query "select * from cols" $results | Where-Object third -notmatch "three" | Should -BeNullOrEmpty $results | Where-Object firstcol -notmatch "one" | Should -BeNullOrEmpty - $results = Invoke-DbaQuery -SqlInstance $script:instance1 -Database tempdb -Query "select * from cols2" + $results = Invoke-DbaQuery -SqlInstance $TestConfig.instance1 -Database tempdb -Query "select * from cols2" $results | Where-Object third -notmatch "three" | Should -BeNullOrEmpty $results | Where-Object firstcol -notmatch "one" | Should -BeNullOrEmpty } if (-not $env:appveyor) { - $results = Import-DbaCsv -Path $path, $path -SqlInstance $script:instance1, $script:instance2 -Database tempdb -Delimiter `t -NotifyAfter 50000 -WarningVariable warn2 -AutoCreateTable + $results = Import-DbaCsv -Path $path, $path -SqlInstance $TestConfig.instance1, $TestConfig.instance2 -Database tempdb -Delimiter `t -NotifyAfter 50000 -WarningVariable warn2 -AutoCreateTable It "performs 4 imports" { ($results).Count | Should -Be 4 @@ -58,14 +58,14 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } } - $result = Import-DbaCsv -Path $path -SqlInstance $script:instance1 -Database tempdb -Delimiter `t -Table SuperSmall -Truncate + $result = Import-DbaCsv -Path $path -SqlInstance $TestConfig.instance1 -Database tempdb -Delimiter `t -Table SuperSmall -Truncate It "doesn't break when truncate is passed" { $result.RowsCopied | Should -Be 999 $result.Database | Should -Be tempdb $result.Table | Should -Be SuperSmall } - $result = Import-DbaCsv -Path $path -SqlInstance $script:instance1 -Database tempdb -Delimiter `t -Table SuperSmall -Truncate -NoTransaction + $result = Import-DbaCsv -Path $path -SqlInstance $TestConfig.instance1 -Database tempdb -Delimiter `t -Table SuperSmall -Truncate -NoTransaction It "works with NoTransaction" { $result.RowsCopied | Should -Be 999 $result.Database | Should -Be tempdb @@ -74,11 +74,11 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } It "Catches the scenario where the database param does not match the server object passed into the command" { - $server = Connect-DbaInstance $script:instance1 -Database tempdb + $server = Connect-DbaInstance $TestConfig.instance1 -Database tempdb $result = Import-DbaCsv -Path $path -SqlInstance $server -Database InvalidDB -Delimiter `t -Table SuperSmall -Truncate -AutoCreateTable $result | Should -BeNullOrEmpty - $server = Connect-DbaInstance $script:instance1 -Database tempdb + $server = Connect-DbaInstance $TestConfig.instance1 -Database tempdb $result = Import-DbaCsv -Path $path -SqlInstance $server -Database tempdb -Delimiter `t -Table SuperSmall -Truncate -AutoCreateTable $result.RowsCopied | Should -Be 999 $result.Database | Should -Be tempdb @@ -87,7 +87,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { It "Catches the scenario where the header is not properly parsed causing param errors" { # create the table using AutoCreate - $server = Connect-DbaInstance $script:instance1 -Database tempdb + $server = Connect-DbaInstance $TestConfig.instance1 -Database tempdb $null = Import-DbaCsv -Path $CommaSeparatedWithHeader -SqlInstance $server -Database tempdb -AutoCreateTable # reload table without AutoCreate parameter to recreate bug #6553 @@ -100,7 +100,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { It "works with NoHeaderRow" { # See #7759 - $server = Connect-DbaInstance $script:instance1 -Database tempdb + $server = Connect-DbaInstance $TestConfig.instance1 -Database tempdb Invoke-DbaQuery -SqlInstance $server -Query 'CREATE TABLE NoHeaderRow (c1 VARCHAR(50), c2 VARCHAR(50), c3 VARCHAR(50))' $result = Import-DbaCsv -Path $col1 -NoHeaderRow -SqlInstance $server -Database tempdb -Table 'NoHeaderRow' -WarningVariable warnNoHeaderRow $data = Invoke-DbaQuery -SqlInstance $server -Query 'SELECT * FROM NoHeaderRow' -As PSObject @@ -114,7 +114,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { It "works with tables which have non-varchar types (date)" { # See #9433 - $server = Connect-DbaInstance $script:instance1 -Database tempdb + $server = Connect-DbaInstance $TestConfig.instance1 -Database tempdb Invoke-DbaQuery -SqlInstance $server -Query 'CREATE TABLE WithTypes ([date] DATE, col1 VARCHAR(50), col2 VARCHAR(50))' $result = Import-DbaCsv -Path $CommaSeparatedWithHeader -SqlInstance $server -Database tempdb -Table 'WithTypes' Invoke-DbaQuery -SqlInstance $server -Query 'DROP TABLE WithTypes' @@ -126,7 +126,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { It "works with tables which have non-varchar types (guid, bit)" { # See #9433 $filePath = '.\foo.csv' - $server = Connect-DbaInstance $script:instance1 -Database tempdb + $server = Connect-DbaInstance $TestConfig.instance1 -Database tempdb Invoke-DbaQuery -SqlInstance $server -Query 'CREATE TABLE WithGuidsAndBits (one_guid UNIQUEIDENTIFIER, one_bit BIT)' $row = [pscustomobject]@{ one_guid = (New-Guid).Guid @@ -140,4 +140,4 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Remove-Item $filePath } } -} \ No newline at end of file +} diff --git a/tests/Import-DbaPfDataCollectorSetTemplate.Tests.ps1 b/tests/Import-DbaPfDataCollectorSetTemplate.Tests.ps1 index 1a54467e66..bb110f8656 100644 --- a/tests/Import-DbaPfDataCollectorSetTemplate.Tests.ps1 +++ b/tests/Import-DbaPfDataCollectorSetTemplate.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Import-DbaRegServer.Tests.ps1 b/tests/Import-DbaRegServer.Tests.ps1 index 1d11f62bd3..2a7f594069 100644 --- a/tests/Import-DbaRegServer.Tests.ps1 +++ b/tests/Import-DbaRegServer.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Validate parameters" { @@ -21,49 +21,49 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $regSrvName = "dbatoolsci-server12" $regSrvDesc = "dbatoolsci-server123" - $newGroup = Add-DbaRegServerGroup -SqlInstance $script:instance2 -Name $group - $newServer = Add-DbaRegServer -SqlInstance $script:instance2 -ServerName $srvName -Name $regSrvName -Description $regSrvDesc -Group $newGroup.Name + $newGroup = Add-DbaRegServerGroup -SqlInstance $TestConfig.instance2 -Name $group + $newServer = Add-DbaRegServer -SqlInstance $TestConfig.instance2 -ServerName $srvName -Name $regSrvName -Description $regSrvDesc -Group $newGroup.Name $srvName2 = "dbatoolsci-server2" $group2 = "dbatoolsci-group1a" $regSrvName2 = "dbatoolsci-server21" $regSrvDesc2 = "dbatoolsci-server321" - $newGroup2 = Add-DbaRegServerGroup -SqlInstance $script:instance2 -Name $group2 - $newServer2 = Add-DbaRegServer -SqlInstance $script:instance2 -ServerName $srvName2 -Name $regSrvName2 -Description $regSrvDesc2 + $newGroup2 = Add-DbaRegServerGroup -SqlInstance $TestConfig.instance2 -Name $group2 + $newServer2 = Add-DbaRegServer -SqlInstance $TestConfig.instance2 -ServerName $srvName2 -Name $regSrvName2 -Description $regSrvDesc2 $regSrvName3 = "dbatoolsci-server3" $srvName3 = "dbatoolsci-server3" $regSrvDesc3 = "dbatoolsci-server3desc" - $newServer3 = Add-DbaRegServer -SqlInstance $script:instance2 -ServerName $srvName3 -Name $regSrvName3 -Description $regSrvDesc3 + $newServer3 = Add-DbaRegServer -SqlInstance $TestConfig.instance2 -ServerName $srvName3 -Name $regSrvName3 -Description $regSrvDesc3 } BeforeEach { - Get-DbaRegServer -SqlInstance $script:instance2 | Where-Object Name -match dbatoolsci | Remove-DbaRegServer -Confirm:$false - Get-DbaRegServerGroup -SqlInstance $script:instance2| Where-Object Name -match dbatoolsci | Remove-DbaRegServerGroup -Confirm:$false + Get-DbaRegServer -SqlInstance $TestConfig.instance2 | Where-Object Name -match dbatoolsci | Remove-DbaRegServer -Confirm:$false + Get-DbaRegServerGroup -SqlInstance $TestConfig.instance2| Where-Object Name -match dbatoolsci | Remove-DbaRegServerGroup -Confirm:$false } Aftereach { - Get-DbaRegServer -SqlInstance $script:instance2 | Where-Object Name -match dbatoolsci | Remove-DbaRegServer -Confirm:$false - Get-DbaRegServerGroup -SqlInstance $script:instance2| Where-Object Name -match dbatoolsci | Remove-DbaRegServerGroup -Confirm:$false + Get-DbaRegServer -SqlInstance $TestConfig.instance2 | Where-Object Name -match dbatoolsci | Remove-DbaRegServer -Confirm:$false + Get-DbaRegServerGroup -SqlInstance $TestConfig.instance2| Where-Object Name -match dbatoolsci | Remove-DbaRegServerGroup -Confirm:$false $results, $results2, $results3 | Remove-Item -ErrorAction Ignore } It "imports group objects" { - $results = $newServer.Parent | Import-DbaRegServer -SqlInstance $script:instance2 + $results = $newServer.Parent | Import-DbaRegServer -SqlInstance $TestConfig.instance2 $results.Description | Should -Be $regSrvDesc $results.ServerName | Should -Be $srvName $results.Parent.Name | Should -Be $group } It "imports registered server objects" { - $results2 = $newServer2 | Import-DbaRegServer -SqlInstance $script:instance2 + $results2 = $newServer2 | Import-DbaRegServer -SqlInstance $TestConfig.instance2 $results2.ServerName | Should -Be $newServer2.ServerName $results2.Parent.Name | Should -Be $newServer2.Parent.Name } It "imports a file from Export-DbaRegServer" { $results3 = $newServer3 | Export-DbaRegServer -Path C:\temp - $results4 = Import-DbaRegServer -SqlInstance $script:instance2 -Path $results3 + $results4 = Import-DbaRegServer -SqlInstance $TestConfig.instance2 -Path $results3 $results4.ServerName | Should -Be @('dbatoolsci-server3') $results4.Description | Should -Be @('dbatoolsci-server3desc') } @@ -71,7 +71,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $object = [pscustomobject]@{ ServerName = 'dbatoolsci-randobject' } - $results = $object | Import-DbaRegServer -SqlInstance $script:instance2 + $results = $object | Import-DbaRegServer -SqlInstance $TestConfig.instance2 $results.ServerName | Should -Be 'dbatoolsci-randobject' $results.Name | Should -Be 'dbatoolsci-randobject' } @@ -79,9 +79,9 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $object = [pscustomobject]@{ Name = 'dbatoolsci-randobject' } - $results = $object | Import-DbaRegServer -SqlInstance $script:instance2 -WarningAction SilentlyContinue -WarningVariable warn + $results = $object | Import-DbaRegServer -SqlInstance $TestConfig.instance2 -WarningAction SilentlyContinue -WarningVariable warn $results | Should -Be $null $warn | Should -Match 'No servers added' } } -} \ No newline at end of file +} diff --git a/tests/Import-DbaSpConfigure.Tests.ps1 b/tests/Import-DbaSpConfigure.Tests.ps1 index 10c18153d5..d7b9657d8f 100644 --- a/tests/Import-DbaSpConfigure.Tests.ps1 +++ b/tests/Import-DbaSpConfigure.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Import-DbaXESessionTemplate.Tests.ps1 b/tests/Import-DbaXESessionTemplate.Tests.ps1 index 9451b6362f..b79fe3dc4c 100644 --- a/tests/Import-DbaXESessionTemplate.Tests.ps1 +++ b/tests/Import-DbaXESessionTemplate.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,13 +15,13 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { AfterAll { - $null = Get-DbaXESession -SqlInstance $script:instance2 -Session 'Overly Complex Queries' | Remove-DbaXESession + $null = Get-DbaXESession -SqlInstance $TestConfig.instance2 -Session 'Overly Complex Queries' | Remove-DbaXESession } Context "Test Importing Session Template" { It -Skip "session imports with proper name and non-default target file location" { - $result = Import-DbaXESessionTemplate -SqlInstance $script:instance2 -Template 'Overly Complex Queries' -TargetFilePath C:\temp + $result = Import-DbaXESessionTemplate -SqlInstance $TestConfig.instance2 -Template 'Overly Complex Queries' -TargetFilePath C:\temp $result.Name | Should Be "Overly Complex Queries" $result.TargetFile -match 'C\:\\temp' | Should Be $true } } -} \ No newline at end of file +} diff --git a/tests/Import-DbatoolsConfig.Tests.ps1 b/tests/Import-DbatoolsConfig.Tests.ps1 index c4e0ff9693..1688859c66 100644 --- a/tests/Import-DbatoolsConfig.Tests.ps1 +++ b/tests/Import-DbatoolsConfig.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/InModule.Commands.Tests.ps1 b/tests/InModule.Commands.Tests.ps1 index 69115cd8b7..21da2d6058 100644 --- a/tests/InModule.Commands.Tests.ps1 +++ b/tests/InModule.Commands.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$commandname Integration Tests" -Tag "IntegrationTests" { Context "duplicate commands are not added" { diff --git a/tests/Install-DbaAgentAdminAlert.Tests.ps1 b/tests/Install-DbaAgentAdminAlert.Tests.ps1 index d52a7903e4..cdad6b6edc 100644 --- a/tests/Install-DbaAgentAdminAlert.Tests.ps1 +++ b/tests/Install-DbaAgentAdminAlert.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,11 +15,11 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeEach { - Get-DbaAgentAlert -SqlInstance $script:instance2, $script:instance3 | Remove-DbaAgentAlert -Confirm:$false + Get-DbaAgentAlert -SqlInstance $TestConfig.instance2, $TestConfig.instance3 | Remove-DbaAgentAlert -Confirm:$false } Context 'Creating a new SQL Server Agent alert' { $parms = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 DelayBetweenResponses = 60 Disabled = $false NotifyMethod = "NotifyEmail" @@ -39,7 +39,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $alert.IsEnabled | Should -Be $true } - $parms.SqlInstance = $script:instance3 + $parms.SqlInstance = $TestConfig.instance3 $parms.ExcludeSeverity = 17 It 'Should create a bunch of new alerts' { @@ -48,7 +48,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { # Assert $alerts.Severity | Should -No -Contain 17 - Get-DbaAgentAlert -SqlInstance $script:instance3 | Should -Not -BeNullOrEmpty + Get-DbaAgentAlert -SqlInstance $TestConfig.instance3 | Should -Not -BeNullOrEmpty } } -} \ No newline at end of file +} diff --git a/tests/Install-DbaDarlingData.Tests.ps1 b/tests/Install-DbaDarlingData.Tests.ps1 index 2ea215c8ca..f203c7c78c 100644 --- a/tests/Install-DbaDarlingData.Tests.ps1 +++ b/tests/Install-DbaDarlingData.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,13 +16,13 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Testing DarlingData installer with download" { BeforeAll { $database = "dbatoolsci_darling_$(Get-Random)" - $server = Connect-DbaInstance -SqlInstance $script:instance3 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance3 $server.Query("CREATE DATABASE $database") - $resultsDownload = Install-DbaDarlingData -SqlInstance $script:instance3 -Database $database -Branch main -Force -Verbose:$false + $resultsDownload = Install-DbaDarlingData -SqlInstance $TestConfig.instance3 -Database $database -Branch main -Force -Verbose:$false } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance3 -Database $database -Confirm:$false + Remove-DbaDatabase -SqlInstance $TestConfig.instance3 -Database $database -Confirm:$false } It "Installs to specified database: $database" { @@ -40,7 +40,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Testing DarlingData installer with LocalFile" { BeforeAll { $database = "dbatoolsci_darling_$(Get-Random)" - $server = Connect-DbaInstance -SqlInstance $script:instance3 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance3 $server.Query("CREATE DATABASE $database") $outfile = "DarlingData-main.zip" @@ -48,10 +48,10 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { if (Test-Path $outfile) { $fullOutfile = (Get-ChildItem $outfile).FullName } - $resultsLocalFile = Install-DbaDarlingData -SqlInstance $script:instance3 -Database $database -Branch main -LocalFile $fullOutfile -Force + $resultsLocalFile = Install-DbaDarlingData -SqlInstance $TestConfig.instance3 -Database $database -Branch main -LocalFile $fullOutfile -Force } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance3 -Database $database -Confirm:$false + Remove-DbaDatabase -SqlInstance $TestConfig.instance3 -Database $database -Confirm:$false } It "Installs to specified database: $database" { @@ -66,4 +66,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { ($result.PsObject.Properties.Name | Sort-Object) | Should -Be ($ExpectedProps | Sort-Object) } } -} \ No newline at end of file +} diff --git a/tests/Install-DbaFirstResponderKit.Tests.ps1 b/tests/Install-DbaFirstResponderKit.Tests.ps1 index 894dfb76e8..7949cc6029 100644 --- a/tests/Install-DbaFirstResponderKit.Tests.ps1 +++ b/tests/Install-DbaFirstResponderKit.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,13 +16,13 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Testing First Responder Kit installer with download" { BeforeAll { $database = "dbatoolsci_frk_$(Get-Random)" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $server.Query("CREATE DATABASE $database") - $resultsDownload = Install-DbaFirstResponderKit -SqlInstance $script:instance2 -Database $database -Branch main -Force -Verbose:$false + $resultsDownload = Install-DbaFirstResponderKit -SqlInstance $TestConfig.instance2 -Database $database -Branch main -Force -Verbose:$false } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance2 -Database $database -Confirm:$false + Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $database -Confirm:$false } It "Installs to specified database: $database" { @@ -40,21 +40,21 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { ($result.PsObject.Properties.Name | Sort-Object) | Should Be ($ExpectedProps | Sort-Object) } It "Shows status of Updated" { - $resultsDownload = Install-DbaFirstResponderKit -SqlInstance $script:instance2 -Database $database -Verbose:$false + $resultsDownload = Install-DbaFirstResponderKit -SqlInstance $TestConfig.instance2 -Database $database -Verbose:$false $resultsDownload[0].Status -eq 'Updated' | Should -Be $true } It "Shows status of Error" { $folder = Join-Path (Get-DbatoolsConfigValue -FullName Path.DbatoolsData) -Child "SQL-Server-First-Responder-Kit-main" $sqlScript = (Get-ChildItem $folder -Filter "sp_*.sql" | Select-Object -First 1).FullName Add-Content $sqlScript (New-Guid).ToString() - $result = Install-DbaFirstResponderKit -SqlInstance $script:instance2 -Database $database -Verbose:$false + $result = Install-DbaFirstResponderKit -SqlInstance $TestConfig.instance2 -Database $database -Verbose:$false $result[0].Status -eq "Error" | Should -Be $true } } Context "Testing First Responder Kit installer with LocalFile" { BeforeAll { $database = "dbatoolsci_frk_$(Get-Random)" - $server = Connect-DbaInstance -SqlInstance $script:instance3 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance3 $server.Query("CREATE DATABASE $database") $outfile = "SQL-Server-First-Responder-Kit-main.zip" @@ -62,10 +62,10 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { if (Test-Path $outfile) { $fullOutfile = (Get-ChildItem $outfile).FullName } - $resultsLocalFile = Install-DbaFirstResponderKit -SqlInstance $script:instance3 -Database $database -Branch main -LocalFile $fullOutfile -Force + $resultsLocalFile = Install-DbaFirstResponderKit -SqlInstance $TestConfig.instance3 -Database $database -Branch main -LocalFile $fullOutfile -Force } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance3 -Database $database -Confirm:$false + Remove-DbaDatabase -SqlInstance $TestConfig.instance3 -Database $database -Confirm:$false } It "Installs to specified database: $database" { @@ -83,15 +83,15 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { ($result.PsObject.Properties.Name | Sort-Object) | Should Be ($ExpectedProps | Sort-Object) } It "Shows status of Updated" { - $resultsLocalFile = Install-DbaFirstResponderKit -SqlInstance $script:instance3 -Database $database + $resultsLocalFile = Install-DbaFirstResponderKit -SqlInstance $TestConfig.instance3 -Database $database $resultsLocalFile[0].Status -eq 'Updated' | Should -Be $true } It "Shows status of Error" { $folder = Join-Path (Get-DbatoolsConfigValue -FullName Path.DbatoolsData) -Child "SQL-Server-First-Responder-Kit-main" $sqlScript = (Get-ChildItem $folder -Filter "sp_*.sql" | Select-Object -First 1).FullName Add-Content $sqlScript (New-Guid).ToString() - $result = Install-DbaFirstResponderKit -SqlInstance $script:instance3 -Database $database + $result = Install-DbaFirstResponderKit -SqlInstance $TestConfig.instance3 -Database $database $result[0].Status -eq "Error" | Should -Be $true } } -} \ No newline at end of file +} diff --git a/tests/Install-DbaInstance.Tests.ps1 b/tests/Install-DbaInstance.Tests.ps1 index 32a3d3a05e..0c00bcc64b 100644 --- a/tests/Install-DbaInstance.Tests.ps1 +++ b/tests/Install-DbaInstance.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { BeforeAll { diff --git a/tests/Install-DbaMaintenanceSolution.Tests.ps1 b/tests/Install-DbaMaintenanceSolution.Tests.ps1 index 41ca7f2abc..7fbe8edebe 100644 --- a/tests/Install-DbaMaintenanceSolution.Tests.ps1 +++ b/tests/Install-DbaMaintenanceSolution.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,22 +16,22 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Limited testing of Maintenance Solution installer" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $server.Databases['tempdb'].Query("CREATE TABLE CommandLog (id int)") } AfterAll { $server.Databases['tempdb'].Query("DROP TABLE CommandLog") - Invoke-DbaQuery -SqlInstance $script:instance3 -Database tempdb -Query "drop procedure CommandExecute; drop procedure DatabaseBackup; drop procedure DatabaseIntegrityCheck; drop procedure IndexOptimize;" + Invoke-DbaQuery -SqlInstance $TestConfig.instance3 -Database tempdb -Query "drop procedure CommandExecute; drop procedure DatabaseBackup; drop procedure DatabaseIntegrityCheck; drop procedure IndexOptimize;" } It "does not overwrite existing " { - $results = Install-DbaMaintenanceSolution -SqlInstance $script:instance2 -Database tempdb -WarningVariable warn -WarningAction SilentlyContinue + $results = Install-DbaMaintenanceSolution -SqlInstance $TestConfig.instance2 -Database tempdb -WarningVariable warn -WarningAction SilentlyContinue $warn -match "already exists" | Should Be $true } It "Continues the installation on other servers " { - $results2 = Install-DbaMaintenanceSolution -SqlInstance $script:instance2, $script:instance3 -Database tempdb - $sproc = Get-DbaDbModule -SqlInstance $script:instance3 -Database tempdb | Where-Object { $_.Name -eq "CommandExecute" } + $results2 = Install-DbaMaintenanceSolution -SqlInstance $TestConfig.instance2, $TestConfig.instance3 -Database tempdb + $sproc = Get-DbaDbModule -SqlInstance $TestConfig.instance3 -Database tempdb | Where-Object { $_.Name -eq "CommandExecute" } $sproc | Should -Not -BeNullOrEmpty } } -} \ No newline at end of file +} diff --git a/tests/Install-DbaMultiTool.Tests.ps1 b/tests/Install-DbaMultiTool.Tests.ps1 index ca5765955e..f385045565 100644 --- a/tests/Install-DbaMultiTool.Tests.ps1 +++ b/tests/Install-DbaMultiTool.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -17,13 +17,13 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { $branch = "main" $database = "dbatoolsci_multitool_$(Get-Random)" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $server.Query("CREATE DATABASE $database") - $resultsDownload = Install-DbaMultiTool -SqlInstance $script:instance2 -Database $database -Branch $branch -Force -Verbose:$false + $resultsDownload = Install-DbaMultiTool -SqlInstance $TestConfig.instance2 -Database $database -Branch $branch -Force -Verbose:$false } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance2 -Database $database -Confirm:$false + Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $database -Confirm:$false } It "Installs to specified database: $database" { @@ -41,14 +41,14 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { ($result.PsObject.Properties.Name | Sort-Object) | Should Be ($ExpectedProps | Sort-Object) } It "Shows status of Updated" { - $resultsDownload = Install-DbaMultiTool -SqlInstance $script:instance2 -Database $database -Verbose:$false + $resultsDownload = Install-DbaMultiTool -SqlInstance $TestConfig.instance2 -Database $database -Verbose:$false $resultsDownload[0].Status -eq 'Updated' | Should -Be $true } It "Shows status of Error" { $folder = Join-Path (Get-DbatoolsConfigValue -FullName Path.DbatoolsData) -Child "dba-multitool-$branch" $sqlScript = Get-ChildItem $folder -Filter "sp_*.sql" | Select-Object -First 1 Add-Content $sqlScript.FullName (New-Guid).ToString() - $result = Install-DbaMultiTool -SqlInstance $script:instance2 -Database $database -Verbose:$false + $result = Install-DbaMultiTool -SqlInstance $TestConfig.instance2 -Database $database -Verbose:$false $result = $result | Where-Object Name -eq $sqlScript.BaseName $result.Status -eq "Error" | Should -Be $true } @@ -57,7 +57,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { $branch = "main" $database = "dbatoolsci_multitool_$(Get-Random)" - $server = Connect-DbaInstance -SqlInstance $script:instance3 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance3 $server.Query("CREATE DATABASE $database") $outfile = "dba-multitool-$branch.zip" @@ -65,10 +65,10 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { if (Test-Path $outfile) { $fullOutfile = (Get-ChildItem $outfile).FullName } - $resultsLocalFile = Install-DbaMultiTool -SqlInstance $script:instance3 -Database $database -Branch $branch -LocalFile $fullOutfile -Force + $resultsLocalFile = Install-DbaMultiTool -SqlInstance $TestConfig.instance3 -Database $database -Branch $branch -LocalFile $fullOutfile -Force } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance3 -Database $database -Confirm:$false + Remove-DbaDatabase -SqlInstance $TestConfig.instance3 -Database $database -Confirm:$false } It "Installs to specified database: $database" { @@ -86,16 +86,16 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { ($result.PsObject.Properties.Name | Sort-Object) | Should -Be ($ExpectedProps | Sort-Object) } It "Shows status of Updated" { - $resultsLocalFile = Install-DbaMultiTool -SqlInstance $script:instance3 -Database $database + $resultsLocalFile = Install-DbaMultiTool -SqlInstance $TestConfig.instance3 -Database $database $resultsLocalFile[0].Status -eq 'Updated' | Should -Be $true } It "Shows status of Error" { $folder = Join-Path (Get-DbatoolsConfigValue -FullName Path.DbatoolsData) -Child "dba-multitool-$branch" $sqlScript = Get-ChildItem $folder -Filter "sp_*.sql" | Select-Object -First 1 Add-Content $sqlScript.FullName (New-Guid).ToString() - $result = Install-DbaMultiTool -SqlInstance $script:instance3 -Database $database -Verbose:$false + $result = Install-DbaMultiTool -SqlInstance $TestConfig.instance3 -Database $database -Verbose:$false $result = $result | Where-Object Name -eq $sqlScript.BaseName $result.Status -eq "Error" | Should -Be $true } } -} \ No newline at end of file +} diff --git a/tests/Install-DbaSqlWatch.Tests.ps1 b/tests/Install-DbaSqlWatch.Tests.ps1 index aa69b735f5..8d82caf25f 100644 --- a/tests/Install-DbaSqlWatch.Tests.ps1 +++ b/tests/Install-DbaSqlWatch.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -17,15 +17,15 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Testing SqlWatch installer" { BeforeAll { $database = "dbatoolsci_sqlwatch_$(Get-Random)" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $server.Query("CREATE DATABASE $database") } AfterAll { - Uninstall-DbaSqlWatch -SqlInstance $script:instance2 -Database $database - Remove-DbaDatabase -SqlInstance $script:instance2 -Database $database -Confirm:$false + Uninstall-DbaSqlWatch -SqlInstance $TestConfig.instance2 -Database $database + Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $database -Confirm:$false } - $results = Install-DbaSqlWatch -SqlInstance $script:instance2 -Database $database + $results = Install-DbaSqlWatch -SqlInstance $TestConfig.instance2 -Database $database It "Installs to specified database: $database" { $results[0].Database -eq $database | Should Be $true @@ -36,21 +36,21 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { ($result.PsObject.Properties.Name | Sort-Object) | Should Be ($ExpectedProps | Sort-Object) } It "Installed tables" { - $tableCount = (Get-DbaDbTable -SqlInstance $script:instance2 -Database $Database | Where-Object { $PSItem.Name -like "sqlwatch_*" }).Count + $tableCount = (Get-DbaDbTable -SqlInstance $TestConfig.instance2 -Database $Database | Where-Object { $PSItem.Name -like "sqlwatch_*" }).Count $tableCount | Should -BeGreaterThan 0 } It "Installed views" { - $viewCount = (Get-DbaDbView -SqlInstance $script:instance2 -Database $Database | Where-Object { $PSItem.Name -like "vw_sqlwatch_*" }).Count + $viewCount = (Get-DbaDbView -SqlInstance $TestConfig.instance2 -Database $Database | Where-Object { $PSItem.Name -like "vw_sqlwatch_*" }).Count $viewCount | Should -BeGreaterThan 0 } It "Installed stored procedures" { - $sprocCount = (Get-DbaDbStoredProcedure -SqlInstance $script:instance2 -Database $Database | Where-Object { $PSItem.Name -like "usp_sqlwatch_*" }).Count + $sprocCount = (Get-DbaDbStoredProcedure -SqlInstance $TestConfig.instance2 -Database $Database | Where-Object { $PSItem.Name -like "usp_sqlwatch_*" }).Count $sprocCount | Should -BeGreaterThan 0 } It "Installed SQL Agent jobs" { - $agentCount = (Get-DbaAgentJob -SqlInstance $script:instance2 | Where-Object {($PSItem.Name -like "SqlWatch-*") -or ($PSItem.Name -like "DBA-PERF-*")}).Count + $agentCount = (Get-DbaAgentJob -SqlInstance $TestConfig.instance2 | Where-Object {($PSItem.Name -like "SqlWatch-*") -or ($PSItem.Name -like "DBA-PERF-*")}).Count $agentCount | Should -BeGreaterThan 0 } } -} \ No newline at end of file +} diff --git a/tests/Install-DbaWhoIsActive.Tests.ps1 b/tests/Install-DbaWhoIsActive.Tests.ps1 index 0850dd1c4d..fe046bf115 100644 --- a/tests/Install-DbaWhoIsActive.Tests.ps1 +++ b/tests/Install-DbaWhoIsActive.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig . "$PSScriptRoot\..\private\functions\Invoke-TlsWebRequest" Describe "$CommandName Unit Tests" -Tag 'UnitTests' { @@ -5315,34 +5315,34 @@ GO } AfterAll { Remove-Item -Path $testfilepath, $testzippath, "$testtemp\who_MOCKED_is_active_v11_32.sql", "$DbatoolsData\spwhoisactive.zip" -Force -ErrorAction SilentlyContinue - Invoke-DbaQuery -SqlInstance $script:instance1 -Database Master -Query 'DROP PROCEDURE [dbo].[sp_WhoIsActive];' + Invoke-DbaQuery -SqlInstance $TestConfig.instance1 -Database Master -Query 'DROP PROCEDURE [dbo].[sp_WhoIsActive];' } Context "Should Install SPWhoisActive with Mock" { AfterAll { - Invoke-DbaQuery -SqlInstance $script:instance1 -Database Master -Query 'DROP PROCEDURE [dbo].[sp_WhoIsActive];' + Invoke-DbaQuery -SqlInstance $TestConfig.instance1 -Database Master -Query 'DROP PROCEDURE [dbo].[sp_WhoIsActive];' } - $results = Install-DbaWhoIsActive -SqlInstance $script:instance1 -Database Master + $results = Install-DbaWhoIsActive -SqlInstance $TestConfig.instance1 -Database Master It "Should simulate install from internet" { $results | Should Not Be Null } } Context "Should Install SPWhoisActive from File" { AfterAll { - Invoke-DbaQuery -SqlInstance $script:instance1 -Query 'DROP PROCEDURE [dbo].[sp_WhoIsActive];' + Invoke-DbaQuery -SqlInstance $TestConfig.instance1 -Query 'DROP PROCEDURE [dbo].[sp_WhoIsActive];' } - $results = Install-DbaWhoIsActive -SqlInstance $script:instance1 -LocalFile $testfilepath -Database Master + $results = Install-DbaWhoIsActive -SqlInstance $TestConfig.instance1 -LocalFile $testfilepath -Database Master It "Should install against .sql file" { $results | Should Not Be Null } } Context "Should Install SPWhoisActive from Zip" { AfterAll { - Invoke-DbaQuery -SqlInstance $script:instance1 -Database tempdb -Query 'DROP PROCEDURE [dbo].[sp_WhoIsActive];' + Invoke-DbaQuery -SqlInstance $TestConfig.instance1 -Database tempdb -Query 'DROP PROCEDURE [dbo].[sp_WhoIsActive];' } - $results = Install-DbaWhoIsActive -SqlInstance $script:instance1 -LocalFile $testzippath -Database tempdb + $results = Install-DbaWhoIsActive -SqlInstance $TestConfig.instance1 -LocalFile $testzippath -Database tempdb It "Should install against ZIP" { $results | Should Not Be Null } } -} \ No newline at end of file +} diff --git a/tests/Invoke-DbaAdvancedInstall.Tests.ps1 b/tests/Invoke-DbaAdvancedInstall.Tests.ps1 index d39329fc21..3568e43dd2 100644 --- a/tests/Invoke-DbaAdvancedInstall.Tests.ps1 +++ b/tests/Invoke-DbaAdvancedInstall.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { BeforeAll { diff --git a/tests/Invoke-DbaAdvancedRestore.Tests.ps1 b/tests/Invoke-DbaAdvancedRestore.Tests.ps1 index 7df6685d69..b5161839eb 100644 --- a/tests/Invoke-DbaAdvancedRestore.Tests.ps1 +++ b/tests/Invoke-DbaAdvancedRestore.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Invoke-DbaAdvancedUpdate.Tests.ps1 b/tests/Invoke-DbaAdvancedUpdate.Tests.ps1 index ba88ee8fbc..cdbfc13233 100644 --- a/tests/Invoke-DbaAdvancedUpdate.Tests.ps1 +++ b/tests/Invoke-DbaAdvancedUpdate.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig $exeDir = "C:\Temp\dbatools_$CommandName" diff --git a/tests/Invoke-DbaAgFailover.Tests.ps1 b/tests/Invoke-DbaAgFailover.Tests.ps1 index 77227536d1..dc71fe5e41 100644 --- a/tests/Invoke-DbaAgFailover.Tests.ps1 +++ b/tests/Invoke-DbaAgFailover.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Invoke-DbaAzSqlDbTip.Tests.ps1 b/tests/Invoke-DbaAzSqlDbTip.Tests.ps1 index 3598498bbb..222e7cfd8a 100644 --- a/tests/Invoke-DbaAzSqlDbTip.Tests.ps1 +++ b/tests/Invoke-DbaAzSqlDbTip.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -17,16 +17,16 @@ Describe "$commandName Integration Tests" -Tags "IntegrationTests" { if ($env:azuredbpasswd -eq "failstoooften") { Context "Run the tips against Azure database" { $securePassword = ConvertTo-SecureString $env:azuredbpasswd -AsPlainText -Force - $cred = New-Object System.Management.Automation.PSCredential ($script:azuresqldblogin, $securePassword) + $cred = New-Object System.Management.Automation.PSCredential ($TestConfig.azuresqldblogin, $securePassword) - $results = Invoke-DbaAzSqlDbTip -SqlInstance $script:azureserver -Database test -SqlCredential $cred -ReturnAllTips + $results = Invoke-DbaAzSqlDbTip -SqlInstance $TestConfig.azureserver -Database test -SqlCredential $cred -ReturnAllTips It "Should get some results" { $results | Should -not -BeNullOrEmpty } It "Should have the right ComputerName" { - $results.ComputerName | Should -Be $script:azureserver + $results.ComputerName | Should -Be $TestConfig.azureserver } It "Database name should be 'test'" { @@ -34,4 +34,4 @@ Describe "$commandName Integration Tests" -Tags "IntegrationTests" { } } } -} \ No newline at end of file +} diff --git a/tests/Invoke-DbaBalanceDataFiles.Tests.ps1 b/tests/Invoke-DbaBalanceDataFiles.Tests.ps1 index c34d92548b..ba875f4931 100644 --- a/tests/Invoke-DbaBalanceDataFiles.Tests.ps1 +++ b/tests/Invoke-DbaBalanceDataFiles.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,7 +16,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { # Create the server object - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 # Get the default data directory to create the additional data file $defaultdata = (Get-DbaDefaultPath -SqlInstance $server).Data @@ -75,4 +75,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $sizeUsedAfter | Should -BeLessThan $sizeUsedBefore } } -} \ No newline at end of file +} diff --git a/tests/Invoke-DbaCycleErrorLog.Tests.ps1 b/tests/Invoke-DbaCycleErrorLog.Tests.ps1 index 11e627189b..a7b1bb5e63 100644 --- a/tests/Invoke-DbaCycleErrorLog.Tests.ps1 +++ b/tests/Invoke-DbaCycleErrorLog.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag "UnitTests" { Context "Validate parameters" { @@ -14,7 +14,7 @@ Describe "$CommandName Unit Tests" -Tag "UnitTests" { } Describe "$CommandName Integration Test" -Tag "IntegrationTests" { - $results = Invoke-DbaCycleErrorLog -SqlInstance $script:instance1 -Type instance + $results = Invoke-DbaCycleErrorLog -SqlInstance $TestConfig.instance1 -Type instance Context "Validate output" { It "Should have correct properties" { @@ -25,4 +25,4 @@ Describe "$CommandName Integration Test" -Tag "IntegrationTests" { $results.LogType | Should Be "instance" } } -} \ No newline at end of file +} diff --git a/tests/Invoke-DbaDbClone.Tests.ps1 b/tests/Invoke-DbaDbClone.Tests.ps1 index e9e819cd08..df0661f42b 100644 --- a/tests/Invoke-DbaDbClone.Tests.ps1 +++ b/tests/Invoke-DbaDbClone.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -20,7 +20,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $clonedb = "dbatoolsci_clonetest_CLONE" $clonedb2 = "dbatoolsci_clonetest_CLONE2" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $server.Query("CREATE DATABASE $dbname") } @@ -29,24 +29,24 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } It "warns if SQL instance version is not supported" { - $results = Invoke-DbaDbClone -SqlInstance $script:instance1 -Database $dbname -CloneDatabase $clonedb -WarningAction SilentlyContinue -WarningVariable versionwarn + $results = Invoke-DbaDbClone -SqlInstance $TestConfig.instance1 -Database $dbname -CloneDatabase $clonedb -WarningAction SilentlyContinue -WarningVariable versionwarn $versionwarn = $versionwarn | Out-String $versionwarn -match "required" } It "warns if destination database already exists" { - $results = Invoke-DbaDbClone -SqlInstance $script:instance2 -Database $dbname -CloneDatabase tempdb -WarningAction SilentlyContinue -WarningVariable dbwarn + $results = Invoke-DbaDbClone -SqlInstance $TestConfig.instance2 -Database $dbname -CloneDatabase tempdb -WarningAction SilentlyContinue -WarningVariable dbwarn $dbwarn = $dbwarn | Out-String $dbwarn -match "exists" } It "warns if a system db is specified to clone" { - $results = Invoke-DbaDbClone -SqlInstance $script:instance2 -Database master -CloneDatabase $clonedb -WarningAction SilentlyContinue -WarningVariable systemwarn + $results = Invoke-DbaDbClone -SqlInstance $TestConfig.instance2 -Database master -CloneDatabase $clonedb -WarningAction SilentlyContinue -WarningVariable systemwarn $systemwarn = $systemwarn | Out-String $systemwarn -match "user database" } - $results = Invoke-DbaDbClone -SqlInstance $script:instance2 -Database $dbname -CloneDatabase $clonedb -WarningAction SilentlyContinue + $results = Invoke-DbaDbClone -SqlInstance $TestConfig.instance2 -Database $dbname -CloneDatabase $clonedb -WarningAction SilentlyContinue It "returns 1 result" { ($results).Count -eq 1 @@ -59,3 +59,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } } } + diff --git a/tests/Invoke-DbaDbCorruption.Tests.ps1 b/tests/Invoke-DbaDbCorruption.Tests.ps1 index dd37cf7918..626f3bc958 100644 --- a/tests/Invoke-DbaDbCorruption.Tests.ps1 +++ b/tests/Invoke-DbaDbCorruption.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig . "$PSScriptRoot\..\private\functions\Invoke-DbaDbCorruption.ps1" Describe "$commandname Unit Tests" -Tags "UnitTests" { @@ -24,35 +24,35 @@ Describe "$commandname Unit Tests" -Tags "UnitTests" { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { BeforeAll { $dbname = "dbatoolsci_InvokeDbaDatabaseCorruptionTest" - $Server = Connect-DbaInstance -SqlInstance $script:instance2 + $Server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $TableName = "Example" # Need a clean empty database $null = $Server.Query("Create Database [$dbname]") - $db = Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbname + $db = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname } AfterAll { # Cleanup - Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbname -Confirm:$false + Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname -Confirm:$false } Context "Validating Database Input" { - Invoke-DbaDbCorruption -SqlInstance $script:instance2 -Database "master" -WarningAction SilentlyContinue -WarningVariable systemwarn + Invoke-DbaDbCorruption -SqlInstance $TestConfig.instance2 -Database "master" -WarningAction SilentlyContinue -WarningVariable systemwarn It "Should not allow you to corrupt system databases." { $systemwarn -match 'may not corrupt system databases' | Should Be $true } It "Should fail if more than one database is specified" { - { Invoke-DbaDbCorruption -SqlInstance $script:instance2 -Database "Database1", "Database2" -EnableException } | Should Throw + { Invoke-DbaDbCorruption -SqlInstance $TestConfig.instance2 -Database "Database1", "Database2" -EnableException } | Should Throw } } It "Require at least a single table in the database specified" { - { Invoke-DbaDbCorruption -SqlInstance $script:instance2 -Database $dbname -EnableException } | Should Throw + { Invoke-DbaDbCorruption -SqlInstance $TestConfig.instance2 -Database $dbname -EnableException } | Should Throw } # Creating a table to make sure these are failing for different reasons It "Fail if the specified table does not exist" { - { Invoke-DbaDbCorruption -SqlInstance $script:instance2 -Database $dbname -Table "DoesntExist$(New-Guid)" -EnableException } | Should Throw + { Invoke-DbaDbCorruption -SqlInstance $TestConfig.instance2 -Database $dbname -Table "DoesntExist$(New-Guid)" -EnableException } | Should Throw } $null = $db.Query(" @@ -62,11 +62,11 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { FROM sys.objects") It "Corrupt a single database" { - Invoke-DbaDbCorruption -SqlInstance $script:instance2 -Database $dbname -Confirm:$false | Select-Object -ExpandProperty Status | Should be "Corrupted" + Invoke-DbaDbCorruption -SqlInstance $TestConfig.instance2 -Database $dbname -Confirm:$false | Select-Object -ExpandProperty Status | Should be "Corrupted" } It "Causes DBCC CHECKDB to fail" { $result = Start-DbccCheck -Server $server -dbname $dbname $result | Should Not Be 'Success' } -} \ No newline at end of file +} diff --git a/tests/Invoke-DbaDbDataGenerator.Tests.ps1 b/tests/Invoke-DbaDbDataGenerator.Tests.ps1 index f2d28f1099..38d4a2cdc1 100644 --- a/tests/Invoke-DbaDbDataGenerator.Tests.ps1 +++ b/tests/Invoke-DbaDbDataGenerator.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -21,24 +21,24 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { [LastName] [varchar](50) NULL, [City] [varchar](100) NULL ) ON [PRIMARY];" - New-DbaDatabase -SqlInstance $script:instance2 -Name $db - Invoke-DbaQuery -SqlInstance $script:instance2 -Database $db -Query $sql + New-DbaDatabase -SqlInstance $TestConfig.instance2 -Name $db + Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database $db -Query $sql } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance2 -Database $db -Confirm:$false + Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $db -Confirm:$false $file | Remove-Item -Confirm:$false -ErrorAction Ignore } Context "Command works" { It "Starts with the right data" { - Invoke-DbaQuery -SqlInstance $script:instance2 -Database $db -Query "select * from people" | Should -Be $null + Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database $db -Query "select * from people" | Should -Be $null } It "Returns the proper output" { - $file = New-DbaDbDataGeneratorConfig -SqlInstance $script:instance2 -Database $db -Path C:\temp -Rows 10 + $file = New-DbaDbDataGeneratorConfig -SqlInstance $TestConfig.instance2 -Database $db -Path C:\temp -Rows 10 - $results = Invoke-DbaDbDataGenerator -SqlInstance $script:instance2 -Database $db -Confirm:$false -FilePath $file.FullName + $results = Invoke-DbaDbDataGenerator -SqlInstance $TestConfig.instance2 -Database $db -Confirm:$false -FilePath $file.FullName foreach ($result in $results) { $result.Rows | Should -Be 10 @@ -47,7 +47,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } It "Generates the data" { - Invoke-DbaQuery -SqlInstance $script:instance2 -Database $db -Query "select * from people" | Should -Not -Be $null + Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database $db -Query "select * from people" | Should -Not -Be $null } } -} \ No newline at end of file +} diff --git a/tests/Invoke-DbaDbDataMasking.Tests.ps1 b/tests/Invoke-DbaDbDataMasking.Tests.ps1 index d1ffda9be6..df728a867b 100644 --- a/tests/Invoke-DbaDbDataMasking.Tests.ps1 +++ b/tests/Invoke-DbaDbDataMasking.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -53,24 +53,24 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { GO INSERT INTO people2 (fname, lname, dob) VALUES ('Layla','Schmoe','2/2/2000') INSERT INTO people2 (fname, lname, dob) VALUES ('Eric','Schmee','2/2/1950')" - New-DbaDatabase -SqlInstance $script:instance2 -SqlCredential $script:SqlCredential -Name $db - Invoke-DbaQuery -SqlInstance $script:instance2 -SqlCredential $script:SqlCredential -Database $db -Query $sql + New-DbaDatabase -SqlInstance $TestConfig.instance2 -SqlCredential $TestConfig.SqlCredential -Name $db + Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -SqlCredential $TestConfig.SqlCredential -Database $db -Query $sql } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance2 -SqlCredential $script:SqlCredential -Database $db -Confirm:$false + Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -SqlCredential $TestConfig.SqlCredential -Database $db -Confirm:$false $file | Remove-Item -Confirm:$false -ErrorAction Ignore } Context "Command works" { It "starts with the right data" { - Invoke-DbaQuery -SqlInstance $script:instance2 -SqlCredential $script:SqlCredential -Database $db -Query "select * from people where fname = 'Joe'" | Should -Not -Be $null - Invoke-DbaQuery -SqlInstance $script:instance2 -SqlCredential $script:SqlCredential -Database $db -Query "select * from people where lname = 'Schmee'" | Should -Not -Be $null + Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -SqlCredential $TestConfig.SqlCredential -Database $db -Query "select * from people where fname = 'Joe'" | Should -Not -Be $null + Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -SqlCredential $TestConfig.SqlCredential -Database $db -Query "select * from people where lname = 'Schmee'" | Should -Not -Be $null } It "returns the proper output" { - $file = New-DbaDbMaskingConfig -SqlInstance $script:instance2 -SqlCredential $script:SqlCredential -Database $db -Path C:\temp + $file = New-DbaDbMaskingConfig -SqlInstance $TestConfig.instance2 -SqlCredential $TestConfig.SqlCredential -Database $db -Path C:\temp - [array]$results = $file | Invoke-DbaDbDataMasking -SqlInstance $script:instance2 -SqlCredential $script:SqlCredential -Database $db -Confirm:$false + [array]$results = $file | Invoke-DbaDbDataMasking -SqlInstance $TestConfig.instance2 -SqlCredential $TestConfig.SqlCredential -Database $db -Confirm:$false $results[0].Rows | Should -Be 2 $results[0].Database | Should -Contain $db @@ -80,9 +80,9 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } It "masks the data and does not delete it" { - Invoke-DbaQuery -SqlInstance $script:instance2 -SqlCredential $script:SqlCredential -Database $db -Query "select * from people" | Should -Not -Be $null - Invoke-DbaQuery -SqlInstance $script:instance2 -SqlCredential $script:SqlCredential -Database $db -Query "select * from people where fname = 'Joe'" | Should -Be $null - Invoke-DbaQuery -SqlInstance $script:instance2 -SqlCredential $script:SqlCredential -Database $db -Query "select * from people where lname = 'Schmee'" | Should -Be $null + Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -SqlCredential $TestConfig.SqlCredential -Database $db -Query "select * from people" | Should -Not -Be $null + Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -SqlCredential $TestConfig.SqlCredential -Database $db -Query "select * from people where fname = 'Joe'" | Should -Be $null + Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -SqlCredential $TestConfig.SqlCredential -Database $db -Query "select * from people where lname = 'Schmee'" | Should -Be $null } } -} \ No newline at end of file +} diff --git a/tests/Invoke-DbaDbDbccCheckConstraint.Tests.ps1 b/tests/Invoke-DbaDbDbccCheckConstraint.Tests.ps1 index b9d692a150..fbd381b813 100644 --- a/tests/Invoke-DbaDbDbccCheckConstraint.Tests.ps1 +++ b/tests/Invoke-DbaDbDbccCheckConstraint.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -14,7 +14,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { } Describe "$commandname Integration Test" -Tag "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $random = Get-Random $tableName = "dbatools_CheckConstraintTbl1" $check1 = "chkTab1" @@ -26,12 +26,12 @@ Describe "$commandname Integration Test" -Tag "IntegrationTests" { $null = $server.Query("ALTER TABLE $tableName WITH NOCHECK ADD CONSTRAINT $check1 CHECK (Col1 > 100); ", $dbname) } AfterAll { - $null = Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbname | Remove-DbaDatabase -Confirm:$false + $null = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname | Remove-DbaDatabase -Confirm:$false } Context "Validate standard output" { $props = 'ComputerName', 'InstanceName', 'SqlInstance', 'Database', 'Cmd', 'Output', 'Table', 'Constraint', 'Where' - $result = Invoke-DbaDbDbccCheckConstraint -SqlInstance $script:instance2 -Database $dbname -Object $tableName -Confirm:$false + $result = Invoke-DbaDbDbccCheckConstraint -SqlInstance $TestConfig.instance2 -Database $dbname -Object $tableName -Confirm:$false foreach ($prop in $props) { $p = $result[0].PSObject.Properties[$prop] @@ -47,4 +47,4 @@ Describe "$commandname Integration Test" -Tag "IntegrationTests" { $result.Output.Substring(0, 25) -eq 'DBCC execution completed.' | Should Be $true } } -} \ No newline at end of file +} diff --git a/tests/Invoke-DbaDbDbccCleanTable.Tests.ps1 b/tests/Invoke-DbaDbDbccCleanTable.Tests.ps1 index b03dd8279b..dc4f799f03 100644 --- a/tests/Invoke-DbaDbDbccCleanTable.Tests.ps1 +++ b/tests/Invoke-DbaDbDbccCleanTable.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -14,7 +14,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { } Describe "$commandname Integration Test" -Tag "IntegrationTests" { BeforeAll { - $db = Get-DbaDatabase -SqlInstance $script:instance1 -Database tempdb + $db = Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database tempdb $null = $db.Query("CREATE TABLE dbo.dbatoolct_example (object_id int, [definition] nvarchar(max),Document varchar(2000)); INSERT INTO dbo.dbatoolct_example([object_id], [definition], Document) Select [object_id], [definition], REPLICATE('ab', 800) from master.sys.sql_modules; ALTER TABLE dbo.dbatoolct_example DROP COLUMN Definition, Document;") @@ -29,7 +29,7 @@ Describe "$commandname Integration Test" -Tag "IntegrationTests" { Context "Validate standard output" { $props = 'ComputerName', 'InstanceName', 'SqlInstance', 'Database', 'Object', 'Cmd', 'Output' - $result = Invoke-DbaDbDbccCleanTable -SqlInstance $script:instance1 -Database 'tempdb' -Object 'dbo.dbatoolct_example' -Confirm:$false + $result = Invoke-DbaDbDbccCleanTable -SqlInstance $TestConfig.instance1 -Database 'tempdb' -Object 'dbo.dbatoolct_example' -Confirm:$false foreach ($prop in $props) { $p = $result[0].PSObject.Properties[$prop] @@ -46,7 +46,7 @@ Describe "$commandname Integration Test" -Tag "IntegrationTests" { } Context "Validate BatchSize parameter " { - $result = Invoke-DbaDbDbccCleanTable -SqlInstance $script:instance1 -Database 'tempdb' -Object 'dbo.dbatoolct_example' -BatchSize 1000 -Confirm:$false + $result = Invoke-DbaDbDbccCleanTable -SqlInstance $TestConfig.instance1 -Database 'tempdb' -Object 'dbo.dbatoolct_example' -BatchSize 1000 -Confirm:$false It "returns results for table" { $result.Cmd -eq "DBCC CLEANTABLE('tempdb', 'dbo.dbatoolct_example', 1000)" | Should Be $true @@ -55,11 +55,11 @@ Describe "$commandname Integration Test" -Tag "IntegrationTests" { } Context "Validate NoInformationalMessages parameter " { - $result = Invoke-DbaDbDbccCleanTable -SqlInstance $script:instance1 -Database 'tempdb' -Object 'dbo.dbatoolct_example' -NoInformationalMessages -Confirm:$false + $result = Invoke-DbaDbDbccCleanTable -SqlInstance $TestConfig.instance1 -Database 'tempdb' -Object 'dbo.dbatoolct_example' -NoInformationalMessages -Confirm:$false It "returns results for table" { $result.Cmd -eq "DBCC CLEANTABLE('tempdb', 'dbo.dbatoolct_example') WITH NO_INFOMSGS" | Should Be $true $result.Output -eq $null | Should Be $true } } -} \ No newline at end of file +} diff --git a/tests/Invoke-DbaDbDbccUpdateUsage.Tests.ps1 b/tests/Invoke-DbaDbDbccUpdateUsage.Tests.ps1 index 530b2b3211..6e011c0612 100644 --- a/tests/Invoke-DbaDbDbccUpdateUsage.Tests.ps1 +++ b/tests/Invoke-DbaDbDbccUpdateUsage.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -14,23 +14,23 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { } Describe "$commandname Integration Test" -Tag "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance1 $random = Get-Random $tableName = "dbatools_getdbtbl1" $dbname = "dbatoolsci_getdbUsage$random" - $db = New-DbaDatabase -SqlInstance $script:instance1 -Name $dbname + $db = New-DbaDatabase -SqlInstance $TestConfig.instance1 -Name $dbname $null = $db.Query("CREATE TABLE $tableName (id int)", $dbname) $null = $db.Query("CREATE CLUSTERED INDEX [PK_Id] ON $tableName ([id] ASC)", $dbname) $null = $db.Query("INSERT $tableName(id) SELECT object_id FROM sys.objects", $dbname) } AfterAll { - $null = Get-DbaDatabase -SqlInstance $script:instance1 -Database $dbname | Remove-DbaDatabase -Confirm:$false + $null = Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $dbname | Remove-DbaDatabase -Confirm:$false } Context "Validate standard output" { $props = 'ComputerName', 'InstanceName', 'SqlInstance', 'Database', 'Cmd', 'Output' - $result = Invoke-DbaDbDbccUpdateUsage -SqlInstance $script:instance1 -Confirm:$false + $result = Invoke-DbaDbDbccUpdateUsage -SqlInstance $TestConfig.instance1 -Confirm:$false It "returns results" { $result.Count -gt 0 | Should Be $true @@ -45,17 +45,17 @@ Describe "$commandname Integration Test" -Tag "IntegrationTests" { } Context "Validate returns results " { - $result = Invoke-DbaDbDbccUpdateUsage -SqlInstance $script:instance1 -Database $dbname -Table $tableName -Confirm:$false + $result = Invoke-DbaDbDbccUpdateUsage -SqlInstance $TestConfig.instance1 -Database $dbname -Table $tableName -Confirm:$false It "returns results for table" { $result.Output -match 'DBCC execution completed. If DBCC printed error messages, contact your system administrator.' | Should Be $true } - $result = Invoke-DbaDbDbccUpdateUsage -SqlInstance $script:instance1 -Database $dbname -Table $tableName -Index 1 -Confirm:$false + $result = Invoke-DbaDbDbccUpdateUsage -SqlInstance $TestConfig.instance1 -Database $dbname -Table $tableName -Index 1 -Confirm:$false It "returns results for index by id" { $result.Output -match 'DBCC execution completed. If DBCC printed error messages, contact your system administrator.' | Should Be $true } } -} \ No newline at end of file +} diff --git a/tests/Invoke-DbaDbDecryptObject.Tests.ps1 b/tests/Invoke-DbaDbDecryptObject.Tests.ps1 index 9ee1846c73..99adf8f9aa 100644 --- a/tests/Invoke-DbaDbDecryptObject.Tests.ps1 +++ b/tests/Invoke-DbaDbDecryptObject.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -22,18 +22,18 @@ Describe "$CommandName Integration Tests" -Tags "UnitTests" { $dbname = "dbatoolsci_decrypt_$random" # Remove the database if it exists - Remove-DbaDatabase -SqlInstance $script:instance1 -Database $dbname -Confirm:$false + Remove-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $dbname -Confirm:$false # Create the database - $db = New-DbaDatabase -SqlInstance $script:instance1 -Name $dbname + $db = New-DbaDatabase -SqlInstance $TestConfig.instance1 -Name $dbname - if ($null -ne $script:instance2SQLUserName) { - $instance2SecurePassword = ConvertTo-SecureString -String $script:instance2SQLPassword -AsPlainText -Force - $instance2SqlCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $script:instance2SQLUserName, $instance2SecurePassword + if ($null -ne $TestConfig.instance2SQLUserName) { + $instance2SecurePassword = ConvertTo-SecureString -String $TestConfig.instance2SQLPassword -AsPlainText -Force + $instance2SqlCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $TestConfig.instance2SQLUserName, $instance2SecurePassword } - Remove-DbaDatabase -SqlInstance $script:instance2 -SqlCredential $instance2SqlCredential -Database $dbname -Confirm:$false - $instance2Db = New-DbaDatabase -SqlInstance $script:instance2 -SqlCredential $instance2SqlCredential -Name $dbname + Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -SqlCredential $instance2SqlCredential -Database $dbname -Confirm:$false + $instance2Db = New-DbaDatabase -SqlInstance $TestConfig.instance2 -SqlCredential $instance2SqlCredential -Name $dbname # test object for usage with sql credential $remoteDacSampleEncryptedView = "CREATE VIEW dbo.dbatoolsci_test_remote_dac_vw WITH ENCRYPTION AS SELECT 'remoteDac' as TestFeature;" @@ -183,96 +183,96 @@ SELECT 'áéíñóú¡¿' as SampleUTF8;" $db.Query($setupViewWithUTF8) # Check if DAC is enabled - $config = Get-DbaSpConfigure -SqlInstance $script:instance1 -ConfigName RemoteDacConnectionsEnabled + $config = Get-DbaSpConfigure -SqlInstance $TestConfig.instance1 -ConfigName RemoteDacConnectionsEnabled if ($config.ConfiguredValue -ne 1) { - Set-DbaSpConfigure -SqlInstance $script:instance1 -ConfigName RemoteDacConnectionsEnabled -Value $true + Set-DbaSpConfigure -SqlInstance $TestConfig.instance1 -ConfigName RemoteDacConnectionsEnabled -Value $true } - $instance2Config = Get-DbaSpConfigure -SqlInstance $script:instance2 -SqlCredential $instance2SqlCredential -ConfigName RemoteDacConnectionsEnabled + $instance2Config = Get-DbaSpConfigure -SqlInstance $TestConfig.instance2 -SqlCredential $instance2SqlCredential -ConfigName RemoteDacConnectionsEnabled if ($instance2Config.ConfiguredValue -ne 1) { - Set-DbaSpConfigure -SqlInstance $script:instance2 -SqlCredential $instance2SqlCredential -ConfigName RemoteDacConnectionsEnabled -Value $true + Set-DbaSpConfigure -SqlInstance $TestConfig.instance2 -SqlCredential $instance2SqlCredential -ConfigName RemoteDacConnectionsEnabled -Value $true } } AfterAll { # Remove the database if it exists - Remove-DbaDatabase -SqlInstance $script:instance1 -Database $dbname -Confirm:$false - Remove-DbaDatabase -SqlInstance $script:instance2 -SqlCredential $instance2SqlCredential -Database $dbname -Confirm:$false + Remove-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $dbname -Confirm:$false + Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -SqlCredential $instance2SqlCredential -Database $dbname -Confirm:$false # Set the original configuration - Set-DbaSpConfigure -SqlInstance $script:instance1 -ConfigName RemoteDacConnectionsEnabled -Value $config.ConfiguredValue -WarningAction SilentlyContinue - Set-DbaSpConfigure -SqlInstance $script:instance2 -SqlCredential $instance2SqlCredential -ConfigName RemoteDacConnectionsEnabled -Value $instance2Config.ConfiguredValue -WarningAction SilentlyContinue + Set-DbaSpConfigure -SqlInstance $TestConfig.instance1 -ConfigName RemoteDacConnectionsEnabled -Value $config.ConfiguredValue -WarningAction SilentlyContinue + Set-DbaSpConfigure -SqlInstance $TestConfig.instance2 -SqlCredential $instance2SqlCredential -ConfigName RemoteDacConnectionsEnabled -Value $instance2Config.ConfiguredValue -WarningAction SilentlyContinue } # these tests are marked as skip to ensure the AppVeyor sql instances are not impacted negatively. These tests can be run locally. Context "DAC enabled" { # too much messing around punts appveyor It -Skip "Should throw error" { - Set-DbaSpConfigure -SqlInstance $script:instance1 -Name RemoteDacConnectionsEnabled -Value $false - Invoke-DbaDbDecryptObject -SqlInstance $script:instance1 -Database $dbname -ObjectName DummyEncryptedStoredProcedure -WarningVariable warn -WarningAction SilentlyContinue + Set-DbaSpConfigure -SqlInstance $TestConfig.instance1 -Name RemoteDacConnectionsEnabled -Value $false + Invoke-DbaDbDecryptObject -SqlInstance $TestConfig.instance1 -Database $dbname -ObjectName DummyEncryptedStoredProcedure -WarningVariable warn -WarningAction SilentlyContinue $error[0].Exception | Should -BeLike "*DAC is not enabled for instance*" - Set-DbaSpConfigure -SqlInstance $script:instance1 -Name RemoteDacConnectionsEnabled -Value $true -WarningAction SilentlyContinue + Set-DbaSpConfigure -SqlInstance $TestConfig.instance1 -Name RemoteDacConnectionsEnabled -Value $true -WarningAction SilentlyContinue } } Context "Decrypt Scalar Function" { It -Skip "Should be successful" { - $result = Invoke-DbaDbDecryptObject -SqlInstance $script:instance1 -Database $dbname -ObjectName DummyEncryptedScalarFunction + $result = Invoke-DbaDbDecryptObject -SqlInstance $TestConfig.instance1 -Database $dbname -ObjectName DummyEncryptedScalarFunction $result.Script | Should -Be $queryScalarFunction } } Context "Decrypt Inline TVF" { It -Skip "Should be successful" { - $result = Invoke-DbaDbDecryptObject -SqlInstance $script:instance1 -Database $dbname -ObjectName DummyEncryptedInlineTVF + $result = Invoke-DbaDbDecryptObject -SqlInstance $TestConfig.instance1 -Database $dbname -ObjectName DummyEncryptedInlineTVF $result.Script | Should -Be $queryInlineTVF } } Context "Decrypt TVF" { It -Skip "Should be successful" { - $result = Invoke-DbaDbDecryptObject -SqlInstance $script:instance1 -Database $dbname -ObjectName DummyEncryptedTableValuedFunction + $result = Invoke-DbaDbDecryptObject -SqlInstance $TestConfig.instance1 -Database $dbname -ObjectName DummyEncryptedTableValuedFunction $result.Script | Should -Be $queryTableValuedFunction } } Context "Decrypt Stored Procedure" { It -Skip "Should be successful" { - $result = Invoke-DbaDbDecryptObject -SqlInstance $script:instance1 -Database $dbname -ObjectName DummyEncryptedStoredProcedure + $result = Invoke-DbaDbDecryptObject -SqlInstance $TestConfig.instance1 -Database $dbname -ObjectName DummyEncryptedStoredProcedure $result.Script | Should -Be $queryStoredProcedure } } Context "Decrypt view" { It -Skip "Should be successful" { - $result = Invoke-DbaDbDecryptObject -SqlInstance $script:instance1 -Database $dbname -ObjectName dbatoolsci_test_vw + $result = Invoke-DbaDbDecryptObject -SqlInstance $TestConfig.instance1 -Database $dbname -ObjectName dbatoolsci_test_vw $result.Script | Should -Be $setupView } } Context "Decrypt trigger in a schema other than dbo" { It -Skip "Should be successful" { - $result = Invoke-DbaDbDecryptObject -SqlInstance $script:instance1 -Database $dbname -ObjectName dbatoolsci_test_trigger + $result = Invoke-DbaDbDecryptObject -SqlInstance $TestConfig.instance1 -Database $dbname -ObjectName dbatoolsci_test_trigger $result.Script | Should -Be $setupTrigger } } Context "Decrypt objects with the same name but in different schemas" { It -Skip "Should be successful" { - @(Invoke-DbaDbDecryptObject -SqlInstance $script:instance1 -Database $dbname -ObjectName dbatoolsci_test_schema_vw).Count | Should -Be 2 + @(Invoke-DbaDbDecryptObject -SqlInstance $TestConfig.instance1 -Database $dbname -ObjectName dbatoolsci_test_schema_vw).Count | Should -Be 2 } } Context "Decrypt view with UTF8" { It -Skip "Should be successful" { - $result = Invoke-DbaDbDecryptObject -SqlInstance $script:instance1 -Database $dbname -ObjectName dbatoolsci_test_UTF8_vw -EncodingType UTF8 + $result = Invoke-DbaDbDecryptObject -SqlInstance $TestConfig.instance1 -Database $dbname -ObjectName dbatoolsci_test_UTF8_vw -EncodingType UTF8 $result.Script | Should -Not -BeNullOrEmpty } } Context "Decrypt view and use a destination folder" { It -Skip "Should be successful" { - $result = Invoke-DbaDbDecryptObject -SqlInstance $script:instance1 -Database $dbname -ObjectName dbatoolsci_test_vw -ExportDestination . + $result = Invoke-DbaDbDecryptObject -SqlInstance $TestConfig.instance1 -Database $dbname -ObjectName dbatoolsci_test_vw -ExportDestination . (Get-Content $result.OutputFile | Out-String).Trim() | Should -Be $setupView.Trim() Remove-Item $result.OutputFile } @@ -281,7 +281,7 @@ SELECT 'áéíñóú¡¿' as SampleUTF8;" # Note: this integration test takes about 3.5 minutes because it searches all objects and can be commented out if troubleshooting the other tests. Context "Decrypt all encrypted objects and use a destination folder" { It -Skip "Should be successful" { - $result = Invoke-DbaDbDecryptObject -SqlInstance $script:instance1 -Database $dbname -ExportDestination . + $result = Invoke-DbaDbDecryptObject -SqlInstance $TestConfig.instance1 -Database $dbname -ExportDestination . @($result | Where-Object { $_.Type -eq 'StoredProcedure' }).Count | Should -Be 1 @($result | Where-Object { $_.Type -eq 'Trigger' }).Count | Should -Be 1 @($result | Where-Object { $_.Type -eq 'UserDefinedFunction' }).Count | Should -Be 3 @@ -291,9 +291,9 @@ SELECT 'áéíñóú¡¿' as SampleUTF8;" Context "Connect to an instance (ideally a remote instance) using a SqlCredential and decrypt an object" { It -Skip "Should be successful" { - $result = Invoke-DbaDbDecryptObject -SqlInstance $script:instance2 -SqlCredential $instance2SqlCredential -Database $dbname -ObjectName dbatoolsci_test_remote_dac_vw -ExportDestination . + $result = Invoke-DbaDbDecryptObject -SqlInstance $TestConfig.instance2 -SqlCredential $instance2SqlCredential -Database $dbname -ObjectName dbatoolsci_test_remote_dac_vw -ExportDestination . (Get-Content $result.OutputFile | Out-String).Trim() | Should -Be $remoteDacSampleEncryptedView.Trim() Remove-Item $result.OutputFile } } -} \ No newline at end of file +} diff --git a/tests/Invoke-DbaDbLogShipRecovery.Tests.ps1 b/tests/Invoke-DbaDbLogShipRecovery.Tests.ps1 index 7849c02a57..968a7745c4 100644 --- a/tests/Invoke-DbaDbLogShipRecovery.Tests.ps1 +++ b/tests/Invoke-DbaDbLogShipRecovery.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Invoke-DbaDbLogShipping.Tests.ps1 b/tests/Invoke-DbaDbLogShipping.Tests.ps1 index 4704c91d5a..f4a9f72f32 100644 --- a/tests/Invoke-DbaDbLogShipping.Tests.ps1 +++ b/tests/Invoke-DbaDbLogShipping.Tests.ps1 @@ -1,6 +1,6 @@ $commandname = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Validate parameters" { @@ -20,7 +20,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } It -Skip "returns success" { - $results = Invoke-DbaDbLogShipping -SourceSqlInstance $script:instance2 -DestinationSqlInstance $script:instance -Database $dbname -BackupNetworkPath C:\temp -BackupLocalPath "C:\temp\logshipping\backup" -GenerateFullBackup -CompressBackup -SecondaryDatabaseSuffix "_LS" -Force + $results = Invoke-DbaDbLogShipping -SourceSqlInstance $TestConfig.instance2 -DestinationSqlInstance $TestConfig.instance -Database $dbname -BackupNetworkPath C:\temp -BackupLocalPath "C:\temp\logshipping\backup" -GenerateFullBackup -CompressBackup -SecondaryDatabaseSuffix "_LS" -Force $results.Status -eq 'Success' | Should Be $true } -} \ No newline at end of file +} diff --git a/tests/Invoke-DbaDbMirrorFailover.Tests.ps1 b/tests/Invoke-DbaDbMirrorFailover.Tests.ps1 index fb7b9ffd21..892730783b 100644 --- a/tests/Invoke-DbaDbMirrorFailover.Tests.ps1 +++ b/tests/Invoke-DbaDbMirrorFailover.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Invoke-DbaDbMirroring.Tests.ps1 b/tests/Invoke-DbaDbMirroring.Tests.ps1 index 3b15acac08..0bbb98ef96 100644 --- a/tests/Invoke-DbaDbMirroring.Tests.ps1 +++ b/tests/Invoke-DbaDbMirroring.Tests.ps1 @@ -1,6 +1,6 @@ $commandname = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$commandname Unit Tests" -Tag "UnitTests" { Context "Validate parameters" { @@ -15,28 +15,28 @@ Describe "$commandname Unit Tests" -Tag "UnitTests" { Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $null = Get-DbaProcess -SqlInstance $script:instance2 | Where-Object Program -Match dbatools | Stop-DbaProcess -Confirm:$false -WarningAction SilentlyContinue - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $null = Get-DbaProcess -SqlInstance $TestConfig.instance2 | Where-Object Program -Match dbatools | Stop-DbaProcess -Confirm:$false -WarningAction SilentlyContinue + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $db1 = "dbatoolsci_mirroring" - Remove-DbaDbMirror -SqlInstance $script:instance2 -Database $db1 -Confirm:$false - Remove-DbaDatabase -SqlInstance $script:instance2 -Database $db1 -Confirm:$false - $null = Get-DbaDatabase -SqlInstance $script:instance2 -Database $db1 | Remove-DbaDatabase -Confirm:$false + Remove-DbaDbMirror -SqlInstance $TestConfig.instance2 -Database $db1 -Confirm:$false + Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $db1 -Confirm:$false + $null = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $db1 | Remove-DbaDatabase -Confirm:$false $null = $server.Query("CREATE DATABASE $db1") - Get-DbaEndpoint -SqlInstance $script:instance2 -Type DatabaseMirroring | Remove-DbaEndpoint -Confirm:$false - New-DbaEndpoint -SqlInstance $script:instance2 -Name dbatoolsci_MirroringEndpoint -Type DatabaseMirroring -Port 5022 -Owner sa - Get-DbaEndpoint -SqlInstance $script:instance3 -Type DatabaseMirroring | Remove-DbaEndpoint -Confirm:$false - New-DbaEndpoint -SqlInstance $script:instance3 -Name dbatoolsci_MirroringEndpoint -Type DatabaseMirroring -Port 5023 -Owner sa + Get-DbaEndpoint -SqlInstance $TestConfig.instance2 -Type DatabaseMirroring | Remove-DbaEndpoint -Confirm:$false + New-DbaEndpoint -SqlInstance $TestConfig.instance2 -Name dbatoolsci_MirroringEndpoint -Type DatabaseMirroring -Port 5022 -Owner sa + Get-DbaEndpoint -SqlInstance $TestConfig.instance3 -Type DatabaseMirroring | Remove-DbaEndpoint -Confirm:$false + New-DbaEndpoint -SqlInstance $TestConfig.instance3 -Name dbatoolsci_MirroringEndpoint -Type DatabaseMirroring -Port 5023 -Owner sa } AfterAll { - $null = Remove-DbaDbMirror -SqlInstance $script:instance2, $script:instance3 -Database $db1 -Confirm:$false - $null = Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance2, $script:instance3 -Database $db1 -ErrorAction SilentlyContinue + $null = Remove-DbaDbMirror -SqlInstance $TestConfig.instance2, $TestConfig.instance3 -Database $db1 -Confirm:$false + $null = Remove-DbaDatabase -Confirm:$false -SqlInstance $TestConfig.instance2, $TestConfig.instance3 -Database $db1 -ErrorAction SilentlyContinue } It "returns success" { - $results = Invoke-DbaDbMirroring -Primary $script:instance2 -Mirror $script:instance3 -Database $db1 -Confirm:$false -Force -SharedPath C:\temp -WarningVariable warn + $results = Invoke-DbaDbMirroring -Primary $TestConfig.instance2 -Mirror $TestConfig.instance3 -Database $db1 -Confirm:$false -Force -SharedPath C:\temp -WarningVariable warn $warn | Should -BeNullOrEmpty $results.Status | Should -Be 'Success' } -} \ No newline at end of file +} diff --git a/tests/Invoke-DbaDbPiiScan.Tests.ps1 b/tests/Invoke-DbaDbPiiScan.Tests.ps1 index 8f1a811705..07facf3a75 100644 --- a/tests/Invoke-DbaDbPiiScan.Tests.ps1 +++ b/tests/Invoke-DbaDbPiiScan.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -77,22 +77,22 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { INSERT INTO dbo.TestTable2 VALUES (2, 'Firstname2') " - New-DbaDatabase -SqlInstance $script:instance1 -Name $db - Invoke-DbaQuery -SqlInstance $script:instance1 -Database $db -Query $sql + New-DbaDatabase -SqlInstance $TestConfig.instance1 -Name $db + Invoke-DbaQuery -SqlInstance $TestConfig.instance1 -Database $db -Query $sql } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance1 -Database $db -Confirm:$false + Remove-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $db -Confirm:$false } Context "Command works" { It "starts with the right data" { - Invoke-DbaQuery -SqlInstance $script:instance1 -Database $db -Query "SELECT * FROM Customer WHERE FirstName = 'Delores'" | Should -Not -Be $null - Invoke-DbaQuery -SqlInstance $script:instance1 -Database $db -Query "SELECT * FROM Customer WHERE RandomText = '6011295760226704'" | Should -Not -Be $null + Invoke-DbaQuery -SqlInstance $TestConfig.instance1 -Database $db -Query "SELECT * FROM Customer WHERE FirstName = 'Delores'" | Should -Not -Be $null + Invoke-DbaQuery -SqlInstance $TestConfig.instance1 -Database $db -Query "SELECT * FROM Customer WHERE RandomText = '6011295760226704'" | Should -Not -Be $null } It "returns the proper output" { - $results = Invoke-DbaDbPiiScan -SqlInstance $script:instance1 -Database $db -SampleCount 500 + $results = Invoke-DbaDbPiiScan -SqlInstance $TestConfig.instance1 -Database $db -SampleCount 500 $results.Count | Should -Be 29 $results."PII-Name" | Should -Contain "Creditcard Discover" $results."PII-Name" | Should -Contain "First name" @@ -100,36 +100,36 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } It "ExcludeColumn param" { - $results = Invoke-DbaDbPiiScan -SqlInstance $script:instance1 -Database $db -ExcludeColumn @('CustomerID', 'Firstname', 'Lastname', 'FullName', 'Address', 'Zip', 'City', 'Randomtext') + $results = Invoke-DbaDbPiiScan -SqlInstance $TestConfig.instance1 -Database $db -ExcludeColumn @('CustomerID', 'Firstname', 'Lastname', 'FullName', 'Address', 'Zip', 'City', 'Randomtext') $results.Count | Should -Be 2 $results."PII-Name" | Should -Contain 'IPv4 Address' $results."PII-Name" | Should -Contain 'IPv6 Address' } It "Table param" { - $results = Invoke-DbaDbPiiScan -SqlInstance $script:instance1 -Database $db -Table Customer + $results = Invoke-DbaDbPiiScan -SqlInstance $TestConfig.instance1 -Database $db -Table Customer $results.Count | Should -Be 27 $results.Table | Should -Not -Contain TestTable $results.Table | Should -Not -Contain TestTable2 - $results = Invoke-DbaDbPiiScan -SqlInstance $script:instance1 -Database $db -Table Customer, TestTable + $results = Invoke-DbaDbPiiScan -SqlInstance $TestConfig.instance1 -Database $db -Table Customer, TestTable $results.Count | Should -Be 28 $results.Table | Should -Not -Contain TestTable2 } It "Column param" { - $results = Invoke-DbaDbPiiScan -SqlInstance $script:instance1 -Database $db -Table Customer -Column UnknownColumn + $results = Invoke-DbaDbPiiScan -SqlInstance $TestConfig.instance1 -Database $db -Table Customer -Column UnknownColumn $results.Count | Should -Be 2 $results."PII-Name" | Should -Contain 'IPv4 Address' $results."PII-Name" | Should -Contain 'IPv6 Address' - $results = Invoke-DbaDbPiiScan -SqlInstance $script:instance1 -Database $db -Table Customer -Column UnknownColumn, Firstname + $results = Invoke-DbaDbPiiScan -SqlInstance $TestConfig.instance1 -Database $db -Table Customer -Column UnknownColumn, Firstname $results.Count | Should -Be 3 $results."PII-Name" | Should -Contain 'IPv4 Address' $results."PII-Name" | Should -Contain 'IPv6 Address' $results."PII-Name" | Should -Contain 'First name' - $results = Invoke-DbaDbPiiScan -SqlInstance $script:instance1 -Database $db -Table Customer, TestTable -Column UnknownColumn, Firstname + $results = Invoke-DbaDbPiiScan -SqlInstance $TestConfig.instance1 -Database $db -Table Customer, TestTable -Column UnknownColumn, Firstname $results.Count | Should -Be 4 $results."PII-Name" | Should -Contain 'IPv4 Address' $results."PII-Name" | Should -Contain 'IPv6 Address' @@ -137,29 +137,29 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } It "Country param" { - $results = Invoke-DbaDbPiiScan -SqlInstance $script:instance1 -Database $db -Table Customer -Country Austria + $results = Invoke-DbaDbPiiScan -SqlInstance $TestConfig.instance1 -Database $db -Table Customer -Country Austria $results.Count | Should -Be 9 (($results | Where-Object { $_.Country -eq "Austria" })."PII-Name" -eq "National ID") | Should -Be $true - $results = Invoke-DbaDbPiiScan -SqlInstance $script:instance1 -Database $db -Table Customer -Country Austria, Slovakia + $results = Invoke-DbaDbPiiScan -SqlInstance $TestConfig.instance1 -Database $db -Table Customer -Country Austria, Slovakia $results.Count | Should -Be 10 (($results | Where-Object { $_.Country -eq "Austria" })."PII-Name" -eq "National ID") | Should -Be $true (($results | Where-Object { $_.Country -eq "Slovakia" })."PII-Name" -eq "National ID") | Should -Be $true } It "CountryCode param" { - $results = Invoke-DbaDbPiiScan -SqlInstance $script:instance1 -Database $db -Table Customer -CountryCode SK + $results = Invoke-DbaDbPiiScan -SqlInstance $TestConfig.instance1 -Database $db -Table Customer -CountryCode SK $results.Count | Should -Be 9 (($results | Where-Object { $_.CountryCode -eq "SK" })."PII-Name" -eq "National ID") | Should -Be $true - $results = Invoke-DbaDbPiiScan -SqlInstance $script:instance1 -Database $db -Table Customer -CountryCode AT, SK + $results = Invoke-DbaDbPiiScan -SqlInstance $TestConfig.instance1 -Database $db -Table Customer -CountryCode AT, SK $results.Count | Should -Be 10 (($results | Where-Object { $_.CountryCode -eq "SK" })."PII-Name" -eq "National ID") | Should -Be $true (($results | Where-Object { $_.CountryCode -eq "AT" })."PII-Name" -eq "National ID") | Should -Be $true } It "Custom scan definitions" { - $results = Invoke-DbaDbPiiScan -SqlInstance $script:instance1 -Database $db -KnownNameFilePath "$PSScriptRoot\ObjectDefinitions\Invoke-DbaDbPiiScan\custom-pii-knownnames.json" -PatternFilePath "$PSScriptRoot\ObjectDefinitions\Invoke-DbaDbPiiScan\custom-pii-patterns.json" -ExcludeDefaultKnownName -ExcludeDefaultPattern + $results = Invoke-DbaDbPiiScan -SqlInstance $TestConfig.instance1 -Database $db -KnownNameFilePath "$PSScriptRoot\ObjectDefinitions\Invoke-DbaDbPiiScan\custom-pii-knownnames.json" -PatternFilePath "$PSScriptRoot\ObjectDefinitions\Invoke-DbaDbPiiScan\custom-pii-patterns.json" -ExcludeDefaultKnownName -ExcludeDefaultPattern $results.Count | Should -Be 6 ($results | Where-Object { $_."PII-Name" -eq "First name" }).Count | Should -Be 3 ($results | Where-Object { $_."PII-Name" -eq "IPv4 Address" }).Count | Should -Be 2 @@ -167,21 +167,21 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } It "ExcludeColumn and ExcludeTable params" { - $results = Invoke-DbaDbPiiScan -SqlInstance $script:instance1 -Database $db -ExcludeTable Customer + $results = Invoke-DbaDbPiiScan -SqlInstance $TestConfig.instance1 -Database $db -ExcludeTable Customer $results.Count | Should -Be 2 ($results | Where-Object { $_."PII-Name" -eq "First name" }).Count | Should -Be 2 - $results = Invoke-DbaDbPiiScan -SqlInstance $script:instance1 -Database $db -ExcludeTable Customer, TestTable + $results = Invoke-DbaDbPiiScan -SqlInstance $TestConfig.instance1 -Database $db -ExcludeTable Customer, TestTable $results.Table | Should -Be TestTable2 - $results = Invoke-DbaDbPiiScan -SqlInstance $script:instance1 -Database $db -ExcludeColumn UnknownColumn + $results = Invoke-DbaDbPiiScan -SqlInstance $TestConfig.instance1 -Database $db -ExcludeColumn UnknownColumn $results.Count | Should -Be 27 $results.Column | Should -Not -Contain UnknownColumn - $results = Invoke-DbaDbPiiScan -SqlInstance $script:instance1 -Database $db -ExcludeColumn UnknownColumn, FirstName + $results = Invoke-DbaDbPiiScan -SqlInstance $TestConfig.instance1 -Database $db -ExcludeColumn UnknownColumn, FirstName $results.Count | Should -Be 24 $results.Column | Should -Not -Contain UnknownColumn $results.Column | Should -Not -Contain FirstName } } -} \ No newline at end of file +} diff --git a/tests/Invoke-DbaDbShrink.Tests.ps1 b/tests/Invoke-DbaDbShrink.Tests.ps1 index 4d950f0f22..7505d42c62 100644 --- a/tests/Invoke-DbaDbShrink.Tests.ps1 +++ b/tests/Invoke-DbaDbShrink.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,7 +16,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Verifying Database is shrunk" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $defaultPath = $server | Get-DbaDefaultPath } BeforeEach { @@ -111,4 +111,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $db.LogFiles[0].Size | Should Be $oldLogSize } } -} \ No newline at end of file +} diff --git a/tests/Invoke-DbaDbTransfer.Tests.ps1 b/tests/Invoke-DbaDbTransfer.Tests.ps1 index 02dbf1733f..bca8d3e753 100644 --- a/tests/Invoke-DbaDbTransfer.Tests.ps1 +++ b/tests/Invoke-DbaDbTransfer.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -33,11 +33,11 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { BeforeAll { $dbName = 'dbatools_transfer' - $source = Connect-DbaInstance -SqlInstance $script:instance2 - $destination = Connect-DbaInstance -SqlInstance $script:instance3 - Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbName -Confirm:$false + $source = Connect-DbaInstance -SqlInstance $TestConfig.instance2 + $destination = Connect-DbaInstance -SqlInstance $TestConfig.instance3 + Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbName -Confirm:$false $source.Query("CREATE DATABASE $dbName") - $db = Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbName + $db = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbName $null = $db.Query("CREATE TABLE dbo.transfer_test (id int); INSERT dbo.transfer_test SELECT top 10 1 @@ -60,11 +60,11 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } catch { $null = 1 } - Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbName -Confirm:$false + Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbName -Confirm:$false } Context "Testing scripting invocation" { It "Should script all objects" { - $transfer = New-DbaDbTransfer -SqlInstance $script:instance2 -Database $dbName -CopyAllObjects + $transfer = New-DbaDbTransfer -SqlInstance $TestConfig.instance2 -Database $dbName -CopyAllObjects $scripts = $transfer | Invoke-DbaDbTransfer -ScriptOnly $script = $scripts -join "`n" $script | Should -BeLike '*CREATE TABLE `[dbo`].`[transfer_test`]*' @@ -73,7 +73,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $script | Should -BeLike '*CREATE TABLE `[dbo`].`[transfer_test4`]*' } It "Should script all tables with schema only" { - $scripts = Invoke-DbaDbTransfer -SqlInstance $script:instance2 -Database $dbName -CopyAll Tables -SchemaOnly -ScriptOnly + $scripts = Invoke-DbaDbTransfer -SqlInstance $TestConfig.instance2 -Database $dbName -CopyAll Tables -SchemaOnly -ScriptOnly $script = $scripts -join "`n" $script | Should -BeLike '*CREATE TABLE `[dbo`].`[transfer_test`]*' $script | Should -BeLike '*CREATE TABLE `[dbo`].`[transfer_test2`]*' @@ -83,44 +83,44 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } Context "Testing object transfer" { BeforeEach { - Remove-DbaDatabase -SqlInstance $script:instance3 -Database $dbName -Confirm:$false + Remove-DbaDatabase -SqlInstance $TestConfig.instance3 -Database $dbName -Confirm:$false $destination.Query("CREATE DATABASE $dbname") - $db2 = Get-DbaDatabase -SqlInstance $script:instance3 -Database $dbName + $db2 = Get-DbaDatabase -SqlInstance $TestConfig.instance3 -Database $dbName } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance3 -Database $dbName -Confirm:$false + Remove-DbaDatabase -SqlInstance $TestConfig.instance3 -Database $dbName -Confirm:$false } It "Should transfer all tables" { - $result = Invoke-DbaDbTransfer -SqlInstance $script:instance2 -DestinationSqlInstance $script:instance3 -Database $dbName -CopyAll Tables - $tables = Get-DbaDbTable -SqlInstance $script:instance3 -Database $dbName -Table transfer_test, transfer_test2, transfer_test3, transfer_test4 + $result = Invoke-DbaDbTransfer -SqlInstance $TestConfig.instance2 -DestinationSqlInstance $TestConfig.instance3 -Database $dbName -CopyAll Tables + $tables = Get-DbaDbTable -SqlInstance $TestConfig.instance3 -Database $dbName -Table transfer_test, transfer_test2, transfer_test3, transfer_test4 $tables.Count | Should -Be 4 $db.Query("select id from dbo.transfer_test").id | Should -Not -BeNullOrEmpty $db.Query("select id from dbo.transfer_test4").id | Should -Not -BeNullOrEmpty $db.Query("select id from dbo.transfer_test").id | Should -BeIn $db2.Query("select id from dbo.transfer_test").id $db.Query("select id from dbo.transfer_test4").id | Should -BeIn $db2.Query("select id from dbo.transfer_test4").id - $result.SourceInstance | Should -Be $script:instance2 + $result.SourceInstance | Should -Be $TestConfig.instance2 $result.SourceDatabase | Should -Be $dbName - $result.DestinationInstance | Should -Be $script:instance3 + $result.DestinationInstance | Should -Be $TestConfig.instance3 $result.DestinationDatabase | Should -Be $dbName $result.Elapsed.TotalMilliseconds | Should -BeGreaterThan 0 $result.Status | Should -Be 'Success' $result.Log -join "`n" | Should -BeLike '*CREATE TABLE `[dbo`].`[transfer_test`]*' } It "Should transfer select tables piping the transfer object" { - $sourceTables = Get-DbaDbTable -SqlInstance $script:instance2 -Database $dbName -Table transfer_test, transfer_test2 - $transfer = $sourceTables | New-DbaDbTransfer -SqlInstance $script:instance2 -DestinationSqlInstance $script:instance3 -Database $dbName + $sourceTables = Get-DbaDbTable -SqlInstance $TestConfig.instance2 -Database $dbName -Table transfer_test, transfer_test2 + $transfer = $sourceTables | New-DbaDbTransfer -SqlInstance $TestConfig.instance2 -DestinationSqlInstance $TestConfig.instance3 -Database $dbName $result = $transfer | Invoke-DbaDbTransfer - $tables = Get-DbaDbTable -SqlInstance $script:instance3 -Database $dbName -Table transfer_test, transfer_test2 + $tables = Get-DbaDbTable -SqlInstance $TestConfig.instance3 -Database $dbName -Table transfer_test, transfer_test2 $tables.Count | Should -Be 2 $db.Query("select id from dbo.transfer_test").id | Should -Not -BeNullOrEmpty $db.Query("select id from dbo.transfer_test").id | Should -BeIn $db2.Query("select id from dbo.transfer_test").id - $result.SourceInstance | Should -Be $script:instance2 + $result.SourceInstance | Should -Be $TestConfig.instance2 $result.SourceDatabase | Should -Be $dbName - $result.DestinationInstance | Should -Be $script:instance3 + $result.DestinationInstance | Should -Be $TestConfig.instance3 $result.DestinationDatabase | Should -Be $dbName $result.Elapsed.TotalMilliseconds | Should -BeGreaterThan 0 $result.Status | Should -Be 'Success' $result.Log -join "`n" | Should -BeLike '*CREATE TABLE `[dbo`].`[transfer_test`]*' } } -} \ No newline at end of file +} diff --git a/tests/Invoke-DbaDbUpgrade.Tests.ps1 b/tests/Invoke-DbaDbUpgrade.Tests.ps1 index aa71489b4a..46712638d2 100644 --- a/tests/Invoke-DbaDbUpgrade.Tests.ps1 +++ b/tests/Invoke-DbaDbUpgrade.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Invoke-DbaDbccDropCleanBuffer.Tests.ps1 b/tests/Invoke-DbaDbccDropCleanBuffer.Tests.ps1 index 3b2167edcd..6bd485d958 100644 --- a/tests/Invoke-DbaDbccDropCleanBuffer.Tests.ps1 +++ b/tests/Invoke-DbaDbccDropCleanBuffer.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -14,7 +14,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { } Describe "$commandname Integration Test" -Tag "IntegrationTests" { $props = 'ComputerName', 'InstanceName', 'SqlInstance', 'Cmd', 'Output' - $result = Invoke-DbaDbccDropCleanBuffer -SqlInstance $script:instance1 -Confirm:$false + $result = Invoke-DbaDbccDropCleanBuffer -SqlInstance $TestConfig.instance1 -Confirm:$false Context "Validate standard output" { foreach ($prop in $props) { @@ -31,11 +31,11 @@ Describe "$commandname Integration Test" -Tag "IntegrationTests" { } It "returns the right results for -NoInformationalMessages" { - $result = Invoke-DbaDbccDropCleanBuffer -SqlInstance $script:instance1 -NoInformationalMessages -Confirm:$false + $result = Invoke-DbaDbccDropCleanBuffer -SqlInstance $TestConfig.instance1 -NoInformationalMessages -Confirm:$false $result.Cmd -match 'DBCC DROPCLEANBUFFERS WITH NO_INFOMSGS' | Should Be $true $result.Output -eq $null | Should Be $true } } -} \ No newline at end of file +} diff --git a/tests/Invoke-DbaDbccFreeCache.Tests.ps1 b/tests/Invoke-DbaDbccFreeCache.Tests.ps1 index 46606ba847..f8fe0bf98d 100644 --- a/tests/Invoke-DbaDbccFreeCache.Tests.ps1 +++ b/tests/Invoke-DbaDbccFreeCache.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -14,7 +14,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { } Describe "$commandname Integration Test" -Tag "IntegrationTests" { $props = 'ComputerName', 'InstanceName', 'SqlInstance', 'Operation', 'Cmd', 'Output' - $result = Invoke-DbaDbccFreeCache -SqlInstance $script:instance2 -Operation FreeSystemCache -Confirm:$false + $result = Invoke-DbaDbccFreeCache -SqlInstance $TestConfig.instance2 -Operation FreeSystemCache -Confirm:$false Context "Validate standard output" { foreach ($prop in $props) { @@ -32,22 +32,22 @@ Describe "$commandname Integration Test" -Tag "IntegrationTests" { } It "returns the right results for FREESESSIONCACHE" { - $result = Invoke-DbaDbccFreeCache -SqlInstance $script:instance2 -Operation FreeSessionCache -Confirm:$false + $result = Invoke-DbaDbccFreeCache -SqlInstance $TestConfig.instance2 -Operation FreeSessionCache -Confirm:$false $result.Operation -match 'FREESESSIONCACHE' | Should Be $true $result.Output -match 'DBCC execution completed. If DBCC printed error messages, contact your system administrator.' | Should Be $true } It "returns the right results for FREEPROCCACHE" { - $result = Invoke-DbaDbccFreeCache -SqlInstance $script:instance2 -Operation FREEPROCCACHE -Confirm:$false + $result = Invoke-DbaDbccFreeCache -SqlInstance $TestConfig.instance2 -Operation FREEPROCCACHE -Confirm:$false $result.Operation -match 'FREEPROCCACHE' | Should Be $true $result.Output -match 'DBCC execution completed. If DBCC printed error messages, contact your system administrator.' | Should Be $true } It "returns the right results for FREESESSIONCACHE and using NoInformationalMessages" { - $result = Invoke-DbaDbccFreeCache -SqlInstance $script:instance2 -Operation FreeSessionCache -NoInformationalMessages -Confirm:$false + $result = Invoke-DbaDbccFreeCache -SqlInstance $TestConfig.instance2 -Operation FreeSessionCache -NoInformationalMessages -Confirm:$false $result.Operation -match 'FREESESSIONCACHE' | Should Be $true $result.Output | Should Be $null } } -} \ No newline at end of file +} diff --git a/tests/Invoke-DbaDiagnosticQuery.Tests.ps1 b/tests/Invoke-DbaDiagnosticQuery.Tests.ps1 index 4ba3d6ad9d..33eeebe17d 100644 --- a/tests/Invoke-DbaDiagnosticQuery.Tests.ps1 +++ b/tests/Invoke-DbaDiagnosticQuery.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -19,7 +19,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $database = "dbatoolsci_frk_$(Get-Random)" $database2 = "dbatoolsci_frk_$(Get-Random)" $database3 = "dbatoolsci_frk_$(Get-Random)" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $server.Query("CREATE DATABASE [$database]") $server.Query("CREATE DATABASE [$database2]") $server.Query("CREATE DATABASE [$database3]") @@ -43,30 +43,30 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "verifying output when running queries" { It "runs a specific query" { - $results = Invoke-DbaDiagnosticQuery -SqlInstance $script:instance2 -QueryName 'Memory Clerk Usage' + $results = Invoke-DbaDiagnosticQuery -SqlInstance $TestConfig.instance2 -QueryName 'Memory Clerk Usage' @($results).Count | Should -Be 1 } It "works with DatabaseSpecific" { - $results = Invoke-DbaDiagnosticQuery -SqlInstance $script:instance2 -DatabaseSpecific + $results = Invoke-DbaDiagnosticQuery -SqlInstance $TestConfig.instance2 -DatabaseSpecific @($results).Count | Should -BeGreaterThan 10 } It "works with specific database provided" { - $results = Invoke-DbaDiagnosticQuery -SqlInstance $script:instance2 -QueryName 'File Sizes and Space', 'Log Space Usage' -Database $database2, $database3 + $results = Invoke-DbaDiagnosticQuery -SqlInstance $TestConfig.instance2 -QueryName 'File Sizes and Space', 'Log Space Usage' -Database $database2, $database3 @($results | Where-Object {$_.Database -eq $Database}).Count | Should -Be 0 @($results | Where-Object {$_.Database -eq $Database2}).Count | Should -Be 2 @($results | Where-Object {$_.Database -eq $Database3}).Count | Should -Be 2 } It "works with Exclude Databases provided" { - $results = Invoke-DbaDiagnosticQuery -SqlInstance $script:instance2 -DatabaseSpecific -ExcludeDatabase $database2 + $results = Invoke-DbaDiagnosticQuery -SqlInstance $TestConfig.instance2 -DatabaseSpecific -ExcludeDatabase $database2 @($results | Where-Object {$_.Database -eq $Database}).Count | Should -BeGreaterThan 1 @($results | Where-Object {$_.Database -eq $Database2}).Count | Should -Be 0 } It "Correctly excludes queries when QueryName and ExcludeQuery parameters are used" { - $results = Invoke-DbaDiagnosticQuery -SqlInstance $script:instance2 -QueryName 'Version Info', 'Core Counts', 'Server Properties' -ExcludeQuery 'Core Counts' + $results = Invoke-DbaDiagnosticQuery -SqlInstance $TestConfig.instance2 -QueryName 'Version Info', 'Core Counts', 'Server Properties' -ExcludeQuery 'Core Counts' @($results).Count | Should be 2 } It "Correctly excludes queries when only ExcludeQuery parameter is used" { - $results = Invoke-DbaDiagnosticQuery -SqlInstance $script:instance2 -ExcludeQuery "Missing Index Warnings", "Buffer Usage" + $results = Invoke-DbaDiagnosticQuery -SqlInstance $TestConfig.instance2 -ExcludeQuery "Missing Index Warnings", "Buffer Usage" @($results).Count | Should -BeGreaterThan 0 @($results | Where-Object Name -eq "Missing Index Warnings").Count | Should be 0 @($results | Where-Object Name -eq "Buffer Usage").Count | Should be 0 @@ -75,7 +75,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $columnnames = 'Item', 'RowError', 'RowState', 'Table', 'ItemArray', 'HasErrors' $TestCases = @() $columnnames.ForEach{$TestCases += @{columnname = $PSItem}} - $results = Invoke-DbaDiagnosticQuery -SqlInstance $script:instance2 -QueryName 'Memory Clerk Usage' + $results = Invoke-DbaDiagnosticQuery -SqlInstance $TestConfig.instance2 -QueryName 'Memory Clerk Usage' It "correctly excludes default column name " -TestCases $TestCases { Param($columnname) @($results.Result | Get-Member | Where-Object Name -eq $columnname).Count | Should be 0 @@ -85,22 +85,22 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { context "verifying output when exporting queries as files instead of running" { It "exports queries to sql files without running" { - $null = Invoke-DbaDiagnosticQuery -SqlInstance $script:instance2 -ExportQueries -QueryName 'Memory Clerk Usage' -OutputPath $script:PesterOutputPath + $null = Invoke-DbaDiagnosticQuery -SqlInstance $TestConfig.instance2 -ExportQueries -QueryName 'Memory Clerk Usage' -OutputPath $script:PesterOutputPath @(Get-ChildItem -path $script:PesterOutputPath -filter *.sql).Count | Should -Be 1 } It "exports single database specific query against single database" { - $null = Invoke-DbaDiagnosticQuery -SqlInstance $script:instance2 -ExportQueries -DatabaseSpecific -QueryName 'Database-scoped Configurations' -Database $database -OutputPath $script:PesterOutputPath + $null = Invoke-DbaDiagnosticQuery -SqlInstance $TestConfig.instance2 -ExportQueries -DatabaseSpecific -QueryName 'Database-scoped Configurations' -Database $database -OutputPath $script:PesterOutputPath @(Get-ChildItem -path $script:PesterOutputPath -filter *.sql | Where-Object {$_.FullName -match "($database)"}).Count | Should -Be 1 } It "exports a database specific query foreach specific database provided" { - $null = Invoke-DbaDiagnosticQuery -SqlInstance $script:instance2 -ExportQueries -DatabaseSpecific -QueryName 'Database-scoped Configurations' -Database @($database, $database2) -OutputPath $script:PesterOutputPath + $null = Invoke-DbaDiagnosticQuery -SqlInstance $TestConfig.instance2 -ExportQueries -DatabaseSpecific -QueryName 'Database-scoped Configurations' -Database @($database, $database2) -OutputPath $script:PesterOutputPath @(Get-ChildItem -path $script:PesterOutputPath -filter *.sql | Where-Object {$_.FullName -match "($database)|($database2)"}).Count | Should -Be 2 } It "exports database specific query when multiple specific databases are referenced" { - $null = Invoke-DbaDiagnosticQuery -SqlInstance $script:instance2 -ExportQueries -DatabaseSpecific -QueryName 'Database-scoped Configurations' -Database @($database, $database2) -OutputPath $script:PesterOutputPath + $null = Invoke-DbaDiagnosticQuery -SqlInstance $TestConfig.instance2 -ExportQueries -DatabaseSpecific -QueryName 'Database-scoped Configurations' -Database @($database, $database2) -OutputPath $script:PesterOutputPath @(Get-ChildItem -path $script:PesterOutputPath -filter *.sql | Where-Object {$_.FullName -match "($database)|($database2)"}).Count | Should -Be 2 } @@ -108,13 +108,13 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { context "verifying output when running database specific queries" { It "runs database specific queries against single database only when providing database name" { - $results = Invoke-DbaDiagnosticQuery -SqlInstance $script:instance2 -DatabaseSpecific -QueryName 'Database-scoped Configurations' -Database $database + $results = Invoke-DbaDiagnosticQuery -SqlInstance $TestConfig.instance2 -DatabaseSpecific -QueryName 'Database-scoped Configurations' -Database $database @($results).Count | Should -Be 1 } It "runs database specific queries against set of databases when provided with multiple database names" { - $results = Invoke-DbaDiagnosticQuery -SqlInstance $script:instance2 -DatabaseSpecific -QueryName 'Database-scoped Configurations' -Database @($database, $database2) + $results = Invoke-DbaDiagnosticQuery -SqlInstance $TestConfig.instance2 -DatabaseSpecific -QueryName 'Database-scoped Configurations' -Database @($database, $database2) @($results).Count | Should -Be 2 } } -} \ No newline at end of file +} diff --git a/tests/Invoke-DbaPfRelog.Tests.ps1 b/tests/Invoke-DbaPfRelog.Tests.ps1 index 64439268cf..372e8c237e 100644 --- a/tests/Invoke-DbaPfRelog.Tests.ps1 +++ b/tests/Invoke-DbaPfRelog.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Invoke-DbaQuery.Tests.ps1 b/tests/Invoke-DbaQuery.Tests.ps1 index 98acdeb4ee..9636656cbc 100644 --- a/tests/Invoke-DbaQuery.Tests.ps1 +++ b/tests/Invoke-DbaQuery.Tests.ps1 @@ -1,14 +1,22 @@ -$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +#HaveParameter - yeah, I know. + +BeforeAll { + $CommandName = (Get-Item $PSCommandPath).Name.Replace(".Tests.ps1", "") + Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan + $global:TestConfig = Get-TestConfig +} + 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', 'Database', 'Query', 'QueryTimeout', 'File', 'SqlObject', 'As', 'SqlParameter', 'AppendServerInstance', 'MessagesToOutput', 'InputObject', 'ReadOnly', 'EnableException', 'CommandType', 'NoExec' - $knownParameters += [System.Management.Automation.PSCmdlet]::CommonParameters + BeforeAll { + $command = Get-Command Invoke-DbaQuery + } It "Should only contain our specific parameters" { - (@(Compare-Object -ReferenceObject ($knownParameters | Where-Object { $_ }) -DifferenceObject $params).Count ) | Should Be 0 + [object[]]$params = $command.Parameters.Keys | Where-Object { $_ -notin ('whatif', 'confirm') } + [object[]]$knownParameters = 'SqlInstance', 'SqlCredential', 'Database', 'Query', 'QueryTimeout', 'File', 'SqlObject', 'As', 'SqlParameter', 'AppendServerInstance', 'MessagesToOutput', 'InputObject', 'ReadOnly', 'EnableException', 'CommandType', 'NoExec' + $knownParameters += [System.Management.Automation.PSCmdlet]::CommonParameters + (@(Compare-Object -ReferenceObject ($knownParameters | Where-Object { $_ }) -DifferenceObject $params).Count ) | Should -Be 0 } } Context "Validate alias" { @@ -20,7 +28,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $db = Get-DbaDatabase -SqlInstance $script:instance2 -Database tempdb + $db = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database tempdb $null = $db.Query("CREATE PROCEDURE dbo.dbatoolsci_procedure_example @p1 [INT] = 0 AS BEGIN SET NOCOUNT OFF; SELECT TestColumn = @p1; END") } AfterAll { @@ -33,30 +41,30 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Remove-Item ".\hellorelative.sql" -ErrorAction SilentlyContinue } It "supports pipable instances" { - $results = $script:instance2, $script:instance3 | Invoke-DbaQuery -Database tempdb -Query "Select 'hello' as TestColumn" + $results = $TestConfig.instance2, $TestConfig.instance3 | Invoke-DbaQuery -Database tempdb -Query "Select 'hello' as TestColumn" foreach ($result in $results) { $result.TestColumn | Should -Be 'hello' } } It "supports parameters" { $sqlParams = @{ testvalue = 'hello' } - $results = $script:instance2 | Invoke-DbaQuery -Database tempdb -Query "Select @testvalue as TestColumn" -SqlParameters $sqlParams + $results = $TestConfig.instance2 | Invoke-DbaQuery -Database tempdb -Query "Select @testvalue as TestColumn" -SqlParameters $sqlParams foreach ($result in $results) { $result.TestColumn | Should -Be 'hello' } } It "supports AppendServerInstance" { - $conn1 = Connect-DbaInstance $script:instance2 - $conn2 = Connect-DbaInstance $script:instance3 + $conn1 = Connect-DbaInstance $TestConfig.instance2 + $conn2 = Connect-DbaInstance $TestConfig.instance3 $serverInstances = $conn1.Name, $conn2.Name - $results = $script:instance2, $script:instance3 | Invoke-DbaQuery -Database tempdb -Query "Select 'hello' as TestColumn" -AppendServerInstance + $results = $TestConfig.instance2, $TestConfig.instance3 | Invoke-DbaQuery -Database tempdb -Query "Select 'hello' as TestColumn" -AppendServerInstance foreach ($result in $results) { $result.ServerInstance | Should -Not -Be Null $result.ServerInstance | Should -BeIn $serverInstances } } It "supports pipable databases" { - $dbs = Get-DbaDatabase -SqlInstance $script:instance2, $script:instance3 + $dbs = Get-DbaDatabase -SqlInstance $TestConfig.instance2, $TestConfig.instance3 $results = $dbs | Invoke-DbaQuery -Query "Select 'hello' as TestColumn, DB_NAME() as dbname" foreach ($result in $results) { $result.TestColumn | Should -Be 'hello' @@ -64,13 +72,13 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { 'tempdb' | Should -BeIn $results.dbname } It "stops when piped databases and -Database" { - $dbs = Get-DbaDatabase -SqlInstance $script:instance2, $script:instance3 - { $dbs | Invoke-DbaQuery -Query "Select 'hello' as TestColumn, DB_NAME() as dbname" -Database tempdb -EnableException } | Should Throw "You can't" + $dbs = Get-DbaDatabase -SqlInstance $TestConfig.instance2, $TestConfig.instance3 + { $dbs | Invoke-DbaQuery -Query "Select 'hello' as TestColumn, DB_NAME() as dbname" -Database tempdb -EnableException } | Should -Throw "You can't*" } It "supports reading files" { $testPath = "TestDrive:\dbasqlquerytest.txt" Set-Content $testPath -Value "Select 'hello' as TestColumn, DB_NAME() as dbname" - $results = Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -File $testPath + $results = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database tempdb -File $testPath foreach ($result in $results) { $result.TestColumn | Should -Be 'hello' } @@ -82,7 +90,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Set-Content "$testPath\dbasqlquerytest2.sql" -Value "Select 'hello2' as TestColumn, DB_NAME() as dbname" Set-Content "$testPath\dbasqlquerytest2.txt" -Value "Select 'hello3' as TestColumn, DB_NAME() as dbname" $pathinfo = Get-Item $testpath - $results = Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -File $pathinfo + $results = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database tempdb -File $pathinfo 'hello' | Should -BeIn $results.TestColumn 'hello2' | Should -BeIn $results.TestColumn 'hello3' | Should -Not -BeIn $results.TestColumn @@ -91,29 +99,29 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } It "supports http files" { $cleanup = "IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[CommandLog]') AND type in (N'U')) DROP TABLE [dbo].[CommandLog]" - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -Query $cleanup + $null = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database tempdb -Query $cleanup $CloudQuery = 'https://raw.githubusercontent.com/dataplat/appveyor-lab/master/sql2016-startup/ola/CommandLog.sql' - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -File $CloudQuery + $null = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database tempdb -File $CloudQuery $check = "SELECT name FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[CommandLog]') AND type in (N'U')" - $results = Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -Query $check + $results = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database tempdb -Query $check $results.Name | Should -Be 'CommandLog' - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -Query $cleanup + $null = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database tempdb -Query $cleanup } It "supports smo objects" { $cleanup = "IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[CommandLog]') AND type in (N'U')) DROP TABLE [dbo].[CommandLog]" - $null = Invoke-DbaQuery -SqlInstance $script:instance2, $script:instance3 -Database tempdb -Query $cleanup + $null = Invoke-DbaQuery -SqlInstance $TestConfig.instance2, $TestConfig.instance3 -Database tempdb -Query $cleanup $CloudQuery = 'https://raw.githubusercontent.com/dataplat/appveyor-lab/master/sql2016-startup/ola/CommandLog.sql' - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -File $CloudQuery - $smoobj = Get-DbaDbTable -SqlInstance $script:instance2 -Database tempdb | Where-Object Name -EQ 'CommandLog' - $null = Invoke-DbaQuery -SqlInstance $script:instance3 -Database tempdb -SqlObject $smoobj + $null = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database tempdb -File $CloudQuery + $smoobj = Get-DbaDbTable -SqlInstance $TestConfig.instance2 -Database tempdb | Where-Object Name -EQ 'CommandLog' + $null = Invoke-DbaQuery -SqlInstance $TestConfig.instance3 -Database tempdb -SqlObject $smoobj $check = "SELECT name FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[CommandLog]') AND type in (N'U')" - $results = Invoke-DbaQuery -SqlInstance $script:instance3 -Database tempdb -Query $check - $results.Name | Should Be 'CommandLog' - $null = Invoke-DbaQuery -SqlInstance $script:instance2, $script:instance3 -Database tempdb -Query $cleanup + $results = Invoke-DbaQuery -SqlInstance $TestConfig.instance3 -Database tempdb -Query $check + $results.Name | Should -Be 'CommandLog' + $null = Invoke-DbaQuery -SqlInstance $TestConfig.instance2, $TestConfig.instance3 -Database tempdb -Query $cleanup } <# It "supports loose objects (with SqlInstance and database props)" { - $dbs = Get-DbaDbState -SqlInstance $script:instance2, $script:instance3 + $dbs = Get-DbaDbState -SqlInstance $TestConfig.instance2, $TestConfig.instance3 $results = $dbs | Invoke-DbaQuery -Query "Select 'hello' as TestColumn, DB_NAME() as dbname" foreach ($result in $results) { $result.TestColumn | Should -Be 'hello' @@ -125,7 +133,7 @@ SELECT DB_NAME() as dbname GO SELECT @@servername as dbname '@ - $results = $script:instance2, $script:instance3 | Invoke-DbaQuery -Database tempdb -Query $Query + $results = $TestConfig.instance2, $TestConfig.instance3 | Invoke-DbaQuery -Database tempdb -Query $Query $results.dbname -contains 'tempdb' | Should -Be $true } It "streams correctly 'messages' with Verbose" { @@ -145,7 +153,7 @@ SELECT @@servername as dbname PRINT 'stmt_6|PRINT end|' + CONVERT(VARCHAR(19), GETUTCDATE(), 126) '@ $results = @() - Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -Query $query -Verbose 4>&1 | ForEach-Object { + Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database tempdb -Query $query -Verbose 4>&1 | ForEach-Object { $results += [pscustomobject]@{ FiredAt = (Get-Date).ToUniversalTime() Out = $_ @@ -176,7 +184,7 @@ SELECT @@servername as dbname PRINT 'stmt_6|PRINT end|' + CONVERT(VARCHAR(19), GETUTCDATE(), 126) '@ $results = @() - Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -Query $query -MessagesToOutput | ForEach-Object { + Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database tempdb -Query $query -MessagesToOutput | ForEach-Object { $results += [pscustomobject]@{ FiredAt = (Get-Date).ToUniversalTime() Out = $_ @@ -186,19 +194,19 @@ SELECT @@servername as dbname ($results | ForEach-Object { Get-Date -Date $_.FiredAt -Format s } | Get-Unique).Count | Should -Not -Be 1 # the first WITH NOWAIT (stmt_4) and after } It "Executes stored procedures with parameters" { - $results = Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -Query "dbatoolsci_procedure_example" -SqlParameters @{p1 = 1 } -CommandType StoredProcedure - $results.TestColumn | Should Be 1 + $results = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database tempdb -Query "dbatoolsci_procedure_example" -SqlParameters @{p1 = 1 } -CommandType StoredProcedure + $results.TestColumn | Should -Be 1 } It "Executes script file with a relative path (see #6184)" { Set-Content -Path ".\hellorelative.sql" -Value "Select 'hello' as TestColumn, DB_NAME() as dbname" - $results = Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -File ".\hellorelative.sql" + $results = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database tempdb -File ".\hellorelative.sql" foreach ($result in $results) { $result.TestColumn | Should -Be 'hello' } 'tempdb' | Should -BeIn $results.dbname } It "supports multiple datatables also as array of PSObjects (see #6921)" { - $results = Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -Query "select 1 as a union all select 2 union all select 3; select 4 as b, 5 as c union all select 6, 7;" -As PSObjectArray + $results = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database tempdb -Query "select 1 as a union all select 2 union all select 3; select 4 as b, 5 as c union all select 6, 7;" -As PSObjectArray $results.Count | Should -Be 2 $results[0].Count | Should -Be 3 $results[0][0].a | Should -Be 1 @@ -207,7 +215,7 @@ SELECT @@servername as dbname $results[1][1].c | Should -Be 7 } It "supports multiple datatables also as PSObjects (see #6921)" { - $results = Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -Query "select 1 as a union all select 2 union all select 3; select 4 as b, 5 as c union all select 6, 7;" -As PSObject + $results = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database tempdb -Query "select 1 as a union all select 2 union all select 3; select 4 as b, 5 as c union all select 6, 7;" -As PSObject $results.Count | Should -Be 5 $results[0].a | Should -Be 1 $results[3].b | Should -Be 4 @@ -215,7 +223,7 @@ SELECT @@servername as dbname } It "supports using SqlParameters as Microsoft.Data.SqlClient.SqlParameter (#7434)" { - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -Query "CREATE OR ALTER PROC [dbo].[my_proc] + $null = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database tempdb -Query "CREATE OR ALTER PROC [dbo].[my_proc] @json_result nvarchar(max) output AS BEGIN @@ -225,12 +233,12 @@ SELECT @@servername as dbname ); END" $output = New-DbaSqlParameter -ParameterName json_result -SqlDbType NVarChar -Size -1 -Direction Output - Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -CommandType StoredProcedure -Query my_proc -SqlParameters $output + Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database tempdb -CommandType StoredProcedure -Query my_proc -SqlParameters $output $output.Value | Should -Be '{"example":"sample"}' } It "supports using multiple and mixed params, even with different names (#7434)" { - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -Query "CREATE OR ALTER PROCEDURE usp_Insertsomething + $null = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database tempdb -Query "CREATE OR ALTER PROCEDURE usp_Insertsomething @somevalue varchar(10), @newid varchar(50) OUTPUT AS @@ -243,14 +251,14 @@ SELECT @@servername as dbname 'newid' = $outparam 'somevalue' = 'asd' } - $result = Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -Query "EXEC usp_Insertsomething @somevalue, @newid output" -SqlParameters $sqlparams + $result = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database tempdb -Query "EXEC usp_Insertsomething @somevalue, @newid output" -SqlParameters $sqlparams $outparam.Value | Should -Be '12345' $result.'input param' | Should -Be 'asd' $result.somevalue | Should -Be 'fixedval' } It "supports using the same parameters multiple times (#9217)" { - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -Query "CREATE OR ALTER PROCEDURE usp_Insertsomething + $null = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database tempdb -Query "CREATE OR ALTER PROCEDURE usp_Insertsomething @somevalue varchar(10), @newid varchar(50) OUTPUT AS @@ -264,19 +272,19 @@ SELECT @@servername as dbname 'newid' = $outparam 'somevalue' = $inparam } - $result1 = Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -Query "EXEC usp_Insertsomething @somevalue, @newid output" -SqlParameters $sqlparams + $result1 = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database tempdb -Query "EXEC usp_Insertsomething @somevalue, @newid output" -SqlParameters $sqlparams $outparam.Value | Should -Be '12345' $result1.'input param' | Should -Be 'example' $result1.somevalue | Should -Be 'fixedval' - $result2 = Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -Query "EXEC usp_Insertsomething @somevalue, @newid output" -SqlParameters $sqlparams + $result2 = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database tempdb -Query "EXEC usp_Insertsomething @somevalue, @newid output" -SqlParameters $sqlparams $outparam.Value | Should -Be '12345' $result2.'input param' | Should -Be 'example' $result2.somevalue | Should -Be 'fixedval' } It "supports complex types, such as datatables (#7434)" { - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -Query " + $null = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database tempdb -Query " IF NOT EXISTS (SELECT * FROM sys.types WHERE name = N'dbatools_tabletype') CREATE TYPE dbatools_tabletype AS TABLE( somestring varchar(50), @@ -305,7 +313,7 @@ END" 'newid' = $outparam 'sometable' = New-DbaSqlParameter -SqlDbType structured -Value (ConvertTo-DbaDataTable -InputObject $inparam) -TypeName 'dbatools_tabletype' } - $result = Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -Query "EXEC usp_Insertsomething @sometable, @newid output" -SqlParameters $sqlparams + $result = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database tempdb -Query "EXEC usp_Insertsomething @sometable, @newid output" -SqlParameters $sqlparams $outparam.Value | Should -Be '12345' $result.Count | Should -Be 2 $result[0].somestring | Should -Be 'string1' @@ -313,7 +321,7 @@ END" } It "support NOEXEC mode" { - $result = Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -Query "SELECT 1" -NoExec + $result = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database tempdb -Query "SELECT 1" -NoExec $result | Should -BeNullOrEmpty #for multiple batches, too $q = @' @@ -321,10 +329,10 @@ SELECT 1 GO SELECT 2 '@ - $result = Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -Query $q -NoExec + $result = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database tempdb -Query $q -NoExec $result | Should -BeNullOrEmpty - { Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -Query "SELEC p FROM c" -NoExec -EnableException } | Should -Throw "Incorrect syntax near 'selec'" + { Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database tempdb -Query "SELEC p FROM c" -NoExec -EnableException } | Should -Throw "Incorrect syntax near 'SELEC'." } It "supports dropping temp objects (#8472)" { @@ -334,17 +342,15 @@ SELECT 2 GO drop procedure #DropStatistics go" - { Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -Query $sql -EnableException } | Should -Not -Throw + { Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database tempdb -Query $sql -EnableException } | Should -Not -Throw } It "supports geography types (#8541)" { - $results = Invoke-DbaQuery -SqlInstance $script:instance2 -Query "select cast(null as geometry)" + $results = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Query "select cast(null as geometry)" $results.Column1 | Should -Be "Null" - $results = Invoke-DbaQuery -SqlInstance $script:instance2 -Query "select cast(null as geography)" + $results = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Query "select cast(null as geography)" $results.Column1 | Should -Be "Null" - $results = Invoke-DbaQuery -SqlInstance $script:instance2 -Query "select cast(null as hierarchyid)" + $results = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Query "select cast(null as hierarchyid)" $results.Column1 | Should -Be "NULL" } - - } diff --git a/tests/Invoke-DbaWhoisActive.Tests.ps1 b/tests/Invoke-DbaWhoisActive.Tests.ps1 index 629d22a60b..44dceabb70 100644 --- a/tests/Invoke-DbaWhoisActive.Tests.ps1 +++ b/tests/Invoke-DbaWhoisActive.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,13 +15,13 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $testzippath = "$script:appveyorlabrepo\CommunitySoftware\sp_whoisactive-12.00.zip" - $resultInstallMaster = Install-DbaWhoIsActive -SqlInstance $script:instance1 -LocalFile $testzippath -Database master -WarningVariable warnInstallMaster - $resultInstallTempdb = Install-DbaWhoIsActive -SqlInstance $script:instance1 -LocalFile $testzippath -Database tempdb -WarningVariable warnInstallTempdb + $testzippath = "$($TestConfig.appveyorlabrepo)\CommunitySoftware\sp_whoisactive-12.00.zip" + $resultInstallMaster = Install-DbaWhoIsActive -SqlInstance $TestConfig.instance1 -LocalFile $testzippath -Database master -WarningVariable warnInstallMaster + $resultInstallTempdb = Install-DbaWhoIsActive -SqlInstance $TestConfig.instance1 -LocalFile $testzippath -Database tempdb -WarningVariable warnInstallTempdb } AfterAll { - Invoke-DbaQuery -SqlInstance $script:instance1 -Database master -Query 'DROP PROCEDURE [dbo].[sp_WhoIsActive];' - Invoke-DbaQuery -SqlInstance $script:instance1 -Database tempdb -Query 'DROP PROCEDURE [dbo].[sp_WhoIsActive];' + Invoke-DbaQuery -SqlInstance $TestConfig.instance1 -Database master -Query 'DROP PROCEDURE [dbo].[sp_WhoIsActive];' + Invoke-DbaQuery -SqlInstance $TestConfig.instance1 -Database tempdb -Query 'DROP PROCEDURE [dbo].[sp_WhoIsActive];' } Context "Should have SPWhoisActive installed correctly" { It "Should be installed to master" { @@ -34,7 +34,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } Context "Should Execute SPWhoisActive" { - $results = Invoke-DbaWhoIsActive -SqlInstance $script:instance1 -Help -WarningVariable warn + $results = Invoke-DbaWhoIsActive -SqlInstance $TestConfig.instance1 -Help -WarningVariable warn It "Should execute and not warn" { $warn | Should -BeNullOrEmpty } @@ -43,44 +43,44 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $results | Should -Not -BeNullOrEmpty } - $results = Invoke-DbaWhoIsActive -SqlInstance $script:instance1 + $results = Invoke-DbaWhoIsActive -SqlInstance $TestConfig.instance1 It -Skip "Should execute with no parameters in default location" { $results | Should -Not -BeNullOrEmpty } - $results = Invoke-DbaWhoIsActive -SqlInstance $script:instance1 -ShowSleepingSpids 2 + $results = Invoke-DbaWhoIsActive -SqlInstance $TestConfig.instance1 -ShowSleepingSpids 2 It "Should execute with ShowSleepingSpids" { $results | Should -Not -BeNullOrEmpty } - $results = Invoke-DbaWhoIsActive -SqlInstance $script:instance1 -Database Tempdb + $results = Invoke-DbaWhoIsActive -SqlInstance $TestConfig.instance1 -Database Tempdb It -Skip "Should execute with no parameters against alternate install location" { $results | Should -Not -BeNullOrEmpty } - $results = Invoke-DbaWhoIsActive -SqlInstance $script:instance1 -ShowOwnSpid + $results = Invoke-DbaWhoIsActive -SqlInstance $TestConfig.instance1 -ShowOwnSpid It "Should execute with ShowOwnSpid" { $results | Should -Not -BeNullOrEmpty } - $results = Invoke-DbaWhoIsActive -SqlInstance $script:instance1 -ShowSystemSpids + $results = Invoke-DbaWhoIsActive -SqlInstance $TestConfig.instance1 -ShowSystemSpids It "Should execute with ShowSystemSpids" { $results | Should Not Be $Null } - $results = Invoke-DbaWhoIsActive -SqlInstance $script:instance1 -Database Tempdb -GetAverageTime + $results = Invoke-DbaWhoIsActive -SqlInstance $TestConfig.instance1 -Database Tempdb -GetAverageTime It -Skip "Should execute with averagetime" { $results | Should Be $Null } - $results = Invoke-DbaWhoIsActive -SqlInstance $script:instance1 -GetOuterCommand -FindBlockLeaders + $results = Invoke-DbaWhoIsActive -SqlInstance $TestConfig.instance1 -GetOuterCommand -FindBlockLeaders It -Skip "Should execute with GetOuterCommand and FindBlockLeaders" { $results | Should Be $Null } - $results = Invoke-DbaWhoIsActive -SqlInstance $script:instance1 -NotFilter 0 -NotFilterType Program + $results = Invoke-DbaWhoIsActive -SqlInstance $TestConfig.instance1 -NotFilter 0 -NotFilterType Program It -Skip "Should execute with NotFilter and NotFilterType" { $results | Should Be $Null } } -} \ No newline at end of file +} diff --git a/tests/Invoke-DbaXEReplay.Tests.ps1 b/tests/Invoke-DbaXEReplay.Tests.ps1 index add3de71e0..04e080afc4 100644 --- a/tests/Invoke-DbaXEReplay.Tests.ps1 +++ b/tests/Invoke-DbaXEReplay.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Invoke-DbatoolsFormatter.Tests.ps1 b/tests/Invoke-DbatoolsFormatter.Tests.ps1 index e2970b68df..48f6cf5297 100644 --- a/tests/Invoke-DbatoolsFormatter.Tests.ps1 +++ b/tests/Invoke-DbatoolsFormatter.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Invoke-DbatoolsRenameHelper.Tests.ps1 b/tests/Invoke-DbatoolsRenameHelper.Tests.ps1 index 327a4877e9..9c797fb611 100644 --- a/tests/Invoke-DbatoolsRenameHelper.Tests.ps1 +++ b/tests/Invoke-DbatoolsRenameHelper.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Join-DbaAvailabilityGroup.Tests.ps1 b/tests/Join-DbaAvailabilityGroup.Tests.ps1 index 9a3d4be576..b87b5ae08b 100644 --- a/tests/Join-DbaAvailabilityGroup.Tests.ps1 +++ b/tests/Join-DbaAvailabilityGroup.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Join-DbaPath.Tests.ps1 b/tests/Join-DbaPath.Tests.ps1 index b3e99bcd8a..22951f62ea 100644 --- a/tests/Join-DbaPath.Tests.ps1 +++ b/tests/Join-DbaPath.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Measure-DbaBackupThroughput.Tests.ps1 b/tests/Measure-DbaBackupThroughput.Tests.ps1 index ca4df9fba2..864e41eb1c 100644 --- a/tests/Measure-DbaBackupThroughput.Tests.ps1 +++ b/tests/Measure-DbaBackupThroughput.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,18 +16,19 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Returns output for single database" { BeforeAll { + $null = Get-DbaProcess -SqlInstance $TestConfig.instance2 | Where-Object Program -Match dbatools | Stop-DbaProcess -Confirm:$false -WarningAction SilentlyContinue $random = Get-Random $db = "dbatoolsci_measurethruput$random" - $null = New-DbaDatabase -SqlInstance $script:instance2 -Database $db | Backup-DbaDatabase + $null = New-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $db | Backup-DbaDatabase } AfterAll { - $null = Remove-DbaDatabase -SqlInstance $script:instance2 -Database $db + $null = Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $db } - $results = Measure-DbaBackupThroughput -SqlInstance $script:instance2 -Database $db + $results = Measure-DbaBackupThroughput -SqlInstance $TestConfig.instance2 -Database $db It "Should return results" { $results.Database | Should -Be $db $results.BackupCount | Should -Be 1 } } -} \ No newline at end of file +} diff --git a/tests/Measure-DbaDbVirtualLogFile.Tests.ps1 b/tests/Measure-DbaDbVirtualLogFile.Tests.ps1 index 45234e160f..d37592e1d6 100644 --- a/tests/Measure-DbaDbVirtualLogFile.Tests.ps1 +++ b/tests/Measure-DbaDbVirtualLogFile.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig <# Unit test is required for any command added @@ -18,10 +18,10 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { # Get-DbaNoun Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $db1 = "dbatoolsci_testvlf" $server.Query("CREATE DATABASE $db1") - $needed = Get-DbaDatabase -SqlInstance $script:instance2 -Database $db1 + $needed = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $db1 $setupright = $true if ($needed.Count -ne 1) { $setupright = $false @@ -31,11 +31,11 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } } AfterAll { - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance2 -Database $db1 + Remove-DbaDatabase -Confirm:$false -SqlInstance $TestConfig.instance2 -Database $db1 } Context "Command actually works" { - $results = Measure-DbaDbVirtualLogFile -SqlInstance $script:instance2 -Database $db1 + $results = Measure-DbaDbVirtualLogFile -SqlInstance $TestConfig.instance2 -Database $db1 It "Should have correct properties" { $ExpectedProps = 'ComputerName,InstanceName,SqlInstance,Database,Total,TotalCount,Inactive,Active,LogFileName,LogFileGrowth,LogFileGrowthType'.Split(',') @@ -55,4 +55,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } } } -} \ No newline at end of file +} diff --git a/tests/Measure-DbaDiskSpaceRequirement.Tests.ps1 b/tests/Measure-DbaDiskSpaceRequirement.Tests.ps1 index c1bcc953bd..47bcd648fe 100644 --- a/tests/Measure-DbaDiskSpaceRequirement.Tests.ps1 +++ b/tests/Measure-DbaDiskSpaceRequirement.Tests.ps1 @@ -1,47 +1,47 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { - [object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object {$_ -notin ('whatif', 'confirm')} + [object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object { $_ -notin ('whatif', 'confirm') } [object[]]$knownParameters = 'Source', 'Database', 'SourceSqlCredential', 'Destination', 'DestinationDatabase', 'DestinationSqlCredential', 'Credential', '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 + (@(Compare-Object -ReferenceObject ($knownParameters | Where-Object { $_ }) -DifferenceObject $params).Count ) | Should Be 0 } } } Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Should Measure Disk Space Required " { - $server1 = Connect-DbaInstance -SqlInstance $script:instance1 - $server2 = Connect-DbaInstance -SqlInstance $script:instance2 - $Options = @{ - Source = $script:instance1 - Destination = $script:instance2 + $server1 = Connect-DbaInstance -SqlInstance $global:TestConfig.instance1 + $server2 = Connect-DbaInstance -SqlInstance $global:TestConfig.instance2 + $script:Options = @{ + Source = $global:TestConfig.instance1 + Destination = $global:TestConfig.instance2 Database = "master" DestinationDatabase = "Dbatoolsci_DestinationDB" } - $results = Measure-DbaDiskSpaceRequirement @Options + $script:results = Measure-DbaDiskSpaceRequirement @Options It "Should have information" { - $results | Should -Not -BeNullOrEmpty + $script:results | Should -Not -BeNullOrEmpty } - foreach ($r in $results) { + foreach ($result in $script:results) { It "Should be sourced from Master" { - $r.SourceDatabase | Should -Be $Options.Database + $result.SourceDatabase | Should -Be $script:Options.Database } - It "Should be sourced from the instance $($script:instance1)" { - $r.SourceSqlInstance | Should -Be $server1.SqlInstance + It "Should be sourced from the instance $($global:TestConfig.instance1)" { + $result.SourceSqlInstance | Should -Be $server1.SqlInstance } It "Should be destined for Dbatoolsci_DestinationDB" { - $r.DestinationDatabase | Should -Be $Options.DestinationDatabase + $result.DestinationDatabase | Should -Be $script:Options.DestinationDatabase } - It "Should be destined for the instance $($script:instance2)" { - $r.DestinationSqlInstance | Should -Be $server2.SqlInstance + It "Should be destined for the instance $($global:TestConfig.instance2)" { + $result.DestinationSqlInstance | Should -Be $server2.SqlInstance } It "Should be have files on source" { - $r.FileLocation | Should Be "Only on Source" + $result.FileLocation | Should Be "Only on Source" } } } diff --git a/tests/Measure-DbatoolsImport.Tests.ps1 b/tests/Measure-DbatoolsImport.Tests.ps1 index 866bbb6176..a6b4501388 100644 --- a/tests/Measure-DbatoolsImport.Tests.ps1 +++ b/tests/Measure-DbatoolsImport.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Mount-DbaDatabase.Tests.ps1 b/tests/Mount-DbaDatabase.Tests.ps1 index a4ad724bbf..7b7a2cb09f 100644 --- a/tests/Mount-DbaDatabase.Tests.ps1 +++ b/tests/Mount-DbaDatabase.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,14 +15,14 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Setup removes, restores and backups on the local drive for Mount-DbaDatabase" { - $null = Get-DbaDatabase -SqlInstance $script:instance1 -Database detachattach | Remove-DbaDatabase -Confirm:$false - $null = Restore-DbaDatabase -SqlInstance $script:instance1 -Path $script:appveyorlabrepo\detachattach\detachattach.bak -WithReplace - $null = Get-DbaDatabase -SqlInstance $script:instance1 -Database detachattach | Backup-DbaDatabase -Type Full - $null = Detach-DbaDatabase -SqlInstance $script:instance1 -Database detachattach -Force + $null = Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database detachattach | Remove-DbaDatabase -Confirm:$false + $null = Restore-DbaDatabase -SqlInstance $TestConfig.instance1 -Path "$($TestConfig.appveyorlabrepo)\detachattach\detachattach.bak" -WithReplace + $null = Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database detachattach | Backup-DbaDatabase -Type Full + $null = Detach-DbaDatabase -SqlInstance $TestConfig.instance1 -Database detachattach -Force } Context "Attaches a single database and tests to ensure the alias still exists" { - $results = Attach-DbaDatabase -SqlInstance $script:instance1 -Database detachattach + $results = Attach-DbaDatabase -SqlInstance $TestConfig.instance1 -Database detachattach It "Should return success" { $results.AttachResult | Should Be "Success" @@ -37,5 +37,5 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } } - $null = Get-DbaDatabase -SqlInstance $script:instance1 -Database detachattach | Remove-DbaDatabase -Confirm:$false -} \ No newline at end of file + $null = Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database detachattach | Remove-DbaDatabase -Confirm:$false +} diff --git a/tests/Move-DbaDbFile.Tests.ps1 b/tests/Move-DbaDbFile.Tests.ps1 index ecbad4f15c..eff7b62a50 100644 --- a/tests/Move-DbaDbFile.Tests.ps1 +++ b/tests/Move-DbaDbFile.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,10 +15,10 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $null = New-DbaDatabase -SqlInstance $script:instance2 -Name 'dbatoolsci_MoveDbFile' - $null = New-DbaDatabase -SqlInstance $script:instance2 -Name 'dbatoolsci_MoveDbFile_2DataFiles' + $null = New-DbaDatabase -SqlInstance $TestConfig.instance2 -Name 'dbatoolsci_MoveDbFile' + $null = New-DbaDatabase -SqlInstance $TestConfig.instance2 -Name 'dbatoolsci_MoveDbFile_2DataFiles' - $dbFiles = Get-DbaDbFile -SqlInstance $script:instance2 -Database dbatoolsci_MoveDbFile_2DataFiles | Where-Object TypeDescription -eq 'ROWS' + $dbFiles = Get-DbaDbFile -SqlInstance $TestConfig.instance2 -Database dbatoolsci_MoveDbFile_2DataFiles | Where-Object TypeDescription -eq 'ROWS' $physicalPathFolder = Split-Path -Path $dbFiles[0].PhysicalName -Parent $physicalPathNewFolder = "$physicalPathFolder\moveFile" $null = New-Item -Path $physicalPathNewFolder -Type Directory @@ -30,10 +30,10 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { TO FILEGROUP [PRIMARY] GO "@ - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Query $addNewDataFile + $null = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Query $addNewDataFile } AfterAll { - $null = Remove-DbaDatabase -SqlInstance $script:instance2 -Database "dbatoolsci_MoveDbFile", "dbatoolsci_MoveDbFile_2DataFiles" -Confirm:$false + $null = Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database "dbatoolsci_MoveDbFile", "dbatoolsci_MoveDbFile_2DataFiles" -Confirm:$false Get-Item -Path "$physicalPathFolder\moveFile" | Remove-Item -Recurse Get-Item -Path "$physicalPathFolder\New" | Remove-Item -Recurse Get-Item -Path "$physicalPathFolder\dbatoolsci_MoveDbFile.mdf" | Remove-Item @@ -41,7 +41,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Should output current database structure" { $variables = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 Database = 'dbatoolsci_MoveDbFile' FileStructureOnly = $true } @@ -60,10 +60,10 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } Context "Should move all database data files" { - $dbDataFiles = Get-DbaDbFile -SqlInstance $script:instance2 -Database dbatoolsci_MoveDbFile | Where-Object TypeDescription -eq 'ROWS' + $dbDataFiles = Get-DbaDbFile -SqlInstance $TestConfig.instance2 -Database dbatoolsci_MoveDbFile | Where-Object TypeDescription -eq 'ROWS' $variables = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 Database = 'dbatoolsci_MoveDbFile' FileType = 'Data' FileDestination = $physicalPathNewFolder @@ -86,15 +86,15 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Test-Path -Path $dbDataFiles.PhysicalName | Should Be $true } It "Should have database Online" { - (Get-DbaDbState -SqlInstance $script:instance2 -Database 'dbatoolsci_MoveDbFile').Status | Should Be 'ONLINE' + (Get-DbaDbState -SqlInstance $TestConfig.instance2 -Database 'dbatoolsci_MoveDbFile').Status | Should Be 'ONLINE' } } Context "Should move all database log files and delete source" { - $dbLogFiles = Get-DbaDbFile -SqlInstance $script:instance2 -Database dbatoolsci_MoveDbFile | Where-Object TypeDescription -eq 'LOG' + $dbLogFiles = Get-DbaDbFile -SqlInstance $TestConfig.instance2 -Database dbatoolsci_MoveDbFile | Where-Object TypeDescription -eq 'LOG' $variables = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 Database = 'dbatoolsci_MoveDbFile' FileType = 'Log' FileDestination = $physicalPathNewFolder @@ -118,15 +118,15 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Test-Path -Path $dbLogFiles.PhysicalName | Should Be $false } It "Should have database Online" { - (Get-DbaDbState -SqlInstance $script:instance2 -Database 'dbatoolsci_MoveDbFile').Status | Should Be 'ONLINE' + (Get-DbaDbState -SqlInstance $TestConfig.instance2 -Database 'dbatoolsci_MoveDbFile').Status | Should Be 'ONLINE' } } Context "Should move only one database file and delete source" { - $dbNDFFile = Get-DbaDbFile -SqlInstance $script:instance2 -Database dbatoolsci_MoveDbFile_2DataFiles | Where-Object LogicalName -eq 'dbatoolsci_MoveDbFile_2DataFiles_2' + $dbNDFFile = Get-DbaDbFile -SqlInstance $TestConfig.instance2 -Database dbatoolsci_MoveDbFile_2DataFiles | Where-Object LogicalName -eq 'dbatoolsci_MoveDbFile_2DataFiles_2' $variables = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 Database = 'dbatoolsci_MoveDbFile_2DataFiles' FileToMove = @{ 'dbatoolsci_MoveDbFile_2DataFiles_2' = $physicalPathNewFolder @@ -151,18 +151,18 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Test-Path -Path $dbNDFFile.PhysicalName | Should Be $false } It "Should have database Online" { - (Get-DbaDbState -SqlInstance $script:instance2 -Database 'dbatoolsci_MoveDbFile_2DataFiles').Status | Should Be 'ONLINE' + (Get-DbaDbState -SqlInstance $TestConfig.instance2 -Database 'dbatoolsci_MoveDbFile_2DataFiles').Status | Should Be 'ONLINE' } } Context "Should move all files and delete source" { - $dbAllFiles = Get-DbaDbFile -SqlInstance $script:instance2 -Database dbatoolsci_MoveDbFile_2DataFiles + $dbAllFiles = Get-DbaDbFile -SqlInstance $TestConfig.instance2 -Database dbatoolsci_MoveDbFile_2DataFiles $destinationFolder = "$physicalPathFolder\New" $null = New-Item -Path $destinationFolder -Type Directory $variables = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 Database = 'dbatoolsci_MoveDbFile_2DataFiles' FileType = 'Both' FileDestination = $destinationFolder @@ -192,7 +192,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } It "Should have database Online" { - (Get-DbaDbState -SqlInstance $script:instance2 -Database 'dbatoolsci_MoveDbFile_2DataFiles').Status | Should Be 'ONLINE' + (Get-DbaDbState -SqlInstance $TestConfig.instance2 -Database 'dbatoolsci_MoveDbFile_2DataFiles').Status | Should Be 'ONLINE' } } -} \ No newline at end of file +} diff --git a/tests/Move-DbaRegServer.Tests.ps1 b/tests/Move-DbaRegServer.Tests.ps1 index e73ca4584b..26a03b9008 100644 --- a/tests/Move-DbaRegServer.Tests.ps1 +++ b/tests/Move-DbaRegServer.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Validate parameters" { @@ -22,36 +22,36 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $regSrvName = "dbatoolsci-server12" $regSrvDesc = "dbatoolsci-server123" - $newGroup = Add-DbaRegServerGroup -SqlInstance $script:instance1 -Name $group - $newServer = Add-DbaRegServer -SqlInstance $script:instance1 -ServerName $srvName -Name $regSrvName -Description $regSrvDesc -Group $newGroup.Name + $newGroup = Add-DbaRegServerGroup -SqlInstance $TestConfig.instance1 -Name $group + $newServer = Add-DbaRegServer -SqlInstance $TestConfig.instance1 -ServerName $srvName -Name $regSrvName -Description $regSrvDesc -Group $newGroup.Name $srvName2 = "dbatoolsci-server2" $group2 = "dbatoolsci-group1a" $regSrvName2 = "dbatoolsci-server21" $regSrvDesc2 = "dbatoolsci-server321" - $newGroup2 = Add-DbaRegServerGroup -SqlInstance $script:instance1 -Name $group2 - $newServer2 = Add-DbaRegServer -SqlInstance $script:instance1 -ServerName $srvName2 -Name $regSrvName2 -Description $regSrvDesc2 + $newGroup2 = Add-DbaRegServerGroup -SqlInstance $TestConfig.instance1 -Name $group2 + $newServer2 = Add-DbaRegServer -SqlInstance $TestConfig.instance1 -ServerName $srvName2 -Name $regSrvName2 -Description $regSrvDesc2 $regSrvName3 = "dbatoolsci-server3" $srvName3 = "dbatoolsci-server3" $regSrvDesc3 = "dbatoolsci-server3desc" - $newServer3 = Add-DbaRegServer -SqlInstance $script:instance1 -ServerName $srvName3 -Name $regSrvName3 -Description $regSrvDesc3 + $newServer3 = Add-DbaRegServer -SqlInstance $TestConfig.instance1 -ServerName $srvName3 -Name $regSrvName3 -Description $regSrvDesc3 $testGroupHR = "dbatoolsci-HR-$random" $testGroupFinance = "dbatoolsci-Finance-$random" $regSrvNameHR = "dbatoolsci-HR-$random" $regSrvNameFinance = "dbatoolsci-Finance-$random" - $newTestGroupHR = Add-DbaRegServerGroup -SqlInstance $script:instance1 -Name $testGroupHR - $newTestGroup5 = Add-DbaRegServerGroup -SqlInstance $script:instance1 -Name $testGroupFinance - $newServerHR = Add-DbaRegServer -SqlInstance $script:instance1 -ServerName $srvName -Name $regSrvNameHR -Group $testGroupHR - $newServerFinance = Add-DbaRegServer -SqlInstance $script:instance1 -ServerName $srvName -Name $regSrvNameFinance -Group $testGroupHR + $newTestGroupHR = Add-DbaRegServerGroup -SqlInstance $TestConfig.instance1 -Name $testGroupHR + $newTestGroup5 = Add-DbaRegServerGroup -SqlInstance $TestConfig.instance1 -Name $testGroupFinance + $newServerHR = Add-DbaRegServer -SqlInstance $TestConfig.instance1 -ServerName $srvName -Name $regSrvNameHR -Group $testGroupHR + $newServerFinance = Add-DbaRegServer -SqlInstance $TestConfig.instance1 -ServerName $srvName -Name $regSrvNameFinance -Group $testGroupHR } AfterAll { - Get-DbaRegServer -SqlInstance $script:instance1 -Name $regSrvName, $regSrvName2, $regSrvName3, $regSrvNameHR, $regSrvNameFinance | Remove-DbaRegServer -Confirm:$false - Get-DbaRegServerGroup -SqlInstance $script:instance1 -Group $group, $group2, $testGroupHR, $testGroupFinance | Remove-DbaRegServerGroup -Confirm:$false + Get-DbaRegServer -SqlInstance $TestConfig.instance1 -Name $regSrvName, $regSrvName2, $regSrvName3, $regSrvNameHR, $regSrvNameFinance | Remove-DbaRegServer -Confirm:$false + Get-DbaRegServerGroup -SqlInstance $TestConfig.instance1 -Group $group, $group2, $testGroupHR, $testGroupFinance | Remove-DbaRegServerGroup -Confirm:$false } It "moves a piped server" { @@ -61,15 +61,15 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } It "moves a manually specified server" { - $results = Move-DbaRegServer -SqlInstance $script:instance1 -ServerName $srvName3 -NewGroup $newGroup2.Name + $results = Move-DbaRegServer -SqlInstance $TestConfig.instance1 -ServerName $srvName3 -NewGroup $newGroup2.Name $results.Parent.Name | Should -Be $newGroup2.Name $results.Description | Should -Be $regSrvDesc3 } # see https://github.com/dataplat/dbatools/issues/7112 It "moves a piped server to a target group" { - $results = Get-DbaRegServer -SqlInstance $script:instance1 -Group $testGroupHR | Move-DbaRegServer -Group $testGroupFinance + $results = Get-DbaRegServer -SqlInstance $TestConfig.instance1 -Group $testGroupHR | Move-DbaRegServer -Group $testGroupFinance $results.Count | Should -Be 2 } } -} \ No newline at end of file +} diff --git a/tests/Move-DbaRegServerGroup.Tests.ps1 b/tests/Move-DbaRegServerGroup.Tests.ps1 index 08352d938c..844986fcff 100644 --- a/tests/Move-DbaRegServerGroup.Tests.ps1 +++ b/tests/Move-DbaRegServerGroup.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Validate parameters" { @@ -21,18 +21,18 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $regSrvName = "dbatoolsci-server12" $regSrvDesc = "dbatoolsci-server123" - $newGroup = Add-DbaRegServerGroup -SqlInstance $script:instance1 -Name $group - $newServer = Add-DbaRegServer -SqlInstance $script:instance1 -ServerName $srvName -Name $regSrvName -Description $regSrvDesc -Group $newGroup.Name + $newGroup = Add-DbaRegServerGroup -SqlInstance $TestConfig.instance1 -Name $group + $newServer = Add-DbaRegServer -SqlInstance $TestConfig.instance1 -ServerName $srvName -Name $regSrvName -Description $regSrvDesc -Group $newGroup.Name $group2 = "dbatoolsci-group1a" - $newGroup2 = Add-DbaRegServerGroup -SqlInstance $script:instance1 -Name $group2 + $newGroup2 = Add-DbaRegServerGroup -SqlInstance $TestConfig.instance1 -Name $group2 $group3 = "dbatoolsci-group1b" - $newGroup3 = Add-DbaRegServerGroup -SqlInstance $script:instance1 -Name $group3 + $newGroup3 = Add-DbaRegServerGroup -SqlInstance $TestConfig.instance1 -Name $group3 } AfterAll { - Get-DbaRegServer -SqlInstance $script:instance1 -Name $regSrvName | Remove-DbaRegServer -Confirm:$false - Get-DbaRegServerGroup -SqlInstance $script:instance1 -Group $group, $group2, $group3 | Remove-DbaRegServerGroup -Confirm:$false + Get-DbaRegServer -SqlInstance $TestConfig.instance1 -Name $regSrvName | Remove-DbaRegServer -Confirm:$false + Get-DbaRegServerGroup -SqlInstance $TestConfig.instance1 -Group $group, $group2, $group3 | Remove-DbaRegServerGroup -Confirm:$false } It "moves a piped group" { @@ -41,8 +41,8 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } It "moves a manually specified group" { - $results = Move-DbaRegServerGroup -SqlInstance $script:instance1 -Group "$group\$group3" -NewGroup Default + $results = Move-DbaRegServerGroup -SqlInstance $TestConfig.instance1 -Group "$group\$group3" -NewGroup Default $results.Parent.Name | Should -Be 'DatabaseEngineServerGroup' } } -} \ No newline at end of file +} diff --git a/tests/New-DbaAgentAlert.Tests.ps1 b/tests/New-DbaAgentAlert.Tests.ps1 index d3de58dc86..1b1f149b08 100644 --- a/tests/New-DbaAgentAlert.Tests.ps1 +++ b/tests/New-DbaAgentAlert.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,14 +15,14 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeEach { - Get-DbaAgentAlert -SqlInstance $script:instance2, $script:instance3 -Alert "Test Alert", "Another Alert" | Remove-DbaAgentAlert -Confirm:$false + Get-DbaAgentAlert -SqlInstance $TestConfig.instance2, $TestConfig.instance3 -Alert "Test Alert", "Another Alert" | Remove-DbaAgentAlert -Confirm:$false } AfterAll { - Get-DbaAgentAlert -SqlInstance $script:instance2, $script:instance3 -Alert "Test Alert", "Another Alert" | Remove-DbaAgentAlert -Confirm:$false + Get-DbaAgentAlert -SqlInstance $TestConfig.instance2, $TestConfig.instance3 -Alert "Test Alert", "Another Alert" | Remove-DbaAgentAlert -Confirm:$false } Context 'Creating a new SQL Server Agent alert' { $parms = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 Alert = "Test Alert" DelayBetweenResponses = 60 Disabled = $false @@ -41,12 +41,12 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $alert.IsEnabled | Should -Be $true $alert.Severity | Should -Be 17 - Get-DbaAgentAlert -SqlInstance $script:instance2 -Alert $parms.Alert | Should -Not -BeNullOrEmpty + Get-DbaAgentAlert -SqlInstance $TestConfig.instance2 -Alert $parms.Alert | Should -Not -BeNullOrEmpty } It 'Should create a new alert' { $parms = @{ - SqlInstance = $script:instance3 + SqlInstance = $TestConfig.instance3 Alert = "Another Alert" DelayBetweenResponses = 60 NotifyMethod = "NotifyEmail" @@ -64,7 +64,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $alert.MessageId | Should -Be 826 $alert.Severity | Should -Be 0 - Get-DbaAgentAlert -SqlInstance $script:instance3 -Alert $parms.Alert | Should -Not -BeNullOrEmpty + Get-DbaAgentAlert -SqlInstance $TestConfig.instance3 -Alert $parms.Alert | Should -Not -BeNullOrEmpty } } -} \ No newline at end of file +} diff --git a/tests/New-DbaAgentAlertCategory.Tests.ps1 b/tests/New-DbaAgentAlertCategory.Tests.ps1 index 83e8c94d79..017975acdf 100644 --- a/tests/New-DbaAgentAlertCategory.Tests.ps1 +++ b/tests/New-DbaAgentAlertCategory.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -17,27 +17,27 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "New Agent Alert Category is added properly" { It "Should have the right name and category type" { - $results = New-DbaAgentAlertCategory -SqlInstance $script:instance2 -Category CategoryTest1 + $results = New-DbaAgentAlertCategory -SqlInstance $TestConfig.instance2 -Category CategoryTest1 $results.Name | Should Be "CategoryTest1" } It "Should have the right name and category type" { - $results = New-DbaAgentAlertCategory -SqlInstance $script:instance2 -Category CategoryTest2 + $results = New-DbaAgentAlertCategory -SqlInstance $TestConfig.instance2 -Category CategoryTest2 $results.Name | Should Be "CategoryTest2" } It "Should actually for sure exist" { - $newresults = Get-DbaAgentAlertCategory -SqlInstance $script:instance2 -Category CategoryTest1, CategoryTest2 + $newresults = Get-DbaAgentAlertCategory -SqlInstance $TestConfig.instance2 -Category CategoryTest1, CategoryTest2 $newresults[0].Name | Should Be "CategoryTest1" $newresults[1].Name | Should Be "CategoryTest2" } It "Should not write over existing job categories" { - $results = New-DbaAgentAlertCategory -SqlInstance $script:instance2 -Category CategoryTest1 -WarningAction SilentlyContinue -WarningVariable warn + $results = New-DbaAgentAlertCategory -SqlInstance $TestConfig.instance2 -Category CategoryTest1 -WarningAction SilentlyContinue -WarningVariable warn $warn -match "already exists" | Should Be $true } # Cleanup and ignore all output - $null = Remove-DbaAgentAlertCategory -SqlInstance $script:instance2 -Category CategoryTest1, CategoryTest2 -Confirm:$false + $null = Remove-DbaAgentAlertCategory -SqlInstance $TestConfig.instance2 -Category CategoryTest1, CategoryTest2 -Confirm:$false } -} \ No newline at end of file +} diff --git a/tests/New-DbaAgentJob.Tests.ps1 b/tests/New-DbaAgentJob.Tests.ps1 index c2572888d8..6abdbe41d3 100644 --- a/tests/New-DbaAgentJob.Tests.ps1 +++ b/tests/New-DbaAgentJob.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -17,23 +17,23 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "New Agent JOb is added properly" { It "Should have the right name and description" { - $results = New-DbaAgentJob -SqlInstance $script:instance2 -Job "Job One" -Description "Just another job" + $results = New-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job "Job One" -Description "Just another job" $results.Name | Should Be "Job One" $results.Description | Should Be "Just another job" } It "Should actually for sure exist" { - $newresults = Get-DbaAgentJob -SqlInstance $script:instance2 -Job "Job One" + $newresults = Get-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job "Job One" $newresults.Name | Should Be "Job One" $newresults.Description | Should Be "Just another job" } It "Should not write over existing jobs" { - $results = New-DbaAgentJob -SqlInstance $script:instance2 -Job "Job One" -Description "Just another job" -WarningAction SilentlyContinue -WarningVariable warn + $results = New-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job "Job One" -Description "Just another job" -WarningAction SilentlyContinue -WarningVariable warn $warn -match "already exists" | Should Be $true } # Cleanup and ignore all output - Remove-DbaAgentJob -SqlInstance $script:instance2 -Job "Job One" -Confirm:$false *> $null + Remove-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job "Job One" -Confirm:$false *> $null } -} \ No newline at end of file +} diff --git a/tests/New-DbaAgentJobCategory.Tests.ps1 b/tests/New-DbaAgentJobCategory.Tests.ps1 index b28aa43492..1d548d0c24 100644 --- a/tests/New-DbaAgentJobCategory.Tests.ps1 +++ b/tests/New-DbaAgentJobCategory.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -17,19 +17,19 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "New Agent Job Category is added properly" { It "Should have the right name and category type" { - $results = New-DbaAgentJobCategory -SqlInstance $script:instance2 -Category CategoryTest1 + $results = New-DbaAgentJobCategory -SqlInstance $TestConfig.instance2 -Category CategoryTest1 $results.Name | Should Be "CategoryTest1" $results.CategoryType | Should Be "LocalJob" } It "Should have the right name and category type" { - $results = New-DbaAgentJobCategory -SqlInstance $script:instance2 -Category CategoryTest2 -CategoryType MultiServerJob + $results = New-DbaAgentJobCategory -SqlInstance $TestConfig.instance2 -Category CategoryTest2 -CategoryType MultiServerJob $results.Name | Should Be "CategoryTest2" $results.CategoryType | Should Be "MultiServerJob" } It "Should actually for sure exist" { - $newresults = Get-DbaAgentJobCategory -SqlInstance $script:instance2 -Category CategoryTest1, CategoryTest2 + $newresults = Get-DbaAgentJobCategory -SqlInstance $TestConfig.instance2 -Category CategoryTest1, CategoryTest2 $newresults[0].Name | Should Be "CategoryTest1" $newresults[0].CategoryType | Should Be "LocalJob" $newresults[1].Name | Should Be "CategoryTest2" @@ -37,11 +37,11 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } It "Should not write over existing job categories" { - $results = New-DbaAgentJobCategory -SqlInstance $script:instance2 -Category CategoryTest1 -WarningAction SilentlyContinue -WarningVariable warn + $results = New-DbaAgentJobCategory -SqlInstance $TestConfig.instance2 -Category CategoryTest1 -WarningAction SilentlyContinue -WarningVariable warn $warn -match "already exists" | Should Be $true } # Cleanup and ignore all output - Remove-DbaAgentJobCategory -SqlInstance $script:instance2 -Category CategoryTest1, CategoryTest2 -Confirm:$false *> $null + Remove-DbaAgentJobCategory -SqlInstance $TestConfig.instance2 -Category CategoryTest1, CategoryTest2 -Confirm:$false *> $null } -} \ No newline at end of file +} diff --git a/tests/New-DbaAgentJobStep.Tests.ps1 b/tests/New-DbaAgentJobStep.Tests.ps1 index a1b427e2d4..60acac0ebe 100644 --- a/tests/New-DbaAgentJobStep.Tests.ps1 +++ b/tests/New-DbaAgentJobStep.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -18,23 +18,23 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { # Create job to add step to $random = Get-Random - $job = New-DbaAgentJob -SqlInstance $script:instance2 -Job "dbatoolsci_job_1_$random" -Description "Just another job" - $jobTwo = New-DbaAgentJob -SqlInstance $script:instance2 -Job "dbatoolsci_job_2_$random" -Description "Just another job" - $jobThree = New-DbaAgentJob -SqlInstance $script:instance2 -Job "dbatoolsci_job_3_$random" -Description "Just another job" + $job = New-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job "dbatoolsci_job_1_$random" -Description "Just another job" + $jobTwo = New-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job "dbatoolsci_job_2_$random" -Description "Just another job" + $jobThree = New-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job "dbatoolsci_job_3_$random" -Description "Just another job" } AfterAll { - Remove-DbaAgentJob -SqlInstance $script:instance2 -Job "dbatoolsci_job_1_$random", "dbatoolsci_job_2_$random", "dbatoolsci_job_3_$random" -Confirm:$false + Remove-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job "dbatoolsci_job_1_$random", "dbatoolsci_job_2_$random", "dbatoolsci_job_3_$random" -Confirm:$false } It "Should have the right name and description" { - $results = New-DbaAgentJobStep -SqlInstance $script:instance2 -Job $job -StepName "Step One" + $results = New-DbaAgentJobStep -SqlInstance $TestConfig.instance2 -Job $job -StepName "Step One" $results.Name | Should -Be "Step One" } It "Should have the right properties" { $jobStep = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 Job = $jobTwo StepName = "Step X" Subsystem = "TransactSql" @@ -56,40 +56,40 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { It "Should actually for sure exist" { - $newresults = Get-DbaAgentJob -SqlInstance $script:instance2 -Job "dbatoolsci_job_1_$random" + $newresults = Get-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job "dbatoolsci_job_1_$random" $newresults.JobSteps.Name | Should -Be "Step One" } It "Should not write over existing job steps" { - New-DbaAgentJobStep -SqlInstance $script:instance2 -Job "dbatoolsci_job_1_$random" -StepName "Step One" -WarningAction SilentlyContinue -WarningVariable warn + New-DbaAgentJobStep -SqlInstance $TestConfig.instance2 -Job "dbatoolsci_job_1_$random" -StepName "Step One" -WarningAction SilentlyContinue -WarningVariable warn $warn -match "already exists" | Should -Be $true - $newresults = Get-DbaAgentJob -SqlInstance $script:instance2 -Job "dbatoolsci_job_1_$random" + $newresults = Get-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job "dbatoolsci_job_1_$random" $newresults.JobSteps.Name | Should -Be "Step One" $newresults.JobSteps | Where-Object Id -eq 1 | Select-Object -ExpandProperty Name | Should -Be "Step One" } It "Force should replace the job step" { - $results = New-DbaAgentJobStep -SqlInstance $script:instance2 -Job "dbatoolsci_job_1_$random" -StepName "New Step One" -StepId 1 -Force + $results = New-DbaAgentJobStep -SqlInstance $TestConfig.instance2 -Job "dbatoolsci_job_1_$random" -StepName "New Step One" -StepId 1 -Force $results.Name | Should -Be "New Step One" - $newresults = Get-DbaAgentJob -SqlInstance $script:instance2 -Job "dbatoolsci_job_1_$random" + $newresults = Get-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job "dbatoolsci_job_1_$random" $newresults.JobSteps | Where-Object Id -eq 1 | Select-Object -ExpandProperty Name | Should -Be "New Step One" } It "Insert should insert jobstep and update IDs" { - $results = New-DbaAgentJobStep -SqlInstance $script:instance2 -Job "dbatoolsci_job_1_$random" -StepName "New Step Three" -StepId 1 -Insert + $results = New-DbaAgentJobStep -SqlInstance $TestConfig.instance2 -Job "dbatoolsci_job_1_$random" -StepName "New Step Three" -StepId 1 -Insert $results.Name | Should -Be "New Step Three" - $newresults = Get-DbaAgentJob -SqlInstance $script:instance2 -Job "dbatoolsci_job_1_$random" + $newresults = Get-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job "dbatoolsci_job_1_$random" $newresults.JobSteps | Where-Object Id -eq 1 | Select-Object -ExpandProperty Name | Should -Be "New Step Three" $newresults.JobSteps | Where-Object Id -eq 2 | Select-Object -ExpandProperty Name | Should -Be "New Step One" } # see 7199 and 7200 It "Job is refreshed from the server" { - $agentStep1 = New-DbaAgentJobStep -SqlInstance $script:instance2 -Job $jobThree -StepName "Error collection" -OnFailAction QuitWithFailure -OnSuccessAction QuitWithFailure - $agentStep2 = New-DbaAgentJobStep -SqlInstance $script:instance2 -Job $jobThree -StepName "Step 1" -OnFailAction GoToStep -OnFailStepId 1 -OnSuccessAction GoToNextStep - $agentStep3 = New-DbaAgentJobStep -SqlInstance $script:instance2 -Job $jobThree -StepName "Step 2" -OnFailAction GoToStep -OnFailStepId 1 -OnSuccessAction GoToNextStep - $agentStep4 = New-DbaAgentJobStep -SqlInstance $script:instance2 -Job $jobThree -StepName "Step 3" -OnFailAction GoToStep -OnFailStepId 1 -OnSuccessAction GoToNextStep - $agentStep5 = New-DbaAgentJobStep -SqlInstance $script:instance2 -Job $jobThree -StepName "Step 4" -OnFailAction GoToStep -OnFailStepId 1 -OnSuccessAction GoToNextStep + $agentStep1 = New-DbaAgentJobStep -SqlInstance $TestConfig.instance2 -Job $jobThree -StepName "Error collection" -OnFailAction QuitWithFailure -OnSuccessAction QuitWithFailure + $agentStep2 = New-DbaAgentJobStep -SqlInstance $TestConfig.instance2 -Job $jobThree -StepName "Step 1" -OnFailAction GoToStep -OnFailStepId 1 -OnSuccessAction GoToNextStep + $agentStep3 = New-DbaAgentJobStep -SqlInstance $TestConfig.instance2 -Job $jobThree -StepName "Step 2" -OnFailAction GoToStep -OnFailStepId 1 -OnSuccessAction GoToNextStep + $agentStep4 = New-DbaAgentJobStep -SqlInstance $TestConfig.instance2 -Job $jobThree -StepName "Step 3" -OnFailAction GoToStep -OnFailStepId 1 -OnSuccessAction GoToNextStep + $agentStep5 = New-DbaAgentJobStep -SqlInstance $TestConfig.instance2 -Job $jobThree -StepName "Step 4" -OnFailAction GoToStep -OnFailStepId 1 -OnSuccessAction GoToNextStep $agentStep1.Name | Should -Be "Error collection" $agentStep2.Name | Should -Be "Step 1" @@ -97,7 +97,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $agentStep4.Name | Should -Be "Step 3" $agentStep5.Name | Should -Be "Step 4" - $results = Get-DbaAgentJob -SqlInstance $script:instance2 -Job $jobThree + $results = Get-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job $jobThree $results.JobSteps | Where-Object Id -eq 1 | Select-Object -ExpandProperty Name | Should -Be "Error collection" $results.JobSteps | Where-Object Id -eq 2 | Select-Object -ExpandProperty Name | Should -Be "Step 1" $results.JobSteps | Where-Object Id -eq 3 | Select-Object -ExpandProperty Name | Should -Be "Step 2" @@ -105,4 +105,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $results.JobSteps | Where-Object Id -eq 5 | Select-Object -ExpandProperty Name | Should -Be "Step 4" } } -} \ No newline at end of file +} diff --git a/tests/New-DbaAgentOperator.Tests.ps1 b/tests/New-DbaAgentOperator.Tests.ps1 index bc6fce76a2..0d1f22baa4 100644 --- a/tests/New-DbaAgentOperator.Tests.ps1 +++ b/tests/New-DbaAgentOperator.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,7 +15,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { $random = Get-Random - $server2 = Connect-DbaInstance -SqlInstance $script:instance2 + $server2 = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $email1 = "test1$($random)@test.com" $email2 = "test2$($random)@test.com" $email3 = "test3$($random)@test.com" @@ -62,4 +62,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $results.WeekdayPagerEndTime.ToString() | Should -Be "19:00:00" } } -} \ No newline at end of file +} diff --git a/tests/New-DbaAgentProxy.Tests.ps1 b/tests/New-DbaAgentProxy.Tests.ps1 index 0fb14b2217..3441c70ab1 100644 --- a/tests/New-DbaAgentProxy.Tests.ps1 +++ b/tests/New-DbaAgentProxy.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -18,7 +18,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { BeforeAll { $random = Get-Random - $instance2 = Connect-DbaInstance -SqlInstance $script:instance2 + $instance2 = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $login = "db$random" $plaintext = "BigOlPassword!" @@ -107,4 +107,4 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $agentProxyLoginRole.IsEnabled | Should -Be $true } } -} \ No newline at end of file +} diff --git a/tests/New-DbaAgentSchedule.Tests.ps1 b/tests/New-DbaAgentSchedule.Tests.ps1 index 74bb1c468c..1056bd302e 100644 --- a/tests/New-DbaAgentSchedule.Tests.ps1 +++ b/tests/New-DbaAgentSchedule.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,14 +15,14 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $null = New-DbaAgentJob -SqlInstance $script:instance2 -Job 'dbatoolsci_newschedule' -OwnerLogin 'sa' - $null = New-DbaAgentJobStep -SqlInstance $script:instance2 -Job 'dbatoolsci_newschedule' -StepId 1 -StepName 'dbatoolsci Test Select' -Subsystem TransactSql -SubsystemServer $script:instance2 -Command "SELECT * FROM master.sys.all_columns;" -CmdExecSuccessCode 0 -OnSuccessAction QuitWithSuccess -OnFailAction QuitWithFailure -Database master -DatabaseUser sa + $null = New-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job 'dbatoolsci_newschedule' -OwnerLogin 'sa' + $null = New-DbaAgentJobStep -SqlInstance $TestConfig.instance2 -Job 'dbatoolsci_newschedule' -StepId 1 -StepName 'dbatoolsci Test Select' -Subsystem TransactSql -SubsystemServer $TestConfig.instance2 -Command "SELECT * FROM master.sys.all_columns;" -CmdExecSuccessCode 0 -OnSuccessAction QuitWithSuccess -OnFailAction QuitWithFailure -Database master -DatabaseUser sa $start = (Get-Date).AddDays(2).ToString('yyyyMMdd') $end = (Get-Date).AddDays(4).ToString('yyyyMMdd') } AfterAll { - $null = Remove-DbaAgentJob -SqlInstance $script:instance2 -Job 'dbatoolsci_newschedule' -Confirm:$false + $null = Remove-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job 'dbatoolsci_newschedule' -Confirm:$false } Context "Should create schedules based on frequency type" { @@ -32,7 +32,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $scheduleOptions = @('Once', 'OneTime', 'Daily', 'Weekly', 'Monthly', 'MonthlyRelative', 'AgentStart', 'AutoStart', 'IdleComputer', 'OnIdle') foreach ($frequency in $scheduleOptions) { - $variables = @{SqlInstance = $script:instance2 + $variables = @{SqlInstance = $TestConfig.instance2 Schedule = "dbatoolsci_$frequency" Job = 'dbatoolsci_newschedule' FrequencyType = $frequency @@ -49,7 +49,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } AfterAll { - $null = Get-DbaAgentSchedule -SqlInstance $script:instance2 | + $null = Get-DbaAgentSchedule -SqlInstance $TestConfig.instance2 | Where-Object { $_.name -like 'dbatools*' } | Remove-DbaAgentSchedule -Confirm:$false -Force Remove-Variable -Name results @@ -60,7 +60,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } It "Should be a schedule on an existing job and have the correct frequency type" { - $jobId = (Get-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_newschedule).JobID + $jobId = (Get-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job dbatoolsci_newschedule).JobID foreach ($key in $results.keys) { $results[$key].EnumJobReferences() | Should -Contain $jobId $results[$key].FrequencyTypes | Should -BeIn $scheduleOptions @@ -92,7 +92,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $frequencyType = "Weekly" } - $variables = @{SqlInstance = $script:instance2 + $variables = @{SqlInstance = $TestConfig.instance2 Schedule = "dbatoolsci_$frequencyinterval" Job = 'dbatoolsci_newschedule' FrequencyType = $frequencyType @@ -108,7 +108,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } AfterAll { - $null = Get-DbaAgentSchedule -SqlInstance $script:instance2 | + $null = Get-DbaAgentSchedule -SqlInstance $TestConfig.instance2 | Where-Object { $_.name -like 'dbatools*' } | Remove-DbaAgentSchedule -Confirm:$false -Force Remove-Variable -Name results @@ -119,7 +119,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } It "Should be a schedule on an existing job and have the correct interval for the frequency type" { - $jobId = (Get-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_newschedule).JobID + $jobId = (Get-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job dbatoolsci_newschedule).JobID foreach ($key in $results.keys) { $results[$key].EnumJobReferences() | Should -Contain $jobId @@ -150,7 +150,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $scheduleOptions = @('Time', 'Once', 'Second', 'Seconds', 'Minute', 'Minutes', 'Hour', 'Hours') foreach ($frequencySubdayType in $scheduleOptions) { - $variables = @{SqlInstance = $script:instance2 + $variables = @{SqlInstance = $TestConfig.instance2 Schedule = "dbatoolsci_$frequencySubdayType" Job = 'dbatoolsci_newschedule' FrequencyType = 'Daily' @@ -168,7 +168,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } AfterAll { - $null = Get-DbaAgentSchedule -SqlInstance $script:instance2 | + $null = Get-DbaAgentSchedule -SqlInstance $TestConfig.instance2 | Where-Object { $_.name -like 'dbatools*' } | Remove-DbaAgentSchedule -Confirm:$false -Force Remove-Variable -Name results @@ -179,7 +179,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } It "Should be a schedule on an existing job and have a valid frequency subday type" { - $jobId = (Get-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_newschedule).JobID + $jobId = (Get-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job dbatoolsci_newschedule).JobID foreach ($key in $results.keys) { $results[$key].EnumJobReferences() | Should -Contain $jobId $results[$key].FrequencySubdayTypes | Should -BeIn $scheduleOptions @@ -207,7 +207,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $scheduleOptions = @('First', 'Second', 'Third', 'Fourth', 'Last') foreach ($frequencyRelativeInterval in $scheduleOptions) { - $variables = @{SqlInstance = $script:instance2 + $variables = @{SqlInstance = $TestConfig.instance2 Schedule = "dbatoolsci_$frequencyRelativeInterval" Job = 'dbatoolsci_newschedule' FrequencyType = 'MonthlyRelative' # required to set the FrequencyRelativeInterval @@ -226,7 +226,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } AfterAll { - $null = Get-DbaAgentSchedule -SqlInstance $script:instance2 | + $null = Get-DbaAgentSchedule -SqlInstance $TestConfig.instance2 | Where-Object { $_.name -like 'dbatools*' } | Remove-DbaAgentSchedule -Confirm:$false -Force Remove-Variable -Name results @@ -237,7 +237,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } It "Should be a schedule on an existing job and have a valid frequency relative interval" { - $jobId = (Get-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_newschedule).JobID + $jobId = (Get-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job dbatoolsci_newschedule).JobID foreach ($key in $results.keys) { $results[$key].EnumJobReferences() | Should -Contain $jobId $results[$key].FrequencyRelativeIntervals | Should -BeIn $scheduleOptions @@ -245,4 +245,4 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } } -} \ No newline at end of file +} diff --git a/tests/New-DbaAvailabilityGroup.Tests.ps1 b/tests/New-DbaAvailabilityGroup.Tests.ps1 index 60a378e8b7..31422fe792 100644 --- a/tests/New-DbaAvailabilityGroup.Tests.ps1 +++ b/tests/New-DbaAvailabilityGroup.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$commandname Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,26 +15,26 @@ Describe "$commandname Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $null = Get-DbaProcess -SqlInstance $script:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue + $null = Get-DbaProcess -SqlInstance $TestConfig.instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue $dbname = "dbatoolsci_addag_agroupdb" $agname = "dbatoolsci_addag_agroup" - $null = New-DbaDatabase -SqlInstance $script:instance3 -Database $dbname | Backup-DbaDatabase + $null = New-DbaDatabase -SqlInstance $TestConfig.instance3 -Database $dbname | Backup-DbaDatabase } AfterEach { - $result = Remove-DbaAvailabilityGroup -SqlInstance $script:instance3 -AvailabilityGroup $agname -Confirm:$false + $result = Remove-DbaAvailabilityGroup -SqlInstance $TestConfig.instance3 -AvailabilityGroup $agname -Confirm:$false } AfterAll { - $null = Remove-DbaDatabase -SqlInstance $script:instance3 -Database $dbname -Confirm:$false + $null = Remove-DbaDatabase -SqlInstance $TestConfig.instance3 -Database $dbname -Confirm:$false } Context "adds an ag" { It "returns an ag with a db named" { - $results = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Database $dbname -Confirm:$false -Certificate dbatoolsci_AGCert + $results = New-DbaAvailabilityGroup -Primary $TestConfig.instance3 -Name $agname -ClusterType None -FailoverMode Manual -Database $dbname -Confirm:$false -Certificate dbatoolsci_AGCert $results.AvailabilityDatabases.Name | Should -Be $dbname $results.AvailabilityDatabases.Count | Should -Be 1 -Because "There should be only the named database in the group" } It "returns an ag with no database if one was not named" { - $results = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Confirm:$false -Certificate dbatoolsci_AGCert + $results = New-DbaAvailabilityGroup -Primary $TestConfig.instance3 -Name $agname -ClusterType None -FailoverMode Manual -Confirm:$false -Certificate dbatoolsci_AGCert $results.AvailabilityDatabases.Count | Should -Be 0 -Because "No database was named" } } -} #$script:instance2 for appveyor \ No newline at end of file +} #$TestConfig.instance2 for appveyor diff --git a/tests/New-DbaAzAccessToken.Tests.ps1 b/tests/New-DbaAzAccessToken.Tests.ps1 index 4436af1411..4ee3bae8a7 100644 --- a/tests/New-DbaAzAccessToken.Tests.ps1 +++ b/tests/New-DbaAzAccessToken.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/New-DbaClientAlias.Tests.ps1 b/tests/New-DbaClientAlias.Tests.ps1 index 46497e9852..f8c6696d2f 100644 --- a/tests/New-DbaClientAlias.Tests.ps1 +++ b/tests/New-DbaClientAlias.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/New-DbaCmConnection.Tests.ps1 b/tests/New-DbaCmConnection.Tests.ps1 index 1fb68dc643..bcae64e3ba 100644 --- a/tests/New-DbaCmConnection.Tests.ps1 +++ b/tests/New-DbaCmConnection.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/New-DbaComputerCertificate.Tests.ps1 b/tests/New-DbaComputerCertificate.Tests.ps1 index b687688818..a3889dd01d 100644 --- a/tests/New-DbaComputerCertificate.Tests.ps1 +++ b/tests/New-DbaComputerCertificate.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/New-DbaComputerCertificateSigningRequest.Tests.ps1 b/tests/New-DbaComputerCertificateSigningRequest.Tests.ps1 index 26cadcaf72..7cc1e39567 100644 --- a/tests/New-DbaComputerCertificateSigningRequest.Tests.ps1 +++ b/tests/New-DbaComputerCertificateSigningRequest.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/New-DbaConnectionString.Tests.ps1 b/tests/New-DbaConnectionString.Tests.ps1 index 696be6bfa8..ce1cd31251 100644 --- a/tests/New-DbaConnectionString.Tests.ps1 +++ b/tests/New-DbaConnectionString.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/New-DbaConnectionStringBuilder.Tests.ps1 b/tests/New-DbaConnectionStringBuilder.Tests.ps1 index 659d5cdc06..b16796a72d 100644 --- a/tests/New-DbaConnectionStringBuilder.Tests.ps1 +++ b/tests/New-DbaConnectionStringBuilder.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/New-DbaCredential.Tests.ps1 b/tests/New-DbaCredential.Tests.ps1 index 42fad9846c..c2bc521897 100644 --- a/tests/New-DbaCredential.Tests.ps1 +++ b/tests/New-DbaCredential.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig . "$PSScriptRoot\..\private\functions\Invoke-Command2.ps1" Describe "$CommandName Unit Tests" -Tag 'UnitTests' { @@ -22,31 +22,32 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { # Add user foreach ($login in $logins) { - $null = Invoke-Command2 -ScriptBlock { net user $args[0] $args[1] /add *>&1 } -ArgumentList $login, $plaintext -ComputerName $script:instance2 + $null = Invoke-Command2 -ScriptBlock { net user $args[0] $args[1] /add *>&1 } -ArgumentList $login, $plaintext -ComputerName $TestConfig.instance2 } } AfterAll { try { - (Get-DbaCredential -SqlInstance $script:instance2 -Identity dbatoolsci_thor, dbatoolsci_thorsmomma -ErrorAction Stop -WarningAction SilentlyContinue).Drop() + (Get-DbaCredential -SqlInstance $TestConfig.instance2 -Identity dbatoolsci_thor, dbatoolsci_thorsmomma -ErrorAction Stop -WarningAction SilentlyContinue).Drop() + (Get-DbaCredential -SqlInstance $TestConfig.instance2 -Name "https://mystorageaccount.blob.core.windows.net/mycontainer" -ErrorAction Stop -WarningAction SilentlyContinue).Drop() } catch { } foreach ($login in $logins) { - $null = Invoke-Command2 -ScriptBlock { net user $args /delete *>&1 } -ArgumentList $login -ComputerName $script:instance2 - $null = Invoke-Command2 -ScriptBlock { net user $args /delete *>&1 } -ArgumentList $login -ComputerName $script:instance2 + $null = Invoke-Command2 -ScriptBlock { net user $args /delete *>&1 } -ArgumentList $login -ComputerName $TestConfig.instance2 + $null = Invoke-Command2 -ScriptBlock { net user $args /delete *>&1 } -ArgumentList $login -ComputerName $TestConfig.instance2 } } Context "Create a new credential" { It "Should create new credentials with the proper properties" { - $results = New-DbaCredential -SqlInstance $script:instance2 -Name dbatoolsci_thorcred -Identity dbatoolsci_thor -Password $password + $results = New-DbaCredential -SqlInstance $TestConfig.instance2 -Name dbatoolsci_thorcred -Identity dbatoolsci_thor -Password $password $results.Name | Should Be "dbatoolsci_thorcred" $results.Identity | Should Be "dbatoolsci_thor" - $results = New-DbaCredential -SqlInstance $script:instance2 -Identity dbatoolsci_thorsmomma -Password $password + $results = New-DbaCredential -SqlInstance $TestConfig.instance2 -Identity dbatoolsci_thorsmomma -Password $password $results | Should Not Be $null } It "Gets the newly created credential" { - $results = Get-DbaCredential -SqlInstance $script:instance2 -Identity dbatoolsci_thorsmomma + $results = Get-DbaCredential -SqlInstance $TestConfig.instance2 -Identity dbatoolsci_thorsmomma $results.Name | Should Be "dbatoolsci_thorsmomma" $results.Identity | Should Be "dbatoolsci_thorsmomma" } @@ -55,7 +56,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Context "Create a new credential without password" { It "Should create new credentials with the proper properties but without password" { $credentialParams = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 Name = "https://mystorageaccount.blob.core.windows.net/mycontainer" Identity = 'Managed Identity' } @@ -64,9 +65,9 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $results.Identity | Should Be "Managed Identity" } It "Gets the newly created credential that doesn't have password" { - $results = Get-DbaCredential -SqlInstance $script:instance2 -Identity "Managed Identity" + $results = Get-DbaCredential -SqlInstance $TestConfig.instance2 -Identity "Managed Identity" $results.Name | Should Be "https://mystorageaccount.blob.core.windows.net/mycontainer" $results.Identity | Should Be "Managed Identity" } } -} \ No newline at end of file +} diff --git a/tests/New-DbaCustomError.Tests.ps1 b/tests/New-DbaCustomError.Tests.ps1 index 82a3975c92..09453163a5 100644 --- a/tests/New-DbaCustomError.Tests.ps1 +++ b/tests/New-DbaCustomError.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -14,8 +14,8 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance1 - $server2 = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance1 + $server2 = Connect-DbaInstance -SqlInstance $TestConfig.instance2 } AfterAll { $server.Query("IF EXISTS (SELECT 1 FROM master.sys.messages WHERE message_id = 70000) BEGIN EXEC msdb.dbo.sp_dropmessage @msgnum = 70000, @lang = 'all'; END") @@ -103,4 +103,4 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $results[1].ID | Should -Be 70006 } } -} \ No newline at end of file +} diff --git a/tests/New-DbaDacOption.Tests.ps1 b/tests/New-DbaDacOption.Tests.ps1 index c5d123a14f..79fb426505 100644 --- a/tests/New-DbaDacOption.Tests.ps1 +++ b/tests/New-DbaDacOption.Tests.ps1 @@ -1,6 +1,6 @@ $commandname = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$commandname Unit Tests" -Tag "UnitTests" { Context "Validate parameters" { @@ -14,7 +14,7 @@ Describe "$commandname Unit Tests" -Tag "UnitTests" { } Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $publishprofile = New-DbaDacProfile -SqlInstance $script:instance1 -Database whatever -Path C:\temp + $publishprofile = New-DbaDacProfile -SqlInstance $TestConfig.instance1 -Database whatever -Path C:\temp } AfterAll { Remove-Item -Confirm:$false -Path $publishprofile.FileName -ErrorAction SilentlyContinue @@ -46,4 +46,4 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { $result.GenerateDeploymentReport | Should -BeTrue $result.DeployOptions.CommandTimeout | Should -Be 5 } -} \ No newline at end of file +} diff --git a/tests/New-DbaDacProfile.Tests.ps1 b/tests/New-DbaDacProfile.Tests.ps1 index 6b7f4b52fe..199256017f 100644 --- a/tests/New-DbaDacProfile.Tests.ps1 +++ b/tests/New-DbaDacProfile.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,19 +16,19 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { $dbname = "dbatoolsci_publishprofile" - $db = New-DbaDatabase -SqlInstance $script:instance1 -Name $dbname + $db = New-DbaDatabase -SqlInstance $TestConfig.instance1 -Name $dbname $null = $db.Query("CREATE TABLE dbo.example (id int); INSERT dbo.example SELECT top 100 1 FROM sys.objects") } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance1 -Database $dbname -Confirm:$false + Remove-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $dbname -Confirm:$false } It "returns the right results" { - $publishprofile = New-DbaDacProfile -SqlInstance $script:instance1 -Database $dbname + $publishprofile = New-DbaDacProfile -SqlInstance $TestConfig.instance1 -Database $dbname $publishprofile.FileName -match 'publish.xml' | Should Be $true Remove-Item -Confirm:$false -Path $publishprofile.FileName -ErrorAction SilentlyContinue } -} \ No newline at end of file +} diff --git a/tests/New-DbaDatabase.Tests.ps1 b/tests/New-DbaDatabase.Tests.ps1 index 9a63382a43..b99ca185f9 100644 --- a/tests/New-DbaDatabase.Tests.ps1 +++ b/tests/New-DbaDatabase.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,8 +16,8 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BeforeAll { $random = Get-Random - $instance2 = Connect-DbaInstance -SqlInstance $script:instance2 - $instance3 = Connect-DbaInstance -SqlInstance $script:instance3 + $instance2 = Connect-DbaInstance -SqlInstance $TestConfig.instance2 + $instance3 = Connect-DbaInstance -SqlInstance $TestConfig.instance3 $null = Get-DbaProcess -SqlInstance $instance2, $instance3 | Where-Object Program -match dbatools | Stop-DbaProcess -Confirm:$false $randomDb = New-DbaDatabase -SqlInstance $instance2 $newDbName = "dbatoolsci_newdb_$random" @@ -147,4 +147,4 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $secondaryFileGroupDb.DefaultFileGroup | Should -Be "$($secondaryFileGroupDbName)_MainData" } } -} \ No newline at end of file +} diff --git a/tests/New-DbaDbAsymmetricKey.Tests.ps1 b/tests/New-DbaDbAsymmetricKey.Tests.ps1 index 6aef3095eb..68631e0038 100644 --- a/tests/New-DbaDbAsymmetricKey.Tests.ps1 +++ b/tests/New-DbaDbAsymmetricKey.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,17 +15,17 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance2 -Database enctest -Confirm:$false + Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database enctest -Confirm:$false } Context "commands work as expected" { $tPassword = ConvertTo-SecureString "ThisIsThePassword1" -AsPlainText -Force - if (!(Get-DbaDbMasterKey -SqlInstance $script:instance2 -Database master )) { - New-DbaDbMasterKey -SqlInstance $script:instance2 -Database master -SecurePassword $tpassword -confirm:$false + if (!(Get-DbaDbMasterKey -SqlInstance $TestConfig.instance2 -Database master )) { + New-DbaDbMasterKey -SqlInstance $TestConfig.instance2 -Database master -SecurePassword $tpassword -confirm:$false } $keyname = 'test1' - $key = New-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname - $results = Get-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname -Database master -WarningVariable warnvar + $key = New-DbaDbAsymmetricKey -SqlInstance $TestConfig.instance2 -Name $keyname + $results = Get-DbaDbAsymmetricKey -SqlInstance $TestConfig.instance2 -Name $keyname -Database master -WarningVariable warnvar It "Should create new key in master called $keyname" { $warnvar | Should -BeNullOrEmpty $results.database | Should -Be 'master' @@ -36,8 +36,8 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Context "Handles pre-existing key" { $keyname = 'test1' - $key = New-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname -Database master -WarningVariable warnvar 3> $null - $null = Remove-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname -Database master -confirm:$false + $key = New-DbaDbAsymmetricKey -SqlInstance $TestConfig.instance2 -Name $keyname -Database master -WarningVariable warnvar 3> $null + $null = Remove-DbaDbAsymmetricKey -SqlInstance $TestConfig.instance2 -Name $keyname -Database master -confirm:$false It "Should Warn that they key $keyname already exists" { $Warnvar | Should -BeLike '*already exists in master on*' } @@ -46,15 +46,15 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Context "Handles Algorithm changes" { $keyname = 'test2' $algorithm = 'Rsa4096' - $key = New-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname -Algorithm $algorithm -WarningVariable warnvar - $results = Get-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname -Database master + $key = New-DbaDbAsymmetricKey -SqlInstance $TestConfig.instance2 -Name $keyname -Algorithm $algorithm -WarningVariable warnvar + $results = Get-DbaDbAsymmetricKey -SqlInstance $TestConfig.instance2 -Name $keyname -Database master It "Should Create new key in master called $keyname" { $warnvar | Should -BeNullOrEmpty $results.database | Should -Be 'master' $results.name | Should -Be $keyname $results.KeyLength | Should -Be 4096 } - $null = Remove-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname -Database master -confirm:$false + $null = Remove-DbaDbAsymmetricKey -SqlInstance $TestConfig.instance2 -Name $keyname -Database master -confirm:$false } @@ -63,12 +63,12 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $algorithm = 'Rsa4096' $dbuser = 'keyowner' $database = 'enctest' - New-DbaDatabase -SqlInstance $script:instance2 -Name $database + New-DbaDatabase -SqlInstance $TestConfig.instance2 -Name $database $tPassword = ConvertTo-SecureString "ThisIsThePassword1" -AsPlainText -Force - New-DbaDbMasterKey -SqlInstance $script:instance2 -Database $database -SecurePassword $tpassword -Confirm:$false - New-DbaDbUser -SqlInstance $script:instance2 -Database $database -UserName $dbuser - $key = New-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Database $database -Name $keyname -Owner keyowner -Algorithm $algorithm -WarningVariable warnvar - $results = Get-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname -Database $database + New-DbaDbMasterKey -SqlInstance $TestConfig.instance2 -Database $database -SecurePassword $tpassword -Confirm:$false + New-DbaDbUser -SqlInstance $TestConfig.instance2 -Database $database -UserName $dbuser + $key = New-DbaDbAsymmetricKey -SqlInstance $TestConfig.instance2 -Database $database -Name $keyname -Owner keyowner -Algorithm $algorithm -WarningVariable warnvar + $results = Get-DbaDbAsymmetricKey -SqlInstance $TestConfig.instance2 -Name $keyname -Database $database It "Should Create new key in master called $keyname" { $warnvar | Should -BeNullOrEmpty $results.database | Should -Be $database @@ -76,7 +76,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $results.KeyLength | Should -Be 4096 $results.Owner | Should -Be $dbuser } - $null = Remove-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname -Database $database -confirm:$false + $null = Remove-DbaDbAsymmetricKey -SqlInstance $TestConfig.instance2 -Name $keyname -Database $database -confirm:$false } @@ -85,8 +85,8 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $algorithm = 'Rsa4096' $dbuser = 'keyowner' $database = 'enctest' - $key = New-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname -Owner keyowner -Database $database -Algorithm $algorithm -WarningVariable warnvar - $results = Get-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname -Database $database + $key = New-DbaDbAsymmetricKey -SqlInstance $TestConfig.instance2 -Name $keyname -Owner keyowner -Database $database -Algorithm $algorithm -WarningVariable warnvar + $results = Get-DbaDbAsymmetricKey -SqlInstance $TestConfig.instance2 -Name $keyname -Database $database It "Should Create new key in master called $keyname" { $warnvar | Should -BeNullOrEmpty @@ -95,7 +95,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $results.KeyLength | Should -Be 4096 $results.Owner | Should -Be $dbuser } - $null = Remove-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname -Database $database -confirm:$false + $null = Remove-DbaDbAsymmetricKey -SqlInstance $TestConfig.instance2 -Name $keyname -Database $database -confirm:$false } Context "Create new key loaded from a keyfile" { @@ -103,10 +103,10 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $keyname = 'filekey' $dbuser = 'keyowner' $database = 'enctest' - $path = "$($script:appveyorlabrepo)\keytests\keypair.snk" + $path = "$($($TestConfig.appveyorlabrepo))\keytests\keypair.snk" if (Test-Path -Path $path) { - $key = New-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Database $database -Name $keyname -Owner keyowner -WarningVariable warnvar -KeySourceType File -KeySource $path - $results = Get-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname -Database $database + $key = New-DbaDbAsymmetricKey -SqlInstance $TestConfig.instance2 -Database $database -Name $keyname -Owner keyowner -WarningVariable warnvar -KeySourceType File -KeySource $path + $results = Get-DbaDbAsymmetricKey -SqlInstance $TestConfig.instance2 -Name $keyname -Database $database } else { Write-Warning -Message "No keypair found in path [$path], skipping tests." $skip = $true @@ -117,21 +117,21 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $results.name | Should -Be $keyname $results.Owner | Should -Be $dbuser } - $null = Remove-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname -Database $database -confirm:$false + $null = Remove-DbaDbAsymmetricKey -SqlInstance $TestConfig.instance2 -Name $keyname -Database $database -confirm:$false } Context "Failed key creation from a missing keyfile" { $keyname = 'filekeybad' $dbuser = 'keyowner' $database = 'enctest' - $path = "$($script:appveyorlabrepo)\keytests\keypair.bad" - $key = New-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Database $database -Name $keyname -Owner keyowner -WarningVariable warnvar -KeySourceType File -KeySource $path 3> $null - $results = Get-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname -Database $database + $path = "$($($TestConfig.appveyorlabrepo))\keytests\keypair.bad" + $key = New-DbaDbAsymmetricKey -SqlInstance $TestConfig.instance2 -Database $database -Name $keyname -Owner keyowner -WarningVariable warnvar -KeySourceType File -KeySource $path 3> $null + $results = Get-DbaDbAsymmetricKey -SqlInstance $TestConfig.instance2 -Name $keyname -Database $database It "Should not Create new key in $database called $keyname" { $warnvar | Should -Not -BeNullOrEmpty $results | Should -BeNullorEmpty } - $null = Remove-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname -Database $database -confirm:$false + $null = Remove-DbaDbAsymmetricKey -SqlInstance $TestConfig.instance2 -Name $keyname -Database $database -confirm:$false } -} \ No newline at end of file +} diff --git a/tests/New-DbaDbCertificate.Tests.ps1 b/tests/New-DbaDbCertificate.Tests.ps1 index 8540d52cc1..78c177c848 100644 --- a/tests/New-DbaDbCertificate.Tests.ps1 +++ b/tests/New-DbaDbCertificate.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,11 +16,11 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Can create a database certificate" { BeforeAll { - if (-not (Get-DbaDbMasterKey -SqlInstance $script:instance1 -Database master)) { - $masterkey = New-DbaDbMasterKey -SqlInstance $script:instance1 -Database master -Password $(ConvertTo-SecureString -String "GoodPass1234!" -AsPlainText -Force) -Confirm:$false + if (-not (Get-DbaDbMasterKey -SqlInstance $TestConfig.instance1 -Database master)) { + $masterkey = New-DbaDbMasterKey -SqlInstance $TestConfig.instance1 -Database master -Password $(ConvertTo-SecureString -String "GoodPass1234!" -AsPlainText -Force) -Confirm:$false } - $tempdbmasterkey = New-DbaDbMasterKey -SqlInstance $script:instance1 -Database tempdb -Password $(ConvertTo-SecureString -String "GoodPass1234!" -AsPlainText -Force) -Confirm:$false + $tempdbmasterkey = New-DbaDbMasterKey -SqlInstance $TestConfig.instance1 -Database tempdb -Password $(ConvertTo-SecureString -String "GoodPass1234!" -AsPlainText -Force) -Confirm:$false $certificateName1 = "Cert_$(Get-random)" $certificateName2 = "Cert_$(Get-random)" } @@ -29,12 +29,12 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { if ($masterKey) { $masterkey | Remove-DbaDbMasterKey -Confirm:$false } } - $cert1 = New-DbaDbCertificate -SqlInstance $script:instance1 -Name $certificateName1 -Confirm:$false + $cert1 = New-DbaDbCertificate -SqlInstance $TestConfig.instance1 -Name $certificateName1 -Confirm:$false It "Successfully creates a new database certificate in default, master database" { "$($cert1.name)" -match $certificateName1 | Should Be $true } - $cert2 = New-DbaDbCertificate -SqlInstance $script:instance1 -Name $certificateName2 -Database tempdb -Confirm:$false + $cert2 = New-DbaDbCertificate -SqlInstance $TestConfig.instance1 -Name $certificateName2 -Database tempdb -Confirm:$false It "Successfully creates a new database certificate in the tempdb database" { "$($cert2.Database)" -match "tempdb" | Should Be $true } @@ -42,4 +42,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $null = $cert1 | Remove-DbaDbCertificate -Confirm:$false $null = $cert2 | Remove-DbaDbCertificate -Confirm:$false } -} \ No newline at end of file +} diff --git a/tests/New-DbaDbDataGeneratorConfig.Tests.ps1 b/tests/New-DbaDbDataGeneratorConfig.Tests.ps1 index b79fbcb1eb..ad52be70d4 100644 --- a/tests/New-DbaDbDataGeneratorConfig.Tests.ps1 +++ b/tests/New-DbaDbDataGeneratorConfig.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -21,18 +21,18 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { [LastName] [varchar](50) NULL, [City] [datetime] NULL ) ON [PRIMARY]" - $db = New-DbaDatabase -SqlInstance $script:instance1 -Name $dbname + $db = New-DbaDatabase -SqlInstance $TestConfig.instance1 -Name $dbname $db.Query($sql) } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance1 -Database $dbname -Confirm:$false + Remove-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $dbname -Confirm:$false $results | Remove-Item -Confirm:$false -ErrorAction Ignore } Context "Command works" { It "Should output a file with specific content" { - $results = New-DbaDbDataGeneratorConfig -SqlInstance $script:instance1 -Database $dbname -Path C:\temp + $results = New-DbaDbDataGeneratorConfig -SqlInstance $TestConfig.instance1 -Database $dbname -Path C:\temp $results.Directory.Name | Should -Be temp $results.FullName | Should -FileContentMatch $dbname @@ -40,4 +40,4 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $results.FullName | Should -FileContentMatch FirstName } } -} \ No newline at end of file +} diff --git a/tests/New-DbaDbEncryptionKey.Tests.ps1 b/tests/New-DbaDbEncryptionKey.Tests.ps1 index 7ed3aed5af..be19b7d80f 100644 --- a/tests/New-DbaDbEncryptionKey.Tests.ps1 +++ b/tests/New-DbaDbEncryptionKey.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Validate parameters" { @@ -20,18 +20,18 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $passwd = ConvertTo-SecureString "dbatools.IO" -AsPlainText -Force $cred = New-Object System.Management.Automation.PSCredential "sqladmin", $passwd - $masterkey = Get-DbaDbMasterKey -SqlInstance $script:instance2 -Database master + $masterkey = Get-DbaDbMasterKey -SqlInstance $TestConfig.instance2 -Database master if (-not $masterkey) { $delmasterkey = $true - $masterkey = New-DbaServiceMasterKey -SqlInstance $script:instance2 -SecurePassword $passwd + $masterkey = New-DbaServiceMasterKey -SqlInstance $TestConfig.instance2 -SecurePassword $passwd } - $mastercert = Get-DbaDbCertificate -SqlInstance $script:instance2 -Database master | Where-Object Name -notmatch "##" | Select-Object -First 1 + $mastercert = Get-DbaDbCertificate -SqlInstance $TestConfig.instance2 -Database master | Where-Object Name -notmatch "##" | Select-Object -First 1 if (-not $mastercert) { $delmastercert = $true - $mastercert = New-DbaDbCertificate -SqlInstance $script:instance2 + $mastercert = New-DbaDbCertificate -SqlInstance $TestConfig.instance2 } - $db = New-DbaDatabase -SqlInstance $script:instance2 + $db = New-DbaDatabase -SqlInstance $TestConfig.instance2 } AfterAll { @@ -52,8 +52,8 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $results.EncryptionAlgorithm | Should -Be "Aes256" } It "should create a new encryption key" { - $null = Get-DbaDbEncryptionKey -SqlInstance $script:instance2 -Database $db.Name | Remove-DbaDbEncryptionKey - $results = New-DbaDbEncryptionKey -SqlInstance $script:instance2 -Database $db.Name -Force -EncryptorName $mastercert.Name + $null = Get-DbaDbEncryptionKey -SqlInstance $TestConfig.instance2 -Database $db.Name | Remove-DbaDbEncryptionKey + $results = New-DbaDbEncryptionKey -SqlInstance $TestConfig.instance2 -Database $db.Name -Force -EncryptorName $mastercert.Name $results.EncryptionAlgorithm | Should -Be "Aes256" } } @@ -65,20 +65,20 @@ Describe "$CommandName Integration Tests for Async" -Tags "IntegrationTests" { BeforeAll { $PSDefaultParameterValues["*:Confirm"] = $false $passwd = ConvertTo-SecureString "dbatools.IO" -AsPlainText -Force - $masterkey = Get-DbaDbMasterKey -SqlInstance $script:instance2 -Database master + $masterkey = Get-DbaDbMasterKey -SqlInstance $TestConfig.instance2 -Database master if (-not $masterkey) { $delmasterkey = $true - $masterkey = New-DbaServiceMasterKey -SqlInstance $script:instance2 -SecurePassword $passwd + $masterkey = New-DbaServiceMasterKey -SqlInstance $TestConfig.instance2 -SecurePassword $passwd } - $masterasym = Get-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Database master + $masterasym = Get-DbaDbAsymmetricKey -SqlInstance $TestConfig.instance2 -Database master if (-not $masterasym) { $delmasterasym = $true - $masterasym = New-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Database master + $masterasym = New-DbaDbAsymmetricKey -SqlInstance $TestConfig.instance2 -Database master } - $db = New-DbaDatabase -SqlInstance $script:instance2 + $db = New-DbaDatabase -SqlInstance $TestConfig.instance2 $db | New-DbaDbMasterKey -SecurePassword $passwd $db | New-DbaDbAsymmetricKey } @@ -106,4 +106,4 @@ Describe "$CommandName Integration Tests for Async" -Tags "IntegrationTests" { $warn | Should -Match "n order to encrypt the database encryption key with an as" } } -} \ No newline at end of file +} diff --git a/tests/New-DbaDbFileGroup.Tests.ps1 b/tests/New-DbaDbFileGroup.Tests.ps1 index 9aca74b29c..3f58df4361 100644 --- a/tests/New-DbaDbFileGroup.Tests.ps1 +++ b/tests/New-DbaDbFileGroup.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -19,14 +19,14 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $db1name = "dbatoolsci_filegroup_test_$random" $db2name = "dbatoolsci_filegroup_test2_$random" - $server = Connect-DbaInstance -SqlInstance $script:instance2 - $newDb1 = New-DbaDatabase -SqlInstance $script:instance2 -Name $db1name - $newDb2 = New-DbaDatabase -SqlInstance $script:instance2 -Name $db2name + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 + $newDb1 = New-DbaDatabase -SqlInstance $TestConfig.instance2 -Name $db1name + $newDb2 = New-DbaDatabase -SqlInstance $TestConfig.instance2 -Name $db2name - $fileStreamStatus = Get-DbaFilestream -SqlInstance $script:instance2 + $fileStreamStatus = Get-DbaFilestream -SqlInstance $TestConfig.instance2 if ($fileStreamStatus.InstanceAccessLevel -eq 0) { - Enable-DbaFilestream -SqlInstance $script:instance2 -Confirm:$false -Force + Enable-DbaFilestream -SqlInstance $TestConfig.instance2 -Confirm:$false -Force $resetFileStream = $true } else { $resetFileStream = $false @@ -37,34 +37,34 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $newDb1, $newDb2 | Remove-DbaDatabase -Confirm:$false if ($resetFileStream) { - Disable-DbaFilestream -SqlInstance $script:instance2 -Confirm:$false -Force + Disable-DbaFilestream -SqlInstance $TestConfig.instance2 -Confirm:$false -Force } } Context "ensure command works" { It "Creates a filegroup" { - $results = New-DbaDbFileGroup -SqlInstance $script:instance2 -Database $db1name -FileGroup "filegroup_$random" + $results = New-DbaDbFileGroup -SqlInstance $TestConfig.instance2 -Database $db1name -FileGroup "filegroup_$random" $results.Parent.Name | Should -Be $db1name $results.Name | Should -Be "filegroup_$random" $results.FileGroupType | Should -Be RowsFileGroup } It "Check the validation for duplicate filegroup names" { - $results = New-DbaDbFileGroup -SqlInstance $script:instance2 -Database $db1name -FileGroup "filegroup_$random" + $results = New-DbaDbFileGroup -SqlInstance $TestConfig.instance2 -Database $db1name -FileGroup "filegroup_$random" $results | Should -BeNullOrEmpty } It "Creates a filegroup of each FileGroupType" { - $results = New-DbaDbFileGroup -SqlInstance $script:instance2 -Database $db1name -FileGroup "filegroup_rows_$random" -FileGroupType RowsFileGroup + $results = New-DbaDbFileGroup -SqlInstance $TestConfig.instance2 -Database $db1name -FileGroup "filegroup_rows_$random" -FileGroupType RowsFileGroup $results.Name | Should -Be "filegroup_rows_$random" $results.FileGroupType | Should -Be RowsFileGroup - $results = New-DbaDbFileGroup -SqlInstance $script:instance2 -Database $db1name -FileGroup "filegroup_filestream_$random" -FileGroupType FileStreamDataFileGroup + $results = New-DbaDbFileGroup -SqlInstance $TestConfig.instance2 -Database $db1name -FileGroup "filegroup_filestream_$random" -FileGroupType FileStreamDataFileGroup $results.Name | Should -Be "filegroup_filestream_$random" $results.FileGroupType | Should -Be FileStreamDataFileGroup - $results = New-DbaDbFileGroup -SqlInstance $script:instance2 -Database $db1name -FileGroup "filegroup_memory_optimized_$random" -FileGroupType MemoryOptimizedDataFileGroup + $results = New-DbaDbFileGroup -SqlInstance $TestConfig.instance2 -Database $db1name -FileGroup "filegroup_memory_optimized_$random" -FileGroupType MemoryOptimizedDataFileGroup $results.Name | Should -Be "filegroup_memory_optimized_$random" $results.FileGroupType | Should -Be MemoryOptimizedDataFileGroup @@ -75,9 +75,9 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $results.Name | Should -Be "filegroup_pipeline_$random" $results.Parent.Name | Should -Be $db1name - $results = $newDb1 | New-DbaDbFileGroup -SqlInstance $script:instance2 -Database $db2name -FileGroup "filegroup_pipeline2_$random" + $results = $newDb1 | New-DbaDbFileGroup -SqlInstance $TestConfig.instance2 -Database $db2name -FileGroup "filegroup_pipeline2_$random" $results.Name | Should -Be "filegroup_pipeline2_$random", "filegroup_pipeline2_$random" $results.Parent.Name | Should -Be $db1name, $db2name } } -} \ No newline at end of file +} diff --git a/tests/New-DbaDbMailAccount.Tests.ps1 b/tests/New-DbaDbMailAccount.Tests.ps1 index 5645633922..8324cb2111 100644 --- a/tests/New-DbaDbMailAccount.Tests.ps1 +++ b/tests/New-DbaDbMailAccount.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,7 +16,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { $accountName = "dbatoolsci_test_$(get-random)" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $description = 'Mail account for email alerts' $email_address = 'dbatoolssci@dbatools.net' $display_name = 'dbatoolsci mail alerts' @@ -28,7 +28,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } } AfterAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $mailAccountSettings = "EXEC msdb.dbo.sysmail_delete_account_sp @account_name = '$accountName';" $server.query($mailAccountSettings) } @@ -36,7 +36,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Gets DbMail Account" { $splat = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 Account = $accountName Description = $description EmailAddress = $email_address @@ -96,4 +96,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $results | Should Be $null } } -} \ No newline at end of file +} diff --git a/tests/New-DbaDbMailProfile.Tests.ps1 b/tests/New-DbaDbMailProfile.Tests.ps1 index 2bd35f8d75..9103ecea94 100644 --- a/tests/New-DbaDbMailProfile.Tests.ps1 +++ b/tests/New-DbaDbMailProfile.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,7 +16,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { BeforeAll { $profilename = "dbatoolsci_test_$(get-random)" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $description = 'Mail account for email alerts' $mailaccountname = 'dbatoolssci@dbatools.io' $mailaccountpriority = 1 @@ -30,7 +30,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $server.Query($sql) } AfterAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $mailAccountSettings = "EXEC msdb.dbo.sysmail_delete_profile_sp @profile_name = '$profilename';" $server.query($mailAccountSettings) $regularaccountsettings = "EXEC msdb.dbo.sysmail_delete_account_sp @account_name = '$mailaccountname';" @@ -40,7 +40,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Sets DbMail Profile" { $splat = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 Profile = $profilename Description = $description MailAccountName = $mailaccountname @@ -58,4 +58,4 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $results.description | Should Be $description } } -} \ No newline at end of file +} diff --git a/tests/New-DbaDbMaskingConfig.Tests.ps1 b/tests/New-DbaDbMaskingConfig.Tests.ps1 index 177f1efb5b..0e5bb9283c 100644 --- a/tests/New-DbaDbMaskingConfig.Tests.ps1 +++ b/tests/New-DbaDbMaskingConfig.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -21,7 +21,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { [lname] [varchar](50) NULL, [dob] [datetime] NULL ) ON [PRIMARY]" - $db = New-DbaDatabase -SqlInstance $script:instance1 -Name $dbname + $db = New-DbaDatabase -SqlInstance $TestConfig.instance1 -Name $dbname $db.Query($sql) $sql = "INSERT INTO people (fname, lname, dob) VALUES ('Joe','Schmoe','2/2/2000') INSERT INTO people (fname, lname, dob) VALUES ('Jane','Schmee','2/2/1950')" @@ -44,21 +44,21 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { (3, 'fe80::7df3:7015:89e9:fbed%15', '123 Fake Street', '123 Fake Street', '123 Fake Street')") } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance1 -Database $dbname -Confirm:$false + Remove-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $dbname -Confirm:$false $results | Remove-Item -Confirm:$false -ErrorAction Ignore } Context "Command works" { It "Should output a file with specific content" { - $results = New-DbaDbMaskingConfig -SqlInstance $script:instance1 -Database $dbname -Path C:\temp + $results = New-DbaDbMaskingConfig -SqlInstance $TestConfig.instance1 -Database $dbname -Path C:\temp $results.Directory.Name | Should -Be temp $results.FullName | Should -FileContentMatch $dbname $results.FullName | Should -FileContentMatch fname } It "Bug 6934: matching IPAddress, Address, and StreetAddress on known names" { - $results = New-DbaDbMaskingConfig -SqlInstance $script:instance1 -Database $dbname -Table DbConfigTest -Path C:\temp + $results = New-DbaDbMaskingConfig -SqlInstance $TestConfig.instance1 -Database $dbname -Table DbConfigTest -Path C:\temp $jsonOutput = Get-Content $results.FullName | ConvertFrom-Json $jsonOutput.Tables.Columns[1].Name | Should -Be "IPAddress" @@ -78,4 +78,4 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $jsonOutput.Tables.Columns[4].SubType | Should -Be "StreetAddress" } } -} \ No newline at end of file +} diff --git a/tests/New-DbaDbMasterKey.Tests.ps1 b/tests/New-DbaDbMasterKey.Tests.ps1 index f4e3165e0a..2fc99beeef 100644 --- a/tests/New-DbaDbMasterKey.Tests.ps1 +++ b/tests/New-DbaDbMasterKey.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -22,18 +22,18 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { $PSDefaultParameterValues["*:Confirm"] = $false $passwd = ConvertTo-SecureString "dbatools.IO" -AsPlainText -Force - $masterkey = Get-DbaDbMasterKey -SqlInstance $script:instance1 -Database master + $masterkey = Get-DbaDbMasterKey -SqlInstance $TestConfig.instance1 -Database master if (-not $masterkey) { $delmasterkey = $true - $masterkey = New-DbaServiceMasterKey -SqlInstance $script:instance1 -SecurePassword $passwd + $masterkey = New-DbaServiceMasterKey -SqlInstance $TestConfig.instance1 -SecurePassword $passwd } - $mastercert = Get-DbaDbCertificate -SqlInstance $script:instance1 -Database master | Where-Object Name -notmatch "##" | Select-Object -First 1 + $mastercert = Get-DbaDbCertificate -SqlInstance $TestConfig.instance1 -Database master | Where-Object Name -notmatch "##" | Select-Object -First 1 if (-not $mastercert) { $delmastercert = $true - $mastercert = New-DbaDbCertificate -SqlInstance $script:instance1 + $mastercert = New-DbaDbCertificate -SqlInstance $TestConfig.instance1 } - $db = New-DbaDatabase -SqlInstance $script:instance1 - $db1 = New-DbaDatabase -SqlInstance $script:instance1 + $db = New-DbaDatabase -SqlInstance $TestConfig.instance1 + $db1 = New-DbaDatabase -SqlInstance $TestConfig.instance1 } AfterAll { @@ -59,8 +59,8 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $results.IsEncryptedByServer | Should -Be $true } It "should create master key on a database" { - $results = New-DbaDbMasterKey -SqlInstance $script:instance1 -Database $db1.Name -SecurePassword $passwd + $results = New-DbaDbMasterKey -SqlInstance $TestConfig.instance1 -Database $db1.Name -SecurePassword $passwd $results.IsEncryptedByServer | Should -Be $true } } -} \ No newline at end of file +} diff --git a/tests/New-DbaDbRole.Tests.ps1 b/tests/New-DbaDbRole.Tests.ps1 index 03f636753c..3b10d519c5 100644 --- a/tests/New-DbaDbRole.Tests.ps1 +++ b/tests/New-DbaDbRole.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Validate parameters" { @@ -15,7 +15,7 @@ Describe "$CommandName Unit Tests" -Tags "UnitTests" { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $instance = Connect-DbaInstance -SqlInstance $script:instance2 + $instance = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $dbname = "dbatoolsci_adddb_newrole" $instance.Query("create database $dbname") $roleExecutor = "dbExecuter" @@ -64,4 +64,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $result.Parent | Should Be $dbname } } -} \ No newline at end of file +} diff --git a/tests/New-DbaDbSchema.Tests.ps1 b/tests/New-DbaDbSchema.Tests.ps1 index abef66b323..1d8906f550 100644 --- a/tests/New-DbaDbSchema.Tests.ps1 +++ b/tests/New-DbaDbSchema.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,8 +16,8 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BeforeAll { $random = Get-Random - $server1 = Connect-DbaInstance -SqlInstance $script:instance1 - $server2 = Connect-DbaInstance -SqlInstance $script:instance2 + $server1 = Connect-DbaInstance -SqlInstance $TestConfig.instance1 + $server2 = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $null = Get-DbaProcess -SqlInstance $server1, $server2 | Where-Object Program -match dbatools | Stop-DbaProcess -Confirm:$false $newDbName = "dbatoolsci_newdb_$random" $newDbs = New-DbaDatabase -SqlInstance $server1, $server2 -Name $newDbName @@ -74,4 +74,4 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $schema.Parent.Name | Should -Be $newDbName } } -} \ No newline at end of file +} diff --git a/tests/New-DbaDbSequence.Tests.ps1 b/tests/New-DbaDbSequence.Tests.ps1 index 40e9f6c90f..2ef4b5e886 100644 --- a/tests/New-DbaDbSequence.Tests.ps1 +++ b/tests/New-DbaDbSequence.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,7 +16,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BeforeAll { $random = Get-Random - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $newDbName = "dbatoolsci_newdb_$random" $newDb = New-DbaDatabase -SqlInstance $server -Name $newDbName @@ -180,4 +180,4 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $warn.message | Should -Not -BeLike "*Schema dbo already exists in the database*" } } -} \ No newline at end of file +} diff --git a/tests/New-DbaDbSnapshot.Tests.ps1 b/tests/New-DbaDbSnapshot.Tests.ps1 index 68b0978e76..487bf959ef 100644 --- a/tests/New-DbaDbSnapshot.Tests.ps1 +++ b/tests/New-DbaDbSnapshot.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -17,24 +17,24 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Context "Parameter validation" { It "Stops if no Database or AllDatabases" { - { New-DbaDbSnapshot -SqlInstance $script:instance2 -EnableException -WarningAction SilentlyContinue } | Should Throw "You must specify" + { New-DbaDbSnapshot -SqlInstance $TestConfig.instance2 -EnableException -WarningAction SilentlyContinue } | Should Throw "You must specify" } It "Is nice by default" { - { New-DbaDbSnapshot -SqlInstance $script:instance2 *> $null -WarningAction SilentlyContinue } | Should Not Throw "You must specify" + { New-DbaDbSnapshot -SqlInstance $TestConfig.instance2 *> $null -WarningAction SilentlyContinue } | Should Not Throw "You must specify" } } Context "Operations on not supported databases" { It "Doesn't support model, master or tempdb" { - $result = New-DbaDbSnapshot -SqlInstance $script:instance2 -EnableException -Database model, master, tempdb -WarningAction SilentlyContinue + $result = New-DbaDbSnapshot -SqlInstance $TestConfig.instance2 -EnableException -Database model, master, tempdb -WarningAction SilentlyContinue $result | Should Be $null } } Context "Operations on databases" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 - Get-DbaProcess -SqlInstance $script:instance2 | Where-Object Program -match dbatools | Stop-DbaProcess -Confirm:$false -WarningAction SilentlyContinue + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 + Get-DbaProcess -SqlInstance $TestConfig.instance2 | Where-Object Program -match dbatools | Stop-DbaProcess -Confirm:$false -WarningAction SilentlyContinue $db1 = "dbatoolsci_SnapMe" $db2 = "dbatoolsci_SnapMe2" $db3 = "dbatoolsci_SnapMe3_Offline" @@ -45,27 +45,27 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $server.Query("CREATE DATABASE [$db4]") } AfterAll { - Remove-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db1, $db2, $db3, $db4 -Confirm:$false - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance2 -Database $db1, $db2, $db3, $db4 + Remove-DbaDbSnapshot -SqlInstance $TestConfig.instance2 -Database $db1, $db2, $db3, $db4 -Confirm:$false + Remove-DbaDatabase -Confirm:$false -SqlInstance $TestConfig.instance2 -Database $db1, $db2, $db3, $db4 } It "Skips over offline databases nicely" { $server.Query("ALTER DATABASE $db3 SET OFFLINE WITH ROLLBACK IMMEDIATE") - $result = New-DbaDbSnapshot -SqlInstance $script:instance2 -EnableException -Database $db3 + $result = New-DbaDbSnapshot -SqlInstance $TestConfig.instance2 -EnableException -Database $db3 $result | Should Be $null $server.Query("ALTER DATABASE $db3 SET ONLINE WITH ROLLBACK IMMEDIATE") } It "Refuses to accept multiple source databases with a single name target" { - { New-DbaDbSnapshot -SqlInstance $script:instance2 -EnableException -Database $db1, $db2 -Name "dbatools_Snapped" -WarningAction SilentlyContinue } | Should Throw + { New-DbaDbSnapshot -SqlInstance $TestConfig.instance2 -EnableException -Database $db1, $db2 -Name "dbatools_Snapped" -WarningAction SilentlyContinue } | Should Throw } It "Halts when path is not accessible" { - { New-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db1 -Path B:\Funnydbatoolspath -EnableException -WarningAction SilentlyContinue } | Should Throw + { New-DbaDbSnapshot -SqlInstance $TestConfig.instance2 -Database $db1 -Path B:\Funnydbatoolspath -EnableException -WarningAction SilentlyContinue } | Should Throw } It "Creates snaps for multiple dbs by default" { - $results = New-DbaDbSnapshot -SqlInstance $script:instance2 -EnableException -Database $db1, $db2 + $results = New-DbaDbSnapshot -SqlInstance $TestConfig.instance2 -EnableException -Database $db1, $db2 $results | Should Not Be $null foreach ($result in $results) { $result.SnapshotOf -in @($db1, $db2) | Should Be $true @@ -73,37 +73,37 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } It "Creates snap with the correct name" { - $result = New-DbaDbSnapshot -SqlInstance $script:instance2 -EnableException -Database $db1 -Name "dbatools_SnapMe_right" + $result = New-DbaDbSnapshot -SqlInstance $TestConfig.instance2 -EnableException -Database $db1 -Name "dbatools_SnapMe_right" $result | Should Not Be $null $result.SnapshotOf | Should Be $db1 $result.Name | Should Be "dbatools_SnapMe_right" } It "Creates snap with the correct name template" { - $result = New-DbaDbSnapshot -SqlInstance $script:instance2 -EnableException -Database $db2 -NameSuffix "dbatools_SnapMe_{0}_funny" + $result = New-DbaDbSnapshot -SqlInstance $TestConfig.instance2 -EnableException -Database $db2 -NameSuffix "dbatools_SnapMe_{0}_funny" $result | Should Not Be $null $result.SnapshotOf | Should Be $db2 $result.Name | Should Be ("dbatools_SnapMe_{0}_funny" -f $db2) } It "has the correct default properties" { - $result = Get-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db2 | Select-Object -First 1 + $result = Get-DbaDbSnapshot -SqlInstance $TestConfig.instance2 -Database $db2 | Select-Object -First 1 $ExpectedPropsDefault = 'ComputerName', 'CreateDate', 'InstanceName', 'Name', 'SnapshotOf', 'SqlInstance', 'DiskUsage' ($result.PSStandardMembers.DefaultDisplayPropertySet.ReferencedPropertyNames | Sort-Object) | Should Be ($ExpectedPropsDefault | Sort-Object) } It "Creates multiple snaps for db with dot in the name (see #8829)" { - $results = New-DbaDbSnapshot -SqlInstance $script:instance2 -EnableException -Database $db4 + $results = New-DbaDbSnapshot -SqlInstance $TestConfig.instance2 -EnableException -Database $db4 $results | Should Not Be $null foreach ($result in $results) { $result.SnapshotOf -in @($db4) | Should Be $true } Start-Sleep -Seconds 2 - $results = New-DbaDbSnapshot -SqlInstance $script:instance2 -EnableException -Database $db4 + $results = New-DbaDbSnapshot -SqlInstance $TestConfig.instance2 -EnableException -Database $db4 $results | Should Not Be $null foreach ($result in $results) { $result.SnapshotOf -in @($db4) | Should Be $true } } } -} \ No newline at end of file +} diff --git a/tests/New-DbaDbSynonym.Tests.ps1 b/tests/New-DbaDbSynonym.Tests.ps1 index 612ae3a3d6..6bebed491e 100644 --- a/tests/New-DbaDbSynonym.Tests.ps1 +++ b/tests/New-DbaDbSynonym.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Validate parameters" { @@ -17,20 +17,20 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { $dbname = "dbatoolsscidb_$(Get-Random)" $dbname2 = "dbatoolsscidb_$(Get-Random)" - $null = New-DbaDatabase -SqlInstance $script:instance2 -Name $dbname - $null = New-DbaDatabase -SqlInstance $script:instance2 -Name $dbname2 + $null = New-DbaDatabase -SqlInstance $TestConfig.instance2 -Name $dbname + $null = New-DbaDatabase -SqlInstance $TestConfig.instance2 -Name $dbname2 } AfterEach { - $null = Remove-DbaDbSynonym -SqlInstance $script:instance2 -Confirm:$false + $null = Remove-DbaDbSynonym -SqlInstance $TestConfig.instance2 -Confirm:$false } AfterAll { - $null = Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbname, $dbname2 -Confirm:$false - $null = Remove-DbaDbSynonym -SqlInstance $script:instance2 -Confirm:$false + $null = Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname, $dbname2 -Confirm:$false + $null = Remove-DbaDbSynonym -SqlInstance $TestConfig.instance2 -Confirm:$false } Context "Functionality" { It 'Add new synonym and returns results' { - $result1 = New-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname -Synonym 'syn1' -BaseObject 'obj1' + $result1 = New-DbaDbSynonym -SqlInstance $TestConfig.instance2 -Database $dbname -Synonym 'syn1' -BaseObject 'obj1' $result1.Count | Should -Be 1 $result1.Name | Should -Be syn1 @@ -39,7 +39,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } It 'Add new synonym with default schema' { - $result2a = New-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname -Synonym 'syn2a' -BaseObject 'obj2a' + $result2a = New-DbaDbSynonym -SqlInstance $TestConfig.instance2 -Database $dbname -Synonym 'syn2a' -BaseObject 'obj2a' $result2a.Count | Should -Be 1 $result2a.Name | Should -Be 'syn2a' @@ -49,8 +49,8 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } It 'Add new synonym with specified schema' { - $null = New-DbaDbSchema -SqlInstance $script:instance2 -Database $dbname -Schema 'sch2' - $result2 = New-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname -Synonym 'syn2' -BaseObject 'obj2' -Schema 'sch2' + $null = New-DbaDbSchema -SqlInstance $TestConfig.instance2 -Database $dbname -Schema 'sch2' + $result2 = New-DbaDbSynonym -SqlInstance $TestConfig.instance2 -Database $dbname -Synonym 'syn2' -BaseObject 'obj2' -Schema 'sch2' $result2.Count | Should -Be 1 $result2.Name | Should -Be 'syn2' @@ -60,7 +60,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } It 'Add new synonym to list of databases' { - $result3 = New-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname, $dbname2 -Synonym 'syn3' -BaseObject 'obj3' + $result3 = New-DbaDbSynonym -SqlInstance $TestConfig.instance2 -Database $dbname, $dbname2 -Synonym 'syn3' -BaseObject 'obj3' $result3.Count | Should -Be 2 $result3.Name | Select-Object -Unique | Should -Be 'syn3' @@ -70,8 +70,8 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } It 'Add new synonym to different schema' { - $null = New-DbaDbSchema -SqlInstance $script:instance2 -Database $dbname -Schema 'sch4' - $result4 = New-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname -Schema 'sch4' -Synonym 'syn4' -BaseObject 'obj4' + $null = New-DbaDbSchema -SqlInstance $TestConfig.instance2 -Database $dbname -Schema 'sch4' + $result4 = New-DbaDbSynonym -SqlInstance $TestConfig.instance2 -Database $dbname -Schema 'sch4' -Synonym 'syn4' -BaseObject 'obj4' $result4.Count | Should -Be 1 $result4.Name | Select-Object -Unique | Should -Be 'syn4' @@ -84,8 +84,8 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } It 'Add new synonym to with a base schema' { - $null = New-DbaDbSchema -SqlInstance $script:instance2 -Database $dbname -Schema 'sch5' - $result5 = New-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname -Schema 'sch5' -Synonym 'syn5' -BaseObject 'obj5' -BaseSchema 'bsch5' + $null = New-DbaDbSchema -SqlInstance $TestConfig.instance2 -Database $dbname -Schema 'sch5' + $result5 = New-DbaDbSynonym -SqlInstance $TestConfig.instance2 -Database $dbname -Schema 'sch5' -Synonym 'syn5' -BaseObject 'obj5' -BaseSchema 'bsch5' $result5.Count | Should -Be 1 $result5.Name | Select-Object -Unique | Should -Be 'syn5' @@ -98,8 +98,8 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } It 'Add new synonym to with a base database' { - $null = New-DbaDbSchema -SqlInstance $script:instance2 -Database $dbname -Schema 'sch6' - $result6 = New-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname -Schema 'sch6' -Synonym 'syn6' -BaseObject 'obj6' -BaseSchema 'bsch6' -BaseDatabase 'bdb6' + $null = New-DbaDbSchema -SqlInstance $TestConfig.instance2 -Database $dbname -Schema 'sch6' + $result6 = New-DbaDbSynonym -SqlInstance $TestConfig.instance2 -Database $dbname -Schema 'sch6' -Synonym 'syn6' -BaseObject 'obj6' -BaseSchema 'bsch6' -BaseDatabase 'bdb6' $result6.Count | Should -Be 1 $result6.Name | Select-Object -Unique | Should -Be 'syn6' @@ -112,8 +112,8 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } It 'Add new synonym to with a base server' { - $null = New-DbaDbSchema -SqlInstance $script:instance2 -Database $dbname -Schema 'sch7' - $result7 = New-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname -Schema 'sch7' -Synonym 'syn7' -BaseObject 'obj7' -BaseSchema 'bsch7' -BaseDatabase 'bdb7' -BaseServer 'bsrv7' + $null = New-DbaDbSchema -SqlInstance $TestConfig.instance2 -Database $dbname -Schema 'sch7' + $result7 = New-DbaDbSynonym -SqlInstance $TestConfig.instance2 -Database $dbname -Schema 'sch7' -Synonym 'syn7' -BaseObject 'obj7' -BaseSchema 'bsch7' -BaseDatabase 'bdb7' -BaseServer 'bsrv7' $result7.Count | Should -Be 1 $result7.Name | Select-Object -Unique | Should -Be 'syn7' @@ -126,4 +126,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } } -} \ No newline at end of file +} diff --git a/tests/New-DbaDbTable.Tests.ps1 b/tests/New-DbaDbTable.Tests.ps1 index d5616b949f..62ffc60a35 100644 --- a/tests/New-DbaDbTable.Tests.ps1 +++ b/tests/New-DbaDbTable.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,7 +16,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BeforeAll { $dbname = "dbatoolsscidb_$(Get-Random)" - $null = New-DbaDatabase -SqlInstance $script:instance1 -Name $dbname + $null = New-DbaDatabase -SqlInstance $TestConfig.instance1 -Name $dbname $tablename = "dbatoolssci_$(Get-Random)" $tablename2 = "dbatoolssci2_$(Get-Random)" $tablename3 = "dbatoolssci2_$(Get-Random)" @@ -24,8 +24,8 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $tablename5 = "dbatoolssci2_$(Get-Random)" } AfterAll { - $null = Invoke-DbaQuery -SqlInstance $script:instance1 -Database $dbname -Query "drop table $tablename, $tablename2" - $null = Remove-DbaDatabase -SqlInstance $script:instance1 -Database $dbname -Confirm:$false + $null = Invoke-DbaQuery -SqlInstance $TestConfig.instance1 -Database $dbname -Query "drop table $tablename, $tablename2" + $null = Remove-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $dbname -Confirm:$false } Context "Should create the table" { BeforeEach { @@ -37,10 +37,10 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } } It "Creates the table" { - (New-DbaDbTable -SqlInstance $script:instance1 -Database $dbname -Name $tablename -ColumnMap $map).Name | Should -Contain $tablename + (New-DbaDbTable -SqlInstance $TestConfig.instance1 -Database $dbname -Name $tablename -ColumnMap $map).Name | Should -Contain $tablename } It "Really created it" { - (Get-DbaDbTable -SqlInstance $script:instance1 -Database $dbname).Name | Should -Contain $tablename + (Get-DbaDbTable -SqlInstance $TestConfig.instance1 -Database $dbname).Name | Should -Contain $tablename } } Context "Should create the table with constraint on column" { @@ -55,10 +55,10 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } } It "Creates the table" { - (New-DbaDbTable -SqlInstance $script:instance1 -Database $dbname -Name $tablename2 -ColumnMap $map).Name | Should -Contain $tablename2 + (New-DbaDbTable -SqlInstance $TestConfig.instance1 -Database $dbname -Name $tablename2 -ColumnMap $map).Name | Should -Contain $tablename2 } It "Has a default constraint" { - $table = Get-DbaDbTable -SqlInstance $script:instance1 -Database $dbname -Table $tablename2 + $table = Get-DbaDbTable -SqlInstance $TestConfig.instance1 -Database $dbname -Table $tablename2 $table.Name | Should -Contain $tablename2 $table.Columns.DefaultConstraint.Name | Should -Contain "DF_MyTest" } @@ -74,10 +74,10 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } } It "Creates the table" { - (New-DbaDbTable -SqlInstance $script:instance1 -Database $dbname -Name $tablename3 -ColumnMap $map).Name | Should -Contain $tablename3 + (New-DbaDbTable -SqlInstance $TestConfig.instance1 -Database $dbname -Name $tablename3 -ColumnMap $map).Name | Should -Contain $tablename3 } It "Has an identity column" { - $table = Get-DbaDbTable -SqlInstance $script:instance1 -Database $dbname -Table $tablename3 + $table = Get-DbaDbTable -SqlInstance $TestConfig.instance1 -Database $dbname -Table $tablename3 $table.Name | Should -Be $tablename3 $table.Columns.Identity | Should -BeTrue $table.Columns.IdentitySeed | Should -Be $map.IdentitySeed @@ -100,7 +100,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } } It "Creates the table" { - { $null = New-DbaDbTable -SqlInstance $script:instance1 -Database $dbname -Name $tablename4 -ColumnMap $map -EnableException } | Should Not Throw + { $null = New-DbaDbTable -SqlInstance $TestConfig.instance1 -Database $dbname -Name $tablename4 -ColumnMap $map -EnableException } | Should Not Throw } } Context "Should create the table with a nvarcharmax column" { @@ -112,10 +112,10 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } } It "Creates the table" { - (New-DbaDbTable -SqlInstance $script:instance1 -Database $dbname -Name $tablename5 -ColumnMap $map).Name | Should -Contain $tablename5 + (New-DbaDbTable -SqlInstance $TestConfig.instance1 -Database $dbname -Name $tablename5 -ColumnMap $map).Name | Should -Contain $tablename5 } It "Has the correct column datatype" { - $table = Get-DbaDbTable -SqlInstance $script:instance1 -Database $dbname -Table $tablename5 + $table = Get-DbaDbTable -SqlInstance $TestConfig.instance1 -Database $dbname -Table $tablename5 $table.Columns['test'].DataType.SqlDataType | Should -Be "NVarCharMax" } } @@ -130,7 +130,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Type = 'int' } - $tableWithSchema = New-DbaDbTable -SqlInstance $script:instance1 -Database $dbname -Name $tableName -ColumnMap $map -Schema $schemaName + $tableWithSchema = New-DbaDbTable -SqlInstance $TestConfig.instance1 -Database $dbname -Name $tableName -ColumnMap $map -Schema $schemaName $tableWithSchema.Count | Should -Be 1 $tableWithSchema.Database | Should -Be $dbname $tableWithSchema.Name | Should -Be "table_$random" @@ -146,10 +146,10 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Type = 'int' } - $tableWithSchema = New-DbaDbTable -SqlInstance $script:instance1 -Database $dbname -Name $tableName -ColumnMap $map -Schema $schemaName -Passthru + $tableWithSchema = New-DbaDbTable -SqlInstance $TestConfig.instance1 -Database $dbname -Name $tableName -ColumnMap $map -Schema $schemaName -Passthru $tableWithSchema[0] | Should -Be "CREATE SCHEMA [$schemaName]" $tableWithSchema[2] | Should -Match "$schemaName" $tableWithSchema[2] | Should -Match "$tableName" } } -} \ No newline at end of file +} diff --git a/tests/New-DbaDbTransfer.Tests.ps1 b/tests/New-DbaDbTransfer.Tests.ps1 index d2228382ea..a0f791d663 100644 --- a/tests/New-DbaDbTransfer.Tests.ps1 +++ b/tests/New-DbaDbTransfer.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -32,10 +32,10 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { BeforeAll { $dbName = 'dbatools_transfer' - $source = Connect-DbaInstance -SqlInstance $script:instance1 - $destination = Connect-DbaInstance -SqlInstance $script:instance2 + $source = Connect-DbaInstance -SqlInstance $TestConfig.instance1 + $destination = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $source.Query("CREATE DATABASE $dbName") - $db = Get-DbaDatabase -SqlInstance $script:instance1 -Database $dbName + $db = Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $dbName $null = $db.Query("CREATE TABLE dbo.transfer_test (id int); INSERT dbo.transfer_test SELECT top 10 1 @@ -90,11 +90,11 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } catch { $null = 1 } - Remove-DbaDatabase -SqlInstance $script:instance1 -Database $dbName -Confirm:$false + Remove-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $dbName -Confirm:$false } Context "Testing connection parameters" { It "Should create a transfer object" { - $transfer = New-DbaDbTransfer -SqlInstance $script:instance1 -Database $dbName + $transfer = New-DbaDbTransfer -SqlInstance $TestConfig.instance1 -Database $dbName $transfer | Should -BeOfType Microsoft.SqlServer.Management.Smo.Transfer $transfer.BatchSize | Should -Be 50000 $transfer.BulkCopyTimeout | Should -Be 5000 @@ -108,7 +108,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $transfer.DestinationServer | Should -BeNullOrEmpty } It "Should properly assign dest server parameters from full connstring" { - $transfer = New-DbaDbTransfer -SqlInstance $script:instance1 -Database $dbName -DestinationSqlInstance 'Data Source=foo;User=bar;password=foobar;Initial Catalog=hog' + $transfer = New-DbaDbTransfer -SqlInstance $TestConfig.instance1 -Database $dbName -DestinationSqlInstance 'Data Source=foo;User=bar;password=foobar;Initial Catalog=hog' $transfer.DestinationDatabase | Should -Be hog $transfer.DestinationLoginSecure | Should -Be $false $transfer.DestinationLogin | Should -Be bar @@ -116,7 +116,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $transfer.DestinationServer | Should -Be foo } It "Should properly assign dest server parameters from trusted connstring" { - $transfer = New-DbaDbTransfer -SqlInstance $script:instance1 -Database $dbName -DestinationSqlInstance 'Data Source=foo;Integrated Security=True' + $transfer = New-DbaDbTransfer -SqlInstance $TestConfig.instance1 -Database $dbName -DestinationSqlInstance 'Data Source=foo;Integrated Security=True' $transfer.DestinationDatabase | Should -Be $dbName $transfer.DestinationLoginSecure | Should -Be $true $transfer.DestinationLogin | Should -BeNullOrEmpty @@ -124,9 +124,9 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $transfer.DestinationServer | Should -Be foo } It "Should properly assign dest server parameters from server object" { - $dest = Connect-DbaInstance -SqlInstance $script:instance2 -Database msdb + $dest = Connect-DbaInstance -SqlInstance $TestConfig.instance2 -Database msdb $connStringBuilder = New-Object Microsoft.Data.SqlClient.SqlConnectionStringBuilder $dest.ConnectionContext.ConnectionString - $transfer = New-DbaDbTransfer -SqlInstance $script:instance1 -Database $dbName -DestinationSqlInstance $dest + $transfer = New-DbaDbTransfer -SqlInstance $TestConfig.instance1 -Database $dbName -DestinationSqlInstance $dest $transfer.DestinationDatabase | Should -Be $connStringBuilder['Initial Catalog'] $transfer.DestinationLoginSecure | Should -Be $connStringBuilder['Integrated Security'] $transfer.DestinationLogin | Should -Be $connStringBuilder['User ID'] @@ -134,7 +134,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $transfer.DestinationServer | Should -Be $connStringBuilder['Data Source'] } It "Should properly assign dest server parameters from plaintext params" { - $transfer = New-DbaDbTransfer -SqlInstance $script:instance1 -Database $dbName -DestinationSqlInstance foo -DestinationDatabase bar -DestinationSqlCredential $creds + $transfer = New-DbaDbTransfer -SqlInstance $TestConfig.instance1 -Database $dbName -DestinationSqlInstance foo -DestinationDatabase bar -DestinationSqlCredential $creds $transfer.DestinationDatabase | Should -Be bar $transfer.DestinationLoginSecure | Should -Be $false $transfer.DestinationLogin | Should -Be $creds.UserName @@ -144,7 +144,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } Context "Testing function parameters" { It "Should script all objects" { - $transfer = New-DbaDbTransfer -SqlInstance $script:instance1 -Database $dbName -CopyAllObjects + $transfer = New-DbaDbTransfer -SqlInstance $TestConfig.instance1 -Database $dbName -CopyAllObjects $transfer.CopyData | Should -Be $true $transfer.CopySchema | Should -Be $true $script = $transfer.ScriptTransfer() -join "`n" @@ -154,7 +154,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $script | Should -BeLike '*CREATE TABLE `[dbo`].`[transfer_test4`]*' } It "Should script all tables with just schemas" { - $transfer = New-DbaDbTransfer -SqlInstance $script:instance1 -Database $dbName -CopyAll Tables -SchemaOnly + $transfer = New-DbaDbTransfer -SqlInstance $TestConfig.instance1 -Database $dbName -CopyAll Tables -SchemaOnly $transfer.CopyData | Should -Be $false $transfer.CopySchema | Should -Be $true $script = $transfer.ScriptTransfer() -join "`n" @@ -164,8 +164,8 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $script | Should -BeLike '*CREATE TABLE `[dbo`].`[transfer_test4`]*' } It "Should script one table with just data" { - $table = Get-DbaDbTable -SqlInstance $script:instance1 -Database $dbName -Table transfer_test - $transfer = New-DbaDbTransfer -SqlInstance $script:instance1 -Database $dbName -InputObject $table -DataOnly + $table = Get-DbaDbTable -SqlInstance $TestConfig.instance1 -Database $dbName -Table transfer_test + $transfer = New-DbaDbTransfer -SqlInstance $TestConfig.instance1 -Database $dbName -InputObject $table -DataOnly $transfer.ObjectList.Count | Should -Be 1 $transfer.CopyData | Should -Be $true $transfer.CopySchema | Should -Be $false @@ -174,8 +174,8 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $script | Should -BeLike '*CREATE TABLE `[dbo`].`[transfer_test`]*' } It "Should script two tables from pipeline" { - $tables = Get-DbaDbTable -SqlInstance $script:instance1 -Database $dbName -Table transfer_test2, transfer_test4 - $transfer = $tables | New-DbaDbTransfer -SqlInstance $script:instance1 -Database $dbName + $tables = Get-DbaDbTable -SqlInstance $TestConfig.instance1 -Database $dbName -Table transfer_test2, transfer_test4 + $transfer = $tables | New-DbaDbTransfer -SqlInstance $TestConfig.instance1 -Database $dbName $transfer.ObjectList.Count | Should -Be 2 $script = $transfer.ScriptTransfer() -join "`n" $script | Should -Not -BeLike '*CREATE TABLE `[dbo`].`[transfer_test`]*' @@ -186,7 +186,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { It "Should accept script options object" { $options = New-DbaScriptingOption $options.ScriptDrops = $true - $transfer = New-DbaDbTransfer -SqlInstance $script:instance1 -Database $dbName -CopyAll Tables -ScriptingOption $options + $transfer = New-DbaDbTransfer -SqlInstance $TestConfig.instance1 -Database $dbName -CopyAll Tables -ScriptingOption $options $transfer.Options.ScriptDrops | Should -BeTrue $script = $transfer.ScriptTransfer() -join "`n" $script | Should -BeLike '*DROP TABLE `[dbo`].`[transfer_test`]*' @@ -195,15 +195,15 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Testing object transfer" { BeforeEach { $destination.Query("CREATE DATABASE $dbname") - $db2 = Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbName + $db2 = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbName } AfterEach { - Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbName -Confirm:$false + Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbName -Confirm:$false } It "Should transfer all tables" { - $transfer = New-DbaDbTransfer -SqlInstance $script:instance1 -DestinationSqlInstance $script:instance2 -Database $dbName -CopyAll Tables + $transfer = New-DbaDbTransfer -SqlInstance $TestConfig.instance1 -DestinationSqlInstance $TestConfig.instance2 -Database $dbName -CopyAll Tables $transfer.TransferData() - $tables = Get-DbaDbTable -SqlInstance $script:instance2 -Database $dbName -Table transfer_test, transfer_test2, transfer_test3, transfer_test4 + $tables = Get-DbaDbTable -SqlInstance $TestConfig.instance2 -Database $dbName -Table transfer_test, transfer_test2, transfer_test3, transfer_test4 $tables.Count | Should -Be 4 $db.Query("select id from dbo.transfer_test").id | Should -Not -BeNullOrEmpty $db.Query("select id from dbo.transfer_test4").id | Should -Not -BeNullOrEmpty @@ -211,23 +211,23 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $db.Query("select id from dbo.transfer_test4").id | Should -BeIn $db2.Query("select id from dbo.transfer_test4").id } It "Should transfer two tables with just schemas" { - $sourceTables = Get-DbaDbTable -SqlInstance $script:instance1 -Database $dbName -Table transfer_test, transfer_test2 - $transfer = $sourceTables | New-DbaDbTransfer -SqlInstance $script:instance1 -DestinationSqlInstance $script:instance2 -Database $dbName -SchemaOnly + $sourceTables = Get-DbaDbTable -SqlInstance $TestConfig.instance1 -Database $dbName -Table transfer_test, transfer_test2 + $transfer = $sourceTables | New-DbaDbTransfer -SqlInstance $TestConfig.instance1 -DestinationSqlInstance $TestConfig.instance2 -Database $dbName -SchemaOnly $transfer.TransferData() - $tables = Get-DbaDbTable -SqlInstance $script:instance2 -Database $dbName -Table transfer_test, transfer_test2 + $tables = Get-DbaDbTable -SqlInstance $TestConfig.instance2 -Database $dbName -Table transfer_test, transfer_test2 $tables.Count | Should -Be 2 $db2.Query("select id from dbo.transfer_test").id | Should -BeNullOrEmpty } It "Should transfer two tables without copying schema" { $null = $db2.Query("CREATE TABLE dbo.transfer_test (id int)") $null = $db2.Query("CREATE TABLE dbo.transfer_test2 (id int)") - $sourceTables = Get-DbaDbTable -SqlInstance $script:instance1 -Database $dbName -Table transfer_test, transfer_test2 - $transfer = $sourceTables | New-DbaDbTransfer -SqlInstance $script:instance1 -DestinationSqlInstance $script:instance2 -Database $dbName -DataOnly + $sourceTables = Get-DbaDbTable -SqlInstance $TestConfig.instance1 -Database $dbName -Table transfer_test, transfer_test2 + $transfer = $sourceTables | New-DbaDbTransfer -SqlInstance $TestConfig.instance1 -DestinationSqlInstance $TestConfig.instance2 -Database $dbName -DataOnly $transfer.TransferData() - $tables = Get-DbaDbTable -SqlInstance $script:instance2 -Database $dbName -Table transfer_test, transfer_test2 + $tables = Get-DbaDbTable -SqlInstance $TestConfig.instance2 -Database $dbName -Table transfer_test, transfer_test2 $tables.Count | Should -Be 2 $db.Query("select id from dbo.transfer_test").id | Should -Not -BeNullOrEmpty $db.Query("select id from dbo.transfer_test").id | Should -BeIn $db2.Query("select id from dbo.transfer_test").id } } -} \ No newline at end of file +} diff --git a/tests/New-DbaDbUser.Tests.ps1 b/tests/New-DbaDbUser.Tests.ps1 index d097970fdd..7211480d30 100644 --- a/tests/New-DbaDbUser.Tests.ps1 +++ b/tests/New-DbaDbUser.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -22,44 +22,44 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $password = 'MyV3ry$ecur3P@ssw0rd' $securePassword = ConvertTo-SecureString $password -AsPlainText -Force - $null = New-DbaLogin -SqlInstance $script:instance2 -Login $userName -Password $securePassword -Force - $null = New-DbaDatabase -SqlInstance $script:instance2 -Name $dbname - $dbContainmentSpValue = (Get-DbaSpConfigure -SqlInstance $script:instance2 -Name ContainmentEnabled).ConfiguredValue - $null = Set-DbaSpConfigure -SqlInstance $script:instance2 -Name ContainmentEnabled -Value 1 - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Query "ALTER DATABASE [$dbname] SET CONTAINMENT = PARTIAL WITH NO_WAIT" + $null = New-DbaLogin -SqlInstance $TestConfig.instance2 -Login $userName -Password $securePassword -Force + $null = New-DbaDatabase -SqlInstance $TestConfig.instance2 -Name $dbname + $dbContainmentSpValue = (Get-DbaSpConfigure -SqlInstance $TestConfig.instance2 -Name ContainmentEnabled).ConfiguredValue + $null = Set-DbaSpConfigure -SqlInstance $TestConfig.instance2 -Name ContainmentEnabled -Value 1 + $null = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Query "ALTER DATABASE [$dbname] SET CONTAINMENT = PARTIAL WITH NO_WAIT" } AfterAll { - $null = Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbname -Confirm:$false - $null = Remove-DbaLogin -SqlInstance $script:instance2 -Login $userName -Confirm:$false - $null = Set-DbaSpConfigure -SqlInstance $script:instance2 -Name ContainmentEnabled -Value $dbContainmentSpValue + $null = Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname -Confirm:$false + $null = Remove-DbaLogin -SqlInstance $TestConfig.instance2 -Login $userName -Confirm:$false + $null = Set-DbaSpConfigure -SqlInstance $TestConfig.instance2 -Name ContainmentEnabled -Value $dbContainmentSpValue } Context "Test error handling" { It "Tries to create the user with an invalid default schema" { - $results = New-DbaDbUser -SqlInstance $script:instance2 -Database $dbname -Login $userName -DefaultSchema invalidSchemaName -WarningVariable warningMessage + $results = New-DbaDbUser -SqlInstance $TestConfig.instance2 -Database $dbname -Login $userName -DefaultSchema invalidSchemaName -WarningVariable warningMessage $results | Should -BeNullOrEmpty $warningMessage | Should -BeLike "*Schema * does not exist in database*" } } Context "Should create the user with login" { It "Creates the user and get it" { - New-DbaDbUser -SqlInstance $script:instance2 -Database $dbname -Login $userName -DefaultSchema guest - $newDbUser = Get-DbaDbUser -SqlInstance $script:instance2 -Database $dbname | Where-Object Name -eq $userName + New-DbaDbUser -SqlInstance $TestConfig.instance2 -Database $dbname -Login $userName -DefaultSchema guest + $newDbUser = Get-DbaDbUser -SqlInstance $TestConfig.instance2 -Database $dbname | Where-Object Name -eq $userName $newDbUser.Name | Should -Be $userName $newDbUser.DefaultSchema | Should -Be 'guest' } } Context "Should create the user with password" { It "Creates the contained sql user and get it." { - New-DbaDbUser -SqlInstance $script:instance2 -Database $dbname -Username $userNameWithPassword -Password $securePassword -DefaultSchema guest - $newDbUser = Get-DbaDbUser -SqlInstance $script:instance2 -Database $dbname | Where-Object Name -eq $userNameWithPassword + New-DbaDbUser -SqlInstance $TestConfig.instance2 -Database $dbname -Username $userNameWithPassword -Password $securePassword -DefaultSchema guest + $newDbUser = Get-DbaDbUser -SqlInstance $TestConfig.instance2 -Database $dbname | Where-Object Name -eq $userNameWithPassword $newDbUser.Name | Should -Be $userNameWithPassword $newDbUser.DefaultSchema | Should -Be 'guest' } } Context "Should create the user without login" { It "Creates the user and get it. Login property is empty" { - New-DbaDbUser -SqlInstance $script:instance2 -Database $dbname -User $userNameWithoutLogin -DefaultSchema guest - $results = Get-DbaDbUser -SqlInstance $script:instance2 -Database $dbname | Where-Object Name -eq $userNameWithoutLogin + New-DbaDbUser -SqlInstance $TestConfig.instance2 -Database $dbname -User $userNameWithoutLogin -DefaultSchema guest + $results = Get-DbaDbUser -SqlInstance $TestConfig.instance2 -Database $dbname | Where-Object Name -eq $userNameWithoutLogin $results.Name | Should -Be $userNameWithoutLogin $results.DefaultSchema | Should -Be 'guest' $results.Login | Should -BeNullOrEmpty @@ -72,25 +72,25 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $password = 'MyV3ry$ecur3P@ssw0rd' $securePassword = ConvertTo-SecureString $password -AsPlainText -Force - $null = New-DbaLogin -SqlInstance $script:instance2 -Login $loginName -Password $securePassword -Force - $null = New-DbaDatabase -SqlInstance $script:instance2 -Name $dbs - $accessibleDbCount = (Get-DbaDatabase -SqlInstance $script:instance2 -ExcludeSystem -OnlyAccessible).count + $null = New-DbaLogin -SqlInstance $TestConfig.instance2 -Login $loginName -Password $securePassword -Force + $null = New-DbaDatabase -SqlInstance $TestConfig.instance2 -Name $dbs + $accessibleDbCount = (Get-DbaDatabase -SqlInstance $TestConfig.instance2 -ExcludeSystem -OnlyAccessible).count } AfterAll { - $null = Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbs -Confirm:$false - $null = Remove-DbaLogin -SqlInstance $script:instance2 -Login $loginName -Confirm:$false + $null = Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbs -Confirm:$false + $null = Remove-DbaLogin -SqlInstance $TestConfig.instance2 -Login $loginName -Confirm:$false } It "Should add login to all databases provided" { - $results = New-DbaDbUser -SqlInstance $script:instance2 -Login $loginName -Database $dbs -Force -EnableException + $results = New-DbaDbUser -SqlInstance $TestConfig.instance2 -Login $loginName -Database $dbs -Force -EnableException $results.Count | Should -Be 3 $results.Name | Should -Be $loginName, $loginName, $loginName $results.DefaultSchema | Should -Be dbo, dbo, dbo } It "Should add user to all user databases" { - $results = New-DbaDbUser -SqlInstance $script:instance2 -Login $loginName -Force -EnableException + $results = New-DbaDbUser -SqlInstance $TestConfig.instance2 -Login $loginName -Force -EnableException $results.Count | Should -Be $accessibleDbCount $results.Name | Get-Unique | Should -Be $loginName } } -} \ No newline at end of file +} diff --git a/tests/New-DbaDiagnosticAdsNotebook.Tests.ps1 b/tests/New-DbaDiagnosticAdsNotebook.Tests.ps1 index b9237bb529..d004f3faf5 100644 --- a/tests/New-DbaDiagnosticAdsNotebook.Tests.ps1 +++ b/tests/New-DbaDiagnosticAdsNotebook.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/New-DbaDirectory.Tests.ps1 b/tests/New-DbaDirectory.Tests.ps1 index bd11bd12c2..00aafc518f 100644 --- a/tests/New-DbaDirectory.Tests.ps1 +++ b/tests/New-DbaDirectory.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/New-DbaEndpoint.Tests.ps1 b/tests/New-DbaEndpoint.Tests.ps1 index dd2e082af4..52b13fc36f 100644 --- a/tests/New-DbaEndpoint.Tests.ps1 +++ b/tests/New-DbaEndpoint.Tests.ps1 @@ -1,6 +1,6 @@ $commandname = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Validate parameters" { @@ -15,23 +15,23 @@ Describe "$CommandName Unit Tests" -Tags "UnitTests" { Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $endpoint = Get-DbaEndpoint -SqlInstance $script:instance2 | Where-Object EndpointType -eq DatabaseMirroring + $endpoint = Get-DbaEndpoint -SqlInstance $TestConfig.instance2 | Where-Object EndpointType -eq DatabaseMirroring $create = $endpoint | Export-DbaScript -Passthru - Get-DbaEndpoint -SqlInstance $script:instance2 | Where-Object EndpointType -eq DatabaseMirroring | Remove-DbaEndpoint -Confirm:$false + Get-DbaEndpoint -SqlInstance $TestConfig.instance2 | Where-Object EndpointType -eq DatabaseMirroring | Remove-DbaEndpoint -Confirm:$false } AfterAll { - Get-DbaEndpoint -SqlInstance $script:instance2 | Where-Object EndpointType -eq DatabaseMirroring | Remove-DbaEndpoint -Confirm:$false + Get-DbaEndpoint -SqlInstance $TestConfig.instance2 | Where-Object EndpointType -eq DatabaseMirroring | Remove-DbaEndpoint -Confirm:$false if ($create) { - Invoke-DbaQuery -SqlInstance $script:instance2 -Query "$create" + Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Query "$create" } } - $results = New-DbaEndpoint -SqlInstance $script:instance2 -Type DatabaseMirroring -Role Partner -Name Mirroring -Confirm:$false | Start-DbaEndpoint -Confirm:$false + $results = New-DbaEndpoint -SqlInstance $TestConfig.instance2 -Type DatabaseMirroring -Role Partner -Name Mirroring -Confirm:$false | Start-DbaEndpoint -Confirm:$false It "creates an endpoint of the db mirroring type" { $results.EndpointType | Should -Be 'DatabaseMirroring' } It "creates it with the right owner" { - $sa = Get-SaLoginName -SqlInstance $script:instance2 + $sa = Get-SaLoginName -SqlInstance $TestConfig.instance2 $results.Owner | Should -Be $sa } -} \ No newline at end of file +} diff --git a/tests/New-DbaFirewallRule.Tests.ps1 b/tests/New-DbaFirewallRule.Tests.ps1 index c58f7f8b61..cc6823d3c3 100644 --- a/tests/New-DbaFirewallRule.Tests.ps1 +++ b/tests/New-DbaFirewallRule.Tests.ps1 @@ -1,6 +1,6 @@ $commandname = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Validate parameters" { @@ -15,19 +15,19 @@ Describe "$CommandName Unit Tests" -Tags "UnitTests" { Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $null = Remove-DbaFirewallRule -SqlInstance $script:instance2 -Confirm:$false + $null = Remove-DbaFirewallRule -SqlInstance $TestConfig.instance2 -Confirm:$false } AfterAll { - $null = Remove-DbaFirewallRule -SqlInstance $script:instance2 -Confirm:$false + $null = Remove-DbaFirewallRule -SqlInstance $TestConfig.instance2 -Confirm:$false } - $resultsNew = New-DbaFirewallRule -SqlInstance $script:instance2 -Confirm:$false - $resultsGet = Get-DbaFirewallRule -SqlInstance $script:instance2 + $resultsNew = New-DbaFirewallRule -SqlInstance $TestConfig.instance2 -Confirm:$false + $resultsGet = Get-DbaFirewallRule -SqlInstance $TestConfig.instance2 $resultsRemoveBrowser = $resultsGet | Where-Object { $_.Type -eq "Browser" } | Remove-DbaFirewallRule -Confirm:$false - $resultsRemove = Remove-DbaFirewallRule -SqlInstance $script:instance2 -Type AllInstance -Confirm:$false + $resultsRemove = Remove-DbaFirewallRule -SqlInstance $TestConfig.instance2 -Type AllInstance -Confirm:$false - $instanceName = ([DbaInstanceParameter]$script:instance2).InstanceName + $instanceName = ([DbaInstanceParameter]$TestConfig.instance2).InstanceName It "creates two firewall rules" { $resultsNew.Count | Should -Be 2 @@ -73,4 +73,4 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { $resultsRemove.IsRemoved | Should -Be $true $resultsRemove.Status | Should -Be 'The rule was successfully removed.' } -} \ No newline at end of file +} diff --git a/tests/New-DbaLinkedServer.Tests.ps1 b/tests/New-DbaLinkedServer.Tests.ps1 index e75b9e2b0e..097b13659a 100644 --- a/tests/New-DbaLinkedServer.Tests.ps1 +++ b/tests/New-DbaLinkedServer.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,8 +16,8 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { BeforeAll { $random = Get-Random - $instance2 = Connect-DbaInstance -SqlInstance $script:instance2 - $instance3 = Connect-DbaInstance -SqlInstance $script:instance3 + $instance2 = Connect-DbaInstance -SqlInstance $TestConfig.instance2 + $instance3 = Connect-DbaInstance -SqlInstance $TestConfig.instance3 $securePassword = ConvertTo-SecureString -String 'securePassword!' -AsPlainText -Force $loginName = "dbatoolscli_test_$random" @@ -102,4 +102,4 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $results.Impersonate | Should -Be $false } } -} \ No newline at end of file +} diff --git a/tests/New-DbaLinkedServerLogin.Tests.ps1 b/tests/New-DbaLinkedServerLogin.Tests.ps1 index c0544face4..7766fa5b8c 100644 --- a/tests/New-DbaLinkedServerLogin.Tests.ps1 +++ b/tests/New-DbaLinkedServerLogin.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,8 +16,8 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { BeforeAll { $random = Get-Random - $instance2 = Connect-DbaInstance -SqlInstance $script:instance2 - $instance3 = Connect-DbaInstance -SqlInstance $script:instance3 + $instance2 = Connect-DbaInstance -SqlInstance $TestConfig.instance2 + $instance3 = Connect-DbaInstance -SqlInstance $TestConfig.instance3 $securePassword = ConvertTo-SecureString -String 'securePassword' -AsPlainText -Force $localLogin1Name = "dbatoolscli_localLogin1_$random" @@ -76,4 +76,4 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $warnings | Should -BeLike "*LocalLogin is required in all scenarios*" } } -} \ No newline at end of file +} diff --git a/tests/New-DbaLogin.Tests.ps1 b/tests/New-DbaLogin.Tests.ps1 index ec9fe7bbf4..0088fa9b66 100644 --- a/tests/New-DbaLogin.Tests.ps1 +++ b/tests/New-DbaLogin.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig . "$PSScriptRoot\..\private\functions\Get-PasswordHash.ps1" . "$PSScriptRoot\..\private\functions\Convert-HexStringToByte.ps1" @@ -22,8 +22,8 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $password = 'MyV3ry$ecur3P@ssw0rd' $securePassword = ConvertTo-SecureString $password -AsPlainText -Force $sid = '0xDBA700131337C0D30123456789ABCDEF' - $server1 = Connect-DbaInstance -SqlInstance $script:instance1 - $server2 = Connect-DbaInstance -SqlInstance $script:instance2 + $server1 = Connect-DbaInstance -SqlInstance $TestConfig.instance1 + $server2 = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $servers = @($server1, $server2) $computerName = $server1.NetName $winLogin = "$computerName\$credLogin" @@ -170,8 +170,8 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { It "Should retain its same properties" { - $login1 = Get-DbaLogin -SqlInstance $script:instance1 -login tester - $login2 = Get-DbaLogin -SqlInstance $script:instance2 -login tester + $login1 = Get-DbaLogin -SqlInstance $TestConfig.instance1 -login tester + $login2 = Get-DbaLogin -SqlInstance $TestConfig.instance2 -login tester $login2 | Should Not BeNullOrEmpty @@ -189,8 +189,8 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { It "Should not have same properties because of the overrides" { - $login1 = Get-DbaLogin -SqlInstance $script:instance1 -login claudio - $login2 = Get-DbaLogin -SqlInstance $script:instance2 -login withMustChange + $login1 = Get-DbaLogin -SqlInstance $TestConfig.instance1 -login claudio + $login2 = Get-DbaLogin -SqlInstance $TestConfig.instance2 -login withMustChange $login2 | Should Not BeNullOrEmpty @@ -216,13 +216,13 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } } - if ((Connect-DbaInstance -SqlInstance $script:instance1).LoginMode -eq "Mixed") { + if ((Connect-DbaInstance -SqlInstance $TestConfig.instance1).LoginMode -eq "Mixed") { Context "Connect with a new login" { It "Should login with newly created Sql Login, get instance name and kill the process" { $cred = New-Object System.Management.Automation.PSCredential ("tester", $securePassword) - $s = Connect-DbaInstance -SqlInstance $script:instance1 -SqlCredential $cred - $s.Name | Should Be $script:instance1 - Stop-DbaProcess -SqlInstance $script:instance1 -Login tester + $s = Connect-DbaInstance -SqlInstance $TestConfig.instance1 -SqlCredential $cred + $s.Name | Should Be $TestConfig.instance1 + Stop-DbaProcess -SqlInstance $TestConfig.instance1 -Login tester } } } @@ -254,7 +254,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $server1.Credentials[$credLogin].Drop() $server1.Databases['master'].Certificates[$certificateName].Drop() if (!$mkey) { - $null = Remove-DbaDbMasterKey -SqlInstance $script:instance1 -Database master -Confirm:$false + $null = Remove-DbaDbMasterKey -SqlInstance $TestConfig.instance1 -Database master -Confirm:$false } } catch { <#nbd#> } -} \ No newline at end of file +} diff --git a/tests/New-DbaReplCreationScriptOptions.Tests.ps1 b/tests/New-DbaReplCreationScriptOptions.Tests.ps1 index c7e06f9e13..cd435a4e90 100644 --- a/tests/New-DbaReplCreationScriptOptions.Tests.ps1 +++ b/tests/New-DbaReplCreationScriptOptions.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Add-ReplicationLibrary diff --git a/tests/New-DbaReplPublication.Tests.ps1 b/tests/New-DbaReplPublication.Tests.ps1 index 7306059d09..7e90d6d42a 100644 --- a/tests/New-DbaReplPublication.Tests.ps1 +++ b/tests/New-DbaReplPublication.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Add-ReplicationLibrary diff --git a/tests/New-DbaReplSubscription.Tests.ps1 b/tests/New-DbaReplSubscription.Tests.ps1 index 64176e3048..236c20fda0 100644 --- a/tests/New-DbaReplSubscription.Tests.ps1 +++ b/tests/New-DbaReplSubscription.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Add-ReplicationLibrary diff --git a/tests/New-DbaRgResourcePool.Tests.ps1 b/tests/New-DbaRgResourcePool.Tests.ps1 index b467b9ff15..cc424856e0 100644 --- a/tests/New-DbaRgResourcePool.Tests.ps1 +++ b/tests/New-DbaRgResourcePool.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,12 +16,12 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Functionality" { BeforeAll { - $null = Set-DbaResourceGovernor -SqlInstance $script:instance2 -Enabled + $null = Set-DbaResourceGovernor -SqlInstance $TestConfig.instance2 -Enabled } It "Creates a resource pool" { $resourcePoolName = "dbatoolssci_poolTest" $splatNewResourcePool = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 ResourcePool = $resourcePoolName MaximumCpuPercentage = 100 MaximumMemoryPercentage = 100 @@ -29,9 +29,9 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { CapCpuPercent = 100 Force = $true } - $result = Get-DbaRgResourcePool -SqlInstance $script:instance2 + $result = Get-DbaRgResourcePool -SqlInstance $TestConfig.instance2 $newResourcePool = New-DbaRgResourcePool @splatNewResourcePool - $result2 = Get-DbaRgResourcePool -SqlInstance $script:instance2 + $result2 = Get-DbaRgResourcePool -SqlInstance $TestConfig.instance2 $result.Count | Should -BeLessThan $result2.Count $result2.Name | Should -Contain $resourcePoolName @@ -41,7 +41,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { It "Works using -Type Internal" { $resourcePoolName = "dbatoolssci_poolTest" $splatNewResourcePool = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 ResourcePool = $resourcePoolName MaximumCpuPercentage = 100 MaximumMemoryPercentage = 100 @@ -53,9 +53,9 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Type = "Internal" Force = $true } - $result = Get-DbaRgResourcePool -SqlInstance $script:instance2 -Type Internal + $result = Get-DbaRgResourcePool -SqlInstance $TestConfig.instance2 -Type Internal $newResourcePool = New-DbaRgResourcePool @splatNewResourcePool - $result2 = Get-DbaRgResourcePool -SqlInstance $script:instance2 -Type Internal + $result2 = Get-DbaRgResourcePool -SqlInstance $TestConfig.instance2 -Type Internal $result.Count | Should -BeLessThan $result2.Count $result2.Name | Should -Contain $resourcePoolName @@ -70,7 +70,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { It "Works using -Type External" { $resourcePoolName = "dbatoolssci_poolTest" $splatNewResourcePool = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 ResourcePool = $resourcePoolName MaximumCpuPercentage = 100 MaximumMemoryPercentage = 100 @@ -78,9 +78,9 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Type = "External" Force = $true } - $result = Get-DbaRgResourcePool -SqlInstance $script:instance2 -Type External + $result = Get-DbaRgResourcePool -SqlInstance $TestConfig.instance2 -Type External $newResourcePool = New-DbaRgResourcePool @splatNewResourcePool - $result2 = Get-DbaRgResourcePool -SqlInstance $script:instance2 -Type External + $result2 = Get-DbaRgResourcePool -SqlInstance $TestConfig.instance2 -Type External $result.Count | Should -BeLessThan $result2.Count $result2.Name | Should -Contain $resourcePoolName @@ -91,7 +91,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { It "Skips Resource Governor reconfiguration" { $resourcePoolName = "dbatoolssci_poolTest" $splatNewResourcePool = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 ResourcePool = $resourcePoolName MaximumCpuPercentage = 100 MaximumMemoryPercentage = 100 @@ -102,15 +102,15 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } $null = New-DbaRgResourcePool @splatNewResourcePool - $result = Get-DbaResourceGovernor -SqlInstance $script:instance2 + $result = Get-DbaResourceGovernor -SqlInstance $TestConfig.instance2 $result.ReconfigurePending | Should -Be $true } AfterEach { $resourcePoolName = "dbatoolssci_poolTest" $resourcePoolName2 = "dbatoolssci_poolTest2" - $null = Remove-DbaRgResourcePool -SqlInstance $script:instance2 -ResourcePool $resourcePoolName, $resourcePoolName2 -Type Internal - $null = Remove-DbaRgResourcePool -SqlInstance $script:instance2 -ResourcePool $resourcePoolName, $resourcePoolName2 -Type External + $null = Remove-DbaRgResourcePool -SqlInstance $TestConfig.instance2 -ResourcePool $resourcePoolName, $resourcePoolName2 -Type Internal + $null = Remove-DbaRgResourcePool -SqlInstance $TestConfig.instance2 -ResourcePool $resourcePoolName, $resourcePoolName2 -Type External } } -} \ No newline at end of file +} diff --git a/tests/New-DbaRgWorkloadGroup.Tests.ps1 b/tests/New-DbaRgWorkloadGroup.Tests.ps1 index 5030aa6ee3..83f7658104 100644 --- a/tests/New-DbaRgWorkloadGroup.Tests.ps1 +++ b/tests/New-DbaRgWorkloadGroup.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,18 +16,18 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Functionality" { BeforeAll { - $null = Set-DbaResourceGovernor -SqlInstance $script:instance2 -Enabled + $null = Set-DbaResourceGovernor -SqlInstance $TestConfig.instance2 -Enabled } It "Creates a workload group in default resource pool" { $wklGroupName = "dbatoolssci_wklgroupTest" $splatNewWorkloadGroup = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 WorkloadGroup = $wklGroupName Force = $true } - $result = Get-DbaRgWorkloadGroup -SqlInstance $script:instance2 | Where-Object Name -eq $wklGroupName + $result = Get-DbaRgWorkloadGroup -SqlInstance $TestConfig.instance2 | Where-Object Name -eq $wklGroupName $newWorkloadGroup = New-DbaRgWorkloadGroup @splatNewWorkloadGroup - $result2 = Get-DbaRgWorkloadGroup -SqlInstance $script:instance2 | Where-Object Name -eq $wklGroupName + $result2 = Get-DbaRgWorkloadGroup -SqlInstance $TestConfig.instance2 | Where-Object Name -eq $wklGroupName $newWorkloadGroup | Should -Not -Be $null $result.Count | Should -BeLessThan $result2.Count @@ -36,7 +36,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { It "Does nothing without -Force if workload group exists" { $wklGroupName = "dbatoolssci_wklgroupTest" $splatNewWorkloadGroup = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 WorkloadGroup = $wklGroupName } $result1 = New-DbaRgWorkloadGroup @splatNewWorkloadGroup @@ -50,13 +50,13 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $resourcePoolName = "dbatoolssci_poolTest" $resourcePoolType = "Internal" $splatNewResourcePool = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 ResourcePool = $resourcePoolName Type = $resourcePoolType Force = $true } $splatNewWorkloadGroup = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 WorkloadGroup = $wklGroupName ResourcePool = $resourcePoolName ResourcePoolType = $resourcePoolType @@ -71,8 +71,8 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $null = New-DbaRgResourcePool @splatNewResourcePool $newWorkloadGroup = New-DbaRgWorkloadGroup @splatNewWorkloadGroup - $null = Remove-DbaRgWorkloadGroup -SqlInstance $script:instance2 -WorkloadGroup $wklGroupName -ResourcePool $resourcePoolName - $null = Remove-DbaRgResourcePool -SqlInstance $script:instance2 -ResourcePool $resourcePoolName -Type $resourcePoolType + $null = Remove-DbaRgWorkloadGroup -SqlInstance $TestConfig.instance2 -WorkloadGroup $wklGroupName -ResourcePool $resourcePoolName + $null = Remove-DbaRgResourcePool -SqlInstance $TestConfig.instance2 -ResourcePool $resourcePoolName -Type $resourcePoolType $newWorkloadGroup.Parent.Name | Should -Be $resourcePoolName $newWorkloadGroup.Parent.GetType().Name | Should -Be "ResourcePool" @@ -87,12 +87,12 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $wklGroupName = "dbatoolssci_wklgroupTest" $wklGroupName2 = "dbatoolssci_wklgroupTest2" $splatNewWorkloadGroup = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 Force = $true } - $result = Get-DbaRgWorkloadGroup -SqlInstance $script:instance2 | Where-Object Name -in $wklGroupName, $wklGroupName2 + $result = Get-DbaRgWorkloadGroup -SqlInstance $TestConfig.instance2 | Where-Object Name -in $wklGroupName, $wklGroupName2 $newWorkloadGroups = New-DbaRgWorkloadGroup @splatNewWorkloadGroup -WorkloadGroup $wklGroupName, $wklGroupName2 - $result2 = Get-DbaRgWorkloadGroup -SqlInstance $script:instance2 | Where-Object Name -in $wklGroupName, $wklGroupName2 + $result2 = Get-DbaRgWorkloadGroup -SqlInstance $TestConfig.instance2 | Where-Object Name -in $wklGroupName, $wklGroupName2 $newWorkloadGroups | Should -Not -Be $null $result2.Count | Should -Be 2 @@ -101,21 +101,21 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { It "Skips Resource Governor reconfiguration" { $wklGroupName = "dbatoolssci_wklgroupTest" $splatNewWorkloadGroup = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 WorkloadGroup = $wklGroupName SkipReconfigure = $true Force = $true } $null = New-DbaRgWorkloadGroup @splatNewWorkloadGroup - $result = Get-DbaResourceGovernor -SqlInstance $script:instance2 + $result = Get-DbaResourceGovernor -SqlInstance $TestConfig.instance2 $result.ReconfigurePending | Should -Be $true } AfterEach { $wklGroupName = "dbatoolssci_wklgroupTest" $wklGroupName2 = "dbatoolssci_wklgroupTest2" - $null = Remove-DbaRgWorkloadGroup -SqlInstance $script:instance2 -WorkloadGroup $wklGroupName, $wklGroupName2 + $null = Remove-DbaRgWorkloadGroup -SqlInstance $TestConfig.instance2 -WorkloadGroup $wklGroupName, $wklGroupName2 } } -} \ No newline at end of file +} diff --git a/tests/New-DbaScriptingOption.Tests.ps1 b/tests/New-DbaScriptingOption.Tests.ps1 index 0f913c0c61..e3a932c728 100644 --- a/tests/New-DbaScriptingOption.Tests.ps1 +++ b/tests/New-DbaScriptingOption.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/New-DbaServerRole.Tests.ps1 b/tests/New-DbaServerRole.Tests.ps1 index eff6157d81..dcfb177ddf 100644 --- a/tests/New-DbaServerRole.Tests.ps1 +++ b/tests/New-DbaServerRole.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Validate parameters" { @@ -15,7 +15,7 @@ Describe "$CommandName Unit Tests" -Tags "UnitTests" { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $instance = Connect-DbaInstance -SqlInstance $script:instance2 + $instance = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $roleExecutor = "serverExecuter" $roleMaster = "serverMaster" $owner = "sa" @@ -48,4 +48,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $result.Name | Should Contain $roleMaster } } -} \ No newline at end of file +} diff --git a/tests/New-DbaServiceMasterKey.Tests.ps1 b/tests/New-DbaServiceMasterKey.Tests.ps1 index 775b46e45f..e3aeca44f2 100644 --- a/tests/New-DbaServiceMasterKey.Tests.ps1 +++ b/tests/New-DbaServiceMasterKey.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/New-DbaSqlParameter.Tests.ps1 b/tests/New-DbaSqlParameter.Tests.ps1 index 556ebafafc..7c68e2b3c0 100644 --- a/tests/New-DbaSqlParameter.Tests.ps1 +++ b/tests/New-DbaSqlParameter.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,7 +15,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -Query "CREATE OR ALTER PROC [dbo].[my_proc] + $null = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database tempdb -Query "CREATE OR ALTER PROC [dbo].[my_proc] @json_result nvarchar(max) output AS BEGIN @@ -27,14 +27,14 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } AfterAll { try { - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -Query "DROP PROCEDURE dbo.my_proc" + $null = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database tempdb -Query "DROP PROCEDURE dbo.my_proc" } catch { $null = 1 } } It "creates a usable sql parameter" { $output = New-DbaSqlParameter -ParameterName json_result -SqlDbType NVarChar -Size -1 -Direction Output - Invoke-DbaQuery -SqlInstance $script:instance2 -Database tempdb -CommandType StoredProcedure -Query my_proc -SqlParameters $output + Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database tempdb -CommandType StoredProcedure -Query my_proc -SqlParameters $output $output.Value | Should -Be '{"example":"sample"}' } -} \ No newline at end of file +} diff --git a/tests/New-DbaSsisCatalog.Tests.ps1 b/tests/New-DbaSsisCatalog.Tests.ps1 index fcc6b5a303..703bc986f6 100644 --- a/tests/New-DbaSsisCatalog.Tests.ps1 +++ b/tests/New-DbaSsisCatalog.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -17,11 +17,11 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Catalog is added properly" { # database name is currently fixed $database = "SSISDB" - $db = Get-DbaDatabase -SqlInstance $ssisserver -Database $database + $db = Get-DbaDatabase -SqlInstance $TestConfig.ssisserver -Database $database if (-not $db) { $password = ConvertTo-SecureString MyVisiblePassWord -AsPlainText -Force - $results = New-DbaSsisCatalog -SqlInstance $ssisserver -Password $password -WarningAction SilentlyContinue -WarningVariable warn + $results = New-DbaSsisCatalog -SqlInstance $TestConfig.ssisserver -Password $password -WarningAction SilentlyContinue -WarningVariable warn # Run the tests only if it worked (this could be more accurate but w/e, it's hard to test on appveyor) if ($warn -match "not running") { @@ -36,7 +36,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { It "creates the catalog" { $results.Created | Should Be $true } - Remove-DbaDatabase -Confirm:$false -SqlInstance $ssisserver -Database $database + Remove-DbaDatabase -Confirm:$false -SqlInstance $TestConfig.ssisserver -Database $database } } } diff --git a/tests/New-DbaXESession.Tests.ps1 b/tests/New-DbaXESession.Tests.ps1 index 0032c236bd..1e58cdeb45 100644 --- a/tests/New-DbaXESession.Tests.ps1 +++ b/tests/New-DbaXESession.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/New-DbaXESmartCsvWriter.Tests.ps1 b/tests/New-DbaXESmartCsvWriter.Tests.ps1 index d12fe7dffa..80e884be62 100644 --- a/tests/New-DbaXESmartCsvWriter.Tests.ps1 +++ b/tests/New-DbaXESmartCsvWriter.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/New-DbaXESmartEmail.Tests.ps1 b/tests/New-DbaXESmartEmail.Tests.ps1 index d2e15f723d..b76d704c84 100644 --- a/tests/New-DbaXESmartEmail.Tests.ps1 +++ b/tests/New-DbaXESmartEmail.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/New-DbaXESmartQueryExec.Tests.ps1 b/tests/New-DbaXESmartQueryExec.Tests.ps1 index d1fe6f3d10..b3640049a4 100644 --- a/tests/New-DbaXESmartQueryExec.Tests.ps1 +++ b/tests/New-DbaXESmartQueryExec.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,11 +15,11 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Creates a smart object" { It "returns the object with all of the correct properties" { - $results = New-DbaXESmartQueryExec -SqlInstance $script:instance2 -Database dbadb -Query "update table set whatever = 1" + $results = New-DbaXESmartQueryExec -SqlInstance $TestConfig.instance2 -Database dbadb -Query "update table set whatever = 1" $results.TSQL | Should -Be 'update table set whatever = 1' - $results.ServerName | Should -Be $script:instance2 + $results.ServerName | Should -Be $TestConfig.instance2 $results.DatabaseName | Should -be 'dbadb' $results.Password | Should -Be $null } } -} \ No newline at end of file +} diff --git a/tests/New-DbaXESmartReplay.Tests.ps1 b/tests/New-DbaXESmartReplay.Tests.ps1 index d540e81174..db0cfadf71 100644 --- a/tests/New-DbaXESmartReplay.Tests.ps1 +++ b/tests/New-DbaXESmartReplay.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,8 +16,8 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Creates a smart object" { It "returns the object with all of the correct properties" { $columns = "cpu_time", "duration", "physical_reads", "logical_reads", "writes", "row_count", "batch_text" - $results = New-DbaXESmartTableWriter -SqlInstance $script:instance2 -Database dbadb -Table deadlocktracker -OutputColumn $columns -Filter "duration > 10000" - $results.ServerName | Should -Be $script:instance2 + $results = New-DbaXESmartTableWriter -SqlInstance $TestConfig.instance2 -Database dbadb -Table deadlocktracker -OutputColumn $columns -Filter "duration > 10000" + $results.ServerName | Should -Be $TestConfig.instance2 $results.DatabaseName | Should -be 'dbadb' $results.Password | Should -Be $null $results.TableName | Should -Be 'deadlocktracker' @@ -25,4 +25,4 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $results.FailOnSingleEventViolation | Should -Be $false } } -} \ No newline at end of file +} diff --git a/tests/New-DbaXESmartTableWriter.Tests.ps1 b/tests/New-DbaXESmartTableWriter.Tests.ps1 index e3d760e869..04adf37e1d 100644 --- a/tests/New-DbaXESmartTableWriter.Tests.ps1 +++ b/tests/New-DbaXESmartTableWriter.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,11 +15,11 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Creates a smart object" { It "returns the object with all of the correct properties" { - $results = New-DbaXESmartReplay -SqlInstance $script:instance2 -Database planning - $results.ServerName | Should -Be $script:instance2 + $results = New-DbaXESmartReplay -SqlInstance $TestConfig.instance2 -Database planning + $results.ServerName | Should -Be $TestConfig.instance2 $results.DatabaseName | Should -be 'planning' $results.Password | Should -Be $null $results.DelaySeconds | Should -Be 0 } } -} \ No newline at end of file +} diff --git a/tests/New-DbatoolsSupportPackage.Tests.ps1 b/tests/New-DbatoolsSupportPackage.Tests.ps1 index 375705038f..cde81edeb1 100644 --- a/tests/New-DbatoolsSupportPackage.Tests.ps1 +++ b/tests/New-DbatoolsSupportPackage.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Publish-DbaDacPackage.Tests.ps1 b/tests/Publish-DbaDacPackage.Tests.ps1 index 9bd63d6aca..3d8e32c891 100644 --- a/tests/Publish-DbaDacPackage.Tests.ps1 +++ b/tests/Publish-DbaDacPackage.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,72 +15,72 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BeforeAll { - Get-DbaProcess -SqlInstance $script:instance1, $script:instance2 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue + Get-DbaProcess -SqlInstance $TestConfig.instance1, $TestConfig.instance2 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue $dbname = "dbatoolsci_publishdacpac" - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance1 $null = $server.Query("Create Database [$dbname]") - $db = Get-DbaDatabase -SqlInstance $script:instance1 -Database $dbname + $db = Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $dbname $null = $db.Query("CREATE TABLE dbo.example (id int, PRIMARY KEY (id)); INSERT dbo.example SELECT top 100 object_id FROM sys.objects") - $publishprofile = New-DbaDacProfile -SqlInstance $script:instance1 -Database $dbname -Path C:\temp + $publishprofile = New-DbaDacProfile -SqlInstance $TestConfig.instance1 -Database $dbname -Path C:\temp } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance1, $script:instance2 -Database $dbname -Confirm:$false + Remove-DbaDatabase -SqlInstance $TestConfig.instance1, $TestConfig.instance2 -Database $dbname -Confirm:$false Remove-Item -Confirm:$false -Path $publishprofile.FileName -ErrorAction SilentlyContinue } AfterEach { - Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbname -Confirm:$false + Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname -Confirm:$false } Context "Dacpac tests" { BeforeAll { $extractOptions = New-DbaDacOption -Action Export $extractOptions.ExtractAllTableData = $true - $dacpac = Export-DbaDacPackage -SqlInstance $script:instance1 -Database $dbname -DacOption $extractOptions + $dacpac = Export-DbaDacPackage -SqlInstance $TestConfig.instance1 -Database $dbname -DacOption $extractOptions } AfterAll { if ($dacpac.Path) { Remove-Item -Confirm:$false -Path $dacpac.Path -ErrorAction SilentlyContinue } } It "Performs an xml-based deployment" { - $results = $dacpac | Publish-DbaDacPackage -PublishXml $publishprofile.FileName -Database $dbname -SqlInstance $script:instance2 -Confirm:$false + $results = $dacpac | Publish-DbaDacPackage -PublishXml $publishprofile.FileName -Database $dbname -SqlInstance $TestConfig.instance2 -Confirm:$false $results.Result | Should -BeLike '*Update complete.*' - $ids = Invoke-DbaQuery -Database $dbname -SqlInstance $script:instance2 -Query 'SELECT id FROM dbo.example' + $ids = Invoke-DbaQuery -Database $dbname -SqlInstance $TestConfig.instance2 -Query 'SELECT id FROM dbo.example' $ids.id | Should -Not -BeNullOrEmpty } It "Performs an SMO-based deployment" { $options = New-DbaDacOption -Action Publish - $results = $dacpac | Publish-DbaDacPackage -DacOption $options -Database $dbname -SqlInstance $script:instance2 -Confirm:$false + $results = $dacpac | Publish-DbaDacPackage -DacOption $options -Database $dbname -SqlInstance $TestConfig.instance2 -Confirm:$false $results.Result | Should -BeLike '*Update complete.*' - $ids = Invoke-DbaQuery -Database $dbname -SqlInstance $script:instance2 -Query 'SELECT id FROM dbo.example' + $ids = Invoke-DbaQuery -Database $dbname -SqlInstance $TestConfig.instance2 -Query 'SELECT id FROM dbo.example' $ids.id | Should -Not -BeNullOrEmpty } It "Performs an SMO-based deployment and generates a deployment report" { $options = New-DbaDacOption -Action Publish - $results = $dacpac | Publish-DbaDacPackage -DacOption $options -Database $dbname -SqlInstance $script:instance2 -GenerateDeploymentReport -Confirm:$false + $results = $dacpac | Publish-DbaDacPackage -DacOption $options -Database $dbname -SqlInstance $TestConfig.instance2 -GenerateDeploymentReport -Confirm:$false $results.Result | Should -BeLike '*Update complete.*' $results.DeploymentReport | Should -Not -BeNullOrEmpty $deploymentReportContent = Get-Content -Path $results.DeploymentReport $deploymentReportContent | Should -BeLike '*DeploymentReport*' - $ids = Invoke-DbaQuery -Database $dbname -SqlInstance $script:instance2 -Query 'SELECT id FROM dbo.example' + $ids = Invoke-DbaQuery -Database $dbname -SqlInstance $TestConfig.instance2 -Query 'SELECT id FROM dbo.example' $ids.id | Should -Not -BeNullOrEmpty } It "Performs a script generation without deployment" { - $results = $dacpac | Publish-DbaDacPackage -Database $dbname -SqlInstance $script:instance2 -ScriptOnly -PublishXml $publishprofile.FileName -Confirm:$false + $results = $dacpac | Publish-DbaDacPackage -Database $dbname -SqlInstance $TestConfig.instance2 -ScriptOnly -PublishXml $publishprofile.FileName -Confirm:$false $results.Result | Should -BeLike '*Reporting and scripting deployment plan (Complete)*' $results.DatabaseScriptPath | Should -Not -BeNullOrEmpty Test-Path ($results.DatabaseScriptPath) | Should -Be $true - Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbname | Should -BeNullOrEmpty + Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname | Should -BeNullOrEmpty Remove-Item $results.DatabaseScriptPath } It "Performs a script generation without deployment and using an input options object" { $opts = New-DbaDacOption -Action Publish $opts.GenerateDeploymentScript = $true - $results = $dacpac | Publish-DbaDacPackage -Database $dbname -SqlInstance $script:instance2 -DacOption $opts -Confirm:$false + $results = $dacpac | Publish-DbaDacPackage -Database $dbname -SqlInstance $TestConfig.instance2 -DacOption $opts -Confirm:$false $results.Result | Should -BeLike '*Reporting and scripting deployment plan (Complete)*' $results.DatabaseScriptPath | Should -Not -BeNullOrEmpty Test-Path ($results.DatabaseScriptPath) | Should -Be $true - Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbname | Should -BeNullOrEmpty + Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname | Should -BeNullOrEmpty Remove-Item $results.DatabaseScriptPath } It "Performs a script generation using custom path" { @@ -88,38 +88,39 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { GenerateDeploymentScript = $true DatabaseScriptPath = 'C:\Temp\testdb.sql' } - $results = $dacpac | Publish-DbaDacPackage -Database $dbname -SqlInstance $script:instance2 -DacOption $opts -Confirm:$false + $results = $dacpac | Publish-DbaDacPackage -Database $dbname -SqlInstance $TestConfig.instance2 -DacOption $opts -Confirm:$false $results.Result | Should -BeLike '*Reporting and scripting deployment plan (Complete)*' $results.DatabaseScriptPath | Should -Be 'C:\Temp\testdb.sql' Test-Path ($results.DatabaseScriptPath) | Should -Be $true - Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbname | Should -BeNullOrEmpty + Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname | Should -BeNullOrEmpty Remove-Item $results.DatabaseScriptPath } } Context "Bacpac tests" { BeforeAll { $extractOptions = New-DbaDacOption -Action Export -Type Bacpac - $bacpac = Export-DbaDacPackage -SqlInstance $script:instance1 -Database $dbname -DacOption $extractOptions -Type Bacpac + $bacpac = Export-DbaDacPackage -SqlInstance $TestConfig.instance1 -Database $dbname -DacOption $extractOptions -Type Bacpac } AfterAll { if ($bacpac.Path) { Remove-Item -Confirm:$false -Path $bacpac.Path -ErrorAction SilentlyContinue } } It "Performs an SMO-based deployment" { $options = New-DbaDacOption -Action Publish -Type Bacpac - $results = $bacpac | Publish-DbaDacPackage -Type Bacpac -DacOption $options -Database $dbname -SqlInstance $script:instance2 -Confirm:$false + $results = $bacpac | Publish-DbaDacPackage -Type Bacpac -DacOption $options -Database $dbname -SqlInstance $TestConfig.instance2 -Confirm:$false $results.Result | Should -BeLike '*Updating database (Complete)*' - $ids = Invoke-DbaQuery -Database $dbname -SqlInstance $script:instance2 -Query 'SELECT id FROM dbo.example' + $ids = Invoke-DbaQuery -Database $dbname -SqlInstance $TestConfig.instance2 -Query 'SELECT id FROM dbo.example' $ids.id | Should -Not -BeNullOrEmpty } It "Auto detects that a .bacpac is being used and sets the Type to Bacpac" { $options = New-DbaDacOption -Action Publish -Type Bacpac - $results = $bacpac | Publish-DbaDacPackage -DacOption $options -Database $dbname -SqlInstance $script:instance2 -Confirm:$false + $results = $bacpac | Publish-DbaDacPackage -DacOption $options -Database $dbname -SqlInstance $TestConfig.instance2 -Confirm:$false $results.Result | Should -BeLike '*Updating database (Complete)*' - $ids = Invoke-DbaQuery -Database $dbname -SqlInstance $script:instance2 -Query 'SELECT id FROM dbo.example' + $ids = Invoke-DbaQuery -Database $dbname -SqlInstance $TestConfig.instance2 -Query 'SELECT id FROM dbo.example' $ids.id | Should -Not -BeNullOrEmpty } It "Should throw when ScriptOnly is used" { - { $bacpac | Publish-DbaDacPackage -Database $dbname -SqlInstance $script:instance2 -ScriptOnly -Type Bacpac -EnableException -Confirm:$false } | Should -Throw + { $bacpac | Publish-DbaDacPackage -Database $dbname -SqlInstance $TestConfig.instance2 -ScriptOnly -Type Bacpac -EnableException -Confirm:$false } | Should -Throw } } } + diff --git a/tests/Read-DbaAuditFile.Tests.ps1 b/tests/Read-DbaAuditFile.Tests.ps1 index 98c97f576c..24aa84a757 100644 --- a/tests/Read-DbaAuditFile.Tests.ps1 +++ b/tests/Read-DbaAuditFile.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig $base = (Get-Module -Name dbatools | Where-Object ModuleBase -notmatch net).ModuleBase @@ -17,7 +17,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $path = $server.ErrorLogPath $sql = "CREATE SERVER AUDIT LoginAudit TO FILE (FILEPATH = N'$path',MAXSIZE = 10 MB,MAX_ROLLOVER_FILES = 1,RESERVE_DISK_SPACE = OFF) @@ -29,8 +29,8 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { ALTER SERVER AUDIT LoginAudit WITH (STATE = ON)" $server.Query($sql) # generate a login - $null = Get-DbaDatabase -SqlInstance $script:instance2 - $null = Get-DbaDbFile -SqlInstance $script:instance2 + $null = Get-DbaDatabase -SqlInstance $TestConfig.instance2 + $null = Get-DbaDbFile -SqlInstance $TestConfig.instance2 # Give it a chance to write Start-Sleep 2 } @@ -43,12 +43,12 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } Context "Verifying command output" { It "returns some results" { - $results = Get-DbaInstanceAudit -SqlInstance $script:instance2 -Audit LoginAudit | Read-DbaAuditFile -Raw -WarningAction SilentlyContinue + $results = Get-DbaInstanceAudit -SqlInstance $TestConfig.instance2 -Audit LoginAudit | Read-DbaAuditFile -Raw -WarningAction SilentlyContinue [System.Linq.Enumerable]::Count($results) -gt 1 | Should Be $true } It "returns some results" { - $results = Get-DbaInstanceAudit -SqlInstance $script:instance2 -Audit LoginAudit | Read-DbaAuditFile | Select-Object -First 1 + $results = Get-DbaInstanceAudit -SqlInstance $TestConfig.instance2 -Audit LoginAudit | Read-DbaAuditFile | Select-Object -First 1 $results.server_principal_name | Should -Not -Be $null } } -} \ No newline at end of file +} diff --git a/tests/Read-DbaBackupHeader.Tests.ps1 b/tests/Read-DbaBackupHeader.Tests.ps1 index 34bf9db849..15b84d3f99 100644 --- a/tests/Read-DbaBackupHeader.Tests.ps1 +++ b/tests/Read-DbaBackupHeader.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Read-DbaTraceFile.Tests.ps1 b/tests/Read-DbaTraceFile.Tests.ps1 index 2f8b9a63dc..2206d74640 100644 --- a/tests/Read-DbaTraceFile.Tests.ps1 +++ b/tests/Read-DbaTraceFile.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,7 +15,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $configs = $script:instance1, $script:instance2 | Get-DbaSpConfigure -Name DefaultTraceEnabled + $configs = $TestConfig.instance1, $TestConfig.instance2 | Get-DbaSpConfigure -Name DefaultTraceEnabled $configs | Set-DbaSpConfigure -Value $true -WarningAction SilentlyContinue } AfterAll { @@ -28,7 +28,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Context "Verifying command output" { It "returns results" { - $results = Get-DbaTrace -SqlInstance $script:instance2 -Id 1 | Read-DbaTraceFile + $results = Get-DbaTrace -SqlInstance $TestConfig.instance2 -Id 1 | Read-DbaTraceFile $results.DatabaseName.Count | Should -BeGreaterThan 0 } @@ -42,22 +42,22 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { and ApplicationName not like 'Microsoft SQL Server Management Studio%'" # Collect the results into a variable so that the bulk import is super fast - Get-DbaTrace -SqlInstance $script:instance2 -Id 1 | Read-DbaTraceFile -Where $where -WarningAction SilentlyContinue -WarningVariable warn > $null + Get-DbaTrace -SqlInstance $TestConfig.instance2 -Id 1 | Read-DbaTraceFile -Where $where -WarningAction SilentlyContinue -WarningVariable warn > $null $warn | Should -Be $null } } Context "Verify Parameter Use" { It "Should execute using parameters Database, Login, Spid" { - $results = Get-DbaTrace -SqlInstance $script:instance2 -Id 1 | Read-DbaTraceFile -Database Master -Login sa -Spid 7 -WarningAction SilentlyContinue -WarningVariable warn + $results = Get-DbaTrace -SqlInstance $TestConfig.instance2 -Id 1 | Read-DbaTraceFile -Database Master -Login sa -Spid 7 -WarningAction SilentlyContinue -WarningVariable warn $warn | Should -Be $null } It "Should execute using parameters EventClass, ObjectType, ErrorId" { - $results = Get-DbaTrace -SqlInstance $script:instance2 -Id 1 | Read-DbaTraceFile -EventClass 4 -ObjectType 4 -ErrorId 4 -WarningAction SilentlyContinue -WarningVariable warn + $results = Get-DbaTrace -SqlInstance $TestConfig.instance2 -Id 1 | Read-DbaTraceFile -EventClass 4 -ObjectType 4 -ErrorId 4 -WarningAction SilentlyContinue -WarningVariable warn $warn | Should -Be $null } It "Should execute using parameters EventSequence, TextData, ApplicationName, ObjectName" { - $results = Get-DbaTrace -SqlInstance $script:instance2 -Id 1 | Read-DbaTraceFile -EventSequence 4 -TextData "Text" -ApplicationName "Application" -ObjectName "Name" -WarningAction SilentlyContinue -WarningVariable warn + $results = Get-DbaTrace -SqlInstance $TestConfig.instance2 -Id 1 | Read-DbaTraceFile -EventSequence 4 -TextData "Text" -ApplicationName "Application" -ObjectName "Name" -WarningAction SilentlyContinue -WarningVariable warn $warn | Should -Be $null } } -} \ No newline at end of file +} diff --git a/tests/Read-DbaTransactionLog.Tests.ps1 b/tests/Read-DbaTransactionLog.Tests.ps1 index b402f67076..b7cda8e260 100644 --- a/tests/Read-DbaTransactionLog.Tests.ps1 +++ b/tests/Read-DbaTransactionLog.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Read-DbaXEFile.Tests.ps1 b/tests/Read-DbaXEFile.Tests.ps1 index cb2e2cea8f..a7bf7346d8 100644 --- a/tests/Read-DbaXEFile.Tests.ps1 +++ b/tests/Read-DbaXEFile.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig $base = (Get-Module -Name dbatools | Where-Object ModuleBase -notmatch net).ModuleBase Describe "$CommandName Unit Tests" -Tag 'UnitTests' { @@ -18,12 +18,12 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Verifying command output" { # THIS WORKS, I SWEAR It "returns some results" { - $results = Get-DbaXESession -SqlInstance $script:instance2 | Read-DbaXEFile -Raw -WarningAction SilentlyContinue + $results = Get-DbaXESession -SqlInstance $TestConfig.instance2 | Read-DbaXEFile -Raw -WarningAction SilentlyContinue [System.Linq.Enumerable]::Count($results) -gt 1 | Should Be $true } It "returns some results" { - $results = Get-DbaXESession -SqlInstance $script:instance2 | Read-DbaXEFile -WarningAction SilentlyContinue + $results = Get-DbaXESession -SqlInstance $TestConfig.instance2 | Read-DbaXEFile -WarningAction SilentlyContinue $results.Count -gt 1 | Should Be $true } } -} \ No newline at end of file +} diff --git a/tests/Register-DbatoolsConfig.Tests.ps1 b/tests/Register-DbatoolsConfig.Tests.ps1 index 917d63890c..26c74e9be7 100644 --- a/tests/Register-DbatoolsConfig.Tests.ps1 +++ b/tests/Register-DbatoolsConfig.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Remove-DbaAgDatabase.Tests.ps1 b/tests/Remove-DbaAgDatabase.Tests.ps1 index 9ac073f717..e75cb27055 100644 --- a/tests/Remove-DbaAgDatabase.Tests.ps1 +++ b/tests/Remove-DbaAgDatabase.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$commandname Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,14 +15,14 @@ Describe "$commandname Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $null = Get-DbaProcess -SqlInstance $script:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue - $server = Connect-DbaInstance -SqlInstance $script:instance3 + $null = Get-DbaProcess -SqlInstance $TestConfig.instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance3 $agname = "dbatoolsci_removeagdb_agroup" $dbname = "dbatoolsci_removeagdb_agroupdb" $server.Query("create database $dbname") - $null = Get-DbaDatabase -SqlInstance $script:instance3 -Database $dbname | Backup-DbaDatabase - $null = Get-DbaDatabase -SqlInstance $script:instance3 -Database $dbname | Backup-DbaDatabase -Type Log - $ag = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Database $dbname -Confirm:$false -Certificate dbatoolsci_AGCert -UseLastBackup + $null = Get-DbaDatabase -SqlInstance $TestConfig.instance3 -Database $dbname | Backup-DbaDatabase + $null = Get-DbaDatabase -SqlInstance $TestConfig.instance3 -Database $dbname | Backup-DbaDatabase -Type Log + $ag = New-DbaAvailabilityGroup -Primary $TestConfig.instance3 -Name $agname -ClusterType None -FailoverMode Manual -Database $dbname -Confirm:$false -Certificate dbatoolsci_AGCert -UseLastBackup } AfterAll { $null = Remove-DbaAvailabilityGroup -SqlInstance $server -AvailabilityGroup $agname -Confirm:$false @@ -30,16 +30,16 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { } Context "removes ag db" { It "returns removed results" { - $results = Remove-DbaAgDatabase -SqlInstance $script:instance3 -Database $dbname -Confirm:$false + $results = Remove-DbaAgDatabase -SqlInstance $TestConfig.instance3 -Database $dbname -Confirm:$false $results.AvailabilityGroup | Should -Be $agname $results.Database | Should -Be $dbname $results.Status | Should -Be 'Removed' } It "really removed the db from the ag" { - $results = Get-DbaAvailabilityGroup -SqlInstance $script:instance3 -AvailabilityGroup $agname + $results = Get-DbaAvailabilityGroup -SqlInstance $TestConfig.instance3 -AvailabilityGroup $agname $results.AvailabilityGroup | Should -Be $agname $results.AvailabilityDatabases.Name | Should -Not -Contain $dbname } } -} #$script:instance2 for appveyor \ No newline at end of file +} #$TestConfig.instance2 for appveyor diff --git a/tests/Remove-DbaAgListener.Tests.ps1 b/tests/Remove-DbaAgListener.Tests.ps1 index 5811f5c158..6926450cdd 100644 --- a/tests/Remove-DbaAgListener.Tests.ps1 +++ b/tests/Remove-DbaAgListener.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,16 +16,16 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { $agname = "dbatoolsci_ag_removelistener" - $ag = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Confirm:$false -Certificate dbatoolsci_AGCert + $ag = New-DbaAvailabilityGroup -Primary $TestConfig.instance3 -Name $agname -ClusterType None -FailoverMode Manual -Confirm:$false -Certificate dbatoolsci_AGCert $aglistener = $ag | Add-DbaAgListener -IPAddress 127.0.20.1 -Port 14330 -Confirm:$false } AfterAll { - $null = Remove-DbaAvailabilityGroup -SqlInstance $script:instance3 -AvailabilityGroup $agname -Confirm:$false + $null = Remove-DbaAvailabilityGroup -SqlInstance $TestConfig.instance3 -AvailabilityGroup $agname -Confirm:$false } Context "removes a listener" { It "returns results with proper data" { - $results = Remove-DbaAgListener -SqlInstance $script:instance3 -Listener $aglistener.Name -Confirm:$false + $results = Remove-DbaAgListener -SqlInstance $TestConfig.instance3 -Listener $aglistener.Name -Confirm:$false $results.Status | Should -Be 'Removed' } } -} #$script:instance2 for appveyor \ No newline at end of file +} #$TestConfig.instance2 for appveyor diff --git a/tests/Remove-DbaAgReplica.Tests.ps1 b/tests/Remove-DbaAgReplica.Tests.ps1 index 768b4c1441..589556d28e 100644 --- a/tests/Remove-DbaAgReplica.Tests.ps1 +++ b/tests/Remove-DbaAgReplica.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$commandname Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Remove-DbaAgentAlert.Tests.ps1 b/tests/Remove-DbaAgentAlert.Tests.ps1 index 05058281d9..aad323cbae 100644 --- a/tests/Remove-DbaAgentAlert.Tests.ps1 +++ b/tests/Remove-DbaAgentAlert.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,7 +16,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BeforeEach { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $alertName = "dbatoolsci_test_$(get-random)" $alertName2 = "dbatoolsci_test_$(get-random)" @@ -52,4 +52,4 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { (Get-DbaAgentAlert -SqlInstance $server ) | Should -BeNullOrEmpty } } -} \ No newline at end of file +} diff --git a/tests/Remove-DbaAgentAlertCategory.Tests.ps1 b/tests/Remove-DbaAgentAlertCategory.Tests.ps1 index c50af63004..6cc2ecc468 100644 --- a/tests/Remove-DbaAgentAlertCategory.Tests.ps1 +++ b/tests/Remove-DbaAgentAlertCategory.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -17,31 +17,31 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "New Agent Alert Category is changed properly" { It "Should have the right name" { - $results = New-DbaAgentAlertCategory -SqlInstance $script:instance2 -Category CategoryTest1, CategoryTest2, CategoryTest3 + $results = New-DbaAgentAlertCategory -SqlInstance $TestConfig.instance2 -Category CategoryTest1, CategoryTest2, CategoryTest3 $results[0].Name | Should Be "CategoryTest1" $results[1].Name | Should Be "CategoryTest2" $results[2].Name | Should Be "CategoryTest3" } It "Should actually for sure exist" { - $newresults = Get-DbaAgentAlertCategory -SqlInstance $script:instance2 -Category CategoryTest1, CategoryTest2, CategoryTest3 + $newresults = Get-DbaAgentAlertCategory -SqlInstance $TestConfig.instance2 -Category CategoryTest1, CategoryTest2, CategoryTest3 $newresults.Count | Should Be 3 } It "Remove the alert categories" { - Remove-DbaAgentAlertCategory -SqlInstance $script:instance2 -Category CategoryTest1, CategoryTest2, Categorytest3 -Confirm:$false + Remove-DbaAgentAlertCategory -SqlInstance $TestConfig.instance2 -Category CategoryTest1, CategoryTest2, Categorytest3 -Confirm:$false - $newresults = Get-DbaAgentAlertCategory -SqlInstance $script:instance2 -Category CategoryTest1, CategoryTest2, CategoryTest3 + $newresults = Get-DbaAgentAlertCategory -SqlInstance $TestConfig.instance2 -Category CategoryTest1, CategoryTest2, CategoryTest3 $newresults.Count | Should Be 0 } It "supports piping SQL Agent alert category" { $categoryName = "dbatoolsci_test_$(get-random)" - $null = New-DbaAgentAlertCategory -SqlInstance $script:instance2 -Category $categoryName - (Get-DbaAgentAlertCategory -SqlInstance $script:instance2 -Category $categoryName ) | Should -Not -BeNullOrEmpty - Get-DbaAgentAlertCategory -SqlInstance $script:instance2 -Category $categoryName | Remove-DbaAgentAlertCategory -Confirm:$false - (Get-DbaAgentAlertCategory -SqlInstance $script:instance2 -Category $categoryName ) | Should -BeNullOrEmpty + $null = New-DbaAgentAlertCategory -SqlInstance $TestConfig.instance2 -Category $categoryName + (Get-DbaAgentAlertCategory -SqlInstance $TestConfig.instance2 -Category $categoryName ) | Should -Not -BeNullOrEmpty + Get-DbaAgentAlertCategory -SqlInstance $TestConfig.instance2 -Category $categoryName | Remove-DbaAgentAlertCategory -Confirm:$false + (Get-DbaAgentAlertCategory -SqlInstance $TestConfig.instance2 -Category $categoryName ) | Should -BeNullOrEmpty } } -} \ No newline at end of file +} diff --git a/tests/Remove-DbaAgentJob.Tests.ps1 b/tests/Remove-DbaAgentJob.Tests.ps1 index 857938e0b3..f54830f28c 100644 --- a/tests/Remove-DbaAgentJob.Tests.ps1 +++ b/tests/Remove-DbaAgentJob.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,52 +16,52 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Context "Command removes jobs" { BeforeAll { - $null = New-DbaAgentSchedule -SqlInstance $script:instance3 -Schedule dbatoolsci_daily -FrequencyType Daily -FrequencyInterval Everyday -Force - $null = New-DbaAgentJob -SqlInstance $script:instance3 -Job dbatoolsci_testjob -Schedule dbatoolsci_daily - $null = New-DbaAgentJobStep -SqlInstance $script:instance3 -Job dbatoolsci_testjob -StepId 1 -StepName dbatoolsci_step1 -Subsystem TransactSql -Command 'select 1' - $null = Start-DbaAgentJob -SqlInstance $script:instance3 -Job dbatoolsci_testjob + $null = New-DbaAgentSchedule -SqlInstance $TestConfig.instance3 -Schedule dbatoolsci_daily -FrequencyType Daily -FrequencyInterval Everyday -Force + $null = New-DbaAgentJob -SqlInstance $TestConfig.instance3 -Job dbatoolsci_testjob -Schedule dbatoolsci_daily + $null = New-DbaAgentJobStep -SqlInstance $TestConfig.instance3 -Job dbatoolsci_testjob -StepId 1 -StepName dbatoolsci_step1 -Subsystem TransactSql -Command 'select 1' + $null = Start-DbaAgentJob -SqlInstance $TestConfig.instance3 -Job dbatoolsci_testjob } AfterAll { - if (Get-DbaAgentSchedule -SqlInstance $script:instance3 -Schedule dbatoolsci_daily) { Remove-DbaAgentSchedule -SqlInstance $script:instance3 -Schedule dbatoolsci_daily -Confirm:$false } + if (Get-DbaAgentSchedule -SqlInstance $TestConfig.instance3 -Schedule dbatoolsci_daily) { Remove-DbaAgentSchedule -SqlInstance $TestConfig.instance3 -Schedule dbatoolsci_daily -Confirm:$false } } - $null = Remove-DbaAgentJob -SqlInstance $script:instance3 -Job dbatoolsci_testjob -Confirm:$false + $null = Remove-DbaAgentJob -SqlInstance $TestConfig.instance3 -Job dbatoolsci_testjob -Confirm:$false It "Should have deleted job: dbatoolsci_testjob" { - (Get-DbaAgentJob -SqlInstance $script:instance3 -Job dbatoolsci_testjob) | Should BeNullOrEmpty + (Get-DbaAgentJob -SqlInstance $TestConfig.instance3 -Job dbatoolsci_testjob) | Should BeNullOrEmpty } It "Should have deleted schedule: dbatoolsci_daily" { - (Get-DbaAgentSchedule -SqlInstance $script:instance3 -Schedule dbatoolsci_daily) | Should BeNullOrEmpty + (Get-DbaAgentSchedule -SqlInstance $TestConfig.instance3 -Schedule dbatoolsci_daily) | Should BeNullOrEmpty } It "Should have deleted history: dbatoolsci_daily" { - (Get-DbaAgentJobHistory -SqlInstance $script:instance3 -Job dbatoolsci_testjob) | Should BeNullOrEmpty + (Get-DbaAgentJobHistory -SqlInstance $TestConfig.instance3 -Job dbatoolsci_testjob) | Should BeNullOrEmpty } } Context "Command removes job but not schedule" { BeforeAll { - $null = New-DbaAgentSchedule -SqlInstance $script:instance3 -Schedule dbatoolsci_weekly -FrequencyType Weekly -FrequencyInterval Everyday -Force - $null = New-DbaAgentJob -SqlInstance $script:instance3 -Job dbatoolsci_testjob_schedule -Schedule dbatoolsci_weekly - $null = New-DbaAgentJobStep -SqlInstance $script:instance3 -Job dbatoolsci_testjob_schedule -StepId 1 -StepName dbatoolsci_step1 -Subsystem TransactSql -Command 'select 1' + $null = New-DbaAgentSchedule -SqlInstance $TestConfig.instance3 -Schedule dbatoolsci_weekly -FrequencyType Weekly -FrequencyInterval Everyday -Force + $null = New-DbaAgentJob -SqlInstance $TestConfig.instance3 -Job dbatoolsci_testjob_schedule -Schedule dbatoolsci_weekly + $null = New-DbaAgentJobStep -SqlInstance $TestConfig.instance3 -Job dbatoolsci_testjob_schedule -StepId 1 -StepName dbatoolsci_step1 -Subsystem TransactSql -Command 'select 1' } AfterAll { - if (Get-DbaAgentSchedule -SqlInstance $script:instance3 -Schedule dbatoolsci_weekly) { Remove-DbaAgentSchedule -SqlInstance $script:instance3 -Schedule dbatoolsci_weekly -Confirm:$false } + if (Get-DbaAgentSchedule -SqlInstance $TestConfig.instance3 -Schedule dbatoolsci_weekly) { Remove-DbaAgentSchedule -SqlInstance $TestConfig.instance3 -Schedule dbatoolsci_weekly -Confirm:$false } } - $null = Remove-DbaAgentJob -SqlInstance $script:instance3 -Job dbatoolsci_testjob_schedule -KeepUnusedSchedule -Confirm:$false + $null = Remove-DbaAgentJob -SqlInstance $TestConfig.instance3 -Job dbatoolsci_testjob_schedule -KeepUnusedSchedule -Confirm:$false It "Should have deleted job: dbatoolsci_testjob_schedule" { - (Get-DbaAgentJob -SqlInstance $script:instance3 -Job dbatoolsci_testjob_schedule) | Should BeNullOrEmpty + (Get-DbaAgentJob -SqlInstance $TestConfig.instance3 -Job dbatoolsci_testjob_schedule) | Should BeNullOrEmpty } It "Should not have deleted schedule: dbatoolsci_weekly" { - (Get-DbaAgentSchedule -SqlInstance $script:instance3 -Schedule dbatoolsci_weekly) | Should Not BeNullOrEmpty + (Get-DbaAgentSchedule -SqlInstance $TestConfig.instance3 -Schedule dbatoolsci_weekly) | Should Not BeNullOrEmpty } } Context "Command removes job but not history and supports piping" { BeforeAll { - $jobId = New-DbaAgentJob -SqlInstance $script:instance3 -Job dbatoolsci_testjob_history | Select-Object -ExpandProperty JobId - $null = New-DbaAgentJobStep -SqlInstance $script:instance3 -Job dbatoolsci_testjob_history -StepId 1 -StepName dbatoolsci_step1 -Subsystem TransactSql -Command 'select 1' - $null = Start-DbaAgentJob -SqlInstance $script:instance3 -Job dbatoolsci_testjob_history - $server = Connect-DbaInstance -SqlInstance $script:instance3 + $jobId = New-DbaAgentJob -SqlInstance $TestConfig.instance3 -Job dbatoolsci_testjob_history | Select-Object -ExpandProperty JobId + $null = New-DbaAgentJobStep -SqlInstance $TestConfig.instance3 -Job dbatoolsci_testjob_history -StepId 1 -StepName dbatoolsci_step1 -Subsystem TransactSql -Command 'select 1' + $null = Start-DbaAgentJob -SqlInstance $TestConfig.instance3 -Job dbatoolsci_testjob_history + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance3 } It "Should have deleted job: dbatoolsci_testjob_history" { - $null = Get-DbaAgentJob -SqlInstance $script:instance3 -Job dbatoolsci_testjob_history | Remove-DbaAgentJob -KeepHistory -Confirm:$false - (Get-DbaAgentJob -SqlInstance $script:instance3 -Job dbatoolsci_testjob_history) | Should BeNullOrEmpty + $null = Get-DbaAgentJob -SqlInstance $TestConfig.instance3 -Job dbatoolsci_testjob_history | Remove-DbaAgentJob -KeepHistory -Confirm:$false + (Get-DbaAgentJob -SqlInstance $TestConfig.instance3 -Job dbatoolsci_testjob_history) | Should BeNullOrEmpty } It -Skip "Should not have deleted history: dbatoolsci_testjob_history" { ($server.Query("select 1 from sysjobhistory where job_id = '$jobId'", "msdb")) | Should Not BeNullOrEmpty @@ -70,4 +70,4 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $server.Query("delete from sysjobhistory where job_id = '$jobId'", "msdb") } } -} # $script:instance2 for appveyor \ No newline at end of file +} # $TestConfig.instance2 for appveyor diff --git a/tests/Remove-DbaAgentJobCategory.Tests.ps1 b/tests/Remove-DbaAgentJobCategory.Tests.ps1 index d56c683d59..504a214cf4 100644 --- a/tests/Remove-DbaAgentJobCategory.Tests.ps1 +++ b/tests/Remove-DbaAgentJobCategory.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -17,7 +17,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "New Agent Job Category is changed properly" { It "Should have the right name and category type" { - $results = New-DbaAgentJobCategory -SqlInstance $script:instance2 -Category CategoryTest1, CategoryTest2, CategoryTest3 + $results = New-DbaAgentJobCategory -SqlInstance $TestConfig.instance2 -Category CategoryTest1, CategoryTest2, CategoryTest3 $results[0].Name | Should Be "CategoryTest1" $results[0].CategoryType | Should Be "LocalJob" $results[1].Name | Should Be "CategoryTest2" @@ -27,16 +27,16 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } It "Should actually for sure exist" { - $newresults = Get-DbaAgentJobCategory -SqlInstance $script:instance2 -Category CategoryTest1, CategoryTest2, CategoryTest3 + $newresults = Get-DbaAgentJobCategory -SqlInstance $TestConfig.instance2 -Category CategoryTest1, CategoryTest2, CategoryTest3 $newresults.Count | Should Be 3 } It "Remove the job categories" { - Remove-DbaAgentJobCategory -SqlInstance $script:instance2 -Category CategoryTest1, CategoryTest2, Categorytest3 -Confirm:$false + Remove-DbaAgentJobCategory -SqlInstance $TestConfig.instance2 -Category CategoryTest1, CategoryTest2, Categorytest3 -Confirm:$false - $newresults = Get-DbaAgentJobCategory -SqlInstance $script:instance2 -Category CategoryTest1, CategoryTest2, CategoryTest3 + $newresults = Get-DbaAgentJobCategory -SqlInstance $TestConfig.instance2 -Category CategoryTest1, CategoryTest2, CategoryTest3 $newresults.Count | Should Be 0 } } -} \ No newline at end of file +} diff --git a/tests/Remove-DbaAgentJobStep.Tests.ps1 b/tests/Remove-DbaAgentJobStep.Tests.ps1 index a210fc34dd..3f91cb9eb3 100644 --- a/tests/Remove-DbaAgentJobStep.Tests.ps1 +++ b/tests/Remove-DbaAgentJobStep.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Remove-DbaAgentOperator.Tests.ps1 b/tests/Remove-DbaAgentOperator.Tests.ps1 index 5dd439f9a4..3523ccbb0a 100644 --- a/tests/Remove-DbaAgentOperator.Tests.ps1 +++ b/tests/Remove-DbaAgentOperator.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,7 +15,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { $random = Get-Random - $instance2 = Connect-DbaInstance -SqlInstance $script:instance2 + $instance2 = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $email1 = "test1$($random)@test.com" $email2 = "test2$($random)@test.com" } @@ -40,4 +40,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { (Get-DbaAgentOperator -SqlInstance $instance2 -Operator $operatorName ) | Should -BeNullOrEmpty } } -} \ No newline at end of file +} diff --git a/tests/Remove-DbaAgentProxy.Tests.ps1 b/tests/Remove-DbaAgentProxy.Tests.ps1 index 6db1decf9d..f71339a131 100644 --- a/tests/Remove-DbaAgentProxy.Tests.ps1 +++ b/tests/Remove-DbaAgentProxy.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -14,7 +14,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $null = Invoke-DbaQuery -SqlInstance $server -Query "CREATE CREDENTIAL proxyCred WITH IDENTITY = 'NT AUTHORITY\SYSTEM', SECRET = 'G31o)lkJ8HNd!';" } @@ -26,7 +26,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BeforeEach { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $proxyName = "dbatoolsci_test_$(get-random)" $proxyName2 = "dbatoolsci_test_$(get-random)" @@ -65,4 +65,4 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { (Get-DbaAgentProxy -SqlInstance $server ) | Should -BeNullOrEmpty } } -} \ No newline at end of file +} diff --git a/tests/Remove-DbaAgentSchedule.Tests.ps1 b/tests/Remove-DbaAgentSchedule.Tests.ps1 index 29d9bcbf11..ebfbad096e 100644 --- a/tests/Remove-DbaAgentSchedule.Tests.ps1 +++ b/tests/Remove-DbaAgentSchedule.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -19,7 +19,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $end = (Get-Date).AddDays(4).ToString('yyyyMMdd') foreach ($FrequencySubdayType in ('Time', 'Seconds', 'Minutes', 'Hours')) { - $variables = @{SqlInstance = $script:instance2 + $variables = @{SqlInstance = $TestConfig.instance2 Schedule = "dbatoolsci_$FrequencySubdayType" FrequencyRecurrenceFactor = '1' FrequencySubdayInterval = '1' @@ -34,21 +34,21 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } Context "Should remove schedules" { - $results = Get-DbaAgentSchedule -SqlInstance $script:instance2 | Where-Object { $_.name -like 'dbatools*' } + $results = Get-DbaAgentSchedule -SqlInstance $TestConfig.instance2 | Where-Object { $_.name -like 'dbatools*' } It "Should find all created schedule" { $results | Should Not BeNullOrEmpty } - $null = Remove-DbaAgentSchedule -SqlInstance $script:instance2 -Schedule dbatoolsci_Minutes -Confirm:$false - $results = Get-DbaAgentSchedule -SqlInstance $script:instance2 -Schedule dbatoolsci_Minutes + $null = Remove-DbaAgentSchedule -SqlInstance $TestConfig.instance2 -Schedule dbatoolsci_Minutes -Confirm:$false + $results = Get-DbaAgentSchedule -SqlInstance $TestConfig.instance2 -Schedule dbatoolsci_Minutes It "Should not find dbatoolsci_Minutes" { $results | Should BeNullOrEmpty } - $null = Get-DbaAgentSchedule -SqlInstance $script:instance2 | Where-Object { $_.name -like 'dbatools*' } | Remove-DbaAgentSchedule -Confirm:$false -Force - $results = Get-DbaAgentSchedule -SqlInstance $script:instance2 | Where-Object { $_.name -like 'dbatools*' } + $null = Get-DbaAgentSchedule -SqlInstance $TestConfig.instance2 | Where-Object { $_.name -like 'dbatools*' } | Remove-DbaAgentSchedule -Confirm:$false -Force + $results = Get-DbaAgentSchedule -SqlInstance $TestConfig.instance2 | Where-Object { $_.name -like 'dbatools*' } It "Should not find any created schedule" { $results | Should BeNullOrEmpty } } -} \ No newline at end of file +} diff --git a/tests/Remove-DbaAvailabilityGroup.Tests.ps1 b/tests/Remove-DbaAvailabilityGroup.Tests.ps1 index bd354a860f..c12240e985 100644 --- a/tests/Remove-DbaAvailabilityGroup.Tests.ps1 +++ b/tests/Remove-DbaAvailabilityGroup.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$commandname Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,17 +16,18 @@ Describe "$commandname Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { $agname = "dbatoolsci_removewholegroup" - $null = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Confirm:$false + $null = New-DbaAvailabilityGroup -Primary $TestConfig.instance3 -Name $agname -ClusterType None -FailoverMode Manual -Certificate dbatoolsci_AGCert -Confirm:$false } Context "removes the newly created ag" { It "removes the ag" { - $results = Remove-DbaAvailabilityGroup -SqlInstance $script:instance3 -AvailabilityGroup $agname -Confirm:$false + $results = Remove-DbaAvailabilityGroup -SqlInstance $TestConfig.instance3 -AvailabilityGroup $agname -Confirm:$false -WarningVariable warn + $warn | Should -BeNullorEmpty $results.Status | Should -Be 'Removed' $results.AvailabilityGroup | Should -Be $agname } It "really removed the ag" { - $results = Get-DbaAvailabilityGroup -SqlInstance $script:instance3 -AvailabilityGroup $agname + $results = Get-DbaAvailabilityGroup -SqlInstance $TestConfig.instance3 -AvailabilityGroup $agname $results | Should -BeNullorEmpty } } -} #$script:instance2 for appveyor \ No newline at end of file +} #$TestConfig.instance2 for appveyor diff --git a/tests/Remove-DbaBackup.Tests.ps1 b/tests/Remove-DbaBackup.Tests.ps1 index d70ff03480..4900e57646 100644 --- a/tests/Remove-DbaBackup.Tests.ps1 +++ b/tests/Remove-DbaBackup.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { diff --git a/tests/Remove-DbaClientAlias.Tests.ps1 b/tests/Remove-DbaClientAlias.Tests.ps1 index 41a340e4e1..53e4f46023 100644 --- a/tests/Remove-DbaClientAlias.Tests.ps1 +++ b/tests/Remove-DbaClientAlias.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Remove-DbaCmConnection.Tests.ps1 b/tests/Remove-DbaCmConnection.Tests.ps1 index f35254f81b..8186ee44dd 100644 --- a/tests/Remove-DbaCmConnection.Tests.ps1 +++ b/tests/Remove-DbaCmConnection.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Remove-DbaComputerCertificate.Tests.ps1 b/tests/Remove-DbaComputerCertificate.Tests.ps1 index 75bb8f0abd..aeed27a811 100644 --- a/tests/Remove-DbaComputerCertificate.Tests.ps1 +++ b/tests/Remove-DbaComputerCertificate.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,7 +16,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Can remove a certificate" { BeforeAll { - $null = Add-DbaComputerCertificate -Path $script:appveyorlabrepo\certificates\localhost.crt -Confirm:$false + $null = Add-DbaComputerCertificate -Path "$($TestConfig.appveyorlabrepo)\certificates\localhost.crt" -Confirm:$false $thumbprint = "29C469578D6C6211076A09CEE5C5797EEA0C2713" } @@ -38,4 +38,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $results | Should Be $null } } -} \ No newline at end of file +} diff --git a/tests/Remove-DbaCredential.Tests.ps1 b/tests/Remove-DbaCredential.Tests.ps1 index 10a51f41f6..00be044234 100644 --- a/tests/Remove-DbaCredential.Tests.ps1 +++ b/tests/Remove-DbaCredential.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,7 +16,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BeforeEach { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $credentialName = "dbatoolsci_test_$(get-random)" $credentialName2 = "dbatoolsci_test_$(get-random)" @@ -53,4 +53,4 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { (Get-DbaCredential -SqlInstance $server ) | Should -BeNullOrEmpty } } -} \ No newline at end of file +} diff --git a/tests/Remove-DbaCustomError.Tests.ps1 b/tests/Remove-DbaCustomError.Tests.ps1 index f16851ba9e..6f23f93ec2 100644 --- a/tests/Remove-DbaCustomError.Tests.ps1 +++ b/tests/Remove-DbaCustomError.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -14,8 +14,8 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance1 - $server2 = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance1 + $server2 = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $results = New-DbaCustomError -SqlInstance $server -MessageID 70000 -Severity 1 -MessageText "test_70000" $results = New-DbaCustomError -SqlInstance $server, $server2 -MessageID 70001 -Severity 1 -MessageText "test_70001" @@ -82,10 +82,10 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } It "Multiple servers via -SqlInstance" { - $results = Remove-DbaCustomError -SqlInstance $script:instance1, $script:instance2 -MessageID 70002 + $results = Remove-DbaCustomError -SqlInstance $TestConfig.instance1, $TestConfig.instance2 -MessageID 70002 # even the SMO server.Refresh() doesn't pick up the changes to the user defined messages - $server1Reconnected = Connect-DbaInstance -SqlInstance $script:instance1 - $server2Reconnected = Connect-DbaInstance -SqlInstance $script:instance2 + $server1Reconnected = Connect-DbaInstance -SqlInstance $TestConfig.instance1 + $server2Reconnected = Connect-DbaInstance -SqlInstance $TestConfig.instance2 ($server1Reconnected.UserDefinedMessages | Where-Object ID -eq 70002).Count | Should -Be 0 ($server2Reconnected.UserDefinedMessages | Where-Object ID -eq 70002).Count | Should -Be 0 } @@ -113,4 +113,4 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $updated.Text | Should -Be "updated text" } } -} \ No newline at end of file +} diff --git a/tests/Remove-DbaDatabase.Tests.ps1 b/tests/Remove-DbaDatabase.Tests.ps1 index 7c0a38d88d..6742869c65 100644 --- a/tests/Remove-DbaDatabase.Tests.ps1 +++ b/tests/Remove-DbaDatabase.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -20,18 +20,18 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { It "Should not attempt to remove system databases." { foreach ($db in $dbs) { - $db1 = Get-DbaDatabase -SqlInstance $script:instance1 -Database $db - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance1 -Database $db - $db2 = Get-DbaDatabase -SqlInstance $script:instance1 -Database $db + $db1 = Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $db + Remove-DbaDatabase -Confirm:$false -SqlInstance $TestConfig.instance1 -Database $db + $db2 = Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $db $db2.Name | Should Be $db1.Name } } It "Should not take system databases offline or change their status." { foreach ($db in $dbs) { - $db1 = Get-DbaDatabase -SqlInstance $script:instance1 -Database $db - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance1 -Database $db - $db2 = Get-DbaDatabase -SqlInstance $script:instance1 -Database $db + $db1 = Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $db + Remove-DbaDatabase -Confirm:$false -SqlInstance $TestConfig.instance1 -Database $db + $db2 = Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $db $db2.Status | Should Be $db1.Status $db2.IsAccessible | Should Be $db1.IsAccessible } @@ -39,22 +39,22 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } Context "Should remove user databases and return useful errors if it cannot." { It "Should remove a non system database." { - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance1 -Database singlerestore - Get-DbaProcess -SqlInstance $script:instance1 -Database singlerestore | Stop-DbaProcess - Restore-DbaDatabase -SqlInstance $script:instance1 -Path $script:appveyorlabrepo\singlerestore\singlerestore.bak -WithReplace - (Get-DbaDatabase -SqlInstance $script:instance1 -Database singlerestore).IsAccessible | Should Be $true - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance1 -Database singlerestore - Get-DbaDatabase -SqlInstance $script:instance1 -Database singlerestore | Should Be $null + Remove-DbaDatabase -Confirm:$false -SqlInstance $TestConfig.instance1 -Database singlerestore + Get-DbaProcess -SqlInstance $TestConfig.instance1 -Database singlerestore | Stop-DbaProcess + Restore-DbaDatabase -SqlInstance $TestConfig.instance1 -Path "$($TestConfig.appveyorlabrepo)\singlerestore\singlerestore.bak" -WithReplace + (Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database singlerestore).IsAccessible | Should Be $true + Remove-DbaDatabase -Confirm:$false -SqlInstance $TestConfig.instance1 -Database singlerestore + Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database singlerestore | Should Be $null } } Context "Should remove restoring database and return useful errors if it cannot." { It "Should remove a non system database." { - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance1 -Database singlerestore - Get-DbaProcess -SqlInstance $script:instance1 -Database singlerestore | Stop-DbaProcess - Restore-DbaDatabase -SqlInstance $script:instance1 -Path $script:appveyorlabrepo\singlerestore\singlerestore.bak -WithReplace -NoRecovery - (Connect-DbaInstance -SqlInstance $script:instance1).Databases['singlerestore'].IsAccessible | Should Be $false - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance1 -Database singlerestore - Get-DbaDatabase -SqlInstance $script:instance1 -Database singlerestore | Should Be $null + Remove-DbaDatabase -Confirm:$false -SqlInstance $TestConfig.instance1 -Database singlerestore + Get-DbaProcess -SqlInstance $TestConfig.instance1 -Database singlerestore | Stop-DbaProcess + Restore-DbaDatabase -SqlInstance $TestConfig.instance1 -Path "$($TestConfig.appveyorlabrepo)\singlerestore\singlerestore.bak" -WithReplace -NoRecovery + (Connect-DbaInstance -SqlInstance $TestConfig.instance1).Databases['singlerestore'].IsAccessible | Should Be $false + Remove-DbaDatabase -Confirm:$false -SqlInstance $TestConfig.instance1 -Database singlerestore + Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database singlerestore | Should Be $null } } -} \ No newline at end of file +} diff --git a/tests/Remove-DbaDatabaseSafely.Tests.ps1 b/tests/Remove-DbaDatabaseSafely.Tests.ps1 index 2fdde65660..89e5c24dbb 100644 --- a/tests/Remove-DbaDatabaseSafely.Tests.ps1 +++ b/tests/Remove-DbaDatabaseSafely.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,43 +16,43 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { BeforeAll { try { - $null = Get-DbaProcess -SqlInstance $script:instance1, $script:instance2 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue + $null = Get-DbaProcess -SqlInstance $TestConfig.instance1, $TestConfig.instance2 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue $db1 = "dbatoolsci_safely" $db2 = "dbatoolsci_safely_otherInstance" - $server3 = Connect-DbaInstance -SqlInstance $script:instance3 + $server3 = Connect-DbaInstance -SqlInstance $TestConfig.instance3 $server3.Query("CREATE DATABASE $db1") - $server2 = Connect-DbaInstance -SqlInstance $script:instance2 + $server2 = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $server2.Query("CREATE DATABASE $db1") $server2.Query("CREATE DATABASE $db2") - $server1 = Connect-DbaInstance -SqlInstance $script:instance1 + $server1 = Connect-DbaInstance -SqlInstance $TestConfig.instance1 } catch { } } AfterAll { - $null = Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance2 -Database $db1, $db2 - $null = Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance3 -Database $db1 - $null = Remove-DbaAgentJob -Confirm:$false -SqlInstance $script:instance2 -Job 'Rationalised Database Restore Script for dbatoolsci_safely' - $null = Remove-DbaAgentJob -Confirm:$false -SqlInstance $script:instance3 -Job 'Rationalised Database Restore Script for dbatoolsci_safely_otherInstance' + $null = Remove-DbaDatabase -Confirm:$false -SqlInstance $TestConfig.instance2 -Database $db1, $db2 + $null = Remove-DbaDatabase -Confirm:$false -SqlInstance $TestConfig.instance3 -Database $db1 + $null = Remove-DbaAgentJob -Confirm:$false -SqlInstance $TestConfig.instance2 -Job 'Rationalised Database Restore Script for dbatoolsci_safely' + $null = Remove-DbaAgentJob -Confirm:$false -SqlInstance $TestConfig.instance3 -Job 'Rationalised Database Restore Script for dbatoolsci_safely_otherInstance' } Context "Command actually works" { It "Should have database name of $db1" { - $results = Remove-DbaDatabaseSafely -SqlInstance $script:instance2 -Database $db1 -BackupFolder C:\temp -NoDbccCheckDb + $results = Remove-DbaDatabaseSafely -SqlInstance $TestConfig.instance2 -Database $db1 -BackupFolder C:\temp -NoDbccCheckDb foreach ($result in $results) { $result.DatabaseName | Should Be $db1 } } It -Skip:$($server1.EngineEdition -notmatch "Express") "should warn and quit on Express Edition" { - $results = Remove-DbaDatabaseSafely -SqlInstance $script:instance1 -Database $db1 -BackupFolder C:\temp -NoDbccCheckDb -WarningAction SilentlyContinue -WarningVariable warn 3> $null + $results = Remove-DbaDatabaseSafely -SqlInstance $TestConfig.instance1 -Database $db1 -BackupFolder C:\temp -NoDbccCheckDb -WarningAction SilentlyContinue -WarningVariable warn 3> $null $results | Should Be $null $warn -match 'Express Edition' | Should Be $true } It "Should restore to another server" { - $results = Remove-DbaDatabaseSafely -SqlInstance $script:instance2 -Database $db2 -BackupFolder c:\temp -NoDbccCheckDb -Destination $script:instance3 + $results = Remove-DbaDatabaseSafely -SqlInstance $TestConfig.instance2 -Database $db2 -BackupFolder c:\temp -NoDbccCheckDb -Destination $TestConfig.instance3 foreach ($result in $results) { $result.SqlInstance | Should Be $server2.SqlInstance $result.TestingInstance | Should Be $server3.SqlInstance } } } -} \ No newline at end of file +} diff --git a/tests/Remove-DbaDbAsymmetricKey.Tests.ps1 b/tests/Remove-DbaDbAsymmetricKey.Tests.ps1 index c22cc985bc..d09b51e7ba 100644 --- a/tests/Remove-DbaDbAsymmetricKey.Tests.ps1 +++ b/tests/Remove-DbaDbAsymmetricKey.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,17 +16,17 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BeforeAll { $database = 'RemAsy' - $null = New-DbaDatabase -SqlInstance $script:instance2 -Name $database + $null = New-DbaDatabase -SqlInstance $TestConfig.instance2 -Name $database } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance2 -Database $database -Confirm:$false + Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $database -Confirm:$false } Context "Remove a certificate" { $keyname = 'test1' $tPassword = ConvertTo-SecureString "ThisIsThePassword1" -AsPlainText -Force - New-DbaDbMasterKey -SqlInstance $script:instance2 -Database $database -SecurePassword $tPassword -confirm:$false - $key = New-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname -database $database - $results = Get-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname -Database $database -WarningVariable warnvar + New-DbaDbMasterKey -SqlInstance $TestConfig.instance2 -Database $database -SecurePassword $tPassword -confirm:$false + $key = New-DbaDbAsymmetricKey -SqlInstance $TestConfig.instance2 -Name $keyname -database $database + $results = Get-DbaDbAsymmetricKey -SqlInstance $TestConfig.instance2 -Name $keyname -Database $database -WarningVariable warnvar It "Should create new key in $database called $keyname" { $warnvar | Should -BeNullOrEmpty @@ -35,8 +35,8 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $results.KeyLength | Should -Be '2048' } - $removeResults = Remove-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname -Database $database -confirm:$false - $getResults = Get-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname -Database $database + $removeResults = Remove-DbaDbAsymmetricKey -SqlInstance $TestConfig.instance2 -Name $keyname -Database $database -confirm:$false + $getResults = Get-DbaDbAsymmetricKey -SqlInstance $TestConfig.instance2 -Name $keyname -Database $database It "Should Remove a certificate" { $getResults | Should -HaveCount 0 $removeResults.Status | Should -Be 'Success' @@ -46,22 +46,23 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $keyname = 'test1' $keyname2 = 'test2' $database = 'RemAsy' - $key = New-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname -Database $database - $key2 = New-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname2 -Database $database - $results = Get-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Database $database -WarningVariable warnvar + $key = New-DbaDbAsymmetricKey -SqlInstance $TestConfig.instance2 -Name $keyname -Database $database + $key2 = New-DbaDbAsymmetricKey -SqlInstance $TestConfig.instance2 -Name $keyname2 -Database $database + $results = Get-DbaDbAsymmetricKey -SqlInstance $TestConfig.instance2 -Database $database -WarningVariable warnvar It "Should created new keys in $database " { $warnvar | Should -BeNullOrEmpty $results | Should -HaveCount 2 } - $removeResults = Remove-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname -Database $database -confirm:$false - $getResults = Get-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Database $database + $removeResults = Remove-DbaDbAsymmetricKey -SqlInstance $TestConfig.instance2 -Name $keyname -Database $database -confirm:$false + $getResults = Get-DbaDbAsymmetricKey -SqlInstance $TestConfig.instance2 -Database $database It "Should Remove a specific certificate" { $getResults | Should -HaveCount 1 $getResults[0].Name | Should -Be $keyname2 $removeResults.Status | Should -Be 'Success' $removeResults.Name | Should -Be $keyname } - Remove-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname2 -Database $database -confirm:$false + Remove-DbaDbAsymmetricKey -SqlInstance $TestConfig.instance2 -Name $keyname2 -Database $database -confirm:$false } } + diff --git a/tests/Remove-DbaDbBackupRestoreHistory.Tests.ps1 b/tests/Remove-DbaDbBackupRestoreHistory.Tests.ps1 index 8089db0e4a..488774f2cc 100644 --- a/tests/Remove-DbaDbBackupRestoreHistory.Tests.ps1 +++ b/tests/Remove-DbaDbBackupRestoreHistory.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Remove-DbaDbCertificate.Tests.ps1 b/tests/Remove-DbaDbCertificate.Tests.ps1 index 67ee0db12e..968c88acc2 100644 --- a/tests/Remove-DbaDbCertificate.Tests.ps1 +++ b/tests/Remove-DbaDbCertificate.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,18 +16,18 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Can remove a database certificate" { BeforeAll { - if (-not (Get-DbaDbMasterKey -SqlInstance $script:instance1 -Database master)) { - $masterkey = New-DbaDbMasterKey -SqlInstance $script:instance1 -Database master -Password $(ConvertTo-SecureString -String "GoodPass1234!" -AsPlainText -Force) -Confirm:$false + if (-not (Get-DbaDbMasterKey -SqlInstance $TestConfig.instance1 -Database master)) { + $masterkey = New-DbaDbMasterKey -SqlInstance $TestConfig.instance1 -Database master -Password $(ConvertTo-SecureString -String "GoodPass1234!" -AsPlainText -Force) -Confirm:$false } } AfterAll { if ($masterKey) { $masterkey | Remove-DbaDbMasterKey -Confirm:$false } } - $results = New-DbaDbCertificate -SqlInstance $script:instance1 -Confirm:$false | Remove-DbaDbCertificate -Confirm:$false + $results = New-DbaDbCertificate -SqlInstance $TestConfig.instance1 -Confirm:$false | Remove-DbaDbCertificate -Confirm:$false It "Successfully removes database certificate in master" { "$($results.Status)" -match 'Success' | Should Be $true } } -} \ No newline at end of file +} diff --git a/tests/Remove-DbaDbCheckConstraint.Tests.ps1 b/tests/Remove-DbaDbCheckConstraint.Tests.ps1 index 2881441b6a..76838a26da 100644 --- a/tests/Remove-DbaDbCheckConstraint.Tests.ps1 +++ b/tests/Remove-DbaDbCheckConstraint.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,7 +16,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $dbname1 = "dbatoolsci_$(Get-Random)" $dbname2 = "dbatoolsci_$(Get-Random)" $null = New-DbaDatabase -SqlInstance $server -Name $dbname1 @@ -46,4 +46,4 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Get-DbaDbCheckConstraint -SqlInstance $server -Database $dbname2 | Should -BeNullOrEmpty } } -} \ No newline at end of file +} diff --git a/tests/Remove-DbaDbData.Tests.ps1 b/tests/Remove-DbaDbData.Tests.ps1 index cb503fc185..a410ddb231 100644 --- a/tests/Remove-DbaDbData.Tests.ps1 +++ b/tests/Remove-DbaDbData.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Validate parameters" { @@ -16,10 +16,10 @@ Describe "$CommandName Unit Tests" -Tags "UnitTests" { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $dbname1 = "dbatoolsci_$(Get-Random)" - $null = New-DbaDatabase -SqlInstance $script:instance2 -Name $dbname1 -Owner sa - Invoke-DbaQuery -SqlInstance $script:instance2 -Database $dbname1 -Query " + $null = New-DbaDatabase -SqlInstance $TestConfig.instance2 -Name $dbname1 -Owner sa + Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database $dbname1 -Query " create table dept ( deptid int identity(1,1) primary key, @@ -39,22 +39,22 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { " } AfterAll { - $null = Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbname1 -confirm:$false + $null = Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname1 -confirm:$false } Context "Functionality" { BeforeAll { - Invoke-DbaQuery -SqlInstance $script:instance2 -Database $dbname1 -Query " + Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database $dbname1 -Query " insert into dept values ('hr'); insert into emp values (1);" } It 'Removes Data for a specified database' { - Remove-DbaDbData -SqlInstance $script:instance2 -Database $dbname1 -Confirm:$false - (Invoke-DbaQuery -SqlInstance $script:instance2 -Database $dbname1 -Query 'Select count(*) as rwCnt from dept').rwCnt | Should Be 0 + Remove-DbaDbData -SqlInstance $TestConfig.instance2 -Database $dbname1 -Confirm:$false + (Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database $dbname1 -Query 'Select count(*) as rwCnt from dept').rwCnt | Should Be 0 } - $fkeys = Get-DbaDbForeignKey -SqlInstance $script:instance2 -Database $dbname1 + $fkeys = Get-DbaDbForeignKey -SqlInstance $TestConfig.instance2 -Database $dbname1 It 'Foreign Keys are recreated' { $fkeys.Name | Should Be 'FK_dept' } @@ -64,23 +64,23 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } It 'Views are recreated' { - (Get-DbaDbView -SqlInstance $script:instance2 -Database $dbname1 -ExcludeSystemView).Name | Should Be 'vw_emp' + (Get-DbaDbView -SqlInstance $TestConfig.instance2 -Database $dbname1 -ExcludeSystemView).Name | Should Be 'vw_emp' } } Context "Functionality - Pipe database" { BeforeAll { - Invoke-DbaQuery -SqlInstance $script:instance2 -Database $dbname1 -Query " + Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database $dbname1 -Query " insert into dept values ('hr'); insert into emp values (1);" } It 'Removes Data for a specified database' { - Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbname1 | Remove-DbaDbData -Confirm:$false - (Invoke-DbaQuery -SqlInstance $script:instance2 -Database $dbname1 -Query 'Select count(*) as rwCnt from dept').rwCnt | Should Be 0 + Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname1 | Remove-DbaDbData -Confirm:$false + (Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database $dbname1 -Query 'Select count(*) as rwCnt from dept').rwCnt | Should Be 0 } - $fkeys = Get-DbaDbForeignKey -SqlInstance $script:instance2 -Database $dbname1 + $fkeys = Get-DbaDbForeignKey -SqlInstance $TestConfig.instance2 -Database $dbname1 It 'Foreign Keys are recreated' { $fkeys.Name | Should Be 'FK_dept' } @@ -90,23 +90,23 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } It 'Views are recreated' { - (Get-DbaDbView -SqlInstance $script:instance2 -Database $dbname1 -ExcludeSystemView).Name | Should Be 'vw_emp' + (Get-DbaDbView -SqlInstance $TestConfig.instance2 -Database $dbname1 -ExcludeSystemView).Name | Should Be 'vw_emp' } } Context "Functionality - Pipe server" { BeforeAll { - Invoke-DbaQuery -SqlInstance $script:instance2 -Database $dbname1 -Query " + Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database $dbname1 -Query " insert into dept values ('hr'); insert into emp values (1);" } It 'Removes Data for a specified database' { - Connect-DbaInstance -SqlInstance $script:instance2 | Remove-DbaDbData -Database $dbname1 -Confirm:$false - (Invoke-DbaQuery -SqlInstance $script:instance2 -Database $dbname1 -Query 'Select count(*) as rwCnt from dept').rwCnt | Should Be 0 + Connect-DbaInstance -SqlInstance $TestConfig.instance2 | Remove-DbaDbData -Database $dbname1 -Confirm:$false + (Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database $dbname1 -Query 'Select count(*) as rwCnt from dept').rwCnt | Should Be 0 } - $fkeys = Get-DbaDbForeignKey -SqlInstance $script:instance2 -Database $dbname1 + $fkeys = Get-DbaDbForeignKey -SqlInstance $TestConfig.instance2 -Database $dbname1 It 'Foreign Keys are recreated' { $fkeys.Name | Should Be 'FK_dept' } @@ -116,7 +116,8 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } It 'Views are recreated' { - (Get-DbaDbView -SqlInstance $script:instance2 -Database $dbname1 -ExcludeSystemView).Name | Should Be 'vw_emp' + (Get-DbaDbView -SqlInstance $TestConfig.instance2 -Database $dbname1 -ExcludeSystemView).Name | Should Be 'vw_emp' } } } + diff --git a/tests/Remove-DbaDbEncryptionKey.Tests.ps1 b/tests/Remove-DbaDbEncryptionKey.Tests.ps1 index d64ce214f1..980637fa7e 100644 --- a/tests/Remove-DbaDbEncryptionKey.Tests.ps1 +++ b/tests/Remove-DbaDbEncryptionKey.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Validate parameters" { @@ -18,18 +18,18 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { $PSDefaultParameterValues["*:Confirm"] = $false $passwd = ConvertTo-SecureString "dbatools.IO" -AsPlainText -Force - $masterkey = Get-DbaDbMasterKey -SqlInstance $script:instance2 -Database master + $masterkey = Get-DbaDbMasterKey -SqlInstance $TestConfig.instance2 -Database master if (-not $masterkey) { $delmasterkey = $true - $masterkey = New-DbaServiceMasterKey -SqlInstance $script:instance2 -SecurePassword $passwd + $masterkey = New-DbaServiceMasterKey -SqlInstance $TestConfig.instance2 -SecurePassword $passwd } - $mastercert = Get-DbaDbCertificate -SqlInstance $script:instance2 -Database master | Where-Object Name -notmatch "##" | Select-Object -First 1 + $mastercert = Get-DbaDbCertificate -SqlInstance $TestConfig.instance2 -Database master | Where-Object Name -notmatch "##" | Select-Object -First 1 if (-not $mastercert) { $delmastercert = $true - $mastercert = New-DbaDbCertificate -SqlInstance $script:instance2 + $mastercert = New-DbaDbCertificate -SqlInstance $TestConfig.instance2 } - $db = New-DbaDatabase -SqlInstance $script:instance2 + $db = New-DbaDatabase -SqlInstance $TestConfig.instance2 $db | New-DbaDbMasterKey -SecurePassword $passwd $db | New-DbaDbCertificate $dbkey = $db | New-DbaDbEncryptionKey -Force @@ -56,10 +56,10 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } It "should remove encryption key on a database" { $null = $db | New-DbaDbEncryptionKey -Force - $results = Remove-DbaDbEncryptionKey -SqlInstance $script:instance2 -Database $db.Name + $results = Remove-DbaDbEncryptionKey -SqlInstance $TestConfig.instance2 -Database $db.Name $results.Status | Should -Be "Success" $db.Refresh() $db | Get-DbaDbEncryptionKey | Should -Be $null } } -} \ No newline at end of file +} diff --git a/tests/Remove-DbaDbFileGroup.Tests.ps1 b/tests/Remove-DbaDbFileGroup.Tests.ps1 index 2fde8cbd67..9758ca6364 100644 --- a/tests/Remove-DbaDbFileGroup.Tests.ps1 +++ b/tests/Remove-DbaDbFileGroup.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -26,10 +26,10 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $fileGroup5Name = "FG5" $fileGroup6Name = "FG6" - $server = Connect-DbaInstance -SqlInstance $script:instance2 - $newDb1 = New-DbaDatabase -SqlInstance $script:instance2 -Name $db1name - $newDb2 = New-DbaDatabase -SqlInstance $script:instance2 -Name $db2name - $newDb3 = New-DbaDatabase -SqlInstance $script:instance2 -Name $db3name + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 + $newDb1 = New-DbaDatabase -SqlInstance $TestConfig.instance2 -Name $db1name + $newDb2 = New-DbaDatabase -SqlInstance $TestConfig.instance2 -Name $db2name + $newDb3 = New-DbaDatabase -SqlInstance $TestConfig.instance2 -Name $db3name $server.Query("ALTER DATABASE $db1name ADD FILEGROUP $fileGroup1Name;") $server.Query("ALTER DATABASE $db2name ADD FILEGROUP $fileGroup1Name;") @@ -48,41 +48,41 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "ensure command works" { It "Removes filegroups" { - $results = Get-DbaDbFileGroup -SqlInstance $script:instance2 -Database $db1name, $db3name -FileGroup $fileGroup1Name, $fileGroup3Name + $results = Get-DbaDbFileGroup -SqlInstance $TestConfig.instance2 -Database $db1name, $db3name -FileGroup $fileGroup1Name, $fileGroup3Name $results.Length | Should -Be 3 - Remove-DbaDbFileGroup -SqlInstance $script:instance2 -Database $db1name, $db3name -FileGroup $fileGroup1Name, $fileGroup3Name -Confirm:$false - $results = Get-DbaDbFileGroup -SqlInstance $script:instance2 -Database $db1name, $db3name -FileGroup $fileGroup1Name, $fileGroup3Name + Remove-DbaDbFileGroup -SqlInstance $TestConfig.instance2 -Database $db1name, $db3name -FileGroup $fileGroup1Name, $fileGroup3Name -Confirm:$false + $results = Get-DbaDbFileGroup -SqlInstance $TestConfig.instance2 -Database $db1name, $db3name -FileGroup $fileGroup1Name, $fileGroup3Name $results | Should -BeNullOrEmpty } It "Tries to remove a non-existent filegroup" { - Remove-DbaDbFileGroup -SqlInstance $script:instance2 -Database $db1name -FileGroup invalidFileGroupName -Confirm:$false -WarningVariable warnings - $warnings | Should -BeLike "*Filegroup invalidFileGroupName does not exist in the database $db1name on $script:instance2" + Remove-DbaDbFileGroup -SqlInstance $TestConfig.instance2 -Database $db1name -FileGroup invalidFileGroupName -Confirm:$false -WarningVariable warnings + $warnings | Should -BeLike "*Filegroup invalidFileGroupName does not exist in the database $db1name on $($TestConfig.instance2)" } It "Tries to remove a filegroup that still has files" { - Remove-DbaDbFileGroup -SqlInstance $script:instance2 -Database $db1name -FileGroup $fileGroup2Name -Confirm:$false -WarningVariable warnings - $warnings | Should -BeLike "*Filegroup $fileGroup2Name is not empty. Before the filegroup can be dropped the files must be removed in $fileGroup2Name on $db1name on $script:instance2" + Remove-DbaDbFileGroup -SqlInstance $TestConfig.instance2 -Database $db1name -FileGroup $fileGroup2Name -Confirm:$false -WarningVariable warnings + $warnings | Should -BeLike "*Filegroup $fileGroup2Name is not empty. Before the filegroup can be dropped the files must be removed in $fileGroup2Name on $db1name on $($TestConfig.instance2)" } It "Removes a filegroup using a database from a pipeline and a filegroup from a pipeline" { - $results = Get-DbaDbFileGroup -SqlInstance $script:instance2 -Database $db2name -FileGroup $fileGroup1Name + $results = Get-DbaDbFileGroup -SqlInstance $TestConfig.instance2 -Database $db2name -FileGroup $fileGroup1Name $results.Length | Should -Be 1 $newDb2 | Remove-DbaDbFileGroup -FileGroup $fileGroup1Name -Confirm:$false - $results = Get-DbaDbFileGroup -SqlInstance $script:instance2 -Database $db2name -FileGroup $fileGroup1Name + $results = Get-DbaDbFileGroup -SqlInstance $TestConfig.instance2 -Database $db2name -FileGroup $fileGroup1Name $results | Should -BeNullOrEmpty - $results = Get-DbaDbFileGroup -SqlInstance $script:instance2 -Database $db1name -FileGroup $fileGroup4Name, $fileGroup5Name + $results = Get-DbaDbFileGroup -SqlInstance $TestConfig.instance2 -Database $db1name -FileGroup $fileGroup4Name, $fileGroup5Name $results.Length | Should -Be 2 $results[0], $newDb1 | Remove-DbaDbFileGroup -FileGroup $fileGroup5Name -Confirm:$false - $results = Get-DbaDbFileGroup -SqlInstance $script:instance2 -Database $db1name -FileGroup $fileGroup4Name, $fileGroup5Name + $results = Get-DbaDbFileGroup -SqlInstance $TestConfig.instance2 -Database $db1name -FileGroup $fileGroup4Name, $fileGroup5Name $results | Should -BeNullOrEmpty - $fileGroup6 = Get-DbaDbFileGroup -SqlInstance $script:instance2 -Database $db1name -FileGroup $fileGroup6Name + $fileGroup6 = Get-DbaDbFileGroup -SqlInstance $TestConfig.instance2 -Database $db1name -FileGroup $fileGroup6Name $fileGroup6 | Should -Not -BeNullOrEmpty $fileGroup6 | Remove-DbaDbFileGroup -Confirm:$false - $fileGroup6 = Get-DbaDbFileGroup -SqlInstance $script:instance2 -Database $db1name -FileGroup $fileGroup6Name + $fileGroup6 = Get-DbaDbFileGroup -SqlInstance $TestConfig.instance2 -Database $db1name -FileGroup $fileGroup6Name $fileGroup6 | Should -BeNullOrEmpty } } -} \ No newline at end of file +} diff --git a/tests/Remove-DbaDbLogShipping.Tests.ps1 b/tests/Remove-DbaDbLogShipping.Tests.ps1 index 137d2bcf88..482beb53a5 100644 --- a/tests/Remove-DbaDbLogShipping.Tests.ps1 +++ b/tests/Remove-DbaDbLogShipping.Tests.ps1 @@ -1,6 +1,6 @@ $commandname = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Validate parameters" { @@ -21,13 +21,13 @@ Describe "$CommandName Unit Tests" -Tags "UnitTests" { $localPath = 'C:\temp\logshipping' $networkPath = '\\localhost\c$\temp\logshipping' - $primaryServer = Connect-DbaInstance -SqlInstance $script:instance2 - $secondaryserver = Connect-DbaInstance -SqlInstance $script:instance2 + $primaryServer = Connect-DbaInstance -SqlInstance $TestConfig.instance2 + $secondaryserver = Connect-DbaInstance -SqlInstance $TestConfig.instance2 # Create the database if ($primaryServer.Databases.Name -notcontains $dbname) { $query = "CREATE DATABASE [$dbname]" - Invoke-DbaQuery -SqlInstance $script:instance2 -Database master -Query $query + Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database master -Query $query } if (-not (Test-Path -Path $localPath)) { @@ -37,8 +37,8 @@ Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Remove database from log shipping with remove secondary database" { $params = @{ - SourceSqlInstance = $script:instance2 - DestinationSqlInstance = $script:instance2 + SourceSqlInstance = $TestConfig.instance2 + DestinationSqlInstance = $TestConfig.instance2 Database = $dbname BackupNetworkPath = $networkPath BackupLocalPath = $localPath @@ -60,22 +60,22 @@ Describe "$CommandName Unit Tests" -Tags "UnitTests" { ON [pd].[primary_id] = [ps].[primary_id] WHERE pd.[primary_database] = '$dbname';" - $results = Invoke-DbaQuery -SqlInstance $script:instance2 -Database master -Query $query + $results = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database master -Query $query $results.PrimaryDatabase | Should -Be $dbname } # Remove the log shipping $params = @{ - PrimarySqlInstance = $script:instance2 - SecondarySqlInstance = $script:instance2 + PrimarySqlInstance = $TestConfig.instance2 + SecondarySqlInstance = $TestConfig.instance2 Database = $dbname } Remove-DbaDbLogShipping @params $primaryServer.Databases.Refresh() - $secondaryserver = Connect-DbaInstance -SqlInstance $script:instance2 + $secondaryserver = Connect-DbaInstance -SqlInstance $TestConfig.instance2 It "Should still have the secondary database" { "$($dbname)_LS" | Should -BeIn $secondaryserver.Databases.Name @@ -90,7 +90,7 @@ Describe "$CommandName Unit Tests" -Tags "UnitTests" { ON [pd].[primary_id] = [ps].[primary_id] WHERE pd.[primary_database] = '$dbname';" - $results = Invoke-DbaQuery -SqlInstance $script:instance2 -Database master -Query $query + $results = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database master -Query $query $results.PrimaryDatabase | Should -Be $null } @@ -98,8 +98,8 @@ Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Remove database from log shipping with remove secondary database" { $params = @{ - SourceSqlInstance = $script:instance2 - DestinationSqlInstance = $script:instance2 + SourceSqlInstance = $TestConfig.instance2 + DestinationSqlInstance = $TestConfig.instance2 Database = $dbname BackupNetworkPath = $networkPath BackupLocalPath = $localPath @@ -120,15 +120,15 @@ Describe "$CommandName Unit Tests" -Tags "UnitTests" { ON [pd].[primary_id] = [ps].[primary_id] WHERE pd.[primary_database] = '$dbname';" - $results = Invoke-DbaQuery -SqlInstance $script:instance2 -Database master -Query $query + $results = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database master -Query $query $results.PrimaryDatabase | Should -Be $dbname } # Remove the log shipping $params = @{ - PrimarySqlInstance = $script:instance2 - SecondarySqlInstance = $script:instance2 + PrimarySqlInstance = $TestConfig.instance2 + SecondarySqlInstance = $TestConfig.instance2 Database = $dbname RemoveSecondaryDatabase = $true } @@ -136,7 +136,7 @@ Describe "$CommandName Unit Tests" -Tags "UnitTests" { Remove-DbaDbLogShipping @params $primaryServer.Databases.Refresh() - $secondaryserver = Connect-DbaInstance -SqlInstance $script:instance2 + $secondaryserver = Connect-DbaInstance -SqlInstance $TestConfig.instance2 It "Should no longer have the secondary database" { "$($dbname)_LS" | Should -Not -BeIn $secondaryserver.Databases.Name @@ -151,9 +151,9 @@ Describe "$CommandName Unit Tests" -Tags "UnitTests" { ON [pd].[primary_id] = [ps].[primary_id] WHERE pd.[primary_database] = '$dbname';" - $results = Invoke-DbaQuery -SqlInstance $script:instance2 -Database master -Query $query + $results = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database master -Query $query $results.PrimaryDatabase | Should -Be $null } } -} #> \ No newline at end of file +} #> diff --git a/tests/Remove-DbaDbMailAccount.Tests.ps1 b/tests/Remove-DbaDbMailAccount.Tests.ps1 index 126f146729..b20b0a57d7 100644 --- a/tests/Remove-DbaDbMailAccount.Tests.ps1 +++ b/tests/Remove-DbaDbMailAccount.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,7 +16,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BeforeEach { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $accountname = "dbatoolsci_test_$(get-random)" $accountname2 = "dbatoolsci_test_$(get-random)" @@ -53,4 +53,4 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { (Get-DbaDbMailAccount -SqlInstance $server ) | Should -BeNullOrEmpty } } -} \ No newline at end of file +} diff --git a/tests/Remove-DbaDbMailProfile.Tests.ps1 b/tests/Remove-DbaDbMailProfile.Tests.ps1 index 9e8538d81e..1e444969c8 100644 --- a/tests/Remove-DbaDbMailProfile.Tests.ps1 +++ b/tests/Remove-DbaDbMailProfile.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,7 +16,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BeforeEach { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $profilename = "dbatoolsci_test_$(get-random)" $profilename2 = "dbatoolsci_test_$(get-random)" @@ -53,4 +53,4 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { (Get-DbaDbMailProfile -SqlInstance $server ) | Should -BeNullOrEmpty } } -} \ No newline at end of file +} diff --git a/tests/Remove-DbaDbMasterKey.Tests.ps1 b/tests/Remove-DbaDbMasterKey.Tests.ps1 index 25e83c13b0..3b21695f45 100644 --- a/tests/Remove-DbaDbMasterKey.Tests.ps1 +++ b/tests/Remove-DbaDbMasterKey.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Remove-DbaDbMirror.Tests.ps1 b/tests/Remove-DbaDbMirror.Tests.ps1 index d6a2e85cf7..029584ed7a 100644 --- a/tests/Remove-DbaDbMirror.Tests.ps1 +++ b/tests/Remove-DbaDbMirror.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Remove-DbaDbMirrorMonitor.Tests.ps1 b/tests/Remove-DbaDbMirrorMonitor.Tests.ps1 index eed85ac91c..5d7cb9c91d 100644 --- a/tests/Remove-DbaDbMirrorMonitor.Tests.ps1 +++ b/tests/Remove-DbaDbMirrorMonitor.Tests.ps1 @@ -1,6 +1,6 @@ $commandname = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Validate parameters" { @@ -15,22 +15,22 @@ Describe "$CommandName Unit Tests" -Tags "UnitTests" { Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $db = Get-DbaDatabase -SqlInstance $script:instance2 -Database msdb + $db = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database msdb if (($db.Tables['dbm_monitor_data'].Name)) { $putback = $true } else { - $null = Add-DbaDbMirrorMonitor -SqlInstance $script:instance2 -WarningAction SilentlyContinue + $null = Add-DbaDbMirrorMonitor -SqlInstance $TestConfig.instance2 -WarningAction SilentlyContinue } } AfterAll { if ($putback) { # add it back - $results = Add-DbaDbMirrorMonitor -SqlInstance $script:instance2 -WarningAction SilentlyContinue + $results = Add-DbaDbMirrorMonitor -SqlInstance $TestConfig.instance2 -WarningAction SilentlyContinue } } It "removes the mirror monitor" { - $results = Remove-DbaDbMirrorMonitor -SqlInstance $script:instance2 -WarningAction SilentlyContinue + $results = Remove-DbaDbMirrorMonitor -SqlInstance $TestConfig.instance2 -WarningAction SilentlyContinue $results.MonitorStatus | Should -Be 'Removed' } -} \ No newline at end of file +} diff --git a/tests/Remove-DbaDbOrphanUser.Tests.ps1 b/tests/Remove-DbaDbOrphanUser.Tests.ps1 index 55f4b97420..4f90be89b6 100644 --- a/tests/Remove-DbaDbOrphanUser.Tests.ps1 +++ b/tests/Remove-DbaDbOrphanUser.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,7 +15,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $random = Get-Random $dbname = "dbatoolsci_$random" $login1 = "dbatoolssci_user1_$random" @@ -28,41 +28,41 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $loginWindows = "db$random" - $null = Invoke-Command2 -ScriptBlock { net user $args[0] $args[1] /add *>&1 } -ArgumentList $loginWindows, $plaintext -ComputerName $script:instance2 + $null = Invoke-Command2 -ScriptBlock { net user $args[0] $args[1] /add *>&1 } -ArgumentList $loginWindows, $plaintext -ComputerName $TestConfig.instance2 } BeforeEach { - $null = New-DbaLogin -SqlInstance $script:instance2 -Login $login1 -Password $securePassword -Force - $null = New-DbaLogin -SqlInstance $script:instance2 -Login $login2 -Password $securePassword -Force - $null = New-DbaLogin -SqlInstance $script:instance2 -Login "$($script:instance2)\$loginWindows" -Force - - $null = New-DbaDbUser -SqlInstance $script:instance2 -Database $dbname -Login $login1 -Username $login1 - $null = New-DbaDbUser -SqlInstance $script:instance2 -Database $dbname -Login $login2 -Username $login2 - $null = New-DbaDbUser -SqlInstance $script:instance2 -Database $dbname -Login "$($script:instance2)\$loginWindows" -Username "$($script:instance2)\$loginWindows" - $null = New-DbaDbUser -SqlInstance $script:instance2 -Database msdb -Login $login1 -Username $login1 -IncludeSystem - $null = New-DbaDbUser -SqlInstance $script:instance2 -Database msdb -Login $login2 -Username $login2 -IncludeSystem - $null = Remove-DbaLogin -SqlInstance $script:instance2 -Login $login1 -Confirm:$false - $null = Remove-DbaLogin -SqlInstance $script:instance2 -Login $login2 -Confirm:$false - $null = Remove-DbaLogin -SqlInstance $script:instance2 -Login "$($script:instance2)\$loginWindows" -Confirm:$false + $null = New-DbaLogin -SqlInstance $TestConfig.instance2 -Login $login1 -Password $securePassword -Force + $null = New-DbaLogin -SqlInstance $TestConfig.instance2 -Login $login2 -Password $securePassword -Force + $null = New-DbaLogin -SqlInstance $TestConfig.instance2 -Login "$($TestConfig.instance2)\$loginWindows" -Force + + $null = New-DbaDbUser -SqlInstance $TestConfig.instance2 -Database $dbname -Login $login1 -Username $login1 + $null = New-DbaDbUser -SqlInstance $TestConfig.instance2 -Database $dbname -Login $login2 -Username $login2 + $null = New-DbaDbUser -SqlInstance $TestConfig.instance2 -Database $dbname -Login "$($TestConfig.instance2)\$loginWindows" -Username "$($TestConfig.instance2)\$loginWindows" + $null = New-DbaDbUser -SqlInstance $TestConfig.instance2 -Database msdb -Login $login1 -Username $login1 -IncludeSystem + $null = New-DbaDbUser -SqlInstance $TestConfig.instance2 -Database msdb -Login $login2 -Username $login2 -IncludeSystem + $null = Remove-DbaLogin -SqlInstance $TestConfig.instance2 -Login $login1 -Confirm:$false + $null = Remove-DbaLogin -SqlInstance $TestConfig.instance2 -Login $login2 -Confirm:$false + $null = Remove-DbaLogin -SqlInstance $TestConfig.instance2 -Login "$($TestConfig.instance2)\$loginWindows" -Confirm:$false } AfterEach { - $users = Get-DbaDbUser -SqlInstance $script:instance2 -Database $dbname, msdb + $users = Get-DbaDbUser -SqlInstance $TestConfig.instance2 -Database $dbname, msdb if ($users.Name -contains $login1) { - $null = Remove-DbaDbUser $script:instance2 -Database $dbname, msdb -User $login1 + $null = Remove-DbaDbUser $TestConfig.instance2 -Database $dbname, msdb -User $login1 } if ($users.Name -contains $login2) { - $null = Remove-DbaDbUser $script:instance2 -Database $dbname, msdb -User $login2 + $null = Remove-DbaDbUser $TestConfig.instance2 -Database $dbname, msdb -User $login2 } } AfterAll { - $null = Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbname -confirm:$false - $null = Invoke-Command2 -ScriptBlock { net user $args /delete *>&1 } -ArgumentList $loginWindows -ComputerName $script:instance2 + $null = Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname -confirm:$false + $null = Invoke-Command2 -ScriptBlock { net user $args /delete *>&1 } -ArgumentList $loginWindows -ComputerName $TestConfig.instance2 } It "Removes Orphan Users" { - $results0 = Get-DbaDbUser -SqlInstance $script:instance2 -Database $dbname, msdb + $results0 = Get-DbaDbUser -SqlInstance $TestConfig.instance2 -Database $dbname, msdb - $null = Remove-DbaDbOrphanUser -SqlInstance $script:instance2 - $results1 = Get-DbaDbUser -SqlInstance $script:instance2 -Database $dbname, msdb + $null = Remove-DbaDbOrphanUser -SqlInstance $TestConfig.instance2 + $results1 = Get-DbaDbUser -SqlInstance $TestConfig.instance2 -Database $dbname, msdb $results0.Name -contains $login1 | Should Be $true $results0.Name -contains $login2 | Should Be $true @@ -70,10 +70,10 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } It "Removes selected Orphan Users" { - $results0 = Get-DbaDbUser -SqlInstance $script:instance2 -Database $dbname, msdb + $results0 = Get-DbaDbUser -SqlInstance $TestConfig.instance2 -Database $dbname, msdb - $null = Remove-DbaDbOrphanUser -SqlInstance $script:instance2 -User $login1 - $results1 = Get-DbaDbUser -SqlInstance $script:instance2 -Database $dbname, msdb + $null = Remove-DbaDbOrphanUser -SqlInstance $TestConfig.instance2 -User $login1 + $results1 = Get-DbaDbUser -SqlInstance $TestConfig.instance2 -Database $dbname, msdb $results0.Count | Should BeGreaterThan $results1.Count $results1.Name -contains $login1 | Should Be $false @@ -81,8 +81,8 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } It "Removes Orphan Users for Database" { - $null = Remove-DbaDbOrphanUser -SqlInstance $script:instance2 -Database msdb -User $login1, $login2 - $results1 = Get-DbaDbUser -SqlInstance $script:instance2 -Database $dbname, msdb + $null = Remove-DbaDbOrphanUser -SqlInstance $TestConfig.instance2 -Database msdb -User $login1, $login2 + $results1 = Get-DbaDbUser -SqlInstance $TestConfig.instance2 -Database $dbname, msdb $results1 = $results1 | Where-Object { $_.Name -eq $login1 -or $_.Name -eq $login2 } $results1.Name -contains $login1 | Should Be $true @@ -93,8 +93,8 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } It "Removes Orphan Users except for excluded databases" { - $null = Remove-DbaDbOrphanUser -SqlInstance $script:instance2 -ExcludeDatabase msdb -User $login1, $login2 - $results1 = Get-DbaDbUser -SqlInstance $script:instance2 -Database $dbname, msdb + $null = Remove-DbaDbOrphanUser -SqlInstance $TestConfig.instance2 -ExcludeDatabase msdb -User $login1, $login2 + $results1 = Get-DbaDbUser -SqlInstance $TestConfig.instance2 -Database $dbname, msdb $results1 = $results1 | Where-Object { $_.Name -eq $login1 -or $_.Name -eq $login2 } $results1.Name -contains $login1 | Should Be $true @@ -104,18 +104,18 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } It "Removes Orphan Users with unmapped logins if force specified" { - $null = New-DbaLogin -SqlInstance $script:instance2 -Login $login1 -Password $securePassword -Force - $null = New-DbaLogin -SqlInstance $script:instance2 -Login $login2 -Password $securePassword -Force + $null = New-DbaLogin -SqlInstance $TestConfig.instance2 -Login $login1 -Password $securePassword -Force + $null = New-DbaLogin -SqlInstance $TestConfig.instance2 -Login $login2 -Password $securePassword -Force - $null = Remove-DbaDbOrphanUser -SqlInstance $script:instance2 -User $login1 -Force - $null = Remove-DbaDbOrphanUser -SqlInstance $script:instance2 -User $login2 - $results1 = Get-DbaDbUser -SqlInstance $script:instance2 -Database $dbname, msdb + $null = Remove-DbaDbOrphanUser -SqlInstance $TestConfig.instance2 -User $login1 -Force + $null = Remove-DbaDbOrphanUser -SqlInstance $TestConfig.instance2 -User $login2 + $results1 = Get-DbaDbUser -SqlInstance $TestConfig.instance2 -Database $dbname, msdb $results1.Name -contains $login1 | Should Be $false $results1.Name -contains $login2 | Should Be $true - $null = Remove-DbaLogin -SqlInstance $script:instance2 -Login $login1 -Confirm:$false - $null = Remove-DbaLogin -SqlInstance $script:instance2 -Login $login2 -Confirm:$false + $null = Remove-DbaLogin -SqlInstance $TestConfig.instance2 -Login $login1 -Confirm:$false + $null = Remove-DbaLogin -SqlInstance $TestConfig.instance2 -Login $login2 -Confirm:$false } @@ -123,8 +123,8 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $sql = "CREATE SCHEMA $schema AUTHORIZATION $login2" $server.Query($sql, $dbname) - $null = Remove-DbaDbOrphanUser -SqlInstance $script:instance2 -Database $dbname, msdb -User $login1, $login2 -Force - $results1 = Get-DbaDbUser -SqlInstance $script:instance2 -Database $dbname, msdb + $null = Remove-DbaDbOrphanUser -SqlInstance $TestConfig.instance2 -Database $dbname, msdb -User $login1, $login2 -Force + $results1 = Get-DbaDbUser -SqlInstance $TestConfig.instance2 -Database $dbname, msdb $results1.Name -contains $login1 | Should Be $false $results1.Name -contains $login2 | Should Be $false @@ -143,9 +143,9 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $sql = "CREATE TABLE [$login2].test2(Id int NULL)" $server.Query($sql, $dbname) - $null = Remove-DbaDbOrphanUser -SqlInstance $script:instance2 -Database $dbname -User $login1 - $null = Remove-DbaDbOrphanUser -SqlInstance $script:instance2 -Database $dbname -User $login2 -Force - $results1 = Get-DbaDbUser -SqlInstance $script:instance2 -Database $dbname + $null = Remove-DbaDbOrphanUser -SqlInstance $TestConfig.instance2 -Database $dbname -User $login1 + $null = Remove-DbaDbOrphanUser -SqlInstance $TestConfig.instance2 -Database $dbname -User $login2 -Force + $results1 = Get-DbaDbUser -SqlInstance $TestConfig.instance2 -Database $dbname $results1.Name -contains $login1 | Should Be $true $results1.Name -contains $login2 | Should Be $false @@ -155,8 +155,8 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } It "Removes the orphaned windows login" { - $null = Remove-DbaDbOrphanUser -SqlInstance $script:instance2 -Database $dbname -User "$($script:instance2)\$loginWindows" - $results1 = Get-DbaDbUser -SqlInstance $script:instance2 -Database $dbname + $null = Remove-DbaDbOrphanUser -SqlInstance $TestConfig.instance2 -Database $dbname -User "$($TestConfig.instance2)\$loginWindows" + $results1 = Get-DbaDbUser -SqlInstance $TestConfig.instance2 -Database $dbname $results1.Name -contains $loginWindows | Should -Be $false } -} \ No newline at end of file +} diff --git a/tests/Remove-DbaDbPartitionFunction.Tests.ps1 b/tests/Remove-DbaDbPartitionFunction.Tests.ps1 index dc90d37b2b..4787de413b 100644 --- a/tests/Remove-DbaDbPartitionFunction.Tests.ps1 +++ b/tests/Remove-DbaDbPartitionFunction.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,7 +16,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $dbname1 = "dbatoolsci_$(Get-Random)" $dbname2 = "dbatoolsci_$(Get-Random)" $null = New-DbaDatabase -SqlInstance $server -Name $dbname1 @@ -46,4 +46,4 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Get-DbaDbPartitionFunction -SqlInstance $server -Database $dbname2 | Should -BeNullOrEmpty } } -} \ No newline at end of file +} diff --git a/tests/Remove-DbaDbPartitionScheme.Tests.ps1 b/tests/Remove-DbaDbPartitionScheme.Tests.ps1 index b6a8ae4ee3..1c6283a71f 100644 --- a/tests/Remove-DbaDbPartitionScheme.Tests.ps1 +++ b/tests/Remove-DbaDbPartitionScheme.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,7 +16,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $dbname1 = "dbatoolsci_$(Get-Random)" $dbname2 = "dbatoolsci_$(Get-Random)" $null = New-DbaDatabase -SqlInstance $server -Name $dbname1 @@ -48,4 +48,4 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Get-DbaDbPartitionScheme -SqlInstance $server -Database $dbname2 | Should -BeNullOrEmpty } } -} \ No newline at end of file +} diff --git a/tests/Remove-DbaDbRole.Tests.ps1 b/tests/Remove-DbaDbRole.Tests.ps1 index 8a6be953c8..ac60d083d4 100644 --- a/tests/Remove-DbaDbRole.Tests.ps1 +++ b/tests/Remove-DbaDbRole.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Validate parameters" { @@ -15,23 +15,23 @@ Describe "$CommandName Unit Tests" -Tags "UnitTests" { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $role1 = "dbatoolssci_role1_$(Get-Random)" $role2 = "dbatoolssci_role2_$(Get-Random)" $dbname1 = "dbatoolsci_$(Get-Random)" - $null = New-DbaDatabase -SqlInstance $script:instance2 -Name $dbname1 -Owner sa + $null = New-DbaDatabase -SqlInstance $TestConfig.instance2 -Name $dbname1 -Owner sa } AfterAll { - $null = Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbname1 -confirm:$false + $null = Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname1 -confirm:$false } Context "Functionality" { It 'Removes Non Fixed Roles' { $null = $server.Query("CREATE ROLE $role1", $dbname1) $null = $server.Query("CREATE ROLE $role2", $dbname1) - $result0 = Get-DbaDbRole -SqlInstance $script:instance2 -Database $dbname1 - Remove-DbaDbRole -SqlInstance $script:instance2 -Database $dbname1 -confirm:$false - $result1 = Get-DbaDbRole -SqlInstance $script:instance2 -Database $dbname1 + $result0 = Get-DbaDbRole -SqlInstance $TestConfig.instance2 -Database $dbname1 + Remove-DbaDbRole -SqlInstance $TestConfig.instance2 -Database $dbname1 -confirm:$false + $result1 = Get-DbaDbRole -SqlInstance $TestConfig.instance2 -Database $dbname1 $result0.Count | Should BeGreaterThan $result1.Count $result1.Name -contains $role1 | Should Be $false @@ -41,9 +41,9 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { It 'Accepts a list of roles' { $null = $server.Query("CREATE ROLE $role1", $dbname1) $null = $server.Query("CREATE ROLE $role2", $dbname1) - $result0 = Get-DbaDbRole -SqlInstance $script:instance2 -Database $dbname1 - Remove-DbaDbRole -SqlInstance $script:instance2 -Database $dbname1 -Role $role1 -confirm:$false - $result1 = Get-DbaDbRole -SqlInstance $script:instance2 -Database $dbname1 + $result0 = Get-DbaDbRole -SqlInstance $TestConfig.instance2 -Database $dbname1 + Remove-DbaDbRole -SqlInstance $TestConfig.instance2 -Database $dbname1 -Role $role1 -confirm:$false + $result1 = Get-DbaDbRole -SqlInstance $TestConfig.instance2 -Database $dbname1 $result0.Count | Should BeGreaterThan $result1.Count $result1.Name -contains $role1 | Should Be $false @@ -51,9 +51,9 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } It 'Excludes databases Roles' { $null = $server.Query("CREATE ROLE $role1", $dbname1) - $result0 = Get-DbaDbRole -SqlInstance $script:instance2 -Database $dbname1 - Remove-DbaDbRole -SqlInstance $script:instance2 -Database $dbname1 -ExcludeRole $role1 -confirm:$false - $result1 = Get-DbaDbRole -SqlInstance $script:instance2 -Database $dbname1 + $result0 = Get-DbaDbRole -SqlInstance $TestConfig.instance2 -Database $dbname1 + Remove-DbaDbRole -SqlInstance $TestConfig.instance2 -Database $dbname1 -ExcludeRole $role1 -confirm:$false + $result1 = Get-DbaDbRole -SqlInstance $TestConfig.instance2 -Database $dbname1 $result0.Count | Should BeGreaterThan $result1.Count $result1.Name -contains $role1 | Should Be $true @@ -61,21 +61,21 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } It 'Excepts input from Get-DbaDbRole' { - $result0 = Get-DbaDbRole -SqlInstance $script:instance2 -Database $dbname1 -Role $role2 + $result0 = Get-DbaDbRole -SqlInstance $TestConfig.instance2 -Database $dbname1 -Role $role2 $result0 | Remove-DbaDbRole -confirm:$false - $result1 = Get-DbaDbRole -SqlInstance $script:instance2 -Database $dbname1 + $result1 = Get-DbaDbRole -SqlInstance $TestConfig.instance2 -Database $dbname1 $result1.Name -contains $role2 | Should Be $false } It 'Removes roles in System DB' { $null = $server.Query("CREATE ROLE $role1", 'msdb') - $result0 = Get-DbaDbRole -SqlInstance $script:instance2 -Database msdb - Remove-DbaDbRole -SqlInstance $script:instance2 -Database msdb -Role $role1 -IncludeSystemDbs -confirm:$false - $result1 = Get-DbaDbRole -SqlInstance $script:instance2 -Database msdb + $result0 = Get-DbaDbRole -SqlInstance $TestConfig.instance2 -Database msdb + Remove-DbaDbRole -SqlInstance $TestConfig.instance2 -Database msdb -Role $role1 -IncludeSystemDbs -confirm:$false + $result1 = Get-DbaDbRole -SqlInstance $TestConfig.instance2 -Database msdb $result0.Count | Should BeGreaterThan $result1.Count $result1.Name -contains $role1 | Should Be $false } } -} \ No newline at end of file +} diff --git a/tests/Remove-DbaDbRoleMember.Tests.ps1 b/tests/Remove-DbaDbRoleMember.Tests.ps1 index 3c8c4cf6f3..e5baca9fc6 100644 --- a/tests/Remove-DbaDbRoleMember.Tests.ps1 +++ b/tests/Remove-DbaDbRoleMember.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Validate parameters" { @@ -16,18 +16,18 @@ Describe "$CommandName Unit Tests" -Tags "UnitTests" { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $user1 = "dbatoolssci_user1_$(Get-Random)" $user2 = "dbatoolssci_user2_$(Get-Random)" $role = "dbatoolssci_role_$(Get-Random)" - $null = New-DbaLogin -SqlInstance $script:instance2 -Login $user1 -Password ('Password1234!' | ConvertTo-SecureString -asPlainText -Force) - $null = New-DbaLogin -SqlInstance $script:instance2 -Login $user2 -Password ('Password1234!' | ConvertTo-SecureString -asPlainText -Force) + $null = New-DbaLogin -SqlInstance $TestConfig.instance2 -Login $user1 -Password ('Password1234!' | ConvertTo-SecureString -asPlainText -Force) + $null = New-DbaLogin -SqlInstance $TestConfig.instance2 -Login $user2 -Password ('Password1234!' | ConvertTo-SecureString -asPlainText -Force) $dbname = "dbatoolsci_$(Get-Random)" - $null = New-DbaDatabase -SqlInstance $script:instance2 -Name $dbname -Owner sa - $null = New-DbaDbUser -SqlInstance $script:instance2 -Database $dbname -Login $user1 -Username 'User1' - $null = New-DbaDbUser -SqlInstance $script:instance2 -Database $dbname -Login $user2 -Username 'User2' - $null = New-DbaDbUser -SqlInstance $script:instance2 -Database msdb -Login $user1 -Username 'User1' -IncludeSystem - $null = New-DbaDbUser -SqlInstance $script:instance2 -Database msdb -Login $user2 -Username 'User2' -IncludeSystem + $null = New-DbaDatabase -SqlInstance $TestConfig.instance2 -Name $dbname -Owner sa + $null = New-DbaDbUser -SqlInstance $TestConfig.instance2 -Database $dbname -Login $user1 -Username 'User1' + $null = New-DbaDbUser -SqlInstance $TestConfig.instance2 -Database $dbname -Login $user2 -Username 'User2' + $null = New-DbaDbUser -SqlInstance $TestConfig.instance2 -Database msdb -Login $user1 -Username 'User1' -IncludeSystem + $null = New-DbaDbUser -SqlInstance $TestConfig.instance2 -Database msdb -Login $user2 -Username 'User2' -IncludeSystem $null = $server.Query("CREATE ROLE $role", $dbname) $null = $server.Query("ALTER ROLE $role ADD MEMBER User1", $dbname) @@ -37,19 +37,19 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $null = $server.Query("ALTER ROLE SQLAgentReaderRole ADD MEMBER User2", 'msdb') } AfterAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $null = $server.Query("DROP USER User1", 'msdb') $null = $server.Query("DROP USER User2", 'msdb') - $null = Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbname -confirm:$false - $null = Remove-DbaLogin -SqlInstance $script:instance2 -Login $user1, $user2 -confirm:$false + $null = Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname -confirm:$false + $null = Remove-DbaLogin -SqlInstance $TestConfig.instance2 -Login $user1, $user2 -confirm:$false } Context "Functionality" { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 It 'Removes Role for User' { - $roleDB = Get-DbaDbRoleMember -SqlInstance $script:instance2 -Database $dbname -Role $role - Remove-DbaDbRoleMember -SqlInstance $script:instance2 -Role $role -User 'User1' -Database $dbname -confirm:$false + $roleDB = Get-DbaDbRoleMember -SqlInstance $TestConfig.instance2 -Database $dbname -Role $role + Remove-DbaDbRoleMember -SqlInstance $TestConfig.instance2 -Role $role -User 'User1' -Database $dbname -confirm:$false $roleDBAfter = Get-DbaDbRoleMember -SqlInstance $server -Database $dbname -Role $role $roleDB.UserName | Should Be 'User1' @@ -78,4 +78,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $roleDBAfter.UserName -contains 'User2' | Should Be $false } } -} \ No newline at end of file +} diff --git a/tests/Remove-DbaDbSchema.Tests.ps1 b/tests/Remove-DbaDbSchema.Tests.ps1 index f532a3b434..4eb7081486 100644 --- a/tests/Remove-DbaDbSchema.Tests.ps1 +++ b/tests/Remove-DbaDbSchema.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,8 +16,8 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BeforeAll { $random = Get-Random - $server1 = Connect-DbaInstance -SqlInstance $script:instance1 - $server2 = Connect-DbaInstance -SqlInstance $script:instance2 + $server1 = Connect-DbaInstance -SqlInstance $TestConfig.instance1 + $server2 = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $null = Get-DbaProcess -SqlInstance $server1, $server2 | Where-Object Program -match dbatools | Stop-DbaProcess -Confirm:$false $newDbName = "dbatoolsci_newdb_$random" $newDbs = New-DbaDatabase -SqlInstance $server1, $server2 -Name $newDbName @@ -60,4 +60,4 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { (Get-DbaDbSchema -SqlInstance $server1 -Database $newDbName -Schema TestSchema1) | Should -BeNullOrEmpty } } -} \ No newline at end of file +} diff --git a/tests/Remove-DbaDbSequence.Tests.ps1 b/tests/Remove-DbaDbSequence.Tests.ps1 index 41e8c2a9bd..e6a14e174a 100644 --- a/tests/Remove-DbaDbSequence.Tests.ps1 +++ b/tests/Remove-DbaDbSequence.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,7 +16,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BeforeAll { $random = Get-Random - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $newDbName = "dbatoolsci_newdb_$random" $null = New-DbaDatabase -SqlInstance $server -Name $newDbName @@ -42,4 +42,4 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { (Get-DbaDbSequence -SqlInstance $server -Database $newDbName -Sequence "Sequence2_$random" -Schema "Schema_$random") | Should -BeNullOrEmpty } } -} \ No newline at end of file +} diff --git a/tests/Remove-DbaDbSnapshot.Tests.ps1 b/tests/Remove-DbaDbSnapshot.Tests.ps1 index 22820414cd..bb3e9ebb2e 100644 --- a/tests/Remove-DbaDbSnapshot.Tests.ps1 +++ b/tests/Remove-DbaDbSnapshot.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,67 +16,67 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { # Targets only instance2 because it's the only one where Snapshots can happen Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { - Get-DbaProcess -SqlInstance $script:instance2 | Where-Object Program -match dbatools | Stop-DbaProcess -Confirm:$false -WarningAction SilentlyContinue - $server = Connect-DbaInstance -SqlInstance $script:instance2 + Get-DbaProcess -SqlInstance $TestConfig.instance2 | Where-Object Program -match dbatools | Stop-DbaProcess -Confirm:$false -WarningAction SilentlyContinue + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $db1 = "dbatoolsci_RemoveSnap" $db1_snap1 = "dbatoolsci_RemoveSnap_snapshotted1" $db1_snap2 = "dbatoolsci_RemoveSnap_snapshotted2" $db2 = "dbatoolsci_RemoveSnap2" $db2_snap1 = "dbatoolsci_RemoveSnap2_snapshotted" - Remove-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db1, $db2 -Confirm:$false - Get-DbaDatabase -SqlInstance $script:instance2 -Database $db1, $db2 | Remove-DbaDatabase -Confirm:$false + Remove-DbaDbSnapshot -SqlInstance $TestConfig.instance2 -Database $db1, $db2 -Confirm:$false + Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $db1, $db2 | Remove-DbaDatabase -Confirm:$false $server.Query("CREATE DATABASE $db1") $server.Query("CREATE DATABASE $db2") } AfterAll { - Remove-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db1, $db2 -Confirm:$false -ErrorAction SilentlyContinue - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance2 -Database $db1, $db2 -ErrorAction SilentlyContinue + Remove-DbaDbSnapshot -SqlInstance $TestConfig.instance2 -Database $db1, $db2 -Confirm:$false -ErrorAction SilentlyContinue + Remove-DbaDatabase -Confirm:$false -SqlInstance $TestConfig.instance2 -Database $db1, $db2 -ErrorAction SilentlyContinue } Context "Parameters validation" { It "Stops if no Database or AllDatabases" { - { Remove-DbaDbSnapshot -SqlInstance $script:instance2 -EnableException -WarningAction SilentlyContinue } | Should Throw "You must pipe" + { Remove-DbaDbSnapshot -SqlInstance $TestConfig.instance2 -EnableException -WarningAction SilentlyContinue } | Should Throw "You must pipe" } It "Is nice by default" { - { Remove-DbaDbSnapshot -SqlInstance $script:instance2 *> $null } | Should Not Throw "You must pipe" + { Remove-DbaDbSnapshot -SqlInstance $TestConfig.instance2 *> $null } | Should Not Throw "You must pipe" } } Context "Operations on snapshots" { BeforeEach { - $null = New-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db1 -Name $db1_snap1 -ErrorAction SilentlyContinue - $null = New-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db1 -Name $db1_snap2 -ErrorAction SilentlyContinue - $null = New-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db2 -Name $db2_snap1 -ErrorAction SilentlyContinue + $null = New-DbaDbSnapshot -SqlInstance $TestConfig.instance2 -Database $db1 -Name $db1_snap1 -ErrorAction SilentlyContinue + $null = New-DbaDbSnapshot -SqlInstance $TestConfig.instance2 -Database $db1 -Name $db1_snap2 -ErrorAction SilentlyContinue + $null = New-DbaDbSnapshot -SqlInstance $TestConfig.instance2 -Database $db2 -Name $db2_snap1 -ErrorAction SilentlyContinue } AfterEach { - Remove-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db1, $db2 -Confirm:$false -ErrorAction SilentlyContinue + Remove-DbaDbSnapshot -SqlInstance $TestConfig.instance2 -Database $db1, $db2 -Confirm:$false -ErrorAction SilentlyContinue } It "Honors the Database parameter, dropping only snapshots of that database" { - $results = Remove-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db1 -Confirm:$false + $results = Remove-DbaDbSnapshot -SqlInstance $TestConfig.instance2 -Database $db1 -Confirm:$false $results.Count | Should Be 2 - $result = Remove-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db2 -Confirm:$false + $result = Remove-DbaDbSnapshot -SqlInstance $TestConfig.instance2 -Database $db2 -Confirm:$false $result.Name | Should Be $db2_snap1 } It "Honors the ExcludeDatabase parameter, returning relevant snapshots" { - $alldbs = (Get-DbaDatabase -SqlInstance $script:instance2 | Where-Object IsDatabaseSnapShot -eq $false | Where-Object Name -notin @($db1, $db2)).Name - $results = Remove-DbaDbSnapshot -SqlInstance $script:instance2 -ExcludeDatabase $alldbs -Confirm:$false + $alldbs = (Get-DbaDatabase -SqlInstance $TestConfig.instance2 | Where-Object IsDatabaseSnapShot -eq $false | Where-Object Name -notin @($db1, $db2)).Name + $results = Remove-DbaDbSnapshot -SqlInstance $TestConfig.instance2 -ExcludeDatabase $alldbs -Confirm:$false $results.Count | Should Be 3 } It "Honors the Snapshot parameter" { - $result = Remove-DbaDbSnapshot -SqlInstance $script:instance2 -Snapshot $db1_snap1 -Confirm:$false + $result = Remove-DbaDbSnapshot -SqlInstance $TestConfig.instance2 -Snapshot $db1_snap1 -Confirm:$false $result.Name | Should Be $db1_snap1 } It "Works with piped snapshots" { - $result = Get-DbaDbSnapshot -SqlInstance $script:instance2 -Snapshot $db1_snap1 | Remove-DbaDbSnapshot -Confirm:$false + $result = Get-DbaDbSnapshot -SqlInstance $TestConfig.instance2 -Snapshot $db1_snap1 | Remove-DbaDbSnapshot -Confirm:$false $result.Name | Should Be $db1_snap1 - $result = Get-DbaDbSnapshot -SqlInstance $script:instance2 -Snapshot $db1_snap1 + $result = Get-DbaDbSnapshot -SqlInstance $TestConfig.instance2 -Snapshot $db1_snap1 $result | Should Be $null } It "Has the correct default properties" { - $result = Remove-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db2 -Confirm:$false + $result = Remove-DbaDbSnapshot -SqlInstance $TestConfig.instance2 -Database $db2 -Confirm:$false $ExpectedPropsDefault = 'ComputerName', 'Name', 'InstanceName', 'SqlInstance', 'Status' ($result.PSStandardMembers.DefaultDisplayPropertySet.ReferencedPropertyNames | Sort-Object) | Should Be ($ExpectedPropsDefault | Sort-Object) } } -} \ No newline at end of file +} diff --git a/tests/Remove-DbaDbSynonym.Tests.ps1 b/tests/Remove-DbaDbSynonym.Tests.ps1 index 51332ab2a7..9d11076164 100644 --- a/tests/Remove-DbaDbSynonym.Tests.ps1 +++ b/tests/Remove-DbaDbSynonym.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Validate parameters" { @@ -17,22 +17,22 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { $dbname = "dbatoolsscidb_$(Get-Random)" $dbname2 = "dbatoolsscidb_$(Get-Random)" - $null = New-DbaDatabase -SqlInstance $script:instance2 -Name $dbname - $null = New-DbaDatabase -SqlInstance $script:instance2 -Name $dbname2 + $null = New-DbaDatabase -SqlInstance $TestConfig.instance2 -Name $dbname + $null = New-DbaDatabase -SqlInstance $TestConfig.instance2 -Name $dbname2 } AfterAll { - $null = Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbname, $dbname2 -Confirm:$false - $null = Remove-DbaDbSynonym -SqlInstance $script:instance2 -Confirm:$false + $null = Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname, $dbname2 -Confirm:$false + $null = Remove-DbaDbSynonym -SqlInstance $TestConfig.instance2 -Confirm:$false } Context "Functionality" { It 'Removes Synonyms' { - $null = New-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname -Synonym 'syn1' -BaseObject 'obj1' - $null = New-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname -Synonym 'syn2' -BaseObject 'obj2' - $result1 = Get-DbaDbSynonym -SqlInstance $script:instance2 - Remove-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname -Synonym 'syn1' -Confirm:$false - $result2 = Get-DbaDbSynonym -SqlInstance $script:instance2 + $null = New-DbaDbSynonym -SqlInstance $TestConfig.instance2 -Database $dbname -Synonym 'syn1' -BaseObject 'obj1' + $null = New-DbaDbSynonym -SqlInstance $TestConfig.instance2 -Database $dbname -Synonym 'syn2' -BaseObject 'obj2' + $result1 = Get-DbaDbSynonym -SqlInstance $TestConfig.instance2 + Remove-DbaDbSynonym -SqlInstance $TestConfig.instance2 -Database $dbname -Synonym 'syn1' -Confirm:$false + $result2 = Get-DbaDbSynonym -SqlInstance $TestConfig.instance2 $result1.Count | Should BeGreaterThan $result2.Count $result2.Name | Should -Not -Contain 'syn1' @@ -40,11 +40,11 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } It 'Accepts a list of synonyms' { - $null = New-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname -Synonym 'syn3' -BaseObject 'obj3' - $null = New-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname -Synonym 'syn4' -BaseObject 'obj4' - $result3 = Get-DbaDbSynonym -SqlInstance $script:instance2 -Synonym 'syn3','syn4' - Remove-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname1 -Synonym 'syn3','syn4' -Confirm:$false - $result4 = Get-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname1 + $null = New-DbaDbSynonym -SqlInstance $TestConfig.instance2 -Database $dbname -Synonym 'syn3' -BaseObject 'obj3' + $null = New-DbaDbSynonym -SqlInstance $TestConfig.instance2 -Database $dbname -Synonym 'syn4' -BaseObject 'obj4' + $result3 = Get-DbaDbSynonym -SqlInstance $TestConfig.instance2 -Synonym 'syn3','syn4' + Remove-DbaDbSynonym -SqlInstance $TestConfig.instance2 -Database $dbname -Synonym 'syn3','syn4' -Confirm:$false + $result4 = Get-DbaDbSynonym -SqlInstance $TestConfig.instance2 -Database $dbname $result3.Count | Should BeGreaterThan $result4.Count $result4.Name | Should -Not -Contain 'syn3' @@ -52,11 +52,11 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } It 'Excludes Synonyms' { - $null = New-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname -Synonym 'syn5' -BaseObject 'obj5' - $null = New-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname -Synonym 'syn6' -BaseObject 'obj6' - $result5 = Get-DbaDbSynonym -SqlInstance $script:instance2 - Remove-DbaDbSynonym -SqlInstance $script:instance2 -ExcludeSynonym 'syn5' -Confirm:$false - $result6 = Get-DbaDbSynonym -SqlInstance $script:instance2 + $null = New-DbaDbSynonym -SqlInstance $TestConfig.instance2 -Database $dbname -Synonym 'syn5' -BaseObject 'obj5' + $null = New-DbaDbSynonym -SqlInstance $TestConfig.instance2 -Database $dbname -Synonym 'syn6' -BaseObject 'obj6' + $result5 = Get-DbaDbSynonym -SqlInstance $TestConfig.instance2 + Remove-DbaDbSynonym -SqlInstance $TestConfig.instance2 -ExcludeSynonym 'syn5' -Confirm:$false + $result6 = Get-DbaDbSynonym -SqlInstance $TestConfig.instance2 $result5.Count | Should BeGreaterThan $result6.Count $result6.Name | Should -Not -Contain 'syn6' @@ -64,10 +64,10 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } It 'Accepts input from Get-DbaDbSynonym' { - $null = New-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname -Synonym 'syn7' -BaseObject 'obj7' - $result7 = Get-DbaDbSynonym -SqlInstance $script:instance2 -Synonym 'syn5','syn7' + $null = New-DbaDbSynonym -SqlInstance $TestConfig.instance2 -Database $dbname -Synonym 'syn7' -BaseObject 'obj7' + $result7 = Get-DbaDbSynonym -SqlInstance $TestConfig.instance2 -Synonym 'syn5','syn7' $result7 | Remove-DbaDbSynonym -confirm:$false - $result8 = Get-DbaDbSynonym -SqlInstance $script:instance2 + $result8 = Get-DbaDbSynonym -SqlInstance $TestConfig.instance2 $result7.Name | Should -Contain 'syn5' $result7.Name | Should -Contain 'syn7' @@ -76,11 +76,11 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } It 'Excludes Synonyms in a specified database' { - $null = New-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname -Synonym 'syn10' -BaseObject 'obj10' - $null = New-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname2 -Synonym 'syn11' -BaseObject 'obj11' - $result11 = Get-DbaDbSynonym -SqlInstance $script:instance2 - Remove-DbaDbSynonym -SqlInstance $script:instance2 -ExcludeDatabase $dbname2 -Confirm:$false - $result12 = Get-DbaDbSynonym -SqlInstance $script:instance2 + $null = New-DbaDbSynonym -SqlInstance $TestConfig.instance2 -Database $dbname -Synonym 'syn10' -BaseObject 'obj10' + $null = New-DbaDbSynonym -SqlInstance $TestConfig.instance2 -Database $dbname2 -Synonym 'syn11' -BaseObject 'obj11' + $result11 = Get-DbaDbSynonym -SqlInstance $TestConfig.instance2 + Remove-DbaDbSynonym -SqlInstance $TestConfig.instance2 -ExcludeDatabase $dbname2 -Confirm:$false + $result12 = Get-DbaDbSynonym -SqlInstance $TestConfig.instance2 $result11.Count | Should BeGreaterThan $result12.Count $result12.Database | Should -Not -Contain $dbname @@ -88,12 +88,12 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } It 'Excludes Synonyms in a specified schema' { - $null = New-DbaDbSchema -SqlInstance $script:instance2 -Database $dbname2 -Schema 'sch2' - $null = New-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname -Synonym 'syn12' -BaseObject 'obj12' - $null = New-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname2 -Synonym 'syn13' -BaseObject 'obj13' -Schema 'sch2' - $result13 = Get-DbaDbSynonym -SqlInstance $script:instance2 - Remove-DbaDbSynonym -SqlInstance $script:instance2 -ExcludeSchema 'sch2' -Confirm:$false - $result14 = Get-DbaDbSynonym -SqlInstance $script:instance2 + $null = New-DbaDbSchema -SqlInstance $TestConfig.instance2 -Database $dbname2 -Schema 'sch2' + $null = New-DbaDbSynonym -SqlInstance $TestConfig.instance2 -Database $dbname -Synonym 'syn12' -BaseObject 'obj12' + $null = New-DbaDbSynonym -SqlInstance $TestConfig.instance2 -Database $dbname2 -Synonym 'syn13' -BaseObject 'obj13' -Schema 'sch2' + $result13 = Get-DbaDbSynonym -SqlInstance $TestConfig.instance2 + Remove-DbaDbSynonym -SqlInstance $TestConfig.instance2 -ExcludeSchema 'sch2' -Confirm:$false + $result14 = Get-DbaDbSynonym -SqlInstance $TestConfig.instance2 $result13.Count | Should BeGreaterThan $result14.Count $result13.Schema | Should -Contain 'dbo' @@ -102,14 +102,14 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } It 'Accepts a list of schemas' { - $null = New-DbaDbSchema -SqlInstance $script:instance2 -Database $dbname -Schema 'sch3' - $null = New-DbaDbSchema -SqlInstance $script:instance2 -Database $dbname2 -Schema 'sch4' - $null = New-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname -Synonym 'syn14' -BaseObject 'obj14' -Schema 'sch3' - $null = New-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname2 -Synonym 'syn15' -BaseObject 'obj15' -Schema 'sch4' - $null = New-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname2 -Synonym 'syn16' -BaseObject 'obj15' -Schema 'dbo' - $result15 = Get-DbaDbSynonym -SqlInstance $script:instance2 - Remove-DbaDbSynonym -SqlInstance $script:instance2 -Schema 'sch3', 'dbo' -Confirm:$false - $result16 = Get-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname1 + $null = New-DbaDbSchema -SqlInstance $TestConfig.instance2 -Database $dbname -Schema 'sch3' + $null = New-DbaDbSchema -SqlInstance $TestConfig.instance2 -Database $dbname2 -Schema 'sch4' + $null = New-DbaDbSynonym -SqlInstance $TestConfig.instance2 -Database $dbname -Synonym 'syn14' -BaseObject 'obj14' -Schema 'sch3' + $null = New-DbaDbSynonym -SqlInstance $TestConfig.instance2 -Database $dbname2 -Synonym 'syn15' -BaseObject 'obj15' -Schema 'sch4' + $null = New-DbaDbSynonym -SqlInstance $TestConfig.instance2 -Database $dbname2 -Synonym 'syn16' -BaseObject 'obj15' -Schema 'dbo' + $result15 = Get-DbaDbSynonym -SqlInstance $TestConfig.instance2 + Remove-DbaDbSynonym -SqlInstance $TestConfig.instance2 -Schema 'sch3', 'dbo' -Confirm:$false + $result16 = Get-DbaDbSynonym -SqlInstance $TestConfig.instance2 $result15.Count | Should BeGreaterThan $result16.Count $result16.Schema | Should -Not -Contain 'sch3' @@ -118,11 +118,11 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } It 'Accepts a list of databases' { - $null = New-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname -Synonym 'syn17' -BaseObject 'obj17' - $null = New-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname2 -Synonym 'syn18' -BaseObject 'obj18' - $result17 = Get-DbaDbSynonym -SqlInstance $script:instance2 - Remove-DbaDbSynonym -SqlInstance $script:instance2 -Database $dbname, $dbname2 -Confirm:$false - $result18 = Get-DbaDbSynonym -SqlInstance $script:instance2 + $null = New-DbaDbSynonym -SqlInstance $TestConfig.instance2 -Database $dbname -Synonym 'syn17' -BaseObject 'obj17' + $null = New-DbaDbSynonym -SqlInstance $TestConfig.instance2 -Database $dbname2 -Synonym 'syn18' -BaseObject 'obj18' + $result17 = Get-DbaDbSynonym -SqlInstance $TestConfig.instance2 + Remove-DbaDbSynonym -SqlInstance $TestConfig.instance2 -Database $dbname, $dbname2 -Confirm:$false + $result18 = Get-DbaDbSynonym -SqlInstance $TestConfig.instance2 $result17.Count | Should BeGreaterThan $result18.Count $result18.Database | Should -Not -Contain $dbname @@ -135,4 +135,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $warn | Should -Match 'You must pipe in a synonym, database, or server or specify a SqlInstance' } } -} \ No newline at end of file +} diff --git a/tests/Remove-DbaDbTable.Tests.ps1 b/tests/Remove-DbaDbTable.Tests.ps1 index 517234725d..ca6be87a5f 100644 --- a/tests/Remove-DbaDbTable.Tests.ps1 +++ b/tests/Remove-DbaDbTable.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,7 +16,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $instance2 = Connect-DbaInstance -SqlInstance $script:instance2 + $instance2 = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $null = Get-DbaProcess -SqlInstance $instance2 | Where-Object Program -match dbatools | Stop-DbaProcess -Confirm:$false $dbname1 = "dbatoolsci_$(Get-Random)" $null = New-DbaDatabase -SqlInstance $instance2 -Name $dbname1 @@ -45,4 +45,4 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { (Get-DbaDbTable -SqlInstance $instance2 -Database $dbname1 -Table $table2) | Should -BeNullOrEmpty } } -} \ No newline at end of file +} diff --git a/tests/Remove-DbaDbTableData.Tests.ps1 b/tests/Remove-DbaDbTableData.Tests.ps1 index 48ba221d7e..debdc9303f 100644 --- a/tests/Remove-DbaDbTableData.Tests.ps1 +++ b/tests/Remove-DbaDbTableData.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Validate parameters" { @@ -14,8 +14,8 @@ Describe "$CommandName Unit Tests" -Tags "UnitTests" { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 - $server2 = Connect-DbaInstance -SqlInstance $script:instance3 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 + $server2 = Connect-DbaInstance -SqlInstance $TestConfig.instance3 # scenario for testing with a db in the simple recovery model $dbnameSimpleModel = "dbatoolsci_$(Get-Random)" @@ -59,41 +59,46 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Param validation" { It "Either -Table or -DeleteSql needs to be specified" { - $result = Remove-DbaDbTableData -SqlInstance $server -Database $dbnameFullModel + $result = Remove-DbaDbTableData -SqlInstance $server -Database $dbnameFullModel -WarningAction SilentlyContinue -WarningVariable warn $result | Should -BeNullOrEmpty + $warn | Should -BeLike '*You must specify either -Table or -DeleteSql.*' - $result = Remove-DbaDbTableData -SqlInstance $server -Database $dbnameFullModel -Table dbo.Test -DeleteSql "DELETE TOP (10) FROM dbo.Test" -Confirm:$false + $result = Remove-DbaDbTableData -SqlInstance $server -Database $dbnameFullModel -Table dbo.Test -DeleteSql "DELETE TOP (10) FROM dbo.Test" -Confirm:$false -WarningAction SilentlyContinue -WarningVariable warn $result | Should -BeNullOrEmpty + $warn | Should -BeLike '*You must specify either -Table or -DeleteSql, but not both.*' } It "-BatchSize cannot be used when -DeleteSql is specified" { - $result = Remove-DbaDbTableData -SqlInstance $server -Database $dbnameFullModel -DeleteSql "DELETE TOP (10) FROM dbo.Test" -BatchSize 10 -Confirm:$false + $result = Remove-DbaDbTableData -SqlInstance $server -Database $dbnameFullModel -DeleteSql "DELETE TOP (10) FROM dbo.Test" -BatchSize 10 -Confirm:$false -WarningAction SilentlyContinue -WarningVariable warn $result | Should -BeNullOrEmpty + $warn | Should -BeLike '*When using -DeleteSql the -BatchSize param cannot be used.*' } It "Invalid -Table value is provided" { - $result = Remove-DbaDbTableData -SqlInstance $server -Database $dbnameFullModel -Table InvalidTableName -Confirm:$false + $result = Remove-DbaDbTableData -SqlInstance $server -Database $dbnameFullModel -Table InvalidTableName -Confirm:$false -WarningAction SilentlyContinue $result | Should -BeNullOrEmpty } It "Invalid -DeleteSql due to missing DELETE keyword (i.e. user has not passed in a DELETE statement)" { - $result = Remove-DbaDbTableData -SqlInstance $server -Database $dbnameFullModel -DeleteSql "SELECT TOP (10) FROM dbo.Test" -Confirm:$false + $result = Remove-DbaDbTableData -SqlInstance $server -Database $dbnameFullModel -DeleteSql "SELECT TOP (10) FROM dbo.Test" -Confirm:$false -WarningAction SilentlyContinue $result | Should -BeNullOrEmpty } It "Invalid -DeleteSql due to missing TOP (N) clause" { - $result = Remove-DbaDbTableData -SqlInstance $server -Database $dbnameFullModel -DeleteSql "DELETE FROM dbo.Test" -Confirm:$false + $result = Remove-DbaDbTableData -SqlInstance $server -Database $dbnameFullModel -DeleteSql "DELETE FROM dbo.Test" -Confirm:$false -WarningAction SilentlyContinue -WarningVariable warn $result | Should -BeNullOrEmpty + $warn | Should -BeLike '*To use the -DeleteSql param you must specify the TOP (N) clause in the DELETE statement.*' } It "Invalid SQL used to test the error handling and reporting" { - $result = Remove-DbaDbTableData -SqlInstance $server -Database $dbnameFullModel -DeleteSql "DELETE TOP (10) FROM dbo.Test WHERE 1/0 = 1" -Confirm:$false + $result = Remove-DbaDbTableData -SqlInstance $server -Database $dbnameFullModel -DeleteSql "DELETE TOP (10) FROM dbo.Test WHERE 1/0 = 1" -Confirm:$false -WarningAction SilentlyContinue $result | Should -BeNullOrEmpty } It "Either -LogBackupPath or -AzureBaseUrl needs to be specified, but not both" { - $result = Remove-DbaDbTableData -SqlInstance $server -Database $dbnameFullModel -Table dbo.Test -LogBackupPath $logBackupPath -AzureBaseUrl https://dbatoolsaz.blob.core.windows.net/azbackups/ + $result = Remove-DbaDbTableData -SqlInstance $server -Database $dbnameFullModel -Table dbo.Test -LogBackupPath $logBackupPath -AzureBaseUrl https://dbatoolsaz.blob.core.windows.net/azbackups/ -WarningAction SilentlyContinue -WarningVariable warn $result | Should -BeNullOrEmpty + $warn | Should -BeLike '*You must specify either -LogBackupPath or -AzureBaseUrl, but not both.*' } } @@ -141,10 +146,11 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Functionality with bulk_logged recovery model" { BeforeEach { - $addRowsToBulkLoggedDb = Invoke-DbaQuery -SqlInstance $server -Database $dbnameBulkLoggedModel -Query $sqlAddRows + $addRowsToBulkLoggedDb = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database $dbnameBulkLoggedModel -Query $sqlAddRows } It 'Removes Data for a specified database' { + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 -Database $dbnameBulkLoggedModel -NonPooledConnection $result = Remove-DbaDbTableData -SqlInstance $server -Database $dbnameBulkLoggedModel -Table dbo.Test -BatchSize 10 -LogBackupPath $logBackupPath -Confirm:$false $result.TotalIterations | Should -Be 10 $result.TotalRowsDeleted | Should -Be 100 @@ -181,7 +187,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } It "Test with an invalid LogBackupPath location" { - $result = Remove-DbaDbTableData -SqlInstance $server -Database $dbnameFullModel -Table dbo.Test -BatchSize 10 -LogBackupPath "C:\dbatools\$(Get-Random)" -Confirm:$false + $result = Remove-DbaDbTableData -SqlInstance $server -Database $dbnameFullModel -Table dbo.Test -BatchSize 10 -LogBackupPath "C:\dbatools\$(Get-Random)" -Confirm:$false -WarningAction SilentlyContinue $result | Should -BeNullOrEmpty } } @@ -262,4 +268,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { (Invoke-DbaQuery -SqlInstance $server2 -Database $dbnameSimpleModel -Query 'SELECT COUNT(1) AS [RowCount] FROM dbo.Test').RowCount | Should -Be 0 } } -} \ No newline at end of file +} diff --git a/tests/Remove-DbaDbUdf.Tests.ps1 b/tests/Remove-DbaDbUdf.Tests.ps1 index c93c8a1992..9a8e3e8aa4 100644 --- a/tests/Remove-DbaDbUdf.Tests.ps1 +++ b/tests/Remove-DbaDbUdf.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,7 +16,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $dbname1 = "dbatoolsci_$(Get-Random)" $null = New-DbaDatabase -SqlInstance $server -Name $dbname1 @@ -44,4 +44,4 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Get-DbaDbUdf -SqlInstance $server -Database $dbname1 -Name $udf2 | Should -BeNullOrEmpty } } -} \ No newline at end of file +} diff --git a/tests/Remove-DbaDbUser.Tests.ps1 b/tests/Remove-DbaDbUser.Tests.ps1 index b1ca3d55d6..bacda3ace3 100644 --- a/tests/Remove-DbaDbUser.Tests.ps1 +++ b/tests/Remove-DbaDbUser.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,7 +16,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Verifying User is removed" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance1 $db = Get-DbaDatabase $server -Database tempdb $securePassword = ConvertTo-SecureString "password" -AsPlainText -Force $loginTest = New-DbaLogin $server -Login dbatoolsci_remove_dba_db_user -Password $securePassword -Force @@ -73,4 +73,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $db.Users[$user.Name] | Should Be $user } } -} \ No newline at end of file +} diff --git a/tests/Remove-DbaDbView.Tests.ps1 b/tests/Remove-DbaDbView.Tests.ps1 index f483faa798..a243c5878c 100644 --- a/tests/Remove-DbaDbView.Tests.ps1 +++ b/tests/Remove-DbaDbView.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,7 +16,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $instance2 = Connect-DbaInstance -SqlInstance $script:instance2 + $instance2 = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $null = Get-DbaProcess -SqlInstance $instance2 | Where-Object Program -match dbatools | Stop-DbaProcess -Confirm:$false $dbname1 = "dbatoolsci_$(Get-Random)" $null = New-DbaDatabase -SqlInstance $instance2 -Name $dbname1 @@ -45,4 +45,4 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { (Get-DbaDbView -SqlInstance $instance2 -Database $dbname1 -View $view2 ) | Should -BeNullOrEmpty } } -} \ No newline at end of file +} diff --git a/tests/Remove-DbaEndpoint.Tests.ps1 b/tests/Remove-DbaEndpoint.Tests.ps1 index 3b1edc3c31..01719808d8 100644 --- a/tests/Remove-DbaEndpoint.Tests.ps1 +++ b/tests/Remove-DbaEndpoint.Tests.ps1 @@ -1,6 +1,6 @@ $commandname = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Validate parameters" { @@ -15,19 +15,19 @@ Describe "$CommandName Unit Tests" -Tags "UnitTests" { Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $endpoint = Get-DbaEndpoint -SqlInstance $script:instance2 | Where-Object EndpointType -eq DatabaseMirroring + $endpoint = Get-DbaEndpoint -SqlInstance $TestConfig.instance2 | Where-Object EndpointType -eq DatabaseMirroring $create = $endpoint | Export-DbaScript -Passthru $null = $endpoint | Remove-DbaEndpoint -Confirm:$false - $results = New-DbaEndpoint -SqlInstance $script:instance2 -Type DatabaseMirroring -Role Partner -Name Mirroring -Confirm:$false | Start-DbaEndpoint -Confirm:$false + $results = New-DbaEndpoint -SqlInstance $TestConfig.instance2 -Type DatabaseMirroring -Role Partner -Name Mirroring -Confirm:$false | Start-DbaEndpoint -Confirm:$false } AfterAll { if ($create) { - Invoke-DbaQuery -SqlInstance $script:instance2 -Query "$create" + Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Query "$create" } } It "removes an endpoint" { - $results = Get-DbaEndpoint -SqlInstance $script:instance2 | Where-Object EndpointType -eq DatabaseMirroring | Remove-DbaEndpoint -Confirm:$false + $results = Get-DbaEndpoint -SqlInstance $TestConfig.instance2 | Where-Object EndpointType -eq DatabaseMirroring | Remove-DbaEndpoint -Confirm:$false $results.Status | Should -Be 'Removed' } -} \ No newline at end of file +} diff --git a/tests/Remove-DbaExtendedProperty.Tests.ps1 b/tests/Remove-DbaExtendedProperty.Tests.ps1 index 1293137ab0..c8c7755578 100644 --- a/tests/Remove-DbaExtendedProperty.Tests.ps1 +++ b/tests/Remove-DbaExtendedProperty.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,7 +16,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BeforeAll { $random = Get-Random - $instance2 = Connect-DbaInstance -SqlInstance $script:instance2 + $instance2 = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $null = Get-DbaProcess -SqlInstance $instance2 | Where-Object Program -match dbatools | Stop-DbaProcess -Confirm:$false $newDbName = "dbatoolsci_newdb_$random" $db = New-DbaDatabase -SqlInstance $instance2 -Name $newDbName @@ -34,4 +34,4 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $results.Status | Should -Be "Dropped" } } -} \ No newline at end of file +} diff --git a/tests/Remove-DbaFirewallRule.Tests.ps1 b/tests/Remove-DbaFirewallRule.Tests.ps1 index db74a97e9d..1d66b6f7c7 100644 --- a/tests/Remove-DbaFirewallRule.Tests.ps1 +++ b/tests/Remove-DbaFirewallRule.Tests.ps1 @@ -1,6 +1,6 @@ $commandname = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Validate parameters" { diff --git a/tests/Remove-DbaLinkedServer.Tests.ps1 b/tests/Remove-DbaLinkedServer.Tests.ps1 index 2ba27cf587..c1e5a86343 100644 --- a/tests/Remove-DbaLinkedServer.Tests.ps1 +++ b/tests/Remove-DbaLinkedServer.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,8 +16,8 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { BeforeAll { $random = Get-Random - $instance2 = Connect-DbaInstance -SqlInstance $script:instance2 - $instance3 = Connect-DbaInstance -SqlInstance $script:instance3 + $instance2 = Connect-DbaInstance -SqlInstance $global:TestConfig.instance2 + $instance3 = Connect-DbaInstance -SqlInstance $global:TestConfig.instance3 $linkedServerName1 = "dbatoolscli_LS1_$random" $linkedServerName2 = "dbatoolscli_LS2_$random" @@ -29,6 +29,11 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $linkedServer3 = New-DbaLinkedServer -SqlInstance $instance2 -LinkedServer $linkedServerName3 $linkedServer4 = New-DbaLinkedServer -SqlInstance $instance2 -LinkedServer $linkedServerName4 + # Add error checking + if (-not ($linkedServer1 -and $linkedServer2 -and $linkedServer3 -and $linkedServer4)) { + Write-Error "Failed to create one or more linked servers" + } + $securePassword = ConvertTo-SecureString -String 's3cur3P4ssw0rd?' -AsPlainText -Force $loginName = "dbatoolscli_test_$random" New-DbaLogin -SqlInstance $instance2, $instance3 -Login $loginName -SecurePassword $securePassword @@ -41,20 +46,11 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $newLinkedServerLogin.Create() } AfterAll { - if ($instance2.LinkedServers.Name -contains $linkedServerName1) { - $instance2.LinkedServers[$linkedServerName1].Drop() - } - - if ($instance2.LinkedServers.Name -contains $linkedServerName2) { - $instance2.LinkedServers[$linkedServerName2].Drop() - } - - if ($instance2.LinkedServers.Name -contains $linkedServerName3) { - $instance2.LinkedServers[$linkedServerName3].Drop() - } - - if ($instance2.LinkedServers.Name -contains $linkedServerName4) { - $instance2.LinkedServers[$linkedServerName4].Drop($true) + $linkedServers = @($linkedServerName1, $linkedServerName2, $linkedServerName3, $linkedServerName4) + foreach ($ls in $linkedServers) { + if ($instance2.LinkedServers.Name -contains $ls) { + $instance2.LinkedServers[$ls].Drop($true) + } } Remove-DbaLogin -SqlInstance $instance2, $instance3 -Login $loginName -Confirm:$false @@ -65,18 +61,18 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { It "Removes a linked server" { $results = Get-DbaLinkedServer -SqlInstance $instance2 -LinkedServer $linkedServerName1 $results.Length | Should -Be 1 - Remove-DbaLinkedServer -SqlInstance $script:instance2 -LinkedServer $linkedServerName1 -Confirm:$false + Remove-DbaLinkedServer -SqlInstance $global:TestConfig.instance2 -LinkedServer $linkedServerName1 -Confirm:$false $results = Get-DbaLinkedServer -SqlInstance $instance2 -LinkedServer $linkedServerName1 $results | Should -BeNullOrEmpty } It "Tries to remove a non-existent linked server" { - Remove-DbaLinkedServer -SqlInstance $script:instance2 -LinkedServer $linkedServerName1 -Confirm:$false -WarningVariable warnings + Remove-DbaLinkedServer -SqlInstance $global:TestConfig.instance2 -LinkedServer $linkedServerName1 -Confirm:$false -WarningVariable warnings $warnings | Should -BeLike "*Linked server $linkedServerName1 does not exist on $($instance2.Name)" } It "Removes a linked server passed in via pipeline" { - $results = Get-DbaLinkedServer -SqlInstance $script:instance2 -LinkedServer $linkedServerName2 + $results = Get-DbaLinkedServer -SqlInstance $global:TestConfig.instance2 -LinkedServer $linkedServerName2 $results.Length | Should -Be 1 Get-DbaLinkedServer -SqlInstance $instance2 -LinkedServer $linkedServerName2 | Remove-DbaLinkedServer -Confirm:$false $results = Get-DbaLinkedServer -SqlInstance $instance2 -LinkedServer $linkedServerName2 @@ -84,7 +80,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } It "Removes a linked server using a server passed in via pipeline" { - $results = Get-DbaLinkedServer -SqlInstance $script:instance2 -LinkedServer $linkedServerName3 + $results = Get-DbaLinkedServer -SqlInstance $global:TestConfig.instance2 -LinkedServer $linkedServerName3 $results.Length | Should -Be 1 $instance2 | Remove-DbaLinkedServer -LinkedServer $linkedServerName3 -Confirm:$false $results = Get-DbaLinkedServer -SqlInstance $instance2 -LinkedServer $linkedServerName3 @@ -92,12 +88,14 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } It "Tries to remove a linked server that still has logins" { - Get-DbaLinkedServer -SqlInstance $instance2 -LinkedServer $linkedServerName4 | Remove-DbaLinkedServer -Confirm:$false -WarningVariable warnings - $warnings | Should -BeLike "*There are still remote logins or linked logins for the server*" + { Get-DbaLinkedServer -SqlInstance $instance2 -LinkedServer $linkedServerName4 | + Remove-DbaLinkedServer -Confirm:$false -ErrorAction Stop } | + Should -Throw -ExpectedMessage "*There are still remote logins or linked logins for the server*" } It "Removes a linked server that requires the -Force param" { - Get-DbaLinkedServer -SqlInstance $instance2 -LinkedServer $linkedServerName4 | Remove-DbaLinkedServer -Confirm:$false -Force + Get-DbaLinkedServer -SqlInstance $instance2 -LinkedServer $linkedServerName4 | + Remove-DbaLinkedServer -Confirm:$false -Force $results = Get-DbaLinkedServer -SqlInstance $instance2 -LinkedServer $linkedServerName4 $results | Should -BeNullOrEmpty } diff --git a/tests/Remove-DbaLinkedServerLogin.Tests.ps1 b/tests/Remove-DbaLinkedServerLogin.Tests.ps1 index 106dbea54b..580b0ac568 100644 --- a/tests/Remove-DbaLinkedServerLogin.Tests.ps1 +++ b/tests/Remove-DbaLinkedServerLogin.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,8 +16,8 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { BeforeAll { $random = Get-Random - $instance2 = Connect-DbaInstance -SqlInstance $script:instance2 - $instance3 = Connect-DbaInstance -SqlInstance $script:instance3 + $instance2 = Connect-DbaInstance -SqlInstance $TestConfig.instance2 + $instance3 = Connect-DbaInstance -SqlInstance $TestConfig.instance3 $securePassword = ConvertTo-SecureString -String 'securePassword' -AsPlainText -Force $localLogin1Name = "dbatoolscli_localLogin1_$random" @@ -114,4 +114,4 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $results.Name | Should -Not -Contain $localLogin7Name } } -} \ No newline at end of file +} diff --git a/tests/Remove-DbaLogin.Tests.ps1 b/tests/Remove-DbaLogin.Tests.ps1 index d619e1dc55..a505cda7bc 100644 --- a/tests/Remove-DbaLogin.Tests.ps1 +++ b/tests/Remove-DbaLogin.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -18,13 +18,13 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $login = "dbatoolsci_removelogin" $password = 'MyV3ry$ecur3P@ssw0rd' $securePassword = ConvertTo-SecureString $password -AsPlainText -Force - $newlogin = New-DbaLogin -SqlInstance $script:instance1 -Login $login -Password $securePassword + $newlogin = New-DbaLogin -SqlInstance $TestConfig.instance1 -Login $login -Password $securePassword } It "removes the login" { - $results = Remove-DbaLogin -SqlInstance $script:instance1 -Login $login -Confirm:$false + $results = Remove-DbaLogin -SqlInstance $TestConfig.instance1 -Login $login -Confirm:$false $results.Status -eq "Dropped" - $login1 = Get-DbaLogin -SqlInstance $script:instance1 -login $removed + $login1 = Get-DbaLogin -SqlInstance $TestConfig.instance1 -login $removed $null -eq $login1 } -} \ No newline at end of file +} diff --git a/tests/Remove-DbaNetworkCertificate.Tests.ps1 b/tests/Remove-DbaNetworkCertificate.Tests.ps1 index 0cc59ab5b5..230663743f 100644 --- a/tests/Remove-DbaNetworkCertificate.Tests.ps1 +++ b/tests/Remove-DbaNetworkCertificate.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Remove-DbaPfDataCollectorCounter.Tests.ps1 b/tests/Remove-DbaPfDataCollectorCounter.Tests.ps1 index c968d9b12e..a347d56011 100644 --- a/tests/Remove-DbaPfDataCollectorCounter.Tests.ps1 +++ b/tests/Remove-DbaPfDataCollectorCounter.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Remove-DbaPfDataCollectorSet.Tests.ps1 b/tests/Remove-DbaPfDataCollectorSet.Tests.ps1 index 52869ea6e6..57a0ef7cb9 100644 --- a/tests/Remove-DbaPfDataCollectorSet.Tests.ps1 +++ b/tests/Remove-DbaPfDataCollectorSet.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Remove-DbaRegServer.Tests.ps1 b/tests/Remove-DbaRegServer.Tests.ps1 index 772c4d3d52..f16961b2df 100644 --- a/tests/Remove-DbaRegServer.Tests.ps1 +++ b/tests/Remove-DbaRegServer.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Validate parameters" { @@ -19,15 +19,15 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $srvName = "dbatoolsci-server1" $regSrvName = "dbatoolsci-server12" $regSrvDesc = "dbatoolsci-server123" - $newServer = Add-DbaRegServer -SqlInstance $script:instance1 -ServerName $srvName -Name $regSrvName -Description $regSrvDesc + $newServer = Add-DbaRegServer -SqlInstance $TestConfig.instance1 -ServerName $srvName -Name $regSrvName -Description $regSrvDesc $srvName2 = "dbatoolsci-server2" $regSrvName2 = "dbatoolsci-server21" $regSrvDesc2 = "dbatoolsci-server321" - $newServer2 = Add-DbaRegServer -SqlInstance $script:instance1 -ServerName $srvName2 -Name $regSrvName2 -Description $regSrvDesc2 + $newServer2 = Add-DbaRegServer -SqlInstance $TestConfig.instance1 -ServerName $srvName2 -Name $regSrvName2 -Description $regSrvDesc2 } AfterAll { - Get-DbaRegServer -SqlInstance $script:instance1 -Name $regSrvName, $regSrvName2, $regSrvName3 | Remove-DbaRegServer -Confirm:$false + Get-DbaRegServer -SqlInstance $TestConfig.instance1 -Name $regSrvName, $regSrvName2, $regSrvName3 | Remove-DbaRegServer -Confirm:$false } It "supports dropping via the pipeline" { @@ -37,9 +37,9 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } It "supports dropping manually" { - $results = Remove-DbaRegServer -Confirm:$false -SqlInstance $script:instance1 -Name $regSrvName2 + $results = Remove-DbaRegServer -Confirm:$false -SqlInstance $TestConfig.instance1 -Name $regSrvName2 $results.Name | Should -Be $regSrvName2 $results.Status | Should -Be 'Dropped' } } -} \ No newline at end of file +} diff --git a/tests/Remove-DbaRegServerGroup.Tests.ps1 b/tests/Remove-DbaRegServerGroup.Tests.ps1 index c2a0cccf18..501d6211f5 100644 --- a/tests/Remove-DbaRegServerGroup.Tests.ps1 +++ b/tests/Remove-DbaRegServerGroup.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Validate parameters" { @@ -17,15 +17,15 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Context "Setup" { BeforeAll { $group = "dbatoolsci-group1" - $newGroup = Add-DbaRegServerGroup -SqlInstance $script:instance1 -Name $group + $newGroup = Add-DbaRegServerGroup -SqlInstance $TestConfig.instance1 -Name $group $group2 = "dbatoolsci-group1a" - $newGroup2 = Add-DbaRegServerGroup -SqlInstance $script:instance1 -Name $group2 + $newGroup2 = Add-DbaRegServerGroup -SqlInstance $TestConfig.instance1 -Name $group2 - $hellagroup = Get-DbaRegServerGroup -SqlInstance $script:instance1 -Id 1 | Add-DbaRegServerGroup -Name dbatoolsci-first | Add-DbaRegServerGroup -Name dbatoolsci-second | Add-DbaRegServerGroup -Name dbatoolsci-third | Add-DbaRegServer -ServerName dbatoolsci-test -Description ridiculous + $hellagroup = Get-DbaRegServerGroup -SqlInstance $TestConfig.instance1 -Id 1 | Add-DbaRegServerGroup -Name dbatoolsci-first | Add-DbaRegServerGroup -Name dbatoolsci-second | Add-DbaRegServerGroup -Name dbatoolsci-third | Add-DbaRegServer -ServerName dbatoolsci-test -Description ridiculous } AfterAll { - Get-DbaRegServerGroup -SqlInstance $script:instance1 | Where-Object Name -match dbatoolsci | Remove-DbaRegServerGroup -Confirm:$false + Get-DbaRegServerGroup -SqlInstance $TestConfig.instance1 | Where-Object Name -match dbatoolsci | Remove-DbaRegServerGroup -Confirm:$false } It "supports dropping via the pipeline" { @@ -35,14 +35,14 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } It "supports dropping manually" { - $results = Remove-DbaRegServerGroup -Confirm:$false -SqlInstance $script:instance1 -Name $group2 + $results = Remove-DbaRegServerGroup -Confirm:$false -SqlInstance $TestConfig.instance1 -Name $group2 $results.Name | Should -Be $group2 $results.Status | Should -Be 'Dropped' } It "supports hella long group name" { - $results = Get-DbaRegServerGroup -SqlInstance $script:instance1 -Group $hellagroup.Group + $results = Get-DbaRegServerGroup -SqlInstance $TestConfig.instance1 -Group $hellagroup.Group $results.Name | Should -Be 'dbatoolsci-third' } } -} \ No newline at end of file +} diff --git a/tests/Remove-DbaReplArticle.Tests.ps1 b/tests/Remove-DbaReplArticle.Tests.ps1 index 3df7559a0f..8ff9603449 100644 --- a/tests/Remove-DbaReplArticle.Tests.ps1 +++ b/tests/Remove-DbaReplArticle.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Add-ReplicationLibrary diff --git a/tests/Remove-DbaReplPublication.Tests.ps1 b/tests/Remove-DbaReplPublication.Tests.ps1 index 7914ec229d..ecaa63b38c 100644 --- a/tests/Remove-DbaReplPublication.Tests.ps1 +++ b/tests/Remove-DbaReplPublication.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Add-ReplicationLibrary diff --git a/tests/Remove-DbaReplSubscription.Tests.ps1 b/tests/Remove-DbaReplSubscription.Tests.ps1 index 730d6870a6..7f2229c168 100644 --- a/tests/Remove-DbaReplSubscription.Tests.ps1 +++ b/tests/Remove-DbaReplSubscription.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Add-ReplicationLibrary diff --git a/tests/Remove-DbaRgResourcePool.Tests.ps1 b/tests/Remove-DbaRgResourcePool.Tests.ps1 index 3eaeb9e0c2..5cacb01ecd 100644 --- a/tests/Remove-DbaRgResourcePool.Tests.ps1 +++ b/tests/Remove-DbaRgResourcePool.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,12 +16,12 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Functionality" { BeforeAll { - $null = Set-DbaResourceGovernor -SqlInstance $script:instance2 -Enabled + $null = Set-DbaResourceGovernor -SqlInstance $TestConfig.instance2 -Enabled } It "Removes a resource pool" { $resourcePoolName = "dbatoolssci_poolTest" $splatNewResourcePool = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 ResourcePool = $resourcePoolName MaximumCpuPercentage = 100 MaximumMemoryPercentage = 100 @@ -30,9 +30,9 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Force = $true } $null = New-DbaRgResourcePool @splatNewResourcePool - $result = Get-DbaRgResourcePool -SqlInstance $script:instance2 - Remove-DbaRgResourcePool -SqlInstance $script:instance2 -ResourcePool $resourcePoolName - $result2 = Get-DbaRgResourcePool -SqlInstance $script:instance2 + $result = Get-DbaRgResourcePool -SqlInstance $TestConfig.instance2 + Remove-DbaRgResourcePool -SqlInstance $TestConfig.instance2 -ResourcePool $resourcePoolName + $result2 = Get-DbaRgResourcePool -SqlInstance $TestConfig.instance2 $result.Count | Should -BeGreaterThan $result2.Count $result2.Name | Should -Not -Contain $resourcePoolName @@ -40,7 +40,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { It "Works using -Type Internal" { $resourcePoolName = "dbatoolssci_poolTest" $splatNewResourcePool = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 ResourcePool = $resourcePoolName MaximumCpuPercentage = 100 MaximumMemoryPercentage = 100 @@ -50,9 +50,9 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Force = $true } $null = New-DbaRgResourcePool @splatNewResourcePool - $result = Get-DbaRgResourcePool -SqlInstance $script:instance2 -Type Internal - Remove-DbaRgResourcePool -SqlInstance $script:instance2 -ResourcePool $resourcePoolName -Type Internal - $result2 = Get-DbaRgResourcePool -SqlInstance $script:instance2 + $result = Get-DbaRgResourcePool -SqlInstance $TestConfig.instance2 -Type Internal + Remove-DbaRgResourcePool -SqlInstance $TestConfig.instance2 -ResourcePool $resourcePoolName -Type Internal + $result2 = Get-DbaRgResourcePool -SqlInstance $TestConfig.instance2 $result.Count | Should -BeGreaterThan $result2.Count $result2.Name | Should -Not -Contain $resourcePoolName @@ -60,7 +60,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { It "Works using -Type External" { $resourcePoolName = "dbatoolssci_poolTest" $splatNewResourcePool = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 ResourcePool = $resourcePoolName MaximumCpuPercentage = 100 MaximumMemoryPercentage = 100 @@ -70,9 +70,9 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Force = $true } $null = New-DbaRgResourcePool @splatNewResourcePool - $result = Get-DbaRgResourcePool -SqlInstance $script:instance2 -Type External - Remove-DbaRgResourcePool -SqlInstance $script:instance2 -ResourcePool $resourcePoolName -Type External - $result2 = Get-DbaRgResourcePool -SqlInstance $script:instance2 -Type External + $result = Get-DbaRgResourcePool -SqlInstance $TestConfig.instance2 -Type External + Remove-DbaRgResourcePool -SqlInstance $TestConfig.instance2 -ResourcePool $resourcePoolName -Type External + $result2 = Get-DbaRgResourcePool -SqlInstance $TestConfig.instance2 -Type External $result.Count | Should -BeGreaterThan $result2.Count $result2.Name | Should -Not -Contain $resourcePoolName @@ -81,7 +81,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $resourcePoolName = "dbatoolssci_poolTest" $resourcePoolName2 = "dbatoolssci_poolTest2" $splatNewResourcePool = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 MaximumCpuPercentage = 100 MaximumMemoryPercentage = 100 MaximumIOPSPerVolume = 100 @@ -90,9 +90,9 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } $null = New-DbaRgResourcePool @splatNewResourcePool -ResourcePool $resourcePoolName $null = New-DbaRgResourcePool @splatNewResourcePool -ResourcePool $resourcePoolName2 - $result = Get-DbaRgResourcePool -SqlInstance $script:instance2 - Remove-DbaRgResourcePool -SqlInstance $script:instance2 -ResourcePool $resourcePoolName, $resourcePoolName2 - $result2 = Get-DbaRgResourcePool -SqlInstance $script:instance2 + $result = Get-DbaRgResourcePool -SqlInstance $TestConfig.instance2 + Remove-DbaRgResourcePool -SqlInstance $TestConfig.instance2 -ResourcePool $resourcePoolName, $resourcePoolName2 + $result2 = Get-DbaRgResourcePool -SqlInstance $TestConfig.instance2 $result.Count | Should -BeGreaterThan $result2.Count $result2.Name | Should -Not -Contain $resourcePoolName @@ -102,7 +102,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $resourcePoolName = "dbatoolssci_poolTest" $resourcePoolName2 = "dbatoolssci_poolTest2" $splatNewResourcePool = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 MaximumCpuPercentage = 100 MaximumMemoryPercentage = 100 MaximumIOPSPerVolume = 100 @@ -111,9 +111,9 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } $null = New-DbaRgResourcePool @splatNewResourcePool -ResourcePool $resourcePoolName $null = New-DbaRgResourcePool @splatNewResourcePool -ResourcePool $resourcePoolName2 - $result = Get-DbaRgResourcePool -SqlInstance $script:instance2 + $result = Get-DbaRgResourcePool -SqlInstance $TestConfig.instance2 $result | Where-Object Name -in ($resourcePoolName, $resourcePoolName2) | Remove-DbaRgResourcePool - $result2 = Get-DbaRgResourcePool -SqlInstance $script:instance2 + $result2 = Get-DbaRgResourcePool -SqlInstance $TestConfig.instance2 $result.Count | Should -BeGreaterThan $result2.Count $result2.Name | Should -Not -Contain $resourcePoolName @@ -122,7 +122,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { It "Skips Resource Governor reconfiguration" { $resourcePoolName = "dbatoolssci_poolTest" $splatNewResourcePool = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 ResourcePool = $resourcePoolName MaximumCpuPercentage = 100 MaximumMemoryPercentage = 100 @@ -131,10 +131,10 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Force = $true } $null = New-DbaRgResourcePool @splatNewResourcePool - Remove-DbaRgResourcePool -SqlInstance $script:instance2 -ResourcePool $resourcePoolName -SkipReconfigure - $result = Get-DbaResourceGovernor -SqlInstance $script:instance2 + Remove-DbaRgResourcePool -SqlInstance $TestConfig.instance2 -ResourcePool $resourcePoolName -SkipReconfigure + $result = Get-DbaResourceGovernor -SqlInstance $TestConfig.instance2 $result.ReconfigurePending | Should -Be $true } } -} \ No newline at end of file +} diff --git a/tests/Remove-DbaRgWorkloadGroup.Tests.ps1 b/tests/Remove-DbaRgWorkloadGroup.Tests.ps1 index 066aa5ea35..c4d472e590 100644 --- a/tests/Remove-DbaRgWorkloadGroup.Tests.ps1 +++ b/tests/Remove-DbaRgWorkloadGroup.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,19 +16,19 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Functionality" { BeforeAll { - $null = Set-DbaResourceGovernor -SqlInstance $script:instance2 -Enabled + $null = Set-DbaResourceGovernor -SqlInstance $TestConfig.instance2 -Enabled } It "Removes a workload group in default resource pool" { $wklGroupName = "dbatoolssci_wklgroupTest" $splatNewWorkloadGroup = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 WorkloadGroup = $wklGroupName Force = $true } $newWorkloadGroup = New-DbaRgWorkloadGroup @splatNewWorkloadGroup - $result = Get-DbaRgWorkloadGroup -SqlInstance $script:instance2 | Where-Object Name -eq $wklGroupName - $result2 = Remove-DbaRgWorkloadGroup -SqlInstance $script:instance2 -WorkloadGroup $wklGroupName - $result3 = Get-DbaRgWorkloadGroup -SqlInstance $script:instance2 | Where-Object Name -eq $wklGroupName + $result = Get-DbaRgWorkloadGroup -SqlInstance $TestConfig.instance2 | Where-Object Name -eq $wklGroupName + $result2 = Remove-DbaRgWorkloadGroup -SqlInstance $TestConfig.instance2 -WorkloadGroup $wklGroupName + $result3 = Get-DbaRgWorkloadGroup -SqlInstance $TestConfig.instance2 | Where-Object Name -eq $wklGroupName $newWorkloadGroup | Should -Not -Be $null $result.Count | Should -BeGreaterThan $result3.Count @@ -41,13 +41,13 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $resourcePoolName = "dbatoolssci_poolTest" $resourcePoolType = "Internal" $splatNewResourcePool = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 ResourcePool = $resourcePoolName Type = $resourcePoolType Force = $true } $splatNewWorkloadGroup = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 WorkloadGroup = $wklGroupName ResourcePool = $resourcePoolName ResourcePoolType = $resourcePoolType @@ -55,11 +55,11 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } $null = New-DbaRgResourcePool @splatNewResourcePool $newWorkloadGroup = New-DbaRgWorkloadGroup @splatNewWorkloadGroup - $result = Get-DbaRgWorkloadGroup -SqlInstance $script:instance2 | Where-Object Name -eq $wklGroupName - $result2 = Remove-DbaRgWorkloadGroup -SqlInstance $script:instance2 -WorkloadGroup $wklGroupName -ResourcePool $resourcePoolName -ResourcePoolType $resourcePoolType - $result3 = Get-DbaRgWorkloadGroup -SqlInstance $script:instance2 | Where-Object Name -eq $wklGroupName + $result = Get-DbaRgWorkloadGroup -SqlInstance $TestConfig.instance2 | Where-Object Name -eq $wklGroupName + $result2 = Remove-DbaRgWorkloadGroup -SqlInstance $TestConfig.instance2 -WorkloadGroup $wklGroupName -ResourcePool $resourcePoolName -ResourcePoolType $resourcePoolType + $result3 = Get-DbaRgWorkloadGroup -SqlInstance $TestConfig.instance2 | Where-Object Name -eq $wklGroupName - $null = Remove-DbaRgResourcePool -SqlInstance $script:instance2 -ResourcePool $resourcePoolName -Type $resourcePoolType + $null = Remove-DbaRgResourcePool -SqlInstance $TestConfig.instance2 -ResourcePool $resourcePoolName -Type $resourcePoolType $newWorkloadGroup | Should -Not -Be $null $result.Count | Should -BeGreaterThan $result3.Count @@ -71,15 +71,15 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $wklGroupName = "dbatoolssci_wklgroupTest" $wklGroupName2 = "dbatoolssci_wklgroupTest" $splatNewWorkloadGroup = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 WorkloadGroup = @($wklGroupName, $wklGroupName2) Force = $true } $newWorkloadGroups = New-DbaRgWorkloadGroup @splatNewWorkloadGroup - $result = Get-DbaRgWorkloadGroup -SqlInstance $script:instance2 | Where-Object Name -in $wklGroupName, $wklGroupName2 - $result2 = Remove-DbaRgWorkloadGroup -SqlInstance $script:instance2 -WorkloadGroup $wklGroupName, $wklGroupName2 - $result3 = Get-DbaRgWorkloadGroup -SqlInstance $script:instance2 | Where-Object Name -in $wklGroupName, $wklGroupName2 + $result = Get-DbaRgWorkloadGroup -SqlInstance $TestConfig.instance2 | Where-Object Name -in $wklGroupName, $wklGroupName2 + $result2 = Remove-DbaRgWorkloadGroup -SqlInstance $TestConfig.instance2 -WorkloadGroup $wklGroupName, $wklGroupName2 + $result3 = Get-DbaRgWorkloadGroup -SqlInstance $TestConfig.instance2 | Where-Object Name -in $wklGroupName, $wklGroupName2 $newWorkloadGroups | Should -Not -Be $null $result.Count | Should -BeGreaterThan $result3.Count @@ -90,14 +90,14 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { It "Removes a piped workload group" { $wklGroupName = "dbatoolssci_wklgroupTest" $splatNewWorkloadGroup = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 WorkloadGroup = $wklGroupName Force = $true } $newWorkloadGroup = New-DbaRgWorkloadGroup @splatNewWorkloadGroup - $result = Get-DbaRgWorkloadGroup -SqlInstance $script:instance2 | Where-Object Name -eq $wklGroupName + $result = Get-DbaRgWorkloadGroup -SqlInstance $TestConfig.instance2 | Where-Object Name -eq $wklGroupName $result2 = $newWorkloadGroup | Remove-DbaRgWorkloadGroup - $result3 = Get-DbaRgWorkloadGroup -SqlInstance $script:instance2 | Where-Object Name -eq $wklGroupName + $result3 = Get-DbaRgWorkloadGroup -SqlInstance $TestConfig.instance2 | Where-Object Name -eq $wklGroupName $newWorkloadGroup | Should -Not -Be $null $result.Count | Should -BeGreaterThan $result3.Count @@ -106,4 +106,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $result3 | Should -Be $null } } -} \ No newline at end of file +} diff --git a/tests/Remove-DbaServerRole.Tests.ps1 b/tests/Remove-DbaServerRole.Tests.ps1 index 00fa20f691..fe8ad68e91 100644 --- a/tests/Remove-DbaServerRole.Tests.ps1 +++ b/tests/Remove-DbaServerRole.Tests.ps1 @@ -3,7 +3,7 @@ #> $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig <# Unit test is required for any command added @@ -21,7 +21,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $instance = Connect-DbaInstance -SqlInstance $script:instance2 + $instance = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $roleExecutor = "serverExecuter" $null = New-DbaServerRole -SqlInstance $instance -ServerRole $roleExecutor } @@ -39,4 +39,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $results | Should Be $null } } -} \ No newline at end of file +} diff --git a/tests/Remove-DbaServerRoleMember.Tests.ps1 b/tests/Remove-DbaServerRoleMember.Tests.ps1 index 776a3e2ebe..9303d2355e 100644 --- a/tests/Remove-DbaServerRoleMember.Tests.ps1 +++ b/tests/Remove-DbaServerRoleMember.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Validate parameters" { @@ -15,24 +15,24 @@ Describe "$CommandName Unit Tests" -Tags "UnitTests" { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $login1 = "dbatoolsci_login1_$(Get-Random)" $login2 = "dbatoolsci_login2_$(Get-Random)" $customServerRole = "dbatoolsci_customrole_$(Get-Random)" $fixedServerRoles = 'dbcreator','processadmin' - $null = New-DbaLogin -SqlInstance $script:instance2 -Login $login1 -Password ('Password1234!' | ConvertTo-SecureString -asPlainText -Force) - $null = New-DbaLogin -SqlInstance $script:instance2 -Login $login2 -Password ('Password1234!' | ConvertTo-SecureString -asPlainText -Force) - $null = New-DbaServerRole -SqlInstance $script:instance2 -ServerRole $customServerRole -Owner sa + $null = New-DbaLogin -SqlInstance $TestConfig.instance2 -Login $login1 -Password ('Password1234!' | ConvertTo-SecureString -asPlainText -Force) + $null = New-DbaLogin -SqlInstance $TestConfig.instance2 -Login $login2 -Password ('Password1234!' | ConvertTo-SecureString -asPlainText -Force) + $null = New-DbaServerRole -SqlInstance $TestConfig.instance2 -ServerRole $customServerRole -Owner sa Add-DbaServerRoleMember -SqlInstance $server -ServerRole $fixedServerRoles[0] -Login $login1, $login2 -Confirm:$false } AfterAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 - $null = Remove-DbaLogin -SqlInstance $script:instance2 -Login $login1, $login2 -Confirm:$false + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 + $null = Remove-DbaLogin -SqlInstance $TestConfig.instance2 -Login $login1, $login2 -Confirm:$false } Context "Functionality" { It 'Removes Login from Role' { - Remove-DbaServerRoleMember -SqlInstance $script:instance2 -ServerRole $fixedServerRoles[0] -Login $login1 -Confirm:$false + Remove-DbaServerRoleMember -SqlInstance $TestConfig.instance2 -ServerRole $fixedServerRoles[0] -Login $login1 -Confirm:$false $roleAfter = Get-DbaServerRole -SqlInstance $server -ServerRole $fixedServerRoles[0] $roleAfter.Role | Should -Be $fixedServerRoles[0] @@ -42,7 +42,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { It 'Removes Login from Multiple Roles' { $serverRoles = Get-DbaServerRole -SqlInstance $server -ServerRole $fixedServerRoles - Remove-DbaServerRoleMember -SqlInstance $script:instance2 -ServerRole $serverRoles -Login $login1 -Confirm:$false + Remove-DbaServerRoleMember -SqlInstance $TestConfig.instance2 -ServerRole $serverRoles -Login $login1 -Confirm:$false $roleDBAfter = Get-DbaServerRole -SqlInstance $server -ServerRole $fixedServerRoles $roleDBAfter.Count | Should -Be $serverRoles.Count @@ -52,7 +52,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } It 'Removes Custom Server-Level Role Membership' { - Remove-DbaServerRoleMember -SqlInstance $script:instance2 -ServerRole $customServerRole -Role $fixedServerRoles[-1] -Confirm:$false + Remove-DbaServerRoleMember -SqlInstance $TestConfig.instance2 -ServerRole $customServerRole -Role $fixedServerRoles[-1] -Confirm:$false $roleAfter = Get-DbaServerRole -SqlInstance $server -ServerRole $fixedServerRoles[-1] $roleAfter.Role | Should -Be $fixedServerRoles[-1] @@ -67,4 +67,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $roleAfter.EnumMemberNames().Contains($login2) | Should -Be $false } } -} \ No newline at end of file +} diff --git a/tests/Remove-DbaSpn.Tests.ps1 b/tests/Remove-DbaSpn.Tests.ps1 index 5a1c6f71d0..5efd2dccf3 100644 --- a/tests/Remove-DbaSpn.Tests.ps1 +++ b/tests/Remove-DbaSpn.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Remove-DbaTrace.Tests.ps1 b/tests/Remove-DbaTrace.Tests.ps1 index d7d9384853..76fe1baa89 100644 --- a/tests/Remove-DbaTrace.Tests.ps1 +++ b/tests/Remove-DbaTrace.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -92,20 +92,20 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { -- display trace id for future references select TraceID=@TraceID" - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance1 $traceid = ($server.Query($sql)).TraceID } AfterAll { Remove-Item C:\windows\temp\temptrace.trc } Context "Test Removing Trace" { - $results = Get-DbaTrace -SqlInstance $script:instance1 -Id $traceid | Remove-DbaTrace + $results = Get-DbaTrace -SqlInstance $TestConfig.instance1 -Id $traceid | Remove-DbaTrace It "returns the right values" { $results.Id | Should Be $traceid $results.Status | Should Be "Stopped, closed and deleted" } It "doesn't return any result for trace file id $traceid" { - Get-DbaTrace -SqlInstance $script:instance1 -Id $traceid | Should Be $null + Get-DbaTrace -SqlInstance $TestConfig.instance1 -Id $traceid | Should Be $null } } -} \ No newline at end of file +} diff --git a/tests/Remove-DbaXESession.Tests.ps1 b/tests/Remove-DbaXESession.Tests.ps1 index 3e237ea94d..f5bcb57c33 100644 --- a/tests/Remove-DbaXESession.Tests.ps1 +++ b/tests/Remove-DbaXESession.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,24 +15,24 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $null = Get-DbaXESession -SqlInstance $script:instance2 -Session 'Profiler TSQL Duration' | Remove-DbaXESession + $null = Get-DbaXESession -SqlInstance $TestConfig.instance2 -Session 'Profiler TSQL Duration' | Remove-DbaXESession } AfterAll { - $null = Get-DbaXESession -SqlInstance $script:instance2 -Session 'Profiler TSQL Duration' | Remove-DbaXESession + $null = Get-DbaXESession -SqlInstance $TestConfig.instance2 -Session 'Profiler TSQL Duration' | Remove-DbaXESession } Context "Test Importing Session Template" { - $results = Import-DbaXESessionTemplate -SqlInstance $script:instance2 -Template 'Profiler TSQL Duration' + $results = Import-DbaXESessionTemplate -SqlInstance $TestConfig.instance2 -Template 'Profiler TSQL Duration' It "session should exist" { $results.Name | Should Be 'Profiler TSQL Duration' } - $null = Get-DbaXESession -SqlInstance $script:instance2 -Session 'Profiler TSQL Duration' | Remove-DbaXESession - $results = Get-DbaXESession -SqlInstance $script:instance2 -Session 'Profiler TSQL Duration' + $null = Get-DbaXESession -SqlInstance $TestConfig.instance2 -Session 'Profiler TSQL Duration' | Remove-DbaXESession + $results = Get-DbaXESession -SqlInstance $TestConfig.instance2 -Session 'Profiler TSQL Duration' It "session should no longer exist" { $results.Name | Should Be $null $results.Status | Should Be $null } } -} \ No newline at end of file +} diff --git a/tests/Remove-DbaXESmartTarget.Tests.ps1 b/tests/Remove-DbaXESmartTarget.Tests.ps1 index ae062d8279..368df19f2f 100644 --- a/tests/Remove-DbaXESmartTarget.Tests.ps1 +++ b/tests/Remove-DbaXESmartTarget.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Rename-DbaDatabase.Tests.ps1 b/tests/Rename-DbaDatabase.Tests.ps1 index 79a5108c8f..bf61fc345b 100644 --- a/tests/Rename-DbaDatabase.Tests.ps1 +++ b/tests/Rename-DbaDatabase.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,23 +15,23 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $null = New-DbaDatabase -SqlInstance $script:instance2 -Name 'dbatoolsci_rename1' - $null = New-DbaDatabase -SqlInstance $script:instance2 -Name 'dbatoolsci_filemove' - $null = New-DbaDatabase -SqlInstance $script:instance2 -Name 'dbatoolsci_logicname' - $null = New-DbaDatabase -SqlInstance $script:instance2 -Name 'dbatoolsci_filegroupname' + $null = New-DbaDatabase -SqlInstance $TestConfig.instance2 -Name 'dbatoolsci_rename1' + $null = New-DbaDatabase -SqlInstance $TestConfig.instance2 -Name 'dbatoolsci_filemove' + $null = New-DbaDatabase -SqlInstance $TestConfig.instance2 -Name 'dbatoolsci_logicname' + $null = New-DbaDatabase -SqlInstance $TestConfig.instance2 -Name 'dbatoolsci_filegroupname' $FileGroupName = @" ALTER DATABASE dbatoolsci_filegroupname ADD FILEGROUP Dbatoolsci_filegroupname "@ - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Query $FileGroupName + $null = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Query $FileGroupName $date = (Get-Date).ToString('yyyyMMdd') } AfterAll { - $null = Remove-DbaDatabase -SqlInstance $script:instance2 -Database "test_dbatoolsci_rename2_$($date)", "Dbatoolsci_filemove", "dbatoolsci_logicname", "dbatoolsci_filegroupname" -Confirm:$false + $null = Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database "test_dbatoolsci_rename2_$($date)", "Dbatoolsci_filemove", "dbatoolsci_logicname", "dbatoolsci_filegroupname" -Confirm:$false } Context "Should preview a rename of a database" { - $variables = @{SqlInstance = $script:instance2 + $variables = @{SqlInstance = $TestConfig.instance2 Database = 'dbatoolsci_rename1' DatabaseName = 'dbatoolsci_rename2' Preview = $true @@ -48,7 +48,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } Context "Should rename a database" { - $variables = @{SqlInstance = $script:instance2 + $variables = @{SqlInstance = $TestConfig.instance2 Database = 'dbatoolsci_rename1' DatabaseName = 'dbatoolsci_rename2' } @@ -70,7 +70,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } Context "Should rename a database with a prefix" { - $variables = @{SqlInstance = $script:instance2 + $variables = @{SqlInstance = $TestConfig.instance2 Database = 'dbatoolsci_rename2' DatabaseName = 'test_' } @@ -92,7 +92,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } Context "Should rename a database with a date" { - $variables = @{SqlInstance = $script:instance2 + $variables = @{SqlInstance = $TestConfig.instance2 Database = 'test_dbatoolsci_rename2' DatabaseName = '_' } @@ -114,7 +114,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } Context "Should preview renaming database files" { - $variables = @{SqlInstance = $script:instance2 + $variables = @{SqlInstance = $TestConfig.instance2 Database = "dbatoolsci_filemove" FileName = "__" Preview = $true @@ -137,7 +137,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } Context "Should rename database files and move them" { - $variables = @{SqlInstance = $script:instance2 + $variables = @{SqlInstance = $TestConfig.instance2 Database = "dbatoolsci_filemove" FileName = "__" Move = $true @@ -160,7 +160,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } Context "Should rename database files and forces the move" { - $variables = @{SqlInstance = $script:instance2 + $variables = @{SqlInstance = $TestConfig.instance2 Database = "dbatoolsci_filemove" FileName = "_" ReplaceBefore = $true @@ -184,7 +184,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } Context "Should rename database files and set the database offline" { - $variables = @{SqlInstance = $script:instance2 + $variables = @{SqlInstance = $TestConfig.instance2 Database = "dbatoolsci_filemove" FileName = "__" SetOffline = $true @@ -210,7 +210,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } Context "Should rename the logical name" { - $variables = @{SqlInstance = $script:instance2 + $variables = @{SqlInstance = $TestConfig.instance2 Database = "dbatoolsci_logicname" LogicalName = "__" } @@ -232,7 +232,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } Context "Should rename the filegroupname name" { - $variables = @{SqlInstance = $script:instance2 + $variables = @{SqlInstance = $TestConfig.instance2 Database = "dbatoolsci_filegroupname" FileGroupName = "__" } @@ -249,4 +249,4 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $results.FGN.Keys | Should BE @('Dbatoolsci_filegroupname') } } -} \ No newline at end of file +} diff --git a/tests/Rename-DbaLogin.Tests.ps1 b/tests/Rename-DbaLogin.Tests.ps1 index 86321d8b67..5bf8496088 100644 --- a/tests/Rename-DbaLogin.Tests.ps1 +++ b/tests/Rename-DbaLogin.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -19,15 +19,15 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $renamed = "dbatoolsci_renamelogin2" $password = 'MyV3ry$ecur3P@ssw0rd' $securePassword = ConvertTo-SecureString $password -AsPlainText -Force - $newlogin = New-DbaLogin -SqlInstance $script:instance1 -Login $login -Password $securePassword + $newlogin = New-DbaLogin -SqlInstance $TestConfig.instance1 -Login $login -Password $securePassword } AfterAll { - $null = Stop-DbaProcess -SqlInstance $script:instance1 -Login $renamed - $null = Remove-DbaLogin -SqlInstance $script:instance1 -Login $renamed -Confirm:$false + $null = Stop-DbaProcess -SqlInstance $TestConfig.instance1 -Login $renamed + $null = Remove-DbaLogin -SqlInstance $TestConfig.instance1 -Login $renamed -Confirm:$false } Context "renames the login" { - $results = Rename-DbaLogin -SqlInstance $script:instance1 -Login $login -NewLogin $renamed + $results = Rename-DbaLogin -SqlInstance $TestConfig.instance1 -Login $login -NewLogin $renamed It "rename is successful" { $results.Status | Should Be "Successful" } @@ -38,7 +38,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $results.NewLogin | Should Be $renamed } It "results aren't null" { - Get-DbaLogin -SqlInstance $script:instance1 -login $renamed | Should Not BeNullOrEmpty + Get-DbaLogin -SqlInstance $TestConfig.instance1 -login $renamed | Should Not BeNullOrEmpty } } -} \ No newline at end of file +} diff --git a/tests/Repair-DbaDbMirror.Tests.ps1 b/tests/Repair-DbaDbMirror.Tests.ps1 index d6a2e85cf7..029584ed7a 100644 --- a/tests/Repair-DbaDbMirror.Tests.ps1 +++ b/tests/Repair-DbaDbMirror.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Repair-DbaDbOrphanUser.Tests.ps1 b/tests/Repair-DbaDbOrphanUser.Tests.ps1 index f179b3de7a..896831d15f 100644 --- a/tests/Repair-DbaDbOrphanUser.Tests.ps1 +++ b/tests/Repair-DbaDbOrphanUser.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -22,7 +22,7 @@ CREATE LOGIN [dbatoolsci_orphan2] WITH PASSWORD = N'password2', CHECK_EXPIRATION CREATE LOGIN [dbatoolsci_orphan3] WITH PASSWORD = N'password3', CHECK_EXPIRATION = OFF, CHECK_POLICY = OFF; CREATE DATABASE dbatoolsci_orphan; '@ - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance1 $null = Remove-DbaLogin -SqlInstance $server -Login dbatoolsci_orphan1, dbatoolsci_orphan2, dbatoolsci_orphan3 -Force -Confirm:$false $null = Remove-DbaDatabase -SqlInstance $server -Database dbatoolsci_orphan -Confirm:$false $null = Invoke-DbaQuery -SqlInstance $server -Query $loginsq @@ -41,14 +41,14 @@ CREATE LOGIN [dbatoolsci_orphan2] WITH PASSWORD = N'password2', CHECK_EXPIRATION Invoke-DbaQuery -SqlInstance $server -Query $loginsq } AfterAll { - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance1 $null = Remove-DbaLogin -SqlInstance $server -Login dbatoolsci_orphan1, dbatoolsci_orphan2, dbatoolsci_orphan3 -Force -Confirm:$false $null = Remove-DbaDatabase -SqlInstance $server -Database dbatoolsci_orphan -Confirm:$false } It "shows time taken for preparation" { 1 | Should -Be 1 } - $results = Repair-DbaDbOrphanUser -SqlInstance $script:instance1 -Database dbatoolsci_orphan + $results = Repair-DbaDbOrphanUser -SqlInstance $TestConfig.instance1 -Database dbatoolsci_orphan It "Finds two orphans" { $results.Count | Should -Be 2 foreach ($user in $Users) { @@ -62,8 +62,8 @@ CREATE LOGIN [dbatoolsci_orphan2] WITH PASSWORD = N'password2', CHECK_EXPIRATION $ExpectedProps = 'ComputerName,InstanceName,SqlInstance,DatabaseName,User,Status'.Split(',') ($result.PsObject.Properties.Name | Sort-Object) | Should Be ($ExpectedProps | Sort-Object) } - $results = Repair-DbaDbOrphanUser -SqlInstance $script:instance1 -Database dbatoolsci_orphan + $results = Repair-DbaDbOrphanUser -SqlInstance $TestConfig.instance1 -Database dbatoolsci_orphan It "does not find any other orphan" { $results | Should -BeNullOrEmpty } -} \ No newline at end of file +} diff --git a/tests/Repair-DbaInstanceName.Tests.ps1 b/tests/Repair-DbaInstanceName.Tests.ps1 index 8107bb826d..47117b9608 100644 --- a/tests/Repair-DbaInstanceName.Tests.ps1 +++ b/tests/Repair-DbaInstanceName.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Reset-DbaAdmin.Tests.ps1 b/tests/Reset-DbaAdmin.Tests.ps1 index 998fdf9da7..eee2109e9d 100644 --- a/tests/Reset-DbaAdmin.Tests.ps1 +++ b/tests/Reset-DbaAdmin.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,16 +15,16 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { AfterAll { - Get-DbaProcess -SqlInstance $script:instance2 -Login dbatoolsci_resetadmin | Stop-DbaProcess -WarningAction SilentlyContinue - Get-DbaLogin -SqlInstance $script:instance2 -Login dbatoolsci_resetadmin| Remove-DbaLogin -Confirm:$false + Get-DbaProcess -SqlInstance $TestConfig.instance2 -Login dbatoolsci_resetadmin | Stop-DbaProcess -WarningAction SilentlyContinue + Get-DbaLogin -SqlInstance $TestConfig.instance2 -Login dbatoolsci_resetadmin| Remove-DbaLogin -Confirm:$false } Context "adds a sql login" { It "adds the login as sysadmin" { $password = ConvertTo-SecureString -Force -AsPlainText resetadmin1 $cred = New-Object System.Management.Automation.PSCredential ("dbatoolsci_resetadmin", $password) - $results = Reset-DbaAdmin -SqlInstance $script:instance2 -Login dbatoolsci_resetadmin -SecurePassword $password -Confirm:$false + $results = Reset-DbaAdmin -SqlInstance $TestConfig.instance2 -Login dbatoolsci_resetadmin -SecurePassword $password -Confirm:$false $results.Name | Should -Be dbatoolsci_resetadmin $results.IsMember("sysadmin") | Should -Be $true } } -} \ No newline at end of file +} diff --git a/tests/Reset-DbatoolsConfig.Tests.ps1 b/tests/Reset-DbatoolsConfig.Tests.ps1 index 336f3e540b..4a5e4ab3a2 100644 --- a/tests/Reset-DbatoolsConfig.Tests.ps1 +++ b/tests/Reset-DbatoolsConfig.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Resolve-DbaNetworkName.Tests.ps1 b/tests/Resolve-DbaNetworkName.Tests.ps1 index fa682db899..5cc546de65 100644 --- a/tests/Resolve-DbaNetworkName.Tests.ps1 +++ b/tests/Resolve-DbaNetworkName.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Resolve-DbaPath.Tests.ps1 b/tests/Resolve-DbaPath.Tests.ps1 index 577fb3fdb5..d146e731fa 100644 --- a/tests/Resolve-DbaPath.Tests.ps1 +++ b/tests/Resolve-DbaPath.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Restart-DbaService.Tests.ps1 b/tests/Restart-DbaService.Tests.ps1 index b0b245590e..a257404ab4 100644 --- a/tests/Restart-DbaService.Tests.ps1 +++ b/tests/Restart-DbaService.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -17,9 +17,9 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Command actually works" { - $instanceName = (Connect-DbaInstance -SqlInstance $script:instance2).ServiceName + $instanceName = (Connect-DbaInstance -SqlInstance $TestConfig.instance2).ServiceName It "restarts some services" { - $services = Restart-DbaService -ComputerName $script:instance2 -InstanceName $instanceName -Type Agent + $services = Restart-DbaService -ComputerName $TestConfig.instance2 -InstanceName $instanceName -Type Agent $services | Should Not Be $null foreach ($service in $services) { $service.State | Should Be 'Running' @@ -28,7 +28,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } It "restarts some services through pipeline" { - $services = Get-DbaService -ComputerName $script:instance2 -InstanceName $instanceName -Type Agent, Engine | Restart-DbaService + $services = Get-DbaService -ComputerName $TestConfig.instance2 -InstanceName $instanceName -Type Agent, Engine | Restart-DbaService $services | Should Not Be $null foreach ($service in $services) { $service.State | Should Be 'Running' @@ -36,4 +36,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } } } -} \ No newline at end of file +} diff --git a/tests/Restore-DbaDatabase.Tests.ps1 b/tests/Restore-DbaDatabase.Tests.ps1 index a3efbcb377..0b69aaefbb 100644 --- a/tests/Restore-DbaDatabase.Tests.ps1 +++ b/tests/Restore-DbaDatabase.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -14,7 +14,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { } Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { - # $script:instance3 to add to the 2016_2017 matrix + # $TestConfig.instance3 to add to the 2016_2017 matrix #Setup variable for multiple contexts $DataFolder = 'c:\temp\datafiles' $LogFolder = 'C:\temp\logfiles' @@ -22,10 +22,10 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { New-Item -ItemType Directory $LogFolder -ErrorAction SilentlyContinue Context "Properly restores a database on the local drive using Path" { - $null = Get-DbaDatabase -SqlInstance $script:instance2 -ExcludeSystem | Remove-DbaDatabase -Confirm:$false - $results = Restore-DbaDatabase -SqlInstance $script:instance2 -Path $script:appveyorlabrepo\singlerestore\singlerestore.bak + $null = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -ExcludeSystem | Remove-DbaDatabase -Confirm:$false + $results = Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -Path "$($TestConfig.appveyorlabrepo)\singlerestore\singlerestore.bak" It "Should Return the proper backup file location" { - $results.BackupFile | Should Be "$script:appveyorlabrepo\singlerestore\singlerestore.bak" + $results.BackupFile | Should Be "$($TestConfig.appveyorlabrepo)\singlerestore\singlerestore.bak" } It "Should return successful restore" { $results.RestoreComplete | Should Be $true @@ -33,7 +33,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } Context "Ensuring warning is thrown if database already exists" { - $results = Restore-DbaDatabase -SqlInstance $script:instance2 -Path $script:appveyorlabrepo\singlerestore\singlerestore.bak -WarningVariable warning -WarningAction SilentlyContinue + $results = Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -Path "$($TestConfig.appveyorlabrepo)\singlerestore\singlerestore.bak" -WarningVariable warning -WarningAction SilentlyContinue It "Should warn" { $warning | Where-Object { $_ -like '*Test-DbaBackupInformation*Database*' } | Should Match "exists, so WithReplace must be specified" } @@ -43,20 +43,20 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } Context "Database is properly removed again after withreplace test" { - Get-DbaProcess $script:instance2 -Database singlerestore | Stop-DbaProcess -WarningVariable warn -WarningAction SilentlyContinue - $results = Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance2 -Database singlerestore - Get-DbaProcess $script:instance2 -Database singlerestore | Stop-DbaProcess -WarningVariable warn -WarningAction SilentlyContinue - $results = Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance2 -Database singlerestore + Get-DbaProcess $TestConfig.instance2 -Database singlerestore | Stop-DbaProcess -WarningVariable warn -WarningAction SilentlyContinue + $results = Remove-DbaDatabase -Confirm:$false -SqlInstance $TestConfig.instance2 -Database singlerestore + Get-DbaProcess $TestConfig.instance2 -Database singlerestore | Stop-DbaProcess -WarningVariable warn -WarningAction SilentlyContinue + $results = Remove-DbaDatabase -Confirm:$false -SqlInstance $TestConfig.instance2 -Database singlerestore It "Should say the status was dropped" { $results.Status -eq "Dropped" -or $results.Status -eq $null } } - Get-DbaProcess $script:instance2 -ExcludeSystemSpids | Stop-DbaProcess -WarningVariable warn -WarningAction SilentlyContinue + Get-DbaProcess $TestConfig.instance2 -ExcludeSystemSpids | Stop-DbaProcess -WarningVariable warn -WarningAction SilentlyContinue Context "Properly restores a database on the local drive using piped Get-ChildItem results" { - $results = Get-ChildItem $script:appveyorlabrepo\singlerestore\singlerestore.bak | Restore-DbaDatabase -SqlInstance $script:instance2 + $results = Get-ChildItem "$($TestConfig.appveyorlabrepo)\singlerestore\singlerestore.bak" | Restore-DbaDatabase -SqlInstance $TestConfig.instance2 It "Should Return the proper backup file location" { - $results.BackupFile | Should Be "$script:appveyorlabrepo\singlerestore\singlerestore.bak" + $results.BackupFile | Should Be "$($TestConfig.appveyorlabrepo)\singlerestore\singlerestore.bak" } It "Should return successful restore" { $results.RestoreComplete | Should Be $true @@ -64,56 +64,56 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } Context "Test VerifyOnly works with db in existence" { - $results = Get-ChildItem $script:appveyorlabrepo\singlerestore\singlerestore.bak | Restore-DbaDatabase -SqlInstance $script:instance2 -VerifyOnly + $results = Get-ChildItem "$($TestConfig.appveyorlabrepo)\singlerestore\singlerestore.bak" | Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -VerifyOnly It "Should have verified Successfully" { $results[0] | Should Be "Verify successful" } } - Get-DbaProcess $script:instance2 -ExcludeSystemSpids | Stop-DbaProcess -WarningVariable warn -WarningAction SilentlyContinue + Get-DbaProcess $TestConfig.instance2 -ExcludeSystemSpids | Stop-DbaProcess -WarningVariable warn -WarningAction SilentlyContinue Context "Database is properly removed again after gci tests" { - $results = Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance2 -Database singlerestore + $results = Remove-DbaDatabase -Confirm:$false -SqlInstance $TestConfig.instance2 -Database singlerestore It "Should say the status was dropped" { $results.Status | Should Be "Dropped" } } Context "Allows continues with Differential Backups" { - $results = Restore-DbaDatabase -SqlInstance $script:instance2 -Path $script:appveyorlabrepo\DoubleDiffing\difftest-full.bak -NoRecovery + $results = Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -Path "$($TestConfig.appveyorlabrepo)\DoubleDiffing\difftest-full.bak" -NoRecovery It "Should restore the root full cleanly" { $results.RestoreComplete | Should -Be $True } - $results1 = Restore-DbaDatabase -SqlInstance $script:instance2 -Path $script:appveyorlabrepo\DoubleDiffing\difftest-diff1.bak -NoRecovery -Continue + $results1 = Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -Path "$($TestConfig.appveyorlabrepo)\DoubleDiffing\difftest-diff1.bak" -NoRecovery -Continue It "Should restore the first diff cleanly" { $results1.RestoreComplete | Should -Be $True } - $results2 = Restore-DbaDatabase -SqlInstance $script:instance2 -Path $script:appveyorlabrepo\DoubleDiffing\difftest-diff2.bak -Continue + $results2 = Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -Path "$($TestConfig.appveyorlabrepo)\DoubleDiffing\difftest-diff2.bak" -Continue It "Should restore the second diff cleanly" { $results2.RestoreComplete | Should -Be $True } } - Get-DbaProcess $script:instance2 -ExcludeSystemSpids | Stop-DbaProcess -WarningVariable warn -WarningAction SilentlyContinue + Get-DbaProcess $TestConfig.instance2 -ExcludeSystemSpids | Stop-DbaProcess -WarningVariable warn -WarningAction SilentlyContinue Clear-DbaConnectionPool Start-Sleep -Seconds 2 Context "Database is restored with correct renamings" { - $results = Get-ChildItem $script:appveyorlabrepo\singlerestore\singlerestore.bak | Restore-DbaDatabase -SqlInstance $script:instance2 -DestinationFilePrefix prefix + $results = Get-ChildItem "$($TestConfig.appveyorlabrepo)\singlerestore\singlerestore.bak" | Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -DestinationFilePrefix prefix It "Should return successful restore with prefix" { $results.RestoreComplete | Should Be $true } It "Should return the 2 prefixed files" { (($results.RestoredFile -split ',').substring(0, 6) -eq 'prefix').count | Should be 2 } - $results = Get-ChildItem $script:appveyorlabrepo\singlerestore\singlerestore.bak | Restore-DbaDatabase -SqlInstance $script:instance2 -DestinationFileSuffix suffix -WithReplace + $results = Get-ChildItem "$($TestConfig.appveyorlabrepo)\singlerestore\singlerestore.bak" | Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -DestinationFileSuffix suffix -WithReplace It "Should return successful restore with suffix" { ($results.RestoreComplete -eq $true) | Should Be $true } It "Should return the 2 suffixed files" { (($Results.RestoredFile -split ',') -match "suffix\.").count | Should be 2 } - $results = Get-ChildItem $script:appveyorlabrepo\singlerestore\singlerestore.bak | Restore-DbaDatabase -SqlInstance $script:instance2 -DestinationFileSuffix suffix -DestinationFilePrefix prefix -WithReplace + $results = Get-ChildItem "$($TestConfig.appveyorlabrepo)\singlerestore\singlerestore.bak" | Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -DestinationFileSuffix suffix -DestinationFilePrefix prefix -WithReplace It "Should return successful restore with suffix and prefix" { ($results.RestoreComplete -eq $true) | Should Be $true } @@ -122,9 +122,9 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } } - Get-DbaProcess $script:instance2 -ExcludeSystemSpids | Stop-DbaProcess -WarningVariable warn -WarningAction SilentlyContinue + Get-DbaProcess $TestConfig.instance2 -ExcludeSystemSpids | Stop-DbaProcess -WarningVariable warn -WarningAction SilentlyContinue Context "Database is properly removed again post prefix and suffix tests" { - $results = Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance2 -Database singlerestore + $results = Remove-DbaDatabase -Confirm:$false -SqlInstance $TestConfig.instance2 -Database singlerestore It "Should say the status was dropped" { $results.Status | Should Be "Dropped" } @@ -132,7 +132,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } Context "Replace databasename in Restored File" { - $results = Get-ChildItem $script:appveyorlabrepo\singlerestore\singlerestore.bak | Restore-DbaDatabase -SqlInstance $script:instance2 -DatabaseName Pestering -replaceDbNameInFile -WithReplace + $results = Get-ChildItem "$($TestConfig.appveyorlabrepo)\singlerestore\singlerestore.bak" | Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -DatabaseName Pestering -replaceDbNameInFile -WithReplace It "Should return the 2 files swapping singlerestore for pestering (output)" { (($Results.RestoredFile -split ',') -like "*pestering*").count | Should be 2 } @@ -144,17 +144,17 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } Context "Replace databasename in Restored File, but don't change backup history #5036" { - $bh = Get-DbaBackupInformation -Path $script:appveyorlabrepo\singlerestore\singlerestore.bak -SqlInstance $script:instance2 + $bh = Get-DbaBackupInformation -Path "$($TestConfig.appveyorlabrepo)\singlerestore\singlerestore.bak" -SqlInstance $TestConfig.instance2 $firstPhysicalName = $bh.FileList.PhysicalName[0] - $null = $bh | Restore-DbaDatabase -SqlInstance $script:instance2 -DatabaseName Pestering -replaceDbNameInFile -WithReplace -OutputScriptOnly + $null = $bh | Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -DatabaseName Pestering -replaceDbNameInFile -WithReplace -OutputScriptOnly It "Should not change the PhysicalName in the FileList of the backup history" { $bh.FileList.PhysicalName[0] | Should be $firstPhysicalName } } Context "Database is properly removed (name change)" { - $results = Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance2 -Database pestering + $results = Remove-DbaDatabase -Confirm:$false -SqlInstance $TestConfig.instance2 -Database pestering It "Should say the status was dropped" { $results.Status | Should Be "Dropped" } @@ -163,49 +163,49 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Context "Test restoring as other login #6992" { #Check first that the db isn't owned by SA - $results = Get-ChildItem $script:appveyorlabrepo\singlerestore\singlerestore.bak | Restore-DbaDatabase -SqlInstance $script:instance2 -DatabaseName Pestering -replaceDbNameInFile -WithReplace - $db = Get-DbaDatabase -SqlInstance $script:instance2 -Database Pestering + $results = Get-ChildItem "$($TestConfig.appveyorlabrepo)\singlerestore\singlerestore.bak" | Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -DatabaseName Pestering -replaceDbNameInFile -WithReplace + $db = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database Pestering It "Should Not be owned by SA this time" { $db.owner | Should Not Be "sa" } - Remove-DbaDatabase -SqlInstance $script:instance2 -Database Pestering -Confirm:$false + Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database Pestering -Confirm:$false - $results = Get-ChildItem $script:appveyorlabrepo\singlerestore\singlerestore.bak | Restore-DbaDatabase -SqlInstance $script:instance2 -DatabaseName Pestering -replaceDbNameInFile -WithReplace -ExecuteAs badlogin -WarningVariable warnvar - $db = Get-DbaDatabase -SqlInstance $script:instance2 -Database Pestering + $results = Get-ChildItem "$($TestConfig.appveyorlabrepo)\singlerestore\singlerestore.bak" | Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -DatabaseName Pestering -replaceDbNameInFile -WithReplace -ExecuteAs badlogin -WarningVariable warnvar + $db = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database Pestering It "Should throw a warning if login doesn't exist" { $warnvar | Should BeLike "*You specified a Login to execute the restore, but the login 'badlogin' does not exist" } - $results = Get-ChildItem $script:appveyorlabrepo\singlerestore\singlerestore.bak | Restore-DbaDatabase -SqlInstance $script:instance2 -DatabaseName Pestering -replaceDbNameInFile -WithReplace -ExecuteAs sa - $db = Get-DbaDatabase -SqlInstance $script:instance2 -Database Pestering + $results = Get-ChildItem "$($TestConfig.appveyorlabrepo)\singlerestore\singlerestore.bak" | Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -DatabaseName Pestering -replaceDbNameInFile -WithReplace -ExecuteAs sa + $db = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database Pestering It "Should be owned by SA this time" { $db.owner | Should Be "sa" } - Remove-DbaDatabase -SqlInstance $script:instance2 -Database Pestering -Confirm:$false + Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database Pestering -Confirm:$false $RestoreAsUser = 'RestoreAs' - New-DbaLogin -SqlInstance $script:instance2 -Login $RestoreAsUser -SecurePassword (ConvertTo-SecureString 'P@ssw0rdl!ng' -AsPlainText -Force) -force - Add-DbaServerRoleMember -SqlInstance $script:instance2 -ServerRole sysadmin -Login $RestoreAsUser -confirm:$false - $results = Get-ChildItem $script:appveyorlabrepo\singlerestore\singlerestore.bak | Restore-DbaDatabase -SqlInstance $script:instance2 -DatabaseName Pestering -replaceDbNameInFile -WithReplace -ExecuteAs $RestoreAsUser - $db2 = Get-DbaDatabase -SqlInstance $script:instance2 -Database Pestering + New-DbaLogin -SqlInstance $TestConfig.instance2 -Login $RestoreAsUser -SecurePassword (ConvertTo-SecureString 'P@ssw0rdl!ng' -AsPlainText -Force) -force + Add-DbaServerRoleMember -SqlInstance $TestConfig.instance2 -ServerRole sysadmin -Login $RestoreAsUser -confirm:$false + $results = Get-ChildItem "$($TestConfig.appveyorlabrepo)\singlerestore\singlerestore.bak" | Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -DatabaseName Pestering -replaceDbNameInFile -WithReplace -ExecuteAs $RestoreAsUser + $db2 = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database Pestering It "Should be owned by $RestoreAsUser this time" { $db2.owner | Should Be "$RestoreAsUser" } - $results6 = Get-ChildItem $script:appveyorlabrepo\singlerestore\singlerestore.bak | Restore-DbaDatabase -SqlInstance $script:instance2 -DatabaseName Pestering -replaceDbNameInFile -WithReplace -ExecuteAs $RestoreAsUser -OutputScriptOnly + $results6 = Get-ChildItem "$($TestConfig.appveyorlabrepo)\singlerestore\singlerestore.bak" | Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -DatabaseName Pestering -replaceDbNameInFile -WithReplace -ExecuteAs $RestoreAsUser -OutputScriptOnly It "Should prefix the script with the Execute As statement" { $results6 | Should BeLike "EXECUTE AS LOGIN='$RestoreAsUser'*" } } - Get-DbaProcess $script:instance2 -ExcludeSystemSpids | Stop-DbaProcess -WarningVariable warn -WarningAction SilentlyContinue + Get-DbaProcess $TestConfig.instance2 -ExcludeSystemSpids | Stop-DbaProcess -WarningVariable warn -WarningAction SilentlyContinue Clear-DbaConnectionPool Start-Sleep -Seconds 2 Context "Folder restore options" { - $results = Get-ChildItem $script:appveyorlabrepo\singlerestore\singlerestore.bak | Restore-DbaDatabase -SqlInstance $script:instance2 -DestinationDataDirectory $DataFolder + $results = Get-ChildItem "$($TestConfig.appveyorlabrepo)\singlerestore\singlerestore.bak" | Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -DestinationDataDirectory $DataFolder It "Should return successful restore with DestinationDataDirectory" { $results.RestoreComplete | Should Be $true } @@ -218,7 +218,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } } - $results = Get-ChildItem $script:appveyorlabrepo\singlerestore\singlerestore.bak | Restore-DbaDatabase -SqlInstance $script:instance2 -DestinationDataDirectory $DataFolder -DestinationLogDirectory $LogFolder -WithReplace + $results = Get-ChildItem "$($TestConfig.appveyorlabrepo)\singlerestore\singlerestore.bak" | Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -DestinationDataDirectory $DataFolder -DestinationLogDirectory $LogFolder -WithReplace It "Should have moved data file to $DataFolder" { (($results.RestoredFileFull -split ',') -like "$DataFolder*").count | Should be 1 } @@ -233,7 +233,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } Context "Database is properly removed again after folder options tests" { - $results = Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance2 -Database singlerestore + $results = Remove-DbaDatabase -Confirm:$false -SqlInstance $TestConfig.instance2 -Database singlerestore It "Should say the status was dropped" { $results.Status | Should Be "Dropped" } @@ -242,7 +242,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Clear-DbaConnectionPool Start-Sleep -Seconds 2 Context "Putting all restore file modification options together" { - $results = Get-ChildItem $script:appveyorlabrepo\singlerestore\singlerestore.bak | Restore-DbaDatabase -SqlInstance $script:instance2 -DestinationDataDirectory $DataFolder -DestinationLogDirectory $LogFolder -DestinationFileSuffix Suffix -DestinationFilePrefix prefix + $results = Get-ChildItem "$($TestConfig.appveyorlabrepo)\singlerestore\singlerestore.bak" | Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -DestinationDataDirectory $DataFolder -DestinationLogDirectory $LogFolder -DestinationFileSuffix Suffix -DestinationFilePrefix prefix It "Should return successful restore with all file mod options" { $results.RestoreComplete | Should Be $true } @@ -266,19 +266,19 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Start-Sleep -Seconds 1 Context "Database is properly removed again after all file mods test" { - $results = Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance2 -Database singlerestore + $results = Remove-DbaDatabase -Confirm:$false -SqlInstance $TestConfig.instance2 -Database singlerestore It "Should say the status was dropped" { $results.Status | Should Be "Dropped" } } - Get-DbaProcess $script:instance2 -ExcludeSystemSpids | Stop-DbaProcess -WarningVariable warn -WarningAction SilentlyContinue + Get-DbaProcess $TestConfig.instance2 -ExcludeSystemSpids | Stop-DbaProcess -WarningVariable warn -WarningAction SilentlyContinue Clear-DbaConnectionPool Start-Sleep -Seconds 5 Clear-DbaConnectionPool Context "Properly restores an instance using ola-style backups via pipe" { - $results = Get-ChildItem $script:appveyorlabrepo\sql2008-backups | Restore-DbaDatabase -SqlInstance $script:instance2 + $results = Get-ChildItem "$($TestConfig.appveyorlabrepo)\sql2008-backups" | Restore-DbaDatabase -SqlInstance $TestConfig.instance2 It "Restored files count should be the right number" { $results.DatabaseName.Count | Should Be 33 } @@ -289,7 +289,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } Context "Should proceed if backups from multiple dbs passed in and databasename specified" { - $results = Get-ChildItem $script:appveyorlabrepo\sql2008-backups | Restore-DbaDatabase -SqlInstance $script:instance2 -DatabaseName test -WarningVariable warnvar + $results = Get-ChildItem "$($TestConfig.appveyorlabrepo)\sql2008-backups" | Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -DatabaseName test -WarningVariable warnvar It "Should return nothing" { $null -eq $results | Should be $True } @@ -300,10 +300,10 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } Context "Database is properly removed again after ola pipe test" { - Get-DbaProcess $script:instance2 -ExcludeSystemSpids | Stop-DbaProcess -WarningVariable warn -WarningAction SilentlyContinue - $results = Get-DbaDatabase -SqlInstance $script:instance2 -ExcludeSystem | Remove-DbaDatabase -Confirm:$false - Get-DbaProcess $script:instance2 -ExcludeSystemSpids | Stop-DbaProcess -WarningVariable warn -WarningAction SilentlyContinue - $results = Get-DbaDatabase -SqlInstance $script:instance2 -ExcludeSystem | Remove-DbaDatabase -Confirm:$false + Get-DbaProcess $TestConfig.instance2 -ExcludeSystemSpids | Stop-DbaProcess -WarningVariable warn -WarningAction SilentlyContinue + $results = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -ExcludeSystem | Remove-DbaDatabase -Confirm:$false + Get-DbaProcess $TestConfig.instance2 -ExcludeSystemSpids | Stop-DbaProcess -WarningVariable warn -WarningAction SilentlyContinue + $results = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -ExcludeSystem | Remove-DbaDatabase -Confirm:$false It "Should say the status was dropped or null" { foreach ($result in $results) { @@ -313,7 +313,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } Context "Properly restores an instance using ola-style backups via string" { - $results = Restore-DbaDatabase -SqlInstance $script:instance2 -Path $script:appveyorlabrepo\sql2008-backups + $results = Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -Path "$($TestConfig.appveyorlabrepo)\sql2008-backups" It "Restored files count should be the right number" { $results.DatabaseName.Count | Should Be 33 } @@ -323,22 +323,22 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } } - Get-DbaProcess $script:instance2 -ExcludeSystemSpids | Stop-DbaProcess -WarningVariable warn -WarningAction SilentlyContinue + Get-DbaProcess $TestConfig.instance2 -ExcludeSystemSpids | Stop-DbaProcess -WarningVariable warn -WarningAction SilentlyContinue Context "All user databases are removed post ola-style test" { - $results = Get-DbaDatabase -SqlInstance $script:instance2 -ExcludeSystem | Remove-DbaDatabase -Confirm:$false + $results = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -ExcludeSystem | Remove-DbaDatabase -Confirm:$false It -Skip "Should say the status was dropped" { $results | ForEach-Object { $_.Status | Should Be "Dropped" } } } - Get-DbaProcess $script:instance2 -ExcludeSystemSpids | Stop-DbaProcess -WarningVariable warn -WarningAction SilentlyContinue + Get-DbaProcess $TestConfig.instance2 -ExcludeSystemSpids | Stop-DbaProcess -WarningVariable warn -WarningAction SilentlyContinue Clear-DbaConnectionPool Start-Sleep -Seconds 2 Context "RestoreTime setup checks" { - $results = Restore-DbaDatabase -SqlInstance $script:instance2 -path $script:appveyorlabrepo\RestoreTimeClean2016 - $sqlResults = Invoke-DbaQuery -SqlInstance $script:instance2 -Query "select convert(datetime,convert(varchar(20),max(dt),120)) as maxdt, convert(datetime,convert(varchar(20),min(dt),120)) as mindt from RestoreTimeClean.dbo.steps" + $results = Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -path "$($TestConfig.appveyorlabrepo)\RestoreTimeClean2016" + $sqlResults = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Query "select convert(datetime,convert(varchar(20),max(dt),120)) as maxdt, convert(datetime,convert(varchar(20),min(dt),120)) as mindt from RestoreTimeClean.dbo.steps" It "Should restore cleanly" { ($results.RestoreComplete -contains $false) | Should Be $false ($results.count -gt 0) | Should be $True @@ -358,7 +358,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Start-Sleep -Seconds 1 Context "All user databases are removed post RestoreTime check" { - $results = Get-DbaDatabase -SqlInstance $script:instance2 -ExcludeSystem | Remove-DbaDatabase -Confirm:$false + $results = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -ExcludeSystem | Remove-DbaDatabase -Confirm:$false It "Should say the status was dropped" { Foreach ($db in $results) { $db.Status | Should Be "Dropped" } } @@ -368,8 +368,8 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Start-Sleep -Seconds 1 Context "RestoreTime point in time" { - $results = Restore-DbaDatabase -SqlInstance $script:instance2 -path $script:appveyorlabrepo\RestoreTimeClean2016 -RestoreTime (Get-Date "2019-05-02 21:12:27") -WarningVariable warnvar -ErrorVariable errvar - $sqlResults = Invoke-DbaQuery -SqlInstance $script:instance2 -Query "select convert(datetime,convert(varchar(20),max(dt),120)) as maxdt, convert(datetime,convert(varchar(20),min(dt),120)) as mindt from RestoreTimeClean.dbo.steps" + $results = Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -path "$($TestConfig.appveyorlabrepo)\RestoreTimeClean2016" -RestoreTime (Get-Date "2019-05-02 21:12:27") -WarningVariable warnvar -ErrorVariable errvar + $sqlResults = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Query "select convert(datetime,convert(varchar(20),max(dt),120)) as maxdt, convert(datetime,convert(varchar(20),min(dt),120)) as mindt from RestoreTimeClean.dbo.steps" It "Should have restored 4 files" { $results.count | Should be 4 } @@ -382,7 +382,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } Context "All user databases are removed" { - $results = Get-DbaDatabase -SqlInstance $script:instance2 -ExcludeSystem | Remove-DbaDatabase -Confirm:$false + $results = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -ExcludeSystem | Remove-DbaDatabase -Confirm:$false It -Skip "Should say the status was dropped post point in time test" { Foreach ($db in $results) { $db.Status | Should Be "Dropped" } } @@ -392,8 +392,8 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Start-Sleep -Seconds 1 Context "RestoreTime point in time with Simple Model" { - $results = Restore-DbaDatabase -SqlInstance $script:instance2 -path $script:appveyorlabrepo\sql2008-backups\SimpleRecovery\ -RestoreTime (Get-Date "2018-04-06 10:37:44") - $sqlResults = Invoke-DbaQuery -SqlInstance $script:instance2 -Query "select convert(datetime,convert(varchar(20),max(dt),120)) as maxdt, convert(datetime,convert(varchar(20),min(dt),120)) as mindt from SimpleBackTest.dbo.steps" + $results = Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -path "$($TestConfig.appveyorlabrepo)\sql2008-backups\SimpleRecovery\" -RestoreTime (Get-Date "2018-04-06 10:37:44") + $sqlResults = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Query "select convert(datetime,convert(varchar(20),max(dt),120)) as maxdt, convert(datetime,convert(varchar(20),min(dt),120)) as mindt from SimpleBackTest.dbo.steps" It "Should have restored 2 files" { $results.count | Should be 2 @@ -407,7 +407,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } Context "All user databases are removed" { - $results = Get-DbaDatabase -SqlInstance $script:instance2 -ExcludeSystem | Remove-DbaDatabase -Confirm:$false + $results = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -ExcludeSystem | Remove-DbaDatabase -Confirm:$false It "Should say the status was dropped post point in time test" { Foreach ($db in $results) { $db.Status | Should Be "Dropped" } } @@ -418,17 +418,17 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Context "RestoreTime point in time and continue" { AfterAll { - $null = Get-DbaDatabase -SqlInstance $script:instance2 -ExcludeSystem | Remove-DbaDatabase -Confirm:$false + $null = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -ExcludeSystem | Remove-DbaDatabase -Confirm:$false } - $Should_Run = (Connect-DbaInstance -SqlInstance $script:instance2).Version.ToString() -like '13.*' + $Should_Run = (Connect-DbaInstance -SqlInstance $TestConfig.instance2).Version.ToString() -like '13.*' if (-not ($Should_Run)) { It "The test can run" { Set-TestInconclusive -Message "a 2016 is strictly needed" } return } - $results = Restore-DbaDatabase -SqlInstance $script:instance2 -path $script:appveyorlabrepo\RestoreTimeClean2016 -RestoreTime (Get-Date "2019-05-02 21:12:27") -StandbyDirectory c:\temp -WarningVariable warnvar -ErrorVariable errvar -ErrorAction SilentlyContinue - $sqlResults = Invoke-DbaQuery -SqlInstance $script:instance2 -Query "select convert(datetime,convert(varchar(20),max(dt),120)) as maxdt, convert(datetime,convert(varchar(20),min(dt),120)) as mindt from RestoreTimeClean.dbo.steps" + $results = Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -path "$($TestConfig.appveyorlabrepo)\RestoreTimeClean2016" -RestoreTime (Get-Date "2019-05-02 21:12:27") -StandbyDirectory c:\temp -WarningVariable warnvar -ErrorVariable errvar -ErrorAction SilentlyContinue + $sqlResults = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Query "select convert(datetime,convert(varchar(20),max(dt),120)) as maxdt, convert(datetime,convert(varchar(20),min(dt),120)) as mindt from RestoreTimeClean.dbo.steps" $warnvar It "Should not warn" { $null -eq (Get-Variable | Where-Object { $_.Name -eq 'warnvar' }) -or '' -eq $warnvar | Should Be $True @@ -443,8 +443,8 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { It "Should have restored to 05/02/2019 21:12:26" { $sqlResults.maxdt | Should be (Get-Date "02 May 2019 21:12:26") } - $results2 = Restore-DbaDatabase -SqlInstance $script:instance2 -path $script:appveyorlabrepo\RestoreTimeClean2016 -Continue - $sqlResults2 = Invoke-DbaQuery -SqlInstance $script:instance2 -Query "select convert(datetime,convert(varchar(20),max(dt),120)) as maxdt, convert(datetime,convert(varchar(20),min(dt),120)) as mindt from RestoreTimeClean.dbo.steps" + $results2 = Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -path "$($TestConfig.appveyorlabrepo)\RestoreTimeClean2016" -Continue + $sqlResults2 = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Query "select convert(datetime,convert(varchar(20),max(dt),120)) as maxdt, convert(datetime,convert(varchar(20),min(dt),120)) as mindt from RestoreTimeClean.dbo.steps" It "Should have restored 4 files" { $results2.count | Should be 4 } @@ -459,17 +459,17 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Context "RestoreTime point in time and continue with rename" { AfterAll { - $null = Get-DbaDatabase -SqlInstance $script:instance2 -ExcludeSystem | Remove-DbaDatabase -Confirm:$false + $null = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -ExcludeSystem | Remove-DbaDatabase -Confirm:$false } - $Should_Run = (Connect-DbaInstance -SqlInstance $script:instance2).Version.ToString() -like '13.*' + $Should_Run = (Connect-DbaInstance -SqlInstance $TestConfig.instance2).Version.ToString() -like '13.*' if (-not ($Should_Run)) { It "The test can run" { Set-TestInconclusive -Message "a 2016 is strictly needed" } return } - $results = Restore-DbaDatabase -SqlInstance $script:instance2 -Databasename contest -path $script:appveyorlabrepo\RestoreTimeClean2016 -RestoreTime (Get-Date "2019-05-02 21:23:58") -StandbyDirectory c:\temp - $sqlResults = Invoke-DbaQuery -SqlInstance $script:instance2 -Query "select convert(datetime,convert(varchar(20),max(dt),120)) as maxdt, convert(datetime,convert(varchar(20),min(dt),120)) as mindt from contest.dbo.steps" + $results = Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -Databasename contest -path "$($TestConfig.appveyorlabrepo)\RestoreTimeClean2016" -RestoreTime (Get-Date "2019-05-02 21:23:58") -StandbyDirectory c:\temp + $sqlResults = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Query "select convert(datetime,convert(varchar(20),max(dt),120)) as maxdt, convert(datetime,convert(varchar(20),min(dt),120)) as mindt from contest.dbo.steps" It "Should have restored 4 files" { $results.count | Should be 4 } @@ -479,8 +479,8 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { It "Should have restored to 05/02/2019 21:23:56" { $sqlResults.maxdt | Should be (Get-Date "02 May 2019 21:23:56") } - $results2 = Restore-DbaDatabase -SqlInstance $script:instance2 -Databasename contest -path $script:appveyorlabrepo\RestoreTimeClean2016 -Continue - $sqlResults2 = Invoke-DbaQuery -SqlInstance $script:instance2 -Query "select convert(datetime,convert(varchar(20),max(dt),120)) as maxdt, convert(datetime,convert(varchar(20),min(dt),120)) as mindt from contest.dbo.steps" + $results2 = Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -Databasename contest -path "$($TestConfig.appveyorlabrepo)\RestoreTimeClean2016" -Continue + $sqlResults2 = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Query "select convert(datetime,convert(varchar(20),max(dt),120)) as maxdt, convert(datetime,convert(varchar(20),min(dt),120)) as mindt from contest.dbo.steps" It "Should have restored 2 files" { $results2.count | Should be 2 } @@ -494,86 +494,86 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Context "Continue Restore with Differentials" { AfterAll { - $null = Get-DbaDatabase -SqlInstance $script:instance2 -ExcludeSystem | Remove-DbaDatabase -Confirm:$false + $null = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -ExcludeSystem | Remove-DbaDatabase -Confirm:$false } - $Results = Restore-DbaDatabase -SqlInstance $script:instance2 -Path $script:appveyorlabrepo\sql2008-backups\ft1\FULL\ -NoRecovery + $Results = Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -Path "$($TestConfig.appveyorlabrepo)\sql2008-backups\ft1\FULL\" -NoRecovery It "Should Have restored the database cleanly" { ($results.RestoreComplete -contains $false) | Should be $False (($results | Measure-Object).count -gt 0) | Should be $True } It "Should have left the db in a norecovery state" { - (Get-DbaDatabase -SqlInstance $script:instance2 -Database ft1).Status | Should Be "Restoring" + (Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database ft1).Status | Should Be "Restoring" } - $Results2 = Restore-DbaDatabase -SqlInstance $script:instance2 -Path $script:appveyorlabrepo\sql2008-backups\ft1\ -Continue + $Results2 = Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -Path "$($TestConfig.appveyorlabrepo)\sql2008-backups\ft1\" -Continue It "Should Have restored the database cleanly" { ($results.RestoreComplete -contains $false) | Should be $False (($results | Measure-Object).count -gt 0) | Should be $True } It "Should have recovered the database" { - (Get-DbaDatabase -SqlInstance $script:instance2 -Database ft1).Status | Should Be "Normal" + (Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database ft1).Status | Should Be "Normal" } } Context "Continue Restore with Differentials and rename " { AfterAll { - $null = Get-DbaDatabase -SqlInstance $script:instance2 -ExcludeSystem | Remove-DbaDatabase -Confirm:$false + $null = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -ExcludeSystem | Remove-DbaDatabase -Confirm:$false } - $Results = Restore-DbaDatabase -SqlInstance $script:instance2 -DatabaseName contest -Path $script:appveyorlabrepo\sql2008-backups\ft1\FULL\ -NoRecovery + $Results = Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -DatabaseName contest -Path "$($TestConfig.appveyorlabrepo)\sql2008-backups\ft1\FULL\" -NoRecovery It "Should Have restored the database cleanly" { ($results.RestoreComplete -contains $false) | Should be $False (($results | Measure-Object).count -gt 0) | Should be $True } It "Should have left the db in a norecovery state" { - (Get-DbaDatabase -SqlInstance $script:instance2 -Database contest).Status | Should Be "Restoring" + (Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database contest).Status | Should Be "Restoring" } - $Results2 = Restore-DbaDatabase -SqlInstance $script:instance2 -DatabaseName contest -Path $script:appveyorlabrepo\sql2008-backups\ft1\ -Continue + $Results2 = Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -DatabaseName contest -Path "$($TestConfig.appveyorlabrepo)\sql2008-backups\ft1\" -Continue It "Should Have restored the database cleanly" { ($results2.RestoreComplete -contains $false) | Should be $False (($results2 | Measure-Object).count -gt 0) | Should be $True } It "Should have recovered the database" { - (Get-DbaDatabase -SqlInstance $script:instance2 -Database contest).Status | Should Be "Normal" + (Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database contest).Status | Should Be "Normal" } } Context "Continue Restore with multiple databases" { AfterAll { - $null = Get-DbaDatabase -SqlInstance $script:instance2 -ExcludeSystem | Remove-DbaDatabase -Confirm:$false + $null = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -ExcludeSystem | Remove-DbaDatabase -Confirm:$false } $files = @() - $files += Get-ChildItem $script:appveyorlabrepo\sql2008-backups\db1\FULL\ - $files += Get-ChildItem $script:appveyorlabrepo\sql2008-backups\dbareports\FULL - $Results = $files | Restore-DbaDatabase -SqlInstance $script:instance2 -NoRecovery + $files += Get-ChildItem "$($TestConfig.appveyorlabrepo)\sql2008-backups\db1\FULL\" + $files += Get-ChildItem "$($TestConfig.appveyorlabrepo)\sql2008-backups\dbareports\FULL" + $Results = $files | Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -NoRecovery It "Should Have restored the database cleanly" { ($results.RestoreComplete -contains $false) | Should be $False (($results | Measure-Object).count -gt 0) | Should be $True } It "Should have left the db in a norecovery state" { - (Get-DbaDatabase -SqlInstance $script:instance2 | Where-Object { $_.Status -eq 'Recovering' }).count | Should Be 0 + (Get-DbaDatabase -SqlInstance $TestConfig.instance2 | Where-Object { $_.Status -eq 'Recovering' }).count | Should Be 0 } $files = @() - $files += Get-ChildItem $script:appveyorlabrepo\sql2008-backups\db1\ -Recurse - $files += Get-ChildItem $script:appveyorlabrepo\sql2008-backups\dbareports\ -Recurse - $Results2 = $files | Where-Object { $_.PsIsContainer -eq $false } | Restore-DbaDatabase -SqlInstance $script:instance2 -Continue + $files += Get-ChildItem "$($TestConfig.appveyorlabrepo)\sql2008-backups\db1\" -Recurse + $files += Get-ChildItem "$($TestConfig.appveyorlabrepo)\sql2008-backups\dbareports\" -Recurse + $Results2 = $files | Where-Object { $_.PsIsContainer -eq $false } | Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -Continue It "Should Have restored the database cleanly" { ($results2.RestoreComplete -contains $false) | Should be $False (($results2 | Measure-Object).count -gt 0) | Should be $True } It "Should have recovered the database" { - (Get-DbaDatabase -SqlInstance $script:instance2 | Where-Object { $_.Status -eq 'Recovering' }).count | Should Be 0 + (Get-DbaDatabase -SqlInstance $TestConfig.instance2 | Where-Object { $_.Status -eq 'Recovering' }).count | Should Be 0 } } Context "Backup DB For next test" { - $null = Restore-DbaDatabase -SqlInstance $script:instance2 -path $script:appveyorlabrepo\RestoreTimeClean2016\restoretimeclean.bak - $results = Backup-DbaDatabase -SqlInstance $script:instance2 -Database RestoreTimeClean -BackupDirectory C:\temp + $null = Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -path "$($TestConfig.appveyorlabrepo)\RestoreTimeClean2016\restoretimeclean.bak" + $results = Backup-DbaDatabase -SqlInstance $TestConfig.instance2 -Database RestoreTimeClean -BackupDirectory C:\temp It "Should return successful backup" { $results.BackupComplete | Should Be $true } } Context "All user databases are removed post continue test" { - $results = Get-DbaDatabase -SqlInstance $script:instance2 -ExcludeSystem | Remove-DbaDatabase -Confirm:$false + $results = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -ExcludeSystem | Remove-DbaDatabase -Confirm:$false It "Should say the status was dropped" { Foreach ($db in $results) { $db.Status | Should Be "Dropped" } } @@ -582,10 +582,10 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Clear-DbaConnectionPool Start-Sleep -Seconds 1 - Get-DbaProcess $script:instance2 | Where-Object Program -match 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue + Get-DbaProcess $TestConfig.instance2 | Where-Object Program -match 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue Context "Check Get-DbaDbBackupHistory pipes into Restore-DbaDatabase" { - $history = Get-DbaDbBackupHistory -SqlInstance $script:instance2 -Database RestoreTimeClean -Last - $results = $history | Restore-DbaDatabase -SqlInstance $script:instance2 -WithReplace -TrustDbBackupHistory + $history = Get-DbaDbBackupHistory -SqlInstance $TestConfig.instance2 -Database RestoreTimeClean -Last + $results = $history | Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -WithReplace -TrustDbBackupHistory It "Should have restored everything successfully" { ($results.RestoreComplete -contains $false) | Should be $False (($results | Measure-Object).count -gt 0) | Should be $True @@ -596,14 +596,14 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Start-Sleep -Seconds 1 Context "All user databases are removed post history test" { - $results = Get-DbaDatabase -SqlInstance $script:instance2 -ExcludeSystem | Remove-DbaDatabase -Confirm:$false + $results = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -ExcludeSystem | Remove-DbaDatabase -Confirm:$false It "Should say the status was dropped" { Foreach ($db in $results) { $db.Status | Should Be "Dropped" } } } Context "Restores a db with log and file files missing extensions" { - $results = Restore-DbaDatabase -SqlInstance $script:instance2 -path $script:appveyorlabrepo\sql2008-backups\Noextension.bak -ErrorVariable Errvar -WarningVariable WarnVar + $results = Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -path "$($TestConfig.appveyorlabrepo)\sql2008-backups\Noextension.bak" -ErrorVariable Errvar -WarningVariable WarnVar It "Should Restore successfully" { ($results.RestoreComplete -contains $false) | Should Be $false (($results | Measure-Object).count -gt 0) | Should be $True @@ -613,7 +613,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Start-Sleep -Seconds 1 Context "All user databases are removed post history test" { - $results = Get-DbaDatabase -SqlInstance $script:instance2 -ExcludeSystem | Remove-DbaDatabase -Confirm:$false + $results = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -ExcludeSystem | Remove-DbaDatabase -Confirm:$false It "Should say the status was dropped" { Foreach ($db in $results) { $db.Status | Should Be "Dropped" } } @@ -621,12 +621,12 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Context "Setup for Recovery Tests" { $DatabaseName = 'rectest' - $results = Restore-DbaDatabase -SqlInstance $script:instance2 -Path $script:appveyorlabrepo\singlerestore\singlerestore.bak -NoRecovery -DatabaseName $DatabaseName -DestinationFilePrefix $DatabaseName -WithReplace + $results = Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -Path "$($TestConfig.appveyorlabrepo)\singlerestore\singlerestore.bak" -NoRecovery -DatabaseName $DatabaseName -DestinationFilePrefix $DatabaseName -WithReplace It "Should have restored everything successfully" { ($results.RestoreComplete -contains $false) | Should be $False (($results | Measure-Object).count -gt 0) | Should be $True } - $check = Get-DbaDatabase -SqlInstance $script:instance2 -Database $DatabaseName + $check = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $DatabaseName It "Should return 1 database" { $check.count | Should Be 1 } @@ -637,12 +637,12 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Context "Test recovery via parameter" { $DatabaseName = 'rectest' - $results = Restore-DbaDatabase -SqlInstance $script:instance2 -Recover -DatabaseName $DatabaseName + $results = Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -Recover -DatabaseName $DatabaseName It "Should have restored everything successfully" { ($results.RestoreComplete -contains $false) | Should be $False (($results | Measure-Object).count -gt 0) | Should be $True } - $check = Get-DbaDatabase -SqlInstance $script:instance2 -Database $DatabaseName + $check = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $DatabaseName It "Should return 1 database" { $check.count | Should Be 1 } @@ -653,12 +653,12 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Context "Setup for Recovery Tests" { $DatabaseName = 'rectest' - $results = Restore-DbaDatabase -SqlInstance $script:instance2 -Path $script:appveyorlabrepo\singlerestore\singlerestore.bak -NoRecovery -DatabaseName $DatabaseName -DestinationFilePrefix $DatabaseName -WithReplace + $results = Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -Path "$($TestConfig.appveyorlabrepo)\singlerestore\singlerestore.bak" -NoRecovery -DatabaseName $DatabaseName -DestinationFilePrefix $DatabaseName -WithReplace It "Should have restored everything successfully" { ($results.RestoreComplete -contains $false) | Should be $False (($results | Measure-Object).count -gt 0) | Should be $True } - $check = Get-DbaDatabase -SqlInstance $script:instance2 -Database $DatabaseName + $check = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $DatabaseName It "Should return 1 database" { $check.count | Should Be 1 } @@ -669,12 +669,12 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Context "Test recovery via pipeline" { $DatabaseName = 'rectest' - $results = Get-DbaDatabase -SqlInstance $script:instance2 -Database $DatabaseName | Restore-DbaDatabase -SqlInstance $script:instance2 -Recover + $results = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $DatabaseName | Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -Recover It "Should have restored everything successfully" { ($results.RestoreComplete -contains $false) | Should be $False (($results | Measure-Object).count -gt 0) | Should be $True } - $check = Get-DbaDatabase -SqlInstance $script:instance2 -Database $DatabaseName + $check = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $DatabaseName It "Should return 1 database" { $check.count | Should Be 1 } @@ -685,7 +685,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Context "Checking we cope with a port number (#244)" { $DatabaseName = 'rectest' - $results = Restore-DbaDatabase -SqlInstance $script:instance2_detailed -Path $script:appveyorlabrepo\singlerestore\singlerestore.bak -DatabaseName $DatabaseName -DestinationFilePrefix $DatabaseName -WithReplace + $results = Restore-DbaDatabase -SqlInstance $TestConfig.instance2_detailed -Path "$($TestConfig.appveyorlabrepo)\singlerestore\singlerestore.bak" -DatabaseName $DatabaseName -DestinationFilePrefix $DatabaseName -WithReplace It "Should have restored everything successfully" { ($results.RestoreComplete -contains $false) | Should be $False (($results | Measure-Object).count -gt 0) | Should be $True @@ -693,7 +693,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } Context "All user databases are removed post port test" { - $results = Get-DbaDatabase -SqlInstance $script:instance2 -ExcludeSystem | Remove-DbaDatabase -Confirm:$false + $results = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -ExcludeSystem | Remove-DbaDatabase -Confirm:$false It "Should say the status was dropped" { Foreach ($db in $results) { $db.Status | Should Be "Dropped" } } @@ -701,8 +701,8 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Context "Checking OutputScriptOnly only outputs script" { $DatabaseName = 'rectestSO' - $results = Restore-DbaDatabase -SqlInstance $script:instance2 -Path $script:appveyorlabrepo\singlerestore\singlerestore.bak -DatabaseName $DatabaseName -OutputScriptOnly - $db = Get-DbaDatabase -SqlInstance $script:instance2 -Database $DatabaseName + $results = Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -Path "$($TestConfig.appveyorlabrepo)\singlerestore\singlerestore.bak" -DatabaseName $DatabaseName -OutputScriptOnly + $db = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $DatabaseName It "Should only output a script" { $results -match 'RESTORE DATABASE' | Should be $True ($null -eq $db) | Should be $True @@ -710,11 +710,11 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } Context "Checking OutputScriptOnly only outputs script without changing state for existing dbs (#2940)" { $DatabaseName = 'dbatoolsci_rectestSO' - Get-DbaDatabase -SqlInstance $script:instance2 -Database $DatabaseName | Remove-DbaDatabase -Confirm:$false - $server = Connect-DbaInstance $script:instance2 + Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $DatabaseName | Remove-DbaDatabase -Confirm:$false + $server = Connect-DbaInstance $TestConfig.instance2 $server.Query("CREATE DATABASE $DatabaseName") - $results = Restore-DbaDatabase -SqlInstance $script:instance2 -Path $script:appveyorlabrepo\singlerestore\singlerestore.bak -DatabaseName $DatabaseName -OutputScriptOnly -WithReplace - $db = Get-DbaDatabase -SqlInstance $script:instance2 -Database $DatabaseName + $results = Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -Path "$($TestConfig.appveyorlabrepo)\singlerestore\singlerestore.bak" -DatabaseName $DatabaseName -OutputScriptOnly -WithReplace + $db = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $DatabaseName It "Should only output a script" { $results -match 'RESTORE DATABASE' | Should be $True } @@ -724,17 +724,17 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $db | Remove-DbaDatabase -Confirm:$false } Context "All user databases are removed post Output script test" { - $results = Get-DbaDatabase -SqlInstance $script:instance2 -ExcludeSystem | Remove-DbaDatabase -Confirm:$false + $results = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -ExcludeSystem | Remove-DbaDatabase -Confirm:$false It "Should say the status was dropped" { Foreach ($db in $results) { $db.Status | Should Be "Dropped" } } } Context "Checking Output vs input" { $DatabaseName = 'rectestSO' - $results = Restore-DbaDatabase -SqlInstance $script:instance2 -Path $script:appveyorlabrepo\singlerestore\singlerestore.bak -DatabaseName $DatabaseName -BufferCount 24 -MaxTransferSize 128kb -BlockSize 64kb + $results = Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -Path "$($TestConfig.appveyorlabrepo)\singlerestore\singlerestore.bak" -DatabaseName $DatabaseName -BufferCount 24 -MaxTransferSize 128kb -BlockSize 64kb It "Should return the destination instance" { - $results.SqlInstance = $script:instance2 + $results.SqlInstance = $TestConfig.instance2 } It "Should have a BlockSize of 65536" { @@ -751,23 +751,23 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } Context "All user databases are removed post Output vs Input test" { - $results = Get-DbaDatabase -SqlInstance $script:instance2 -ExcludeSystem | Remove-DbaDatabase -Confirm:$false + $results = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -ExcludeSystem | Remove-DbaDatabase -Confirm:$false It "Should say the status was dropped" { Foreach ($db in $results) { $db.Status | Should Be "Dropped" } } } Context "Checking CDC parameter " { - $output = Restore-DbaDatabase -SqlInstance $script:instance2 -Path $script:appveyorlabrepo\singlerestore\singlerestore.bak -DatabaseName $DatabaseName -OutputScriptOnly -KeepCDC -WithReplace + $output = Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -Path "$($TestConfig.appveyorlabrepo)\singlerestore\singlerestore.bak" -DatabaseName $DatabaseName -OutputScriptOnly -KeepCDC -WithReplace It "Should have KEEP_CDC in the SQL" { ($output -like '*KEEP_CDC*') | Should be $True } - $output = Restore-DbaDatabase -SqlInstance $script:instance2 -Path $script:appveyorlabrepo\singlerestore\singlerestore.bak -DatabaseName $DatabaseName -OutputScriptOnly -KeepCDC -WithReplace -WarningVariable warnvar -NoRecovery -WarningAction SilentlyContinue + $output = Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -Path "$($TestConfig.appveyorlabrepo)\singlerestore\singlerestore.bak" -DatabaseName $DatabaseName -OutputScriptOnly -KeepCDC -WithReplace -WarningVariable warnvar -NoRecovery -WarningAction SilentlyContinue It "Should not output, and warn if Norecovery and KeepCDC specified" { ($warnvar -like '*KeepCDC cannot be specified with Norecovery or Standby as it needs recovery to work') | Should be $True $output | Should be $null } - $output = Restore-DbaDatabase -SqlInstance $script:instance2 -Path $script:appveyorlabrepo\singlerestore\singlerestore.bak -DatabaseName $DatabaseName -OutputScriptOnly -KeepCDC -WithReplace -WarningVariable warnvar -StandbyDirectory c:\temp\ -WarningAction SilentlyContinue + $output = Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -Path "$($TestConfig.appveyorlabrepo)\singlerestore\singlerestore.bak" -DatabaseName $DatabaseName -OutputScriptOnly -KeepCDC -WithReplace -WarningVariable warnvar -StandbyDirectory c:\temp\ -WarningAction SilentlyContinue It "Should not output, and warn if StandbyDirectory and KeepCDC specified" { ($warnvar -like '*KeepCDC cannot be specified with Norecovery or Standby as it needs recovery to work') | Should be $True $output | Should be $null @@ -775,8 +775,8 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } Context "Page level restores" { - Get-DbaDatabase -SqlInstance $script:instance2 -ExcludeSystem | Remove-DbaDatabase -confirm:$false - $null = Restore-DbaDatabase -SqlInstance $script:instance2 -Path $script:appveyorlabrepo\singlerestore\singlerestore.bak -DatabaseName PageRestore -DestinationFilePrefix PageRestore + Get-DbaDatabase -SqlInstance $TestConfig.instance2 -ExcludeSystem | Remove-DbaDatabase -confirm:$false + $null = Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -Path "$($TestConfig.appveyorlabrepo)\singlerestore\singlerestore.bak" -DatabaseName PageRestore -DestinationFilePrefix PageRestore $sql = "alter database PageRestore set Recovery Full Create table testpage( Filler char(8000) @@ -828,14 +828,14 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { insert into testpage values (REPLICATE('f','8000')) use master" - $null = Invoke-DbaQuery -SqlInstance $script:instance2 -Query $sql -Database Pagerestore - $sqlResults2 = Invoke-DbaQuery -SqlInstance $script:instance2 -Database Master -Query "select * from pagerestore.dbo.testpage where filler like 'a%'" -ErrorVariable errvar -ErrorAction SilentlyContinue + $null = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Query $sql -Database Pagerestore + $sqlResults2 = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database Master -Query "select * from pagerestore.dbo.testpage where filler like 'a%'" -ErrorVariable errvar -ErrorAction SilentlyContinue It "Should have warned about corruption" { ($errvar -match "SQL Server detected a logical consistency-based I/O error: incorrect checksum \(expected") | Should be $True ($null -eq $sqlResults2) | Should be $True } - $null = Get-DbaDbBackupHistory -SqlInstance $script:instance2 -Database pagerestore -last | Restore-DbaDatabase -SqlInstance $script:instance2 -PageRestore (Get-DbaSuspectPage -SqlInstance $script:instance2 -Database PageRestore) -TrustDbBackupHistory -DatabaseName PageRestore -PageRestoreTailFolder c:\temp -ErrorAction SilentlyContinue - $sqlResults3 = Invoke-DbaQuery -SqlInstance $script:instance2 -Query "select * from pagerestore.dbo.testpage where filler like 'f%'" -ErrorVariable errvar3 -ErrorAction SilentlyContinue + $null = Get-DbaDbBackupHistory -SqlInstance $TestConfig.instance2 -Database pagerestore -last | Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -PageRestore (Get-DbaSuspectPage -SqlInstance $TestConfig.instance2 -Database PageRestore) -TrustDbBackupHistory -DatabaseName PageRestore -PageRestoreTailFolder c:\temp -ErrorAction SilentlyContinue + $sqlResults3 = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Query "select * from pagerestore.dbo.testpage where filler like 'f%'" -ErrorVariable errvar3 -ErrorAction SilentlyContinue It -Skip "Should work after page restore" { #($null -eq $errvar3) | Should Be $True ($null -eq $sqlResults3) | Should be $False @@ -845,112 +845,112 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } Context "Testing Backup to Restore piping" { - Get-DbaDatabase -SqlInstance $script:instance2 -ExcludeSystem | Remove-DbaDatabase -Confirm:$false - $null = Restore-DbaDatabase -SqlInstance $script:instance2 -Path $script:appveyorlabrepo\singlerestore\singlerestore.bak -DatabaseName PipeTest -DestinationFilePrefix PipeTest - $results = Backup-DbaDatabase -SqlInstance $script:instance2 -Database Pipetest -BackupDirectory c:\temp -CopyOnly -WarningAction SilentlyContinue -WarningVariable bwarnvar -ErrorAction SilentlyContinue -ErrorVariable berrvar | Restore-DbaDatabase -SqlInstance $script:instance2 -DatabaseName restored -ReplaceDbNameInFile -WarningAction SilentlyContinue -WarningVariable rwarnvar -ErrorAction SilentlyContinue -ErrorVariable rerrvar + Get-DbaDatabase -SqlInstance $TestConfig.instance2 -ExcludeSystem | Remove-DbaDatabase -Confirm:$false + $null = Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -Path "$($TestConfig.appveyorlabrepo)\singlerestore\singlerestore.bak" -DatabaseName PipeTest -DestinationFilePrefix PipeTest + $results = Backup-DbaDatabase -SqlInstance $TestConfig.instance2 -Database Pipetest -BackupDirectory c:\temp -CopyOnly -WarningAction SilentlyContinue -WarningVariable bwarnvar -ErrorAction SilentlyContinue -ErrorVariable berrvar | Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -DatabaseName restored -ReplaceDbNameInFile -WarningAction SilentlyContinue -WarningVariable rwarnvar -ErrorAction SilentlyContinue -ErrorVariable rerrvar It "Should backup and restore cleanly" { $results.RestoreComplete | Should Be $True } } Context "Check we restore striped database" { - Get-DbaDatabase -SqlInstance $script:instance2 -ExcludeSystem | Remove-DbaDatabase -Confirm:$false - $results = Restore-DbaDatabase -SqlInstance $script:instance2 -Path $script:appveyorlabrepo\sql2008-backups\RestoreTimeStripe -DatabaseName StripeTest -DestinationFilePrefix StripeTest + Get-DbaDatabase -SqlInstance $TestConfig.instance2 -ExcludeSystem | Remove-DbaDatabase -Confirm:$false + $results = Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -Path "$($TestConfig.appveyorlabrepo)\sql2008-backups\RestoreTimeStripe" -DatabaseName StripeTest -DestinationFilePrefix StripeTest It "Should backup and restore cleanly" { ($results | Where-Object { $_.RestoreComplete -eq $True }).count | Should Be $Results.count } - $null = Remove-DbaDatabase -SqlInstance $script:instance2 -Database StripeTest + $null = Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database StripeTest } Context "Don't try to create/test folders with OutputScriptOnly (Issue 4046)" { - $null = Restore-DbaDatabase -SqlInstance $script:instance2 -Path $script:appveyorlabrepo\RestoreTimeClean2016\RestoreTimeClean.bak -DestinationDataDirectory g:\DoesNtExist -OutputScriptOnly -WarningVariable warnvar + $null = Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -Path "$($TestConfig.appveyorlabrepo)\RestoreTimeClean2016\RestoreTimeClean.bak" -DestinationDataDirectory g:\DoesNtExist -OutputScriptOnly -WarningVariable warnvar It "Should not raise a warning" { ('' -eq $warnvar) | Should -Be $True } } Context "Checking that WITH KEEP_REPLICATION gets properly added" { $DatabaseName = 'reptestSO' - $results = Restore-DbaDatabase -SqlInstance $script:instance2 -Path $script:appveyorlabrepo\singlerestore\singlerestore.bak -DatabaseName $DatabaseName -OutputScriptOnly -KeepReplication + $results = Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -Path "$($TestConfig.appveyorlabrepo)\singlerestore\singlerestore.bak" -DatabaseName $DatabaseName -OutputScriptOnly -KeepReplication It "Should output a script with keep replication clause" { $results -match 'RESTORE DATABASE.*WITH.*KEEP_REPLICATION' | Should be $True } } Context "Test restoring a Backup encrypted with Certificate" { - New-DbaDatabase -SqlInstance $script:instance2 -Name EncRestTest -Confirm:$false + New-DbaDatabase -SqlInstance $TestConfig.instance2 -Name EncRestTest -Confirm:$false $securePass = ConvertTo-SecureString "estBackupDir\master\script:instance1).split('\')[1])\Full\master-Full.bak" -AsPlainText -Force - New-DbaDbMasterKey -SqlInstance $script:instance2 -Database Master -SecurePassword $securePass -confirm:$false - $cert = New-DbaDbCertificate -SqlInstance $script:instance2 -Database Master -Name RestoreTestCert -Subject RestoreTestCert - $encBackupResults = Backup-DbaDatabase -SqlInstance $script:instance2 -Database EncRestTest -EncryptionAlgorithm AES128 -EncryptionCertificate RestoreTestCert + New-DbaDbMasterKey -SqlInstance $TestConfig.instance2 -Database Master -SecurePassword $securePass -confirm:$false + $cert = New-DbaDbCertificate -SqlInstance $TestConfig.instance2 -Database Master -Name RestoreTestCert -Subject RestoreTestCert + $encBackupResults = Backup-DbaDatabase -SqlInstance $TestConfig.instance2 -Database EncRestTest -EncryptionAlgorithm AES128 -EncryptionCertificate RestoreTestCert It "Should encrypt the backup" { $encBackupResults.EncryptorType | Should Be "CERTIFICATE" $encBackupResults.KeyAlgorithm | Should Be "aes_128" } - $results = $encBackupResults | Restore-DbaDatabase -SqlInstance $script:instance2 -TrustDbBackupHistory -RestoredDatabaseNamePrefix cert -DestinationFilePrefix cert -confirm:$false + $results = $encBackupResults | Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -TrustDbBackupHistory -RestoredDatabaseNamePrefix cert -DestinationFilePrefix cert -confirm:$false It "Should have restored the backup" { $results.RestoreComplete | Should Be $True } - Remove-DbaDbCertificate -SqlInstance $script:instance2 -Database Master -Certificate RestoreTestCert -Confirm:$false - Remove-DbaDbMasterKey -SqlInstance $script:instance2 -Database Master -confirm:$false - Remove-DbaDatabase -SqlInstance $script:instance2 -Database EncRestTest, certEncRestTest -confirm:$false + Remove-DbaDbCertificate -SqlInstance $TestConfig.instance2 -Database Master -Certificate RestoreTestCert -Confirm:$false + Remove-DbaDbMasterKey -SqlInstance $TestConfig.instance2 -Database Master -confirm:$false + Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database EncRestTest, certEncRestTest -confirm:$false } Context "Test restoring with StopAt" { - $restoreOutput = Restore-DbaDatabase -SqlInstance $script:instance2 -Name StopAt2 -Path $script:appveyorlabrepo\sql2008-backups\StopAt -StopMark dbatoolstest -WithReplace - $null = Restore-DbaDatabase -SqlInstance $script:instance2 -Name StopAt2 -Recover - $sqlOut = Invoke-DbaQuery -SqlInstance $script:instance2 -Database StopAt2 -Query "select max(step) as ms from steps" + $restoreOutput = Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -Name StopAt2 -Path "$($TestConfig.appveyorlabrepo)\sql2008-backups\StopAt" -StopMark dbatoolstest -WithReplace + $null = Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -Name StopAt2 -Recover + $sqlOut = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database StopAt2 -Query "select max(step) as ms from steps" It "Should have stoped at mark" { $sqlOut.ms | Should -Be 9876 } - $null = Remove-DbaDatabase -SqlInstance $script:instance2 -Database StopAt2 + $null = Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database StopAt2 } Context "Test restoring with StopAtBefore" { - $restoreOutput = Restore-DbaDatabase -SqlInstance $script:instance2 -Name StopAt2 -Path $script:appveyorlabrepo\sql2008-backups\StopAt -StopMark dbatoolstest -WithReplace -StopBefore - $null = Restore-DbaDatabase -SqlInstance $script:instance2 -Name StopAt2 -Recover - $sqlOut = Invoke-DbaQuery -SqlInstance $script:instance2 -Database StopAt2 -Query "select max(step) as ms from steps" + $restoreOutput = Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -Name StopAt2 -Path "$($TestConfig.appveyorlabrepo)\sql2008-backups\StopAt" -StopMark dbatoolstest -WithReplace -StopBefore + $null = Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -Name StopAt2 -Recover + $sqlOut = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database StopAt2 -Query "select max(step) as ms from steps" It "Should have stoped at mark" { $sqlOut.ms | Should -Be 8764 } - $null = Remove-DbaDatabase -SqlInstance $script:instance2 -Database StopAt2 + $null = Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database StopAt2 } Context "Test restoring with StopAt and StopAfterDate" { - $restoreOutput = Restore-DbaDatabase -SqlInstance $script:instance2 -Name StopAt2 -Path $script:appveyorlabrepo\sql2008-backups\StopAt -StopMark dbatoolstest -StopAfterDate (Get-Date '2020-05-12 13:33:35') -WithReplace - $null = Restore-DbaDatabase -SqlInstance $script:instance2 -Name StopAt2 -Recover - $sqlOut = Invoke-DbaQuery -SqlInstance $script:instance2 -Database StopAt2 -Query "select max(step) as ms from steps" + $restoreOutput = Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -Name StopAt2 -Path "$($TestConfig.appveyorlabrepo)\sql2008-backups\StopAt" -StopMark dbatoolstest -StopAfterDate (Get-Date '2020-05-12 13:33:35') -WithReplace + $null = Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -Name StopAt2 -Recover + $sqlOut = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database StopAt2 -Query "select max(step) as ms from steps" It "Should have stoped at mark" { $sqlOut.ms | Should -Be 29876 } - $null = Remove-DbaDatabase -SqlInstance $script:instance2 -Database StopAt2 + $null = Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database StopAt2 } Context "Warn if OutputScriptOnly and VerifyOnly specified together #6987" { - $restoreOutput = Restore-DbaDatabase -SqlInstance $script:instance2 -Name StopAt2 -Path $script:appveyorlabrepo\sql2008-backups\StopAt -OutputScriptOnly -VerifyOnly -WarningVariable warnvar + $restoreOutput = Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -Name StopAt2 -Path "$($TestConfig.appveyorlabrepo)\sql2008-backups\StopAt" -OutputScriptOnly -VerifyOnly -WarningVariable warnvar It "Should return a warning" { $warnvar | Should -BeLike '*The switches OutputScriptOnly and VerifyOnly cannot both be specified at the same time, stopping' } - $null = Remove-DbaDatabase -SqlInstance $script:instance2 -Database StopAt2 + $null = Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database StopAt2 } if ($env:azurepasswd) { Context "Restores From Azure using SAS" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 - if (Get-DbaCredential -SqlInstance $script:instance2 -Name "[$script:azureblob]" ) { - $sql = "DROP CREDENTIAL [$script:azureblob]" + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 + if (Get-DbaCredential -SqlInstance $TestConfig.instance2 -Name "[$TestConfig.azureblob]" ) { + $sql = "DROP CREDENTIAL [$TestConfig.azureblob]" $server.Query($sql) } - $sql = "CREATE CREDENTIAL [$script:azureblob] WITH IDENTITY = N'SHARED ACCESS SIGNATURE', SECRET = N'$env:azurepasswd'" + $sql = "CREATE CREDENTIAL [$TestConfig.azureblob] WITH IDENTITY = N'SHARED ACCESS SIGNATURE', SECRET = N'$env:azurepasswd'" $server.Query($sql) $server.Query("CREATE DATABASE dbatoolsci_azure") } AfterAll { - $server.Query("DROP CREDENTIAL [$script:azureblob]") - Get-DbaDatabase -SqlInstance $script:instance2 -Database "dbatoolsci_azure" | Remove-DbaDatabase -Confirm:$false + $server.Query("DROP CREDENTIAL [$TestConfig.azureblob]") + Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database "dbatoolsci_azure" | Remove-DbaDatabase -Confirm:$false } It "Should restore cleanly" { - $results = Restore-DbaDatabase -SqlInstance $script:instance2 -WithReplace -DatabaseName dbatoolsci_azure -Path $script:azureblob/dbatoolsci_azure.bak - $results.BackupFile | Should -Be "$script:azureblob/dbatoolsci_azure.bak" + $results = Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -WithReplace -DatabaseName dbatoolsci_azure -Path $TestConfig.azureblob/dbatoolsci_azure.bak + $results.BackupFile | Should -Be "$TestConfig.azureblob/dbatoolsci_azure.bak" $results.RestoreComplete | Should Be $True } } @@ -959,21 +959,21 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { if ($env:azurepasswd -and -not $env:appveyor) { Context "Restores Striped backup From Azure using SAS" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 - if (Get-DbaCredential -SqlInstance $script:instance2 -name "[$script:azureblob]" ) { - $sql = "DROP CREDENTIAL [$script:azureblob]" + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 + if (Get-DbaCredential -SqlInstance $TestConfig.instance2 -name "[$TestConfig.azureblob]" ) { + $sql = "DROP CREDENTIAL [$TestConfig.azureblob]" $server.Query($sql) } - $sql = "CREATE CREDENTIAL [$script:azureblob] WITH IDENTITY = N'SHARED ACCESS SIGNATURE', SECRET = N'$env:azurepasswd'" + $sql = "CREATE CREDENTIAL [$TestConfig.azureblob] WITH IDENTITY = N'SHARED ACCESS SIGNATURE', SECRET = N'$env:azurepasswd'" $server.Query($sql) $server.Query("CREATE DATABASE dbatoolsci_azure") } AfterAll { - $server.Query("DROP CREDENTIAL [$script:azureblob]") - Get-DbaDatabase -SqlInstance $script:instance2 -Database "dbatoolsci_azure" | Remove-DbaDatabase -Confirm:$false + $server.Query("DROP CREDENTIAL [$TestConfig.azureblob]") + Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database "dbatoolsci_azure" | Remove-DbaDatabase -Confirm:$false } It "Should restore cleanly" { - $results = @("$script:azureblob/az-1.bak", "$script:azureblob/az-2.bak", "$script:azureblob/az-3.bak") | Restore-DbaDatabase -SqlInstance $script:instance2 -DatabaseName azstripetest -WithReplace -ReplaceDbNameInFile + $results = @("$TestConfig.azureblob/az-1.bak", "$TestConfig.azureblob/az-2.bak", "$TestConfig.azureblob/az-3.bak") | Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -DatabaseName azstripetest -WithReplace -ReplaceDbNameInFile $results.RestoreComplete | Should Be $True } } @@ -981,22 +981,22 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { if ($env:azurelegacypasswd) { Context "Restores from Azure using Access Key" { BeforeAll { - Get-DbaDatabase -SqlInstance $script:instance2 -Database "dbatoolsci_azure" | Remove-DbaDatabase -Confirm:$false - $server = Connect-DbaInstance -SqlInstance $script:instance2 - if (Get-DbaCredential -SqlInstance $script:instance2 -name dbatools_ci) { + Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database "dbatoolsci_azure" | Remove-DbaDatabase -Confirm:$false + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 + if (Get-DbaCredential -SqlInstance $TestConfig.instance2 -name dbatools_ci) { $sql = "DROP CREDENTIAL dbatools_ci" $server.Query($sql) } - $sql = "CREATE CREDENTIAL [dbatools_ci] WITH IDENTITY = N'$script:azureblobaccount', SECRET = N'$env:azurelegacypasswd'" + $sql = "CREATE CREDENTIAL [dbatools_ci] WITH IDENTITY = N'$TestConfig.azureblobaccount', SECRET = N'$env:azurelegacypasswd'" $server.Query($sql) $server.Query("CREATE DATABASE dbatoolsci_azure") } AfterAll { $server.Query("DROP CREDENTIAL dbatools_ci") - Get-DbaDatabase -SqlInstance $script:instance2 -Database "dbatoolsci_azure" | Remove-DbaDatabase -Confirm:$false + Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database "dbatoolsci_azure" | Remove-DbaDatabase -Confirm:$false } It -Skip "supports legacy credential setups" { - $results = Restore-DbaDatabase -SqlInstance $script:instance2 -WithReplace -DatabaseName dbatoolsci_azure -Path https://dbatools.blob.core.windows.net/legacy/dbatoolsci_azure.bak -AzureCredential dbatools_ci + $results = Restore-DbaDatabase -SqlInstance $TestConfig.instance2 -WithReplace -DatabaseName dbatoolsci_azure -Path https://dbatools.blob.core.windows.net/legacy/dbatoolsci_azure.bak -AzureCredential dbatools_ci $results.BackupFile | Should -Be 'https://dbatools.blob.core.windows.net/legacy/dbatoolsci_azure.bak' $results.Script -match 'CREDENTIAL' | Should -Be $true $results.RestoreComplete | Should Be $True @@ -1004,4 +1004,4 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } } #> -} \ No newline at end of file +} diff --git a/tests/Restore-DbaDbCertificate.Tests.ps1 b/tests/Restore-DbaDbCertificate.Tests.ps1 index 41e327e803..98d95c9381 100644 --- a/tests/Restore-DbaDbCertificate.Tests.ps1 +++ b/tests/Restore-DbaDbCertificate.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,14 +16,14 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Can create a database certificate" { BeforeAll { - $masterkey = New-DbaDbMasterKey -SqlInstance $script:instance1 -Database tempdb -Password $(ConvertTo-SecureString -String "GoodPass1234!" -AsPlainText -Force) -Confirm:$false + $masterkey = New-DbaDbMasterKey -SqlInstance $TestConfig.instance1 -Database tempdb -Password $(ConvertTo-SecureString -String "GoodPass1234!" -AsPlainText -Force) -Confirm:$false $password = ConvertTo-SecureString -AsPlainText "GoodPass1234!!" -Force - $cert = New-DbaDbCertificate -SqlInstance $script:instance1 -Database tempdb -Confirm:$false - $backup = Backup-DbaDbCertificate -SqlInstance $script:instance1 -Certificate $cert.Name -Database tempdb -EncryptionPassword $password -Confirm:$false + $cert = New-DbaDbCertificate -SqlInstance $TestConfig.instance1 -Database tempdb -Confirm:$false + $backup = Backup-DbaDbCertificate -SqlInstance $TestConfig.instance1 -Certificate $cert.Name -Database tempdb -EncryptionPassword $password -Confirm:$false $cert | Remove-DbaDbCertificate -Confirm:$false } AfterEach { - $null = Remove-DbaDbCertificate -SqlInstance $script:instance1 -Certificate $cert.Name -Database tempdb -Confirm:$false + $null = Remove-DbaDbCertificate -SqlInstance $TestConfig.instance1 -Certificate $cert.Name -Database tempdb -Confirm:$false } AfterAll { $null = $masterkey | Remove-DbaDbMasterKey -Confirm:$false @@ -31,7 +31,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } It "restores the db cert when passing in a .cer file" { - $results = Restore-DbaDbCertificate -SqlInstance $script:instance1 -Path $backup.ExportPath -Password $password -Database tempdb -EncryptionPassword $password -Confirm:$false + $results = Restore-DbaDbCertificate -SqlInstance $TestConfig.instance1 -Path $backup.ExportPath -Password $password -Database tempdb -EncryptionPassword $password -Confirm:$false $results.Parent.Name | Should Be 'tempdb' $results.Name | Should Not BeNullOrEmpty $results.PrivateKeyEncryptionType | Should Be "Password" @@ -42,7 +42,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { It "restores the db cert when passing in a folder" { $folder = Split-Path $backup.ExportPath -Parent - $results = Restore-DbaDbCertificate -SqlInstance $script:instance1 -Path $folder -Password $password -Database tempdb -EncryptionPassword $password -Confirm:$false + $results = Restore-DbaDbCertificate -SqlInstance $TestConfig.instance1 -Path $folder -Password $password -Database tempdb -EncryptionPassword $password -Confirm:$false $results.Parent.Name | Should Be 'tempdb' $results.Name | Should Not BeNullOrEmpty $results.PrivateKeyEncryptionType | Should Be "Password" @@ -51,11 +51,11 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { It "restores the db cert and encrypts with master key" { $folder = Split-Path $backup.ExportPath -Parent - $results = Restore-DbaDbCertificate -SqlInstance $script:instance1 -Path $folder -Password $password -Database tempdb -Confirm:$false + $results = Restore-DbaDbCertificate -SqlInstance $TestConfig.instance1 -Path $folder -Password $password -Database tempdb -Confirm:$false $results.Parent.Name | Should Be 'tempdb' $results.Name | Should Not BeNullOrEmpty $results.PrivateKeyEncryptionType | Should Be "MasterKey" $results | Remove-DbaDbCertificate -Confirm:$false } } -} \ No newline at end of file +} diff --git a/tests/Restore-DbaDbSnapshot.Tests.ps1 b/tests/Restore-DbaDbSnapshot.Tests.ps1 index b8491b61bb..81b9177358 100644 --- a/tests/Restore-DbaDbSnapshot.Tests.ps1 +++ b/tests/Restore-DbaDbSnapshot.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,15 +16,15 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { # Targets only instance2 because it's the only one where Snapshots can happen Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { - Get-DbaProcess -SqlInstance $script:instance2 | Where-Object Program -match dbatools | Stop-DbaProcess -Confirm:$false -WarningAction SilentlyContinue - $server = Connect-DbaInstance -SqlInstance $script:instance2 + Get-DbaProcess -SqlInstance $TestConfig.instance2 | Where-Object Program -match dbatools | Stop-DbaProcess -Confirm:$false -WarningAction SilentlyContinue + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $db1 = "dbatoolsci_RestoreSnap1" $db1_snap1 = "dbatoolsci_RestoreSnap1_snapshotted1" $db1_snap2 = "dbatoolsci_RestoreSnap1_snapshotted2" $db2 = "dbatoolsci_RestoreSnap2" $db2_snap1 = "dbatoolsci_RestoreSnap2_snapshotted1" - Remove-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db1, $db2 -Confirm:$false - Get-DbaDatabase -SqlInstance $script:instance2 -Database $db1, $db2 | Remove-DbaDatabase -Confirm:$false + Remove-DbaDbSnapshot -SqlInstance $TestConfig.instance2 -Database $db1, $db2 -Confirm:$false + Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $db1, $db2 | Remove-DbaDatabase -Confirm:$false $server.Query("CREATE DATABASE $db1") $server.Query("ALTER DATABASE $db1 MODIFY FILE ( NAME = N'$($db1)_log', SIZE = 13312KB )") $server.Query("CREATE DATABASE $db2") @@ -34,52 +34,52 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { $server.Query("INSERT INTO [$db2].[dbo].[Example] values ('sample')") } AfterAll { - Remove-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db1, $db2 -Confirm:$false -ErrorAction SilentlyContinue - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance2 -Database $db1, $db2 -ErrorAction SilentlyContinue + Remove-DbaDbSnapshot -SqlInstance $TestConfig.instance2 -Database $db1, $db2 -Confirm:$false -ErrorAction SilentlyContinue + Remove-DbaDatabase -Confirm:$false -SqlInstance $TestConfig.instance2 -Database $db1, $db2 -ErrorAction SilentlyContinue } Context "Parameters validation" { It "Stops if no Database or Snapshot" { - { Restore-DbaDbSnapshot -SqlInstance $script:instance2 -EnableException } | Should Throw "You must specify" + { Restore-DbaDbSnapshot -SqlInstance $TestConfig.instance2 -EnableException } | Should Throw "You must specify" } It "Is nice by default" { - { Restore-DbaDbSnapshot -SqlInstance $script:instance2 *> $null } | Should Not Throw "You must specify" + { Restore-DbaDbSnapshot -SqlInstance $TestConfig.instance2 *> $null } | Should Not Throw "You must specify" } } Context "Operations on snapshots" { BeforeEach { - $null = New-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db1 -Name $db1_snap1 -ErrorAction SilentlyContinue - $null = New-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db1 -Name $db1_snap2 -ErrorAction SilentlyContinue - $null = New-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db2 -Name $db2_snap1 -ErrorAction SilentlyContinue + $null = New-DbaDbSnapshot -SqlInstance $TestConfig.instance2 -Database $db1 -Name $db1_snap1 -ErrorAction SilentlyContinue + $null = New-DbaDbSnapshot -SqlInstance $TestConfig.instance2 -Database $db1 -Name $db1_snap2 -ErrorAction SilentlyContinue + $null = New-DbaDbSnapshot -SqlInstance $TestConfig.instance2 -Database $db2 -Name $db2_snap1 -ErrorAction SilentlyContinue } AfterEach { - Remove-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db1, $db2 -Confirm:$false -ErrorAction SilentlyContinue + Remove-DbaDbSnapshot -SqlInstance $TestConfig.instance2 -Database $db1, $db2 -Confirm:$false -ErrorAction SilentlyContinue } It "Honors the Database parameter, restoring only snapshots of that database" { - $result = Restore-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db2 -Confirm:$false -EnableException -Force + $result = Restore-DbaDbSnapshot -SqlInstance $TestConfig.instance2 -Database $db2 -Confirm:$false -EnableException -Force $result.Status | Should Be "Normal" $result.Name | Should Be $db2 $server.Query("INSERT INTO [$db1].[dbo].[Example] values ('sample2')") - $result = Restore-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db1 -Confirm:$false -Force + $result = Restore-DbaDbSnapshot -SqlInstance $TestConfig.instance2 -Database $db1 -Confirm:$false -Force $result.Name | Should Be $db1 # the other snapshot has been dropped - $result = Get-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db1 + $result = Get-DbaDbSnapshot -SqlInstance $TestConfig.instance2 -Database $db1 $result.Count | Should Be 1 # the query doesn't return records inserted before the restore - $result = Invoke-DbaQuery -SqlInstance $script:instance2 -Query "SELECT * FROM [$db1].[dbo].[Example]" -QueryTimeout 10 + $result = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Query "SELECT * FROM [$db1].[dbo].[Example]" -QueryTimeout 10 $result.id | Should Be 1 } It "Honors the Snapshot parameter" { - $result = Restore-DbaDbSnapshot -SqlInstance $script:instance2 -Snapshot $db1_snap1 -Confirm:$false -EnableException -Force + $result = Restore-DbaDbSnapshot -SqlInstance $TestConfig.instance2 -Snapshot $db1_snap1 -Confirm:$false -EnableException -Force $result.Name | Should Be $db1 $result.Status | Should Be "Normal" # the other snapshot has been dropped - $result = Get-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db1 + $result = Get-DbaDbSnapshot -SqlInstance $TestConfig.instance2 -Database $db1 $result.SnapshotOf | Should Be $db1 $result.Database.Name | Should Be $db1_snap @@ -88,14 +88,14 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { } It "Stops if multiple snapshot for the same db are passed" { - $result = Restore-DbaDbSnapshot -SqlInstance $script:instance2 -Snapshot $db1_snap1, $db1_snap2 -Confirm:$false *> $null + $result = Restore-DbaDbSnapshot -SqlInstance $TestConfig.instance2 -Snapshot $db1_snap1, $db1_snap2 -Confirm:$false *> $null $result | Should Be $null } It "has the correct default properties" { - $result = Get-DbaDbSnapshot -SqlInstance $script:instance2 -Database $db2 + $result = Get-DbaDbSnapshot -SqlInstance $TestConfig.instance2 -Database $db2 $ExpectedPropsDefault = 'ComputerName', 'CreateDate', 'InstanceName', 'Name', 'SnapshotOf', 'SqlInstance', 'DiskUsage' ($result.PSStandardMembers.DefaultDisplayPropertySet.ReferencedPropertyNames | Sort-Object) | Should Be ($ExpectedPropsDefault | Sort-Object) } } -} \ No newline at end of file +} diff --git a/tests/Resume-DbaAgDbDataMovement.Tests.ps1 b/tests/Resume-DbaAgDbDataMovement.Tests.ps1 index 6f1d221c33..37d6f34916 100644 --- a/tests/Resume-DbaAgDbDataMovement.Tests.ps1 +++ b/tests/Resume-DbaAgDbDataMovement.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$commandname Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,15 +15,15 @@ Describe "$commandname Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $null = Get-DbaProcess -SqlInstance $script:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue - $server = Connect-DbaInstance -SqlInstance $script:instance3 + $null = Get-DbaProcess -SqlInstance $TestConfig.instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance3 $agname = "dbatoolsci_resumeagdb_agroup" $dbname = "dbatoolsci_resumeagdb_agroupdb" $server.Query("create database $dbname") - $null = Get-DbaDatabase -SqlInstance $script:instance3 -Database $dbname | Backup-DbaDatabase - $null = Get-DbaDatabase -SqlInstance $script:instance3 -Database $dbname | Backup-DbaDatabase -Type Log - $ag = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Database $dbname -Confirm:$false -Certificate dbatoolsci_AGCert -UseLastBackup - $null = Get-DbaAgDatabase -SqlInstance $script:instance3 -AvailabilityGroup $agname | Suspend-DbaAgDbDataMovement -Confirm:$false + $null = Get-DbaDatabase -SqlInstance $TestConfig.instance3 -Database $dbname | Backup-DbaDatabase + $null = Get-DbaDatabase -SqlInstance $TestConfig.instance3 -Database $dbname | Backup-DbaDatabase -Type Log + $ag = New-DbaAvailabilityGroup -Primary $TestConfig.instance3 -Name $agname -ClusterType None -FailoverMode Manual -Database $dbname -Confirm:$false -Certificate dbatoolsci_AGCert -UseLastBackup + $null = Get-DbaAgDatabase -SqlInstance $TestConfig.instance3 -AvailabilityGroup $agname | Suspend-DbaAgDbDataMovement -Confirm:$false } AfterAll { $null = Remove-DbaAvailabilityGroup -SqlInstance $server -AvailabilityGroup $agname -Confirm:$false @@ -31,10 +31,10 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { } Context "resumes data movement" { It "returns resumed results" { - $results = Resume-DbaAgDbDataMovement -SqlInstance $script:instance3 -Database $dbname -Confirm:$false + $results = Resume-DbaAgDbDataMovement -SqlInstance $TestConfig.instance3 -Database $dbname -Confirm:$false $results.AvailabilityGroup | Should -Be $agname $results.Name | Should -Be $dbname $results.SynchronizationState | Should -Be 'Synchronized' } } -} #$script:instance2 for appveyor \ No newline at end of file +} #$TestConfig.instance2 for appveyor diff --git a/tests/Revoke-DbaAgPermission.Tests.ps1 b/tests/Revoke-DbaAgPermission.Tests.ps1 index 523d96b161..722531f0f4 100644 --- a/tests/Revoke-DbaAgPermission.Tests.ps1 +++ b/tests/Revoke-DbaAgPermission.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,17 +15,17 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $null = Invoke-DbaQuery -SqlInstance $script:instance3 -InputFile $script:appveyorlabrepo\sql2008-scripts\logins.sql -ErrorAction SilentlyContinue + $null = Invoke-DbaQuery -SqlInstance $TestConfig.instance3 -InputFile "$($TestConfig.appveyorlabrepo)\sql2008-scripts\logins.sql" -ErrorAction SilentlyContinue $agname = "dbatoolsci_ag_revoke" - $null = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Confirm:$false -Certificate dbatoolsci_AGCert + $null = New-DbaAvailabilityGroup -Primary $TestConfig.instance3 -Name $agname -ClusterType None -FailoverMode Manual -Confirm:$false -Certificate dbatoolsci_AGCert } AfterAll { - $null = Remove-DbaAvailabilityGroup -SqlInstance $script:instance3 -AvailabilityGroup $agname -Confirm:$false + $null = Remove-DbaAvailabilityGroup -SqlInstance $TestConfig.instance3 -AvailabilityGroup $agname -Confirm:$false } Context "revokes big perms" { It "returns results with proper data" { - $results = Get-DbaLogin -SqlInstance $script:instance3 -Login tester | Revoke-DbaAgPermission -Type EndPoint + $results = Get-DbaLogin -SqlInstance $TestConfig.instance3 -Login tester | Revoke-DbaAgPermission -Type EndPoint $results.Status | Should -Be 'Success' } } -} #$script:instance2 for appveyor \ No newline at end of file +} #$TestConfig.instance2 for appveyor diff --git a/tests/Save-DbaCommunitySoftware.Tests.ps1 b/tests/Save-DbaCommunitySoftware.Tests.ps1 index a7fa6a8e3e..46cdecd232 100644 --- a/tests/Save-DbaCommunitySoftware.Tests.ps1 +++ b/tests/Save-DbaCommunitySoftware.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Save-DbaDiagnosticQueryScript.Tests.ps1 b/tests/Save-DbaDiagnosticQueryScript.Tests.ps1 index fa2e005401..f34dfa5851 100644 --- a/tests/Save-DbaDiagnosticQueryScript.Tests.ps1 +++ b/tests/Save-DbaDiagnosticQueryScript.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Save-DbaKbUpdate.Tests.ps1 b/tests/Save-DbaKbUpdate.Tests.ps1 index 8a7a4ea353..cf7e842c32 100644 --- a/tests/Save-DbaKbUpdate.Tests.ps1 +++ b/tests/Save-DbaKbUpdate.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Select-DbaBackupInformation.Tests.ps1 b/tests/Select-DbaBackupInformation.Tests.ps1 index e643960bab..48098116d6 100644 --- a/tests/Select-DbaBackupInformation.Tests.ps1 +++ b/tests/Select-DbaBackupInformation.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$commandname Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Select-DbaDbSequenceNextValue.Tests.ps1 b/tests/Select-DbaDbSequenceNextValue.Tests.ps1 index 877be34563..ad93a279f7 100644 --- a/tests/Select-DbaDbSequenceNextValue.Tests.ps1 +++ b/tests/Select-DbaDbSequenceNextValue.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,7 +16,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BeforeAll { $random = Get-Random - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $newDbName = "dbatoolsci_newdb_$random" $newDb = New-DbaDatabase -SqlInstance $server -Name $newDbName @@ -48,4 +48,4 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $sequenceValue | Should -Be 102 } } -} \ No newline at end of file +} diff --git a/tests/Select-DbaObject.Tests.ps1 b/tests/Select-DbaObject.Tests.ps1 index 61e8e62e5c..4bb5e28446 100644 --- a/tests/Select-DbaObject.Tests.ps1 +++ b/tests/Select-DbaObject.Tests.ps1 @@ -1,6 +1,6 @@ $commandname = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$commandname Unit Tests" -Tag "UnitTests" { Context "Validate parameters" { diff --git a/tests/Set-DbaAgListener.Tests.ps1 b/tests/Set-DbaAgListener.Tests.ps1 index 77ea1bb946..af18e10fde 100644 --- a/tests/Set-DbaAgListener.Tests.ps1 +++ b/tests/Set-DbaAgListener.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Set-DbaAgReplica.Tests.ps1 b/tests/Set-DbaAgReplica.Tests.ps1 index 37e2461fe1..acbe868f6d 100644 --- a/tests/Set-DbaAgReplica.Tests.ps1 +++ b/tests/Set-DbaAgReplica.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,26 +16,27 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { $agname = "dbatoolsci_arepgroup" - $ag = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Certificate dbatoolsci_AGCert -Confirm:$false + $ag = New-DbaAvailabilityGroup -Primary $TestConfig.instance3 -Name $agname -ClusterType None -FailoverMode Manual -Certificate dbatoolsci_AGCert -Confirm:$false $replicaName = $ag.PrimaryReplica } AfterAll { - Remove-DbaAvailabilityGroup -SqlInstance $script:instance3 -AvailabilityGroup $agname -Confirm:$false + Remove-DbaAvailabilityGroup -SqlInstance $TestConfig.instance3 -AvailabilityGroup $agname -Confirm:$false } Context "sets ag properties" { It "returns modified results" { - $results = Set-DbaAgReplica -SqlInstance $script:instance3 -AvailabilityGroup $agname -Replica $replicaName -BackupPriority 100 -Confirm:$false + $results = Set-DbaAgReplica -SqlInstance $TestConfig.instance3 -AvailabilityGroup $agname -Replica $replicaName -BackupPriority 100 -Confirm:$false $results.AvailabilityGroup | Should -Be $agname $results.BackupPriority | Should -Be 100 } It "returns modified results" { - $results = Set-DbaAgReplica -SqlInstance $script:instance3 -AvailabilityGroup $agname -Replica $replicaName -SeedingMode Automatic -Confirm:$false + $results = Set-DbaAgReplica -SqlInstance $TestConfig.instance3 -AvailabilityGroup $agname -Replica $replicaName -SeedingMode Automatic -Confirm:$false $results.AvailabilityGroup | Should -Be $agname $results.SeedingMode | Should -Be Automatic } It "attempts to add a ReadOnlyRoutingList" { - $null = Get-DbaAgReplica -SqlInstance $script:instance3 -AvailabilityGroup $agname | Select-Object -First 1 | Set-DbaAgReplica -ReadOnlyRoutingList nondockersql -WarningAction SilentlyContinue -WarningVariable warn -Confirm:$false + $null = Get-DbaAgReplica -SqlInstance $TestConfig.instance3 -AvailabilityGroup $agname | Select-Object -First 1 | Set-DbaAgReplica -ReadOnlyRoutingList nondockersql -WarningAction SilentlyContinue -WarningVariable warn -Confirm:$false $warn | Should -match "does not exist. Only availability" } } -} #$script:instance2 for appveyor +} #$TestConfig.instance2 for appveyor + diff --git a/tests/Set-DbaAgentAlert.Tests.ps1 b/tests/Set-DbaAgentAlert.Tests.ps1 index b3ee387b0c..9d14c1bfe2 100644 --- a/tests/Set-DbaAgentAlert.Tests.ps1 +++ b/tests/Set-DbaAgentAlert.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,21 +15,21 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 -Database master + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 -Database master $server.Query("EXEC msdb.dbo.sp_add_alert @name=N'dbatoolsci test alert',@message_id=0,@severity=6,@enabled=1,@delay_between_responses=0,@include_event_description_in=0,@category_name=N'[Uncategorized]',@job_id=N'00000000-0000-0000-0000-000000000000'") } AfterAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 -Database master + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 -Database master $server.Query("EXEC msdb.dbo.sp_delete_alert @name=N'dbatoolsci test alert NEW'") } - $results = Set-DbaAgentAlert -SqlInstance $script:instance2 -Alert 'dbatoolsci test alert' -Disabled + $results = Set-DbaAgentAlert -SqlInstance $TestConfig.instance2 -Alert 'dbatoolsci test alert' -Disabled It "changes new alert to disabled" { $results.IsEnabled | Should Be 'False' } - $results = Set-DbaAgentAlert -SqlInstance $script:instance2 -Alert 'dbatoolsci test alert' -NewName 'dbatoolsci test alert NEW' + $results = Set-DbaAgentAlert -SqlInstance $TestConfig.instance2 -Alert 'dbatoolsci test alert' -NewName 'dbatoolsci test alert NEW' It "changes new alert name to dbatoolsci test alert NEW" { $results.Name | Should Be 'dbatoolsci test alert NEW' } -} \ No newline at end of file +} diff --git a/tests/Set-DbaAgentJob.Tests.ps1 b/tests/Set-DbaAgentJob.Tests.ps1 index 7279a20a0b..3cf8126364 100644 --- a/tests/Set-DbaAgentJob.Tests.ps1 +++ b/tests/Set-DbaAgentJob.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Set-DbaAgentJobCategory.Tests.ps1 b/tests/Set-DbaAgentJobCategory.Tests.ps1 index 895dc2c7b7..3aef7d5544 100644 --- a/tests/Set-DbaAgentJobCategory.Tests.ps1 +++ b/tests/Set-DbaAgentJobCategory.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -17,23 +17,23 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "New Agent Job Category is changed properly" { It "Should have the right name and category type" { - $results = New-DbaAgentJobCategory -SqlInstance $script:instance2 -Category CategoryTest1 + $results = New-DbaAgentJobCategory -SqlInstance $TestConfig.instance2 -Category CategoryTest1 $results.Name | Should Be "CategoryTest1" $results.CategoryType | Should Be "LocalJob" } It "Should actually for sure exist" { - $newresults = Get-DbaAgentJobCategory -SqlInstance $script:instance2 -Category CategoryTest1 + $newresults = Get-DbaAgentJobCategory -SqlInstance $TestConfig.instance2 -Category CategoryTest1 $newresults.Name | Should Be "CategoryTest1" $newresults.CategoryType | Should Be "LocalJob" } It "Change the name of the job category" { - $results = Set-DbaAgentJobCategory -SqlInstance $script:instance2 -Category CategoryTest1 -NewName CategoryTest2 + $results = Set-DbaAgentJobCategory -SqlInstance $TestConfig.instance2 -Category CategoryTest1 -NewName CategoryTest2 $results.Name | Should Be "CategoryTest2" } # Cleanup and ignore all output - Remove-DbaAgentJobCategory -SqlInstance $script:instance2 -Category CategoryTest2 -Confirm:$false *> $null + Remove-DbaAgentJobCategory -SqlInstance $TestConfig.instance2 -Category CategoryTest2 -Confirm:$false *> $null } -} \ No newline at end of file +} diff --git a/tests/Set-DbaAgentJobOutputFile.Tests.ps1 b/tests/Set-DbaAgentJobOutputFile.Tests.ps1 index 3b5dfd9b67..995452535f 100644 --- a/tests/Set-DbaAgentJobOutputFile.Tests.ps1 +++ b/tests/Set-DbaAgentJobOutputFile.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Set-DbaAgentJobOwner.Tests.ps1 b/tests/Set-DbaAgentJobOwner.Tests.ps1 index e301937f77..cf2880e2cc 100644 --- a/tests/Set-DbaAgentJobOwner.Tests.ps1 +++ b/tests/Set-DbaAgentJobOwner.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Set-DbaAgentJobStep.Tests.ps1 b/tests/Set-DbaAgentJobStep.Tests.ps1 index 58e2e4c002..ea7492a0a3 100644 --- a/tests/Set-DbaAgentJobStep.Tests.ps1 +++ b/tests/Set-DbaAgentJobStep.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,13 +16,13 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BeforeAll { $random = Get-Random - $job1Instance1 = New-DbaAgentJob -SqlInstance $script:instance1 -Job "dbatoolsci_job_1_$random" - $job1Instance2 = New-DbaAgentJob -SqlInstance $script:instance2 -Job "dbatoolsci_job_1_$random" - $agentStep1 = New-DbaAgentJobStep -SqlInstance $script:instance1 -Job $job1Instance1 -StepName "Step 1" -OnFailAction QuitWithFailure -OnSuccessAction QuitWithSuccess - $agentStep1 = New-DbaAgentJobStep -SqlInstance $script:instance2 -Job $job1Instance2 -StepName "Step 1" -OnFailAction QuitWithFailure -OnSuccessAction QuitWithSuccess + $job1Instance1 = New-DbaAgentJob -SqlInstance $TestConfig.instance1 -Job "dbatoolsci_job_1_$random" + $job1Instance2 = New-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job "dbatoolsci_job_1_$random" + $agentStep1 = New-DbaAgentJobStep -SqlInstance $TestConfig.instance1 -Job $job1Instance1 -StepName "Step 1" -OnFailAction QuitWithFailure -OnSuccessAction QuitWithSuccess + $agentStep1 = New-DbaAgentJobStep -SqlInstance $TestConfig.instance2 -Job $job1Instance2 -StepName "Step 1" -OnFailAction QuitWithFailure -OnSuccessAction QuitWithSuccess - $instance1 = Connect-DbaInstance -SqlInstance $script:instance1 - $instance2 = Connect-DbaInstance -SqlInstance $script:instance2 + $instance1 = Connect-DbaInstance -SqlInstance $TestConfig.instance1 + $instance2 = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $login = "db$random" $plaintext = "BigOlPassword!" @@ -30,7 +30,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $null = Invoke-Command2 -ScriptBlock { net user $login $plaintext /add *>&1 } -ComputerName $instance2.ComputerName - $credential = New-DbaCredential -SqlInstance $script:instance2 -Name "dbatoolsci_$random" -Identity "$($instance2.ComputerName)\$login" -Password $password + $credential = New-DbaCredential -SqlInstance $TestConfig.instance2 -Name "dbatoolsci_$random" -Identity "$($instance2.ComputerName)\$login" -Password $password $agentProxyInstance2 = New-DbaAgentProxy -SqlInstance $instance2 -Name "dbatoolsci_proxy_1_$random" -ProxyCredential "dbatoolsci_$random" -Subsystem PowerShell @@ -47,22 +47,22 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { AfterAll { Remove-DbaDatabase -SqlInstance $instance2 -Database "dbatoolsci_newdb_$random" -Confirm:$false Remove-DbaLogin -SqlInstance $instance2 -Login "user_$random" -Confirm:$false - Remove-DbaAgentJob -SqlInstance $script:instance1 -Job "dbatoolsci_job_1_$random" -Confirm:$false - Remove-DbaAgentJob -SqlInstance $script:instance2 -Job "dbatoolsci_job_1_$random" -Confirm:$false + Remove-DbaAgentJob -SqlInstance $TestConfig.instance1 -Job "dbatoolsci_job_1_$random" -Confirm:$false + Remove-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job "dbatoolsci_job_1_$random" -Confirm:$false $null = Invoke-Command2 -ScriptBlock { net user $args /delete *>&1 } -ArgumentList $login -ComputerName $instance2.ComputerName $credential.Drop() $agentProxyInstance2.Drop() } Context "command works" { It "Change the job step name" { - $results = Get-DbaAgentJob -SqlInstance $script:instance2 -Job $job1Instance2 + $results = Get-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job $job1Instance2 $results.JobSteps | Where-Object Id -eq 1 | Select-Object -ExpandProperty Name | Should -Be "Step 1" - $jobStep = Set-DbaAgentJobStep -SqlInstance $script:instance2 -Job $job1Instance2 -StepName "Step 1" -NewName "Step 1 updated" - $results = Get-DbaAgentJob -SqlInstance $script:instance2 -Job $job1Instance2 + $jobStep = Set-DbaAgentJobStep -SqlInstance $TestConfig.instance2 -Job $job1Instance2 -StepName "Step 1" -NewName "Step 1 updated" + $results = Get-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job $job1Instance2 $results.JobSteps | Where-Object Id -eq 1 | Select-Object -ExpandProperty Name | Should -Be "Step 1 updated" - $jobStep = Set-DbaAgentJobStep -SqlInstance $script:instance2 -Job $job1Instance2 -StepName "Step 1 updated" -NewName "Step 1" + $jobStep = Set-DbaAgentJobStep -SqlInstance $TestConfig.instance2 -Job $job1Instance2 -StepName "Step 1 updated" -NewName "Step 1" } It "pipeline input of pre-connected servers" { @@ -75,8 +75,8 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } It "use the -Force to add a new step" { - $jobStep = Set-DbaAgentJobStep -SqlInstance $script:instance2 -Job $job1Instance2 -StepName "Step 2" -Force - $results = Get-DbaAgentJob -SqlInstance $script:instance2 -Job $job1Instance2 + $jobStep = Set-DbaAgentJobStep -SqlInstance $TestConfig.instance2 -Job $job1Instance2 -StepName "Step 2" -Force + $results = Get-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job $job1Instance2 $results.JobSteps | Where-Object Id -eq 1 | Select-Object -ExpandProperty Name | Should -Be "Step 1" $results.JobSteps | Where-Object Id -eq 2 | Select-Object -ExpandProperty Name | Should -Be "Step 2" } @@ -87,7 +87,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { It "set a step with all attributes for Subsystem=PowerShell" { $jobStep = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 Job = $job1Instance2 StepName = "Step 3" Subsystem = "PowerShell" @@ -108,7 +108,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $results = Set-DbaAgentJobStep @jobStep - $results = Get-DbaAgentJob -SqlInstance $script:instance2 -Job $job1Instance2 + $results = Get-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job $job1Instance2 $newJobStep = $results.JobSteps | Where-Object Id -eq 3 $newJobStep.Name | Should -Be "Step 3" @@ -129,7 +129,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { It "set a step with all attributes for Subsystem=TransactSql" { $jobStep = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 Job = $job1Instance2 StepName = "Step 4" Subsystem = "TransactSql" @@ -150,7 +150,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $results = Set-DbaAgentJobStep @jobStep - $results = Get-DbaAgentJob -SqlInstance $script:instance2 -Job $job1Instance2 + $results = Get-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job $job1Instance2 $newJobStep = $results.JobSteps | Where-Object Id -eq 4 $newJobStep.Name | Should -Be "Step 4" @@ -172,7 +172,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { It "set a step with all attributes for Subsystem=ActiveScripting" { # ActiveScripting was discontinued in SQL Server 2016 $jobStep = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 Job = $job1Instance2 StepName = "Step 5" Subsystem = "ActiveScripting" @@ -198,7 +198,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { It "set a step with all attributes for Subsystem=AnalysisCommand" { $jobStep = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 Job = $job1Instance2 StepName = "Step 5" Subsystem = "AnalysisCommand" @@ -219,7 +219,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $results = Set-DbaAgentJobStep @jobStep - $results = Get-DbaAgentJob -SqlInstance $script:instance2 -Job $job1Instance2 + $results = Get-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job $job1Instance2 $newJobStep = $results.JobSteps | Where-Object Id -eq 5 $newJobStep.Name | Should -Be "Step 5" @@ -240,7 +240,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { It "set a step with all attributes for Subsystem=AnalysisQuery" { $jobStep = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 Job = $job1Instance2 StepName = "Step 6" Subsystem = "AnalysisQuery" @@ -261,7 +261,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $results = Set-DbaAgentJobStep @jobStep - $results = Get-DbaAgentJob -SqlInstance $script:instance2 -Job $job1Instance2 + $results = Get-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job $job1Instance2 $newJobStep = $results.JobSteps | Where-Object Id -eq 6 $newJobStep.Name | Should -Be "Step 6" @@ -282,7 +282,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { It "set a step with all attributes for Subsystem=CmdExec" { $jobStep = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 Job = $job1Instance2 StepName = "Step 7" Subsystem = "CmdExec" @@ -302,7 +302,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $results = Set-DbaAgentJobStep @jobStep - $results = Get-DbaAgentJob -SqlInstance $script:instance2 -Job $job1Instance2 + $results = Get-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job $job1Instance2 $newJobStep = $results.JobSteps | Where-Object Id -eq 7 $newJobStep.Name | Should -Be "Step 7" @@ -322,7 +322,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { It "set a step with all attributes for Subsystem=Distribution" { $jobStep = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 Job = $job1Instance2 StepName = "Step 8" Subsystem = "Distribution" @@ -341,7 +341,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $results = Set-DbaAgentJobStep @jobStep - $results = Get-DbaAgentJob -SqlInstance $script:instance2 -Job $job1Instance2 + $results = Get-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job $job1Instance2 $newJobStep = $results.JobSteps | Where-Object Id -eq 8 $newJobStep.Name | Should -Be "Step 8" @@ -360,7 +360,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { It "set a step with all attributes for Subsystem=LogReader" { $jobStep = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 Job = $job1Instance2 StepName = "Step 9" Subsystem = "LogReader" @@ -379,7 +379,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $results = Set-DbaAgentJobStep @jobStep - $results = Get-DbaAgentJob -SqlInstance $script:instance2 -Job $job1Instance2 + $results = Get-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job $job1Instance2 $newJobStep = $results.JobSteps | Where-Object Id -eq 9 $newJobStep.Name | Should -Be "Step 9" @@ -398,7 +398,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { It "set a step with all attributes for Subsystem=Merge" { $jobStep = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 Job = $job1Instance2 StepName = "Step 10" Subsystem = "Merge" @@ -417,7 +417,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $results = Set-DbaAgentJobStep @jobStep - $results = Get-DbaAgentJob -SqlInstance $script:instance2 -Job $job1Instance2 + $results = Get-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job $job1Instance2 $newJobStep = $results.JobSteps | Where-Object Id -eq 10 $newJobStep.Name | Should -Be "Step 10" @@ -436,7 +436,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { It "set a step with all attributes for Subsystem=QueueReader" { $jobStep = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 Job = $job1Instance2 StepName = "Step 11" Subsystem = "QueueReader" @@ -455,7 +455,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $results = Set-DbaAgentJobStep @jobStep - $results = Get-DbaAgentJob -SqlInstance $script:instance2 -Job $job1Instance2 + $results = Get-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job $job1Instance2 $newJobStep = $results.JobSteps | Where-Object Id -eq 11 $newJobStep.Name | Should -Be "Step 11" @@ -474,7 +474,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { It "set a step with all attributes for Subsystem=Snapshot" { $jobStep = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 Job = $job1Instance2 StepName = "Step 12" Subsystem = "Snapshot" @@ -493,7 +493,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $results = Set-DbaAgentJobStep @jobStep - $results = Get-DbaAgentJob -SqlInstance $script:instance2 -Job $job1Instance2 + $results = Get-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job $job1Instance2 $newJobStep = $results.JobSteps | Where-Object Id -eq 12 $newJobStep.Name | Should -Be "Step 12" @@ -512,7 +512,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { It "set a step with all attributes for Subsystem=SSIS" { $jobStep = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 Job = $job1Instance2 StepName = "Step 13" Subsystem = "SSIS" @@ -530,7 +530,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $results = Set-DbaAgentJobStep @jobStep - $results = Get-DbaAgentJob -SqlInstance $script:instance2 -Job $job1Instance2 + $results = Get-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job $job1Instance2 $newJobStep = $results.JobSteps | Where-Object Id -eq 13 $newJobStep.Name | Should -Be "Step 13" @@ -546,4 +546,4 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $newJobStep.JobStepFlags | Should -Be AppendAllCmdExecOutputToJobHistory } } -} \ No newline at end of file +} diff --git a/tests/Set-DbaAgentOperator.Tests.ps1 b/tests/Set-DbaAgentOperator.Tests.ps1 index 77ada9c057..4d5e75b5aa 100644 --- a/tests/Set-DbaAgentOperator.Tests.ps1 +++ b/tests/Set-DbaAgentOperator.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -14,7 +14,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $instance2 = Connect-DbaInstance -SqlInstance $script:instance2 -Database msdb + $instance2 = Connect-DbaInstance -SqlInstance $TestConfig.instance2 -Database msdb $instance2.Invoke("EXEC msdb.dbo.sp_add_operator @name=N'dbatools dba', @enabled=1, @pager_days=0") } @@ -30,4 +30,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $results.EmailAddress | Should -Be "new@new.com" } } -} \ No newline at end of file +} diff --git a/tests/Set-DbaAgentSchedule.Tests.ps1 b/tests/Set-DbaAgentSchedule.Tests.ps1 index e17857359a..00202209f2 100644 --- a/tests/Set-DbaAgentSchedule.Tests.ps1 +++ b/tests/Set-DbaAgentSchedule.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,19 +15,19 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $null = New-DbaAgentJob -SqlInstance $script:instance2 -Job 'dbatoolsci_setschedule1' -OwnerLogin 'sa' - $null = New-DbaAgentJob -SqlInstance $script:instance2 -Job 'dbatoolsci_setschedule2' -OwnerLogin 'sa' + $null = New-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job 'dbatoolsci_setschedule1' -OwnerLogin 'sa' + $null = New-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job 'dbatoolsci_setschedule2' -OwnerLogin 'sa' $start = (Get-Date).AddDays(2).ToString('yyyyMMdd') $end = (Get-Date).AddDays(4).ToString('yyyyMMdd') $altstart = (Get-Date).AddDays(3).ToString('yyyyMMdd') $altend = (Get-Date).AddDays(5).ToString('yyyyMMdd') } AfterAll { - $null = Remove-DbaAgentJob -SqlInstance $script:instance2 -Job 'dbatoolsci_setschedule1', 'dbatoolsci_setschedule2' -Confirm:$false + $null = Remove-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job 'dbatoolsci_setschedule1', 'dbatoolsci_setschedule2' -Confirm:$false } Context "Should rename schedule" { BeforeAll { - $variables = @{SqlInstance = $script:instance2 + $variables = @{SqlInstance = $TestConfig.instance2 Schedule = 'dbatoolsci_oldname' Job = 'dbatoolsci_setschedule1' FrequencyRecurrenceFactor = '1' @@ -42,12 +42,12 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $null = New-DbaAgentSchedule @variables } AfterAll { - $null = Get-DbaAgentSchedule -SqlInstance $script:instance2 | + $null = Get-DbaAgentSchedule -SqlInstance $TestConfig.instance2 | Where-Object {$_.name -like 'dbatools*'} | Remove-DbaAgentSchedule -Confirm:$false -Force } - $schedules = Get-DbaAgentSchedule -SqlInstance $script:instance2 | Where-Object {$_.name -like 'dbatools*'} - $variables = @{SqlInstance = $script:instance2 + $schedules = Get-DbaAgentSchedule -SqlInstance $TestConfig.instance2 | Where-Object {$_.name -like 'dbatools*'} + $variables = @{SqlInstance = $TestConfig.instance2 Schedule = "dbatoolsci_oldname" NewName = "dbatoolsci_newname" Job = 'dbatoolsci_setschedule1' @@ -60,7 +60,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } $null = Set-DbaAgentSchedule @variables - $results = Get-DbaAgentSchedule -SqlInstance $script:instance2 | Where-Object {$_.name -like 'dbatools*'} + $results = Get-DbaAgentSchedule -SqlInstance $TestConfig.instance2 | Where-Object {$_.name -like 'dbatools*'} It "Should have Results" { $results | Should Not BeNullOrEmpty @@ -75,7 +75,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Should set schedules based on static frequency" { BeforeAll { foreach ($frequency in ('Once', 'AgentStart', 'IdleComputer')) { - $variables = @{SqlInstance = $script:instance2 + $variables = @{SqlInstance = $TestConfig.instance2 Schedule = "dbatoolsci_$frequency" Job = 'dbatoolsci_setschedule1' FrequencyType = $frequency @@ -90,15 +90,15 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } AfterAll { - $null = Get-DbaAgentSchedule -SqlInstance $script:instance2 | + $null = Get-DbaAgentSchedule -SqlInstance $TestConfig.instance2 | Where-Object {$_.name -like 'dbatools*'} | Remove-DbaAgentSchedule -Confirm:$false -Force } - $schedules = Get-DbaAgentSchedule -SqlInstance $script:instance2 | Where-Object {$_.name -like 'dbatools*'} + $schedules = Get-DbaAgentSchedule -SqlInstance $TestConfig.instance2 | Where-Object {$_.name -like 'dbatools*'} foreach ($schedule in $schedules) { foreach ($frequency in ('Once', '1' , 'AgentStart', '64', 'IdleComputer', '128')) { - $variables = @{SqlInstance = $script:instance2 + $variables = @{SqlInstance = $TestConfig.instance2 Schedule = "$($schedule.name)" Job = 'dbatoolsci_setschedule1' FrequencyType = $frequency @@ -112,7 +112,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } } - $results = Get-DbaAgentSchedule -SqlInstance $script:instance2 | Where-Object {$_.name -like 'dbatools*'} + $results = Get-DbaAgentSchedule -SqlInstance $TestConfig.instance2 | Where-Object {$_.name -like 'dbatools*'} It "Should have Results" { $results | Should Not BeNullOrEmpty @@ -130,7 +130,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Should set schedules based on calendar frequency" { BeforeAll { foreach ($frequency in ('Daily', 'Weekly', 'Monthly', 'MonthlyRelative')) { - $variables = @{SqlInstance = $script:instance2 + $variables = @{SqlInstance = $TestConfig.instance2 Schedule = "dbatoolsci_$frequency" Job = 'dbatoolsci_setschedule2' FrequencyType = $frequency @@ -147,15 +147,15 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } AfterAll { - $null = Get-DbaAgentSchedule -SqlInstance $script:instance2 | + $null = Get-DbaAgentSchedule -SqlInstance $TestConfig.instance2 | Where-Object {$_.name -like 'dbatools*'} | Remove-DbaAgentSchedule -Confirm:$false -Force } - $schedules = Get-DbaAgentSchedule -SqlInstance $script:instance2 | Where-Object {$_.name -like 'dbatools*'} + $schedules = Get-DbaAgentSchedule -SqlInstance $TestConfig.instance2 | Where-Object {$_.name -like 'dbatools*'} foreach ($schedule in $schedules) { foreach ($frequency in ('Daily', '4', 'Weekly', '8', 'Monthly', '16', 'MonthlyRelative', '32')) { - $variables = @{SqlInstance = $script:instance2 + $variables = @{SqlInstance = $TestConfig.instance2 Schedule = "$($schedule.name)" Job = 'dbatoolsci_setschedule2' FrequencyType = $frequency @@ -171,7 +171,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $null = Set-DbaAgentSchedule @variables } } - $results = Get-DbaAgentSchedule -SqlInstance $script:instance2 | Where-Object {$_.name -like 'dbatools*'} + $results = Get-DbaAgentSchedule -SqlInstance $TestConfig.instance2 | Where-Object {$_.name -like 'dbatools*'} It "Should have Results" { $results | Should Not BeNullOrEmpty @@ -189,7 +189,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Should set schedules with various frequency subday type" { BeforeAll { foreach ($FrequencySubdayType in ('Once', 'Time', 'Seconds', 'Second', 'Minutes', 'Minute', 'Hours', 'Hour')) { - $variables = @{SqlInstance = $script:instance2 + $variables = @{SqlInstance = $TestConfig.instance2 Schedule = "dbatoolsci_$FrequencySubdayType" Job = 'dbatoolsci_setschedule1' FrequencyRecurrenceFactor = '1' @@ -205,14 +205,14 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } AfterAll { - $null = Get-DbaAgentSchedule -SqlInstance $script:instance2 | + $null = Get-DbaAgentSchedule -SqlInstance $TestConfig.instance2 | Where-Object {$_.name -like 'dbatools*'} | Remove-DbaAgentSchedule -Confirm:$false -Force } - $schedules = Get-DbaAgentSchedule -SqlInstance $script:instance2 | Where-Object {$_.name -like 'dbatools*'} + $schedules = Get-DbaAgentSchedule -SqlInstance $TestConfig.instance2 | Where-Object {$_.name -like 'dbatools*'} foreach ($schedule in $schedules) { foreach ($FrequencySubdayType in ('Once', 'Time', 'Seconds', 'Second', 'Minutes', 'Minute', 'Hours', 'Hour')) { - $variables = @{SqlInstance = $script:instance2 + $variables = @{SqlInstance = $TestConfig.instance2 Schedule = "$schedule" Job = 'dbatoolsci_setschedule1' FrequencyRecurrenceFactor = '6' @@ -227,7 +227,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $null = Set-DbaAgentSchedule @variables } } - $results = Get-DbaAgentSchedule -SqlInstance $script:instance2 | Where-Object {$_.name -like 'dbatools*'} + $results = Get-DbaAgentSchedule -SqlInstance $TestConfig.instance2 | Where-Object {$_.name -like 'dbatools*'} It "Should have Results" { $results | Should Not BeNullOrEmpty @@ -242,7 +242,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Should set schedules with various frequency relative interval" { BeforeAll { foreach ($FrequencyRelativeInterval in ('Unused', 'First', 'Second', 'Third', 'Fourth', 'Last')) { - $variables = @{SqlInstance = $script:instance2 + $variables = @{SqlInstance = $TestConfig.instance2 Schedule = "dbatoolsci_$FrequencyRelativeInterval" Job = 'dbatoolsci_setschedule2' FrequencyRecurrenceFactor = '1' @@ -257,14 +257,14 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } AfterAll { - $null = Get-DbaAgentSchedule -SqlInstance $script:instance2 | + $null = Get-DbaAgentSchedule -SqlInstance $TestConfig.instance2 | Where-Object {$_.name -like 'dbatools*'} | Remove-DbaAgentSchedule -Confirm:$false -Force } - $schedules = Get-DbaAgentSchedule -SqlInstance $script:instance2 | Where-Object {$_.name -like 'dbatools*'} + $schedules = Get-DbaAgentSchedule -SqlInstance $TestConfig.instance2 | Where-Object {$_.name -like 'dbatools*'} foreach ($schedule in $schedules) { foreach ($FrequencyRelativeInterval in ('Unused', 'First', 'Second', 'Third', 'Fourth', 'Last')) { - $variables = @{SqlInstance = $script:instance2 + $variables = @{SqlInstance = $TestConfig.instance2 Schedule = "$schedule" Job = 'dbatoolsci_setschedule2' FrequencyRecurrenceFactor = '4' @@ -278,7 +278,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $null = Set-DbaAgentSchedule @variables } } - $results = Get-DbaAgentSchedule -SqlInstance $script:instance2 | Where-Object {$_.name -like 'dbatools*'} + $results = Get-DbaAgentSchedule -SqlInstance $TestConfig.instance2 | Where-Object {$_.name -like 'dbatools*'} It "Should have Results" { $results | Should Not BeNullOrEmpty @@ -289,4 +289,4 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } } -} \ No newline at end of file +} diff --git a/tests/Set-DbaAgentServer.Tests.ps1 b/tests/Set-DbaAgentServer.Tests.ps1 index ab22032d4a..8e05a52513 100644 --- a/tests/Set-DbaAgentServer.Tests.ps1 +++ b/tests/Set-DbaAgentServer.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,7 +15,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $testServer = $script:instance2 + $testServer = $TestConfig.instance2 $random = Get-Random $mailProfileName = "dbatoolsci_$random" $mailProfile = New-DbaDbMailProfile -SqlInstance $testServer -Name $mailProfileName @@ -310,4 +310,4 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } $validationError | Should Be $true } -} \ No newline at end of file +} diff --git a/tests/Set-DbaAvailabilityGroup.Tests.ps1 b/tests/Set-DbaAvailabilityGroup.Tests.ps1 index 409612a2a9..9d0cf6916c 100644 --- a/tests/Set-DbaAvailabilityGroup.Tests.ps1 +++ b/tests/Set-DbaAvailabilityGroup.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,21 +16,21 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { $agname = "dbatoolsci_agroup" - $null = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Confirm:$false -Certificate dbatoolsci_AGCert + $null = New-DbaAvailabilityGroup -Primary $TestConfig.instance3 -Name $agname -ClusterType None -FailoverMode Manual -Confirm:$false -Certificate dbatoolsci_AGCert } AfterAll { - Remove-DbaAvailabilityGroup -SqlInstance $script:instance3 -AvailabilityGroup $agname -Confirm:$false + Remove-DbaAvailabilityGroup -SqlInstance $TestConfig.instance3 -AvailabilityGroup $agname -Confirm:$false } Context "sets ag properties" { It "returns modified results" { - $results = Set-DbaAvailabilityGroup -SqlInstance $script:instance3 -AvailabilityGroup $agname -Confirm:$false -DtcSupportEnabled:$false + $results = Set-DbaAvailabilityGroup -SqlInstance $TestConfig.instance3 -AvailabilityGroup $agname -Confirm:$false -DtcSupportEnabled:$false $results.AvailabilityGroup | Should -Be $agname $results.DtcSupportEnabled | Should -Be $false } It "returns newly modified results" { - $results = Set-DbaAvailabilityGroup -SqlInstance $script:instance3 -AvailabilityGroup $agname -Confirm:$false -DtcSupportEnabled + $results = Set-DbaAvailabilityGroup -SqlInstance $TestConfig.instance3 -AvailabilityGroup $agname -Confirm:$false -DtcSupportEnabled $results.AvailabilityGroup | Should -Be $agname $results.DtcSupportEnabled | Should -Be $true } } -} #$script:instance2 for appveyor \ No newline at end of file +} #$TestConfig.instance2 for appveyor diff --git a/tests/Set-DbaCmConnection.Tests.ps1 b/tests/Set-DbaCmConnection.Tests.ps1 index 72cfe4ced1..b5fbae3801 100644 --- a/tests/Set-DbaCmConnection.Tests.ps1 +++ b/tests/Set-DbaCmConnection.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Set-DbaDbCompatibility.Tests.ps1 b/tests/Set-DbaDbCompatibility.Tests.ps1 index 59e53703bc..83d33ff320 100644 --- a/tests/Set-DbaDbCompatibility.Tests.ps1 +++ b/tests/Set-DbaDbCompatibility.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace('.Tests.ps1', '') Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,16 +15,16 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tag 'IntegrationTests' { BeforeAll { - Get-DbaProcess -SqlInstance $script:instance1 -Database model | Stop-DbaProcess -Confirm:$false - $sqlCn = Connect-DbaInstance -SqlInstance $script:instance2 + Get-DbaProcess -SqlInstance $TestConfig.instance1 -Database model | Stop-DbaProcess -Confirm:$false + $sqlCn = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $sqlCn.Refresh() $dbNameNotMatches = "dbatoolscliCompatibilityLevelNotMatch_$(Get-Random -Minimum 600 -Maximum 1100)" $instanceLevel = $sqlCn.Databases['master'].CompatibilityLevel <# create a database that is one level down from instance level, any version tested against supports the prior level #> $previousCompatLevel = [int]($instanceLevel.ToString().Trim('Version')) - 10 - Get-DbaProcess -SqlInstance $script:instance2 -Database model | Stop-DbaProcess -Confirm:$false + Get-DbaProcess -SqlInstance $TestConfig.instance2 -Database model | Stop-DbaProcess -Confirm:$false $queryNot = "CREATE DATABASE $dbNameNotMatches" - #$null = New-DbaDatabase -SqlInstance $script:instance2 -Name $dbNameNotMatches + #$null = New-DbaDatabase -SqlInstance $TestConfig.instance2 -Name $dbNameNotMatches $sqlCn.Query($queryNot) Start-Sleep 5 $queryAlter = "ALTER DATABASE $dbNameNotMatches SET COMPATIBILITY_LEVEL = $($previousCompatLevel)" @@ -41,7 +41,7 @@ Describe "$CommandName Integration Tests" -Tag 'IntegrationTests' { $verboseSetMsg = '*Performing the operation "Setting*Compatibility Level*' } AfterAll { - $sqlCn = Connect-DbaInstance -SqlInstance $script:instance2 + $sqlCn = Connect-DbaInstance -SqlInstance $TestConfig.instance2 Remove-DbaDatabase -SqlInstance $sqlCn -Database $dbNameNotMatches -Confirm:$false $sqlCn.ConnectionContext.Disconnect() } @@ -62,4 +62,4 @@ Describe "$CommandName Integration Tests" -Tag 'IntegrationTests' { } } } -#$script:instance3 \ No newline at end of file +#$TestConfig.instance3 diff --git a/tests/Set-DbaDbCompression.Tests.ps1 b/tests/Set-DbaDbCompression.Tests.ps1 index 9a905721e5..d24dff49b4 100644 --- a/tests/Set-DbaDbCompression.Tests.ps1 +++ b/tests/Set-DbaDbCompression.Tests.ps1 @@ -1,6 +1,6 @@ $commandname = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,7 +16,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { BeforeAll { $dbname = "dbatoolsci_test_$(get-random)" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $null = $server.Query("Create Database [$dbname]") $null = $server.Query("select * into syscols from sys.all_columns select * into sysallparams from sys.all_parameters @@ -24,11 +24,11 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { create nonclustered index NC_syscols on syscols (precision) include (collation_name)", $dbname) } AfterAll { - Get-DbaProcess -SqlInstance $script:instance2 -Database $dbname | Stop-DbaProcess -WarningAction SilentlyContinue - Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbname -Confirm:$false + Get-DbaProcess -SqlInstance $TestConfig.instance2 -Database $dbname | Stop-DbaProcess -WarningAction SilentlyContinue + Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname -Confirm:$false } - $InputObject = Test-DbaDbCompression -SqlInstance $script:instance2 -Database $dbname - $results = Set-DbaDbCompression -SqlInstance $script:instance2 -Database $dbname -MaxRunTime 5 -PercentCompression 0 + $InputObject = Test-DbaDbCompression -SqlInstance $TestConfig.instance2 -Database $dbname + $results = Set-DbaDbCompression -SqlInstance $TestConfig.instance2 -Database $dbname -MaxRunTime 5 -PercentCompression 0 Context "Command gets results" { It "Should contain objects" { $results | Should Not Be $null @@ -53,11 +53,11 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $server.Databases[$dbname].Tables['syscols'].PhysicalPartitions[0].DataCompression = "NONE" $server.Databases[$dbname].Tables['syscols'].Rebuild() It "Shouldn't get any results for $dbname" { - $(Set-DbaDbCompression -SqlInstance $script:instance2 -Database $dbname -ExcludeDatabase $dbname -MaxRunTime 5 -PercentCompression 0).Database | Should not Match $dbname + $(Set-DbaDbCompression -SqlInstance $TestConfig.instance2 -Database $dbname -ExcludeDatabase $dbname -MaxRunTime 5 -PercentCompression 0).Database | Should not Match $dbname } } Context "Command can accept InputObject from Test-DbaDbCompression" { - $results = @(Set-DbaDbCompression -SqlInstance $script:instance2 -Database $dbname -MaxRunTime 5 -PercentCompression 0 -InputObject $InputObject) + $results = @(Set-DbaDbCompression -SqlInstance $TestConfig.instance2 -Database $dbname -MaxRunTime 5 -PercentCompression 0 -InputObject $InputObject) It "Should get results" { $results | Should not be $null } @@ -68,8 +68,8 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } Context "Command sets compression to Row all objects" { - $null = Set-DbaDbCompression -SqlInstance $script:instance2 -Database $dbname -CompressionType Row - $results = Get-DbaDbCompression -SqlInstance $script:instance2 -Database $dbname + $null = Set-DbaDbCompression -SqlInstance $TestConfig.instance2 -Database $dbname -CompressionType Row + $results = Get-DbaDbCompression -SqlInstance $TestConfig.instance2 -Database $dbname foreach ($row in $results) { It "The $($row.IndexType) for $($row.schema).$($row.TableName) is row compressed" { $row.DataCompression | Should Be "Row" @@ -77,8 +77,8 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } Context "Command sets compression to Page for all objects" { - $null = Set-DbaDbCompression -SqlInstance $script:instance2 -Database $dbname -CompressionType Page - $results = Get-DbaDbCompression -SqlInstance $script:instance2 -Database $dbname + $null = Set-DbaDbCompression -SqlInstance $TestConfig.instance2 -Database $dbname -CompressionType Page + $results = Get-DbaDbCompression -SqlInstance $TestConfig.instance2 -Database $dbname foreach ($row in $results) { It "The $($row.IndexType) for $($row.schema).$($row.TableName) is page compressed" { $row.DataCompression | Should Be "Page" @@ -86,12 +86,12 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } Context "Command sets compression to None for all objects" { - $null = Set-DbaDbCompression -SqlInstance $script:instance2 -Database $dbname -CompressionType None - $results = Get-DbaDbCompression -SqlInstance $script:instance2 -Database $dbname + $null = Set-DbaDbCompression -SqlInstance $TestConfig.instance2 -Database $dbname -CompressionType None + $results = Get-DbaDbCompression -SqlInstance $TestConfig.instance2 -Database $dbname foreach ($row in $results) { It "The $($row.IndexType) for $($row.schema).$($row.TableName) is not compressed" { $row.DataCompression | Should Be "None" } } } -} \ No newline at end of file +} diff --git a/tests/Set-DbaDbFileGroup.Tests.ps1 b/tests/Set-DbaDbFileGroup.Tests.ps1 index 9da34fd474..3861f361ea 100644 --- a/tests/Set-DbaDbFileGroup.Tests.ps1 +++ b/tests/Set-DbaDbFileGroup.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -21,8 +21,8 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $fileGroup2Name = "FG2" $fileGroupROName = "FG1RO" - $server = Connect-DbaInstance -SqlInstance $script:instance2 - $newDb1 = New-DbaDatabase -SqlInstance $script:instance2 -Name $db1name + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 + $newDb1 = New-DbaDatabase -SqlInstance $TestConfig.instance2 -Name $db1name $server.Query("ALTER DATABASE $db1name ADD FILEGROUP $fileGroup1Name") $server.Query("ALTER DATABASE $db1name ADD FILEGROUP $fileGroup2Name") @@ -37,34 +37,34 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "ensure command works" { It "Sets the options for default, readonly, readwrite, autogrow all files, and not autogrow all files" { - $results = Set-DbaDbFileGroup -SqlInstance $script:instance2 -Database $db1name -FileGroup $fileGroup1Name -Default -AutoGrowAllFiles -Confirm:$false + $results = Set-DbaDbFileGroup -SqlInstance $TestConfig.instance2 -Database $db1name -FileGroup $fileGroup1Name -Default -AutoGrowAllFiles -Confirm:$false $results.Name | Should -Be $fileGroup1Name $results.AutogrowAllFiles | Should -Be $true $results.IsDefault | Should -Be $true - $results = Set-DbaDbFileGroup -SqlInstance $script:instance2 -Database $db1name -FileGroup $fileGroup1Name -AutoGrowAllFiles:$false -Confirm:$false + $results = Set-DbaDbFileGroup -SqlInstance $TestConfig.instance2 -Database $db1name -FileGroup $fileGroup1Name -AutoGrowAllFiles:$false -Confirm:$false $results.Name | Should -Be $fileGroup1Name $results.AutogrowAllFiles | Should -Be $false - $results = Set-DbaDbFileGroup -SqlInstance $script:instance2 -Database $db1name -FileGroup $fileGroupROName -ReadOnly -Confirm:$false + $results = Set-DbaDbFileGroup -SqlInstance $TestConfig.instance2 -Database $db1name -FileGroup $fileGroupROName -ReadOnly -Confirm:$false $results.Name | Should -Be $fileGroupROName $results.AutogrowAllFiles | Should -Be $false $results.IsDefault | Should -Be $false $results.ReadOnly | Should -Be $true - $results = Set-DbaDbFileGroup -SqlInstance $script:instance2 -Database $db1name -FileGroup $fileGroup1Name, $fileGroupROName -ReadOnly:$false -Confirm:$false + $results = Set-DbaDbFileGroup -SqlInstance $TestConfig.instance2 -Database $db1name -FileGroup $fileGroup1Name, $fileGroupROName -ReadOnly:$false -Confirm:$false $results.Name | Should -Be $fileGroup1Name, $fileGroupROName $results.ReadOnly | Should -Be $false, $false } It "A warning is returned when trying to set the options for a filegroup that doesn't exist" { - $results = Set-DbaDbFileGroup -SqlInstance $script:instance2 -Database $db1name -FileGroup invalidFileGroupName -Default -AutoGrowAllFiles -Confirm:$false -WarningVariable warnings - $warnings | Should -BeLike "*Filegroup invalidFileGroupName does not exist in the database $db1name on $($script:instance2)" + $results = Set-DbaDbFileGroup -SqlInstance $TestConfig.instance2 -Database $db1name -FileGroup invalidFileGroupName -Default -AutoGrowAllFiles -Confirm:$false -WarningVariable warnings + $warnings | Should -BeLike "*Filegroup invalidFileGroupName does not exist in the database $db1name on $($TestConfig.instance2)" } It "A warning is returned when trying to set the options for an empty filegroup" { - $results = Set-DbaDbFileGroup -SqlInstance $script:instance2 -Database $db1name -FileGroup $fileGroup2Name -Default -AutoGrowAllFiles -Confirm:$false -WarningVariable warnings - $warnings | Should -BeLike "*Filegroup $fileGroup2Name is empty on $db1name on $($script:instance2). Before the options can be set there must be at least one file in the filegroup." + $results = Set-DbaDbFileGroup -SqlInstance $TestConfig.instance2 -Database $db1name -FileGroup $fileGroup2Name -Default -AutoGrowAllFiles -Confirm:$false -WarningVariable warnings + $warnings | Should -BeLike "*Filegroup $fileGroup2Name is empty on $db1name on $($TestConfig.instance2). Before the options can be set there must be at least one file in the filegroup." } It "Sets the filegroup options using a database from a pipeline and a filegroup from a pipeline" { @@ -72,14 +72,14 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $results.Name | Should -Be Primary $results.IsDefault | Should -Be $true - $results = Get-DbaDbFileGroup -SqlInstance $script:instance2 -Database $db1name -FileGroup $fileGroup1Name | Set-DbaDbFileGroup -Default -Confirm:$false + $results = Get-DbaDbFileGroup -SqlInstance $TestConfig.instance2 -Database $db1name -FileGroup $fileGroup1Name | Set-DbaDbFileGroup -Default -Confirm:$false $results.Name | Should -Be $fileGroup1Name $results.IsDefault | Should -Be $true - $fg1 = Get-DbaDbFileGroup -SqlInstance $script:instance2 -Database $db1name -FileGroup $fileGroup1Name + $fg1 = Get-DbaDbFileGroup -SqlInstance $TestConfig.instance2 -Database $db1name -FileGroup $fileGroup1Name $results = $fg1, $newDb1 | Set-DbaDbFileGroup -FileGroup Primary -AutoGrowAllFiles -Confirm:$false $results.Name | Should -Be $fileGroup1Name, Primary $results.AutoGrowAllFiles | Should -Be $true, $true } } -} \ No newline at end of file +} diff --git a/tests/Set-DbaDbFileGrowth.Tests.ps1 b/tests/Set-DbaDbFileGrowth.Tests.ps1 index 4758d449fc..1a68a85bcc 100644 --- a/tests/Set-DbaDbFileGrowth.Tests.ps1 +++ b/tests/Set-DbaDbFileGrowth.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,13 +15,13 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $newdb = New-DbaDatabase -SqlInstance $script:instance2 -Name newdb + $newdb = New-DbaDatabase -SqlInstance $TestConfig.instance2 -Name newdb } AfterAll { $newdb | Remove-DbaDatabase -Confirm:$false } Context "Should return file information for only newdb" { - $result = Set-DbaDbFileGrowth -SqlInstance $script:instance2 -Database newdb | Select-Object -First 1 + $result = Set-DbaDbFileGrowth -SqlInstance $TestConfig.instance2 -Database newdb | Select-Object -First 1 It "returns the proper info" { $result.Database | Should -Be "newdb" $result.GrowthType | Should -Be "kb" @@ -29,9 +29,9 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } Context "Supports piping" { - $result = Get-DbaDatabase $script:instance2 -Database newdb | Set-DbaDbFileGrowth | Select-Object -First 1 + $result = Get-DbaDatabase $TestConfig.instance2 -Database newdb | Set-DbaDbFileGrowth | Select-Object -First 1 It "returns only newdb files" { $result.Database | Should -Be "newdb" } } -} \ No newline at end of file +} diff --git a/tests/Set-DbaDbIdentity.Tests.ps1 b/tests/Set-DbaDbIdentity.Tests.ps1 index 3cac3b10a1..57ce986216 100644 --- a/tests/Set-DbaDbIdentity.Tests.ps1 +++ b/tests/Set-DbaDbIdentity.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,7 +16,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { } Describe "$commandname Integration Test" -Tag "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $random = Get-Random $tableName1 = "dbatools_getdbtbl1" $tableName2 = "dbatools_getdbtbl2" @@ -30,12 +30,12 @@ Describe "$commandname Integration Test" -Tag "IntegrationTests" { $null = $server.Query("INSERT $tableName2(Value) SELECT 2", $dbname) } AfterAll { - $null = Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbname | Remove-DbaDatabase -Confirm:$false + $null = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname | Remove-DbaDatabase -Confirm:$false } Context "Validate standard output " { $props = 'ComputerName', 'InstanceName', 'SqlInstance', 'Database', 'Table', 'Cmd', 'IdentityValue', 'ColumnValue', 'Output' - $result = Set-DbaDbIdentity -SqlInstance $script:instance2 -Database $dbname -Table $tableName1, $tableName2 -Confirm:$false + $result = Set-DbaDbIdentity -SqlInstance $TestConfig.instance2 -Database $dbname -Table $tableName1, $tableName2 -Confirm:$false foreach ($prop in $props) { $p = $result[0].PSObject.Properties[$prop] @@ -54,11 +54,11 @@ Describe "$commandname Integration Test" -Tag "IntegrationTests" { } Context "Reseed option returns correct results " { - $result = Set-DbaDbIdentity -SqlInstance $script:instance2 -Database $dbname -Table $tableName2 -ReSeedValue 400 -Confirm:$false + $result = Set-DbaDbIdentity -SqlInstance $TestConfig.instance2 -Database $dbname -Table $tableName2 -ReSeedValue 400 -Confirm:$false It "returns correct results" { $result.cmd -eq "DBCC CHECKIDENT('$tableName2', RESEED, 400)" | Should Be $true $result.IdentityValue -eq '5.' | Should Be $true } } -} \ No newline at end of file +} diff --git a/tests/Set-DbaDbMirror.Tests.ps1 b/tests/Set-DbaDbMirror.Tests.ps1 index bfdfd567cb..84c29c18f7 100644 --- a/tests/Set-DbaDbMirror.Tests.ps1 +++ b/tests/Set-DbaDbMirror.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Set-DbaDbOwner.Tests.ps1 b/tests/Set-DbaDbOwner.Tests.ps1 index 54693f0fe6..49c26b0c47 100644 --- a/tests/Set-DbaDbOwner.Tests.ps1 +++ b/tests/Set-DbaDbOwner.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,23 +15,23 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $svr = Connect-DbaInstance -SqlInstance $script:instance1 + $svr = Connect-DbaInstance -SqlInstance $TestConfig.instance1 $owner = "dbatoolssci_owner_$(Get-Random)" $ownertwo = "dbatoolssci_owner2_$(Get-Random)" - $null = New-DbaLogin -SqlInstance $script:instance1 -Login $owner -Password ('Password1234!' | ConvertTo-SecureString -asPlainText -Force) - $null = New-DbaLogin -SqlInstance $script:instance1 -Login $ownertwo -Password ('Password1234!' | ConvertTo-SecureString -asPlainText -Force) + $null = New-DbaLogin -SqlInstance $TestConfig.instance1 -Login $owner -Password ('Password1234!' | ConvertTo-SecureString -asPlainText -Force) + $null = New-DbaLogin -SqlInstance $TestConfig.instance1 -Login $ownertwo -Password ('Password1234!' | ConvertTo-SecureString -asPlainText -Force) $dbname = "dbatoolsci_$(Get-Random)" $dbnametwo = "dbatoolsci_$(Get-Random)" - $null = New-DbaDatabase -SqlInstance $script:instance1 -Name $dbname -Owner sa - $null = New-DbaDatabase -SqlInstance $script:instance1 -Name $dbnametwo -Owner sa + $null = New-DbaDatabase -SqlInstance $TestConfig.instance1 -Name $dbname -Owner sa + $null = New-DbaDatabase -SqlInstance $TestConfig.instance1 -Name $dbnametwo -Owner sa } AfterAll { - $null = Remove-DbaDatabase -SqlInstance $script:instance1 -Database $dbname, $dbnametwo -confirm:$false - $null = Remove-DbaLogin -SqlInstance $script:instance1 -Login $owner, $ownertwo -confirm:$false + $null = Remove-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $dbname, $dbnametwo -confirm:$false + $null = Remove-DbaLogin -SqlInstance $TestConfig.instance1 -Login $owner, $ownertwo -confirm:$false } Context "Should set the database owner" { It "Sets the database owner on a specific database" { - $results = Set-DbaDbOwner -SqlInstance $script:instance1 -Database $dbName -TargetLogin $owner + $results = Set-DbaDbOwner -SqlInstance $TestConfig.instance1 -Database $dbName -TargetLogin $owner $results.Owner | Should Be $owner } It "Check it actually set the owner" { @@ -41,7 +41,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } Context "Sets multiple database owners" { - $results = Set-DbaDbOwner -SqlInstance $script:instance1 -Database $dbName, $dbnametwo -TargetLogin $ownertwo + $results = Set-DbaDbOwner -SqlInstance $TestConfig.instance1 -Database $dbName, $dbnametwo -TargetLogin $ownertwo It "Sets the database owner on multiple databases" { foreach ($r in $results) { $r.owner | Should Be $ownertwo @@ -54,7 +54,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Context "Excludes databases" { $svr.Databases[$dbName].refresh() - $results = Set-DbaDbOwner -SqlInstance $script:instance1 -ExcludeDatabase $dbnametwo -TargetLogin $owner + $results = Set-DbaDbOwner -SqlInstance $TestConfig.instance1 -ExcludeDatabase $dbnametwo -TargetLogin $owner It "Excludes specified database" { $results.Database | Should Not Contain $dbnametwo } @@ -65,7 +65,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Context "Enables input from Get-DbaDatabase" { $svr.Databases[$dbnametwo].refresh() - $db = Get-DbaDatabase -SqlInstance $script:instance1 -Database $dbnametwo + $db = Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $dbnametwo $results = Set-DbaDbOwner -InputObject $db -TargetLogin $owner It "Includes specified database" { @@ -77,7 +77,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } Context "Sets database owner to sa" { - $results = Set-DbaDbOwner -SqlInstance $script:instance1 + $results = Set-DbaDbOwner -SqlInstance $TestConfig.instance1 It "Sets the database owner on multiple databases" { foreach ($r in $results) { $r.owner | Should Be 'sa' @@ -87,4 +87,4 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { @($results).Count | Should BeGreaterOrEqual 1 } } -} \ No newline at end of file +} diff --git a/tests/Set-DbaDbQueryStoreOption.Tests.ps1 b/tests/Set-DbaDbQueryStoreOption.Tests.ps1 index af2e115d6d..9a007badcd 100644 --- a/tests/Set-DbaDbQueryStoreOption.Tests.ps1 +++ b/tests/Set-DbaDbQueryStoreOption.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,14 +15,14 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { - Get-DbaDatabase -SqlInstance $script:instance1, $script:instance2 | Where-Object Name -Match 'dbatoolsci' | Remove-DbaDatabase -Confirm:$false - New-DbaDatabase -SqlInstance $script:instance1, $script:instance2 -Name dbatoolsciqs + Get-DbaDatabase -SqlInstance $TestConfig.instance1, $TestConfig.instance2 | Where-Object Name -Match 'dbatoolsci' | Remove-DbaDatabase -Confirm:$false + New-DbaDatabase -SqlInstance $TestConfig.instance1, $TestConfig.instance2 -Name dbatoolsciqs } AfterAll { - Get-DbaDatabase -SqlInstance $script:instance1, $script:instance2 | Where-Object Name -Match 'dbatoolsci' | Remove-DbaDatabase -Confirm:$false + Get-DbaDatabase -SqlInstance $TestConfig.instance1, $TestConfig.instance2 | Where-Object Name -Match 'dbatoolsci' | Remove-DbaDatabase -Confirm:$false } Context "Get some client protocols" { - foreach ($instance in ($script:instance1, $script:instance2)) { + foreach ($instance in ($TestConfig.instance1, $TestConfig.instance2)) { $server = Connect-DbaInstance -SqlInstance $instance $results = Get-DbaDbQueryStoreOption -SqlInstance $server -WarningVariable warning 3>&1 @@ -60,4 +60,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } } } -} \ No newline at end of file +} diff --git a/tests/Set-DbaDbRecoveryModel.Tests.ps1 b/tests/Set-DbaDbRecoveryModel.Tests.ps1 index 89a6da20d6..828cf78a2f 100644 --- a/tests/Set-DbaDbRecoveryModel.Tests.ps1 +++ b/tests/Set-DbaDbRecoveryModel.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,30 +16,30 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Recovery model is correctly set" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $dbname = "dbatoolsci_recoverymodel" Get-DbaDatabase -SqlInstance $server -Database $dbname | Remove-DbaDatabase -Confirm:$false $server.Query("CREATE DATABASE $dbname") } AfterAll { - Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbname | Remove-DbaDatabase -Confirm:$false + Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname | Remove-DbaDatabase -Confirm:$false } - $results = Set-DbaDbRecoveryModel -SqlInstance $script:instance2 -Database $dbname -RecoveryModel BulkLogged -Confirm:$false + $results = Set-DbaDbRecoveryModel -SqlInstance $TestConfig.instance2 -Database $dbname -RecoveryModel BulkLogged -Confirm:$false It "sets the proper recovery model" { $results.RecoveryModel -eq "BulkLogged" | Should Be $true } It "supports the pipeline" { - $results = Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbname | Set-DbaDbRecoveryModel -RecoveryModel Simple -Confirm:$false + $results = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname | Set-DbaDbRecoveryModel -RecoveryModel Simple -Confirm:$false $results.RecoveryModel -eq "Simple" | Should Be $true } It "requires Database, ExcludeDatabase or AllDatabases" { - $results = Set-DbaDbRecoveryModel -SqlInstance $script:instance2 -RecoveryModel Simple -WarningAction SilentlyContinue -WarningVariable warn -Confirm:$false + $results = Set-DbaDbRecoveryModel -SqlInstance $TestConfig.instance2 -RecoveryModel Simple -WarningAction SilentlyContinue -WarningVariable warn -Confirm:$false $warn -match "AllDatabases" | Should Be $true } } -} \ No newline at end of file +} diff --git a/tests/Set-DbaDbSchema.Tests.ps1 b/tests/Set-DbaDbSchema.Tests.ps1 index 12a300cb5a..3d4fb08929 100644 --- a/tests/Set-DbaDbSchema.Tests.ps1 +++ b/tests/Set-DbaDbSchema.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,8 +16,8 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BeforeAll { $random = Get-Random - $server1 = Connect-DbaInstance -SqlInstance $script:instance1 - $server2 = Connect-DbaInstance -SqlInstance $script:instance2 + $server1 = Connect-DbaInstance -SqlInstance $TestConfig.instance1 + $server2 = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $null = Get-DbaProcess -SqlInstance $server1, $server2 | Where-Object Program -match dbatools | Stop-DbaProcess -Confirm:$false $newDbName = "dbatoolsci_newdb_$random" $newDbs = New-DbaDatabase -SqlInstance $server1, $server2 -Name $newDbName @@ -73,4 +73,4 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $schema.Parent.Name | Should -Be $newDbName } } -} \ No newline at end of file +} diff --git a/tests/Set-DbaDbSequence.Tests.ps1 b/tests/Set-DbaDbSequence.Tests.ps1 index a0859c51f7..11a4f50004 100644 --- a/tests/Set-DbaDbSequence.Tests.ps1 +++ b/tests/Set-DbaDbSequence.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,7 +16,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BeforeAll { $random = Get-Random - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $newDbName = "dbatoolsci_newdb_$random" $newDb = New-DbaDatabase -SqlInstance $server -Name $newDbName @@ -117,4 +117,4 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $error.Exception | Should -Match "cannot be zero" } } -} \ No newline at end of file +} diff --git a/tests/Set-DbaDbState.Tests.ps1 b/tests/Set-DbaDbState.Tests.ps1 index 2060ebf234..ce2ae950d4 100644 --- a/tests/Set-DbaDbState.Tests.ps1 +++ b/tests/Set-DbaDbState.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,51 +16,51 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Parameters validation" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $db1 = "dbatoolsci_dbsetstate_online" $server.Query("CREATE DATABASE $db1") } AfterAll { - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance2 -Database $db1 + Remove-DbaDatabase -Confirm:$false -SqlInstance $TestConfig.instance2 -Database $db1 } It "Stops if no Database or AllDatabases" { - { Set-DbaDbState -SqlInstance $script:instance2 -EnableException } | Should Throw "You must specify" + { Set-DbaDbState -SqlInstance $TestConfig.instance2 -EnableException } | Should Throw "You must specify" } It "Is nice by default" { - { Set-DbaDbState -SqlInstance $script:instance2 *> $null } | Should Not Throw "You must specify" + { Set-DbaDbState -SqlInstance $TestConfig.instance2 *> $null } | Should Not Throw "You must specify" } It "Errors out when multiple 'access' params are passed with EnableException" { - { Set-DbaDbState -SqlInstance $script:instance2 -Database $db1 -SingleUser -RestrictedUser -EnableException } | Should Throw "You can only specify one of: -SingleUser,-RestrictedUser,-MultiUser" - { Set-DbaDbState -SqlInstance $script:instance2 -Database $db1 -MultiUser -RestrictedUser -EnableException } | Should Throw "You can only specify one of: -SingleUser,-RestrictedUser,-MultiUser" + { Set-DbaDbState -SqlInstance $TestConfig.instance2 -Database $db1 -SingleUser -RestrictedUser -EnableException } | Should Throw "You can only specify one of: -SingleUser,-RestrictedUser,-MultiUser" + { Set-DbaDbState -SqlInstance $TestConfig.instance2 -Database $db1 -MultiUser -RestrictedUser -EnableException } | Should Throw "You can only specify one of: -SingleUser,-RestrictedUser,-MultiUser" } It "Errors out when multiple 'access' params are passed without EnableException" { - { Set-DbaDbState -SqlInstance $script:instance2 -Database $db1 -SingleUser -RestrictedUser *> $null } | Should Not Throw - { Set-DbaDbState -SqlInstance $script:instance2 -Database $db1 -MultiUser -RestrictedUser *> $null } | Should Not Throw - $result = Set-DbaDbState -SqlInstance $script:instance2 -Database $db1 -SingleUser -RestrictedUser *> $null + { Set-DbaDbState -SqlInstance $TestConfig.instance2 -Database $db1 -SingleUser -RestrictedUser *> $null } | Should Not Throw + { Set-DbaDbState -SqlInstance $TestConfig.instance2 -Database $db1 -MultiUser -RestrictedUser *> $null } | Should Not Throw + $result = Set-DbaDbState -SqlInstance $TestConfig.instance2 -Database $db1 -SingleUser -RestrictedUser *> $null $result | Should Be $null } It "Errors out when multiple 'status' params are passed with EnableException" { - { Set-DbaDbState -SqlInstance $script:instance2 -Database $db1 -Offline -Online -EnableException } | Should Throw "You can only specify one of: -Online,-Offline,-Emergency,-Detached" - { Set-DbaDbState -SqlInstance $script:instance2 -Database $db1 -Emergency -Online -EnableException } | Should Throw "You can only specify one of: -Online,-Offline,-Emergency,-Detached" + { Set-DbaDbState -SqlInstance $TestConfig.instance2 -Database $db1 -Offline -Online -EnableException } | Should Throw "You can only specify one of: -Online,-Offline,-Emergency,-Detached" + { Set-DbaDbState -SqlInstance $TestConfig.instance2 -Database $db1 -Emergency -Online -EnableException } | Should Throw "You can only specify one of: -Online,-Offline,-Emergency,-Detached" } It "Errors out when multiple 'status' params are passed without Silent" { - { Set-DbaDbState -SqlInstance $script:instance2 -Database $db1 -Offline -Online *> $null } | Should Not Throw - { Set-DbaDbState -SqlInstance $script:instance2 -Database $db1 -Emergency -Online *> $null } | Should Not Throw - $result = Set-DbaDbState -SqlInstance $script:instance2 -Database $db1 -Offline -Online *> $null + { Set-DbaDbState -SqlInstance $TestConfig.instance2 -Database $db1 -Offline -Online *> $null } | Should Not Throw + { Set-DbaDbState -SqlInstance $TestConfig.instance2 -Database $db1 -Emergency -Online *> $null } | Should Not Throw + $result = Set-DbaDbState -SqlInstance $TestConfig.instance2 -Database $db1 -Offline -Online *> $null $result | Should Be $null } It "Errors out when multiple 'rw' params are passed with EnableException" { - { Set-DbaDbState -SqlInstance $script:instance2 -Database $db1 -ReadOnly -ReadWrite -EnableException } | Should Throw "You can only specify one of: -ReadOnly,-ReadWrite" + { Set-DbaDbState -SqlInstance $TestConfig.instance2 -Database $db1 -ReadOnly -ReadWrite -EnableException } | Should Throw "You can only specify one of: -ReadOnly,-ReadWrite" } It "Errors out when multiple 'rw' params are passed without EnableException" { - { Set-DbaDbState -SqlInstance $script:instance2 -Database $db1 -ReadOnly -ReadWrite *> $null } | Should Not Throw - $result = Set-DbaDbState -SqlInstance $script:instance2 -Database $db1 -ReadOnly -ReadWrite *> $null + { Set-DbaDbState -SqlInstance $TestConfig.instance2 -Database $db1 -ReadOnly -ReadWrite *> $null } | Should Not Throw + $result = Set-DbaDbState -SqlInstance $TestConfig.instance2 -Database $db1 -ReadOnly -ReadWrite *> $null $result | Should Be $null } } Context "Operations on databases" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $db1 = "dbatoolsci_dbsetstate_online" $db2 = "dbatoolsci_dbsetstate_offline" $db3 = "dbatoolsci_dbsetstate_emergency" @@ -69,7 +69,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $db6 = "dbatoolsci_dbsetstate_multi" $db7 = "dbatoolsci_dbsetstate_rw" $db8 = "dbatoolsci_dbsetstate_ro" - Get-DbaDatabase -SqlInstance $script:instance2 -Database $db1, $db2, $db3, $db4, $db5, $db6, $db7, $db8 | Remove-DbaDatabase -Confirm:$false + Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $db1, $db2, $db3, $db4, $db5, $db6, $db7, $db8 | Remove-DbaDatabase -Confirm:$false $server.Query("CREATE DATABASE $db1") $server.Query("CREATE DATABASE $db2") $server.Query("CREATE DATABASE $db3") @@ -89,8 +89,8 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } } AfterAll { - $null = Set-DbaDbState -Sqlinstance $script:instance2 -Database $db1, $db2, $db3, $db4, $db5, $db7 -Online -ReadWrite -MultiUser -Force - $null = Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance2 -Database $db1, $db2, $db3, $db4, $db5, $db6, $db7, $db8 + $null = Set-DbaDbState -Sqlinstance $TestConfig.instance2 -Database $db1, $db2, $db3, $db4, $db5, $db7 -Online -ReadWrite -MultiUser -Force + $null = Remove-DbaDatabase -Confirm:$false -SqlInstance $TestConfig.instance2 -Database $db1, $db2, $db3, $db4, $db5, $db6, $db7, $db8 } if ($setupright) { # just to have a correct report on how much time BeforeAll takes @@ -98,80 +98,80 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $true | Should Be $true } It "Honors the Database parameter" { - $result = Set-DbaDbState -SqlInstance $script:instance2 -Database $db2 -Emergency -Force + $result = Set-DbaDbState -SqlInstance $TestConfig.instance2 -Database $db2 -Emergency -Force $result.DatabaseName | Should be $db2 $result.Status | Should Be 'EMERGENCY' - $results = Set-DbaDbState -SqlInstance $script:instance2 -Database $db1, $db2 -Emergency -Force + $results = Set-DbaDbState -SqlInstance $TestConfig.instance2 -Database $db1, $db2 -Emergency -Force $results.Count | Should be 2 } It "Honors the ExcludeDatabase parameter" { $alldbs_ = $server.Query("select name from sys.databases") $alldbs = ($alldbs_ | Where-Object Name -notin @($db1, $db2, $db3, $db4, $db5, $db6, $db7, $db8)).name - $results = Set-DbaDbState -SqlInstance $script:instance2 -ExcludeDatabase $alldbs -Online -Force + $results = Set-DbaDbState -SqlInstance $TestConfig.instance2 -ExcludeDatabase $alldbs -Online -Force $comparison = Compare-Object -ReferenceObject ($results.DatabaseName) -DifferenceObject (@($db1, $db2, $db3, $db4, $db5, $db6, $db7, $db8)) $comparison.Count | Should Be 0 } It "Sets a database as online" { - $null = Set-DbaDbState -SqlInstance $script:instance2 -Database $db1 -Emergency -Force - $result = Set-DbaDbState -SqlInstance $script:instance2 -Database $db1 -Online -Force + $null = Set-DbaDbState -SqlInstance $TestConfig.instance2 -Database $db1 -Emergency -Force + $result = Set-DbaDbState -SqlInstance $TestConfig.instance2 -Database $db1 -Online -Force $result.DatabaseName | Should Be $db1 $result.Status | Should Be "ONLINE" } It "Sets a database as offline" { - $result = Set-DbaDbState -SqlInstance $script:instance2 -Database $db2 -Offline -Force + $result = Set-DbaDbState -SqlInstance $TestConfig.instance2 -Database $db2 -Offline -Force $result.DatabaseName | Should Be $db2 $result.Status | Should Be "OFFLINE" } It "Sets a database as emergency" { - $result = Set-DbaDbState -SqlInstance $script:instance2 -Database $db3 -Emergency -Force + $result = Set-DbaDbState -SqlInstance $TestConfig.instance2 -Database $db3 -Emergency -Force $result.DatabaseName | Should Be $db3 $result.Status | Should Be "EMERGENCY" } It "Sets a database as single_user" { - $result = Set-DbaDbState -SqlInstance $script:instance2 -Database $db4 -SingleUser -Force + $result = Set-DbaDbState -SqlInstance $TestConfig.instance2 -Database $db4 -SingleUser -Force $result.DatabaseName | Should Be $db4 $result.Access | Should Be "SINGLE_USER" } It "Sets a database as multi_user" { - $null = Set-DbaDbState -SqlInstance $script:instance2 -Database $db6 -RestrictedUser -Force - $result = Set-DbaDbState -SqlInstance $script:instance2 -Database $db6 -MultiUser -Force + $null = Set-DbaDbState -SqlInstance $TestConfig.instance2 -Database $db6 -RestrictedUser -Force + $result = Set-DbaDbState -SqlInstance $TestConfig.instance2 -Database $db6 -MultiUser -Force $result.DatabaseName | Should Be $db6 $result.Access | Should Be "MULTI_USER" } It "Sets a database as restricted_user" { - $result = Set-DbaDbState -SqlInstance $script:instance2 -Database $db5 -RestrictedUser -Force + $result = Set-DbaDbState -SqlInstance $TestConfig.instance2 -Database $db5 -RestrictedUser -Force $result.DatabaseName | Should Be $db5 $result.Access | Should Be "RESTRICTED_USER" } It "Sets a database as read_write" { - $null = Set-DbaDbState -SqlInstance $script:instance2 -Database $db7 -ReadOnly -Force - $result = Set-DbaDbState -SqlInstance $script:instance2 -Database $db7 -ReadWrite -Force + $null = Set-DbaDbState -SqlInstance $TestConfig.instance2 -Database $db7 -ReadOnly -Force + $result = Set-DbaDbState -SqlInstance $TestConfig.instance2 -Database $db7 -ReadWrite -Force $result.DatabaseName | Should Be $db7 $result.RW | Should Be "READ_WRITE" } It "Sets a database as read_only" { - $result = Set-DbaDbState -SqlInstance $script:instance2 -Database $db8 -ReadOnly -Force + $result = Set-DbaDbState -SqlInstance $TestConfig.instance2 -Database $db8 -ReadOnly -Force $result.DatabaseName | Should Be $db8 $result.RW | Should Be "READ_ONLY" } It "Works when piped from Get-DbaDbState" { - $results = Get-DbaDbState -SqlInstance $script:instance2 -Database $db7, $db8 | Set-DbaDbState -Online -MultiUser -Force + $results = Get-DbaDbState -SqlInstance $TestConfig.instance2 -Database $db7, $db8 | Set-DbaDbState -Online -MultiUser -Force $results.Count | Should Be 2 $comparison = Compare-Object -ReferenceObject ($results.DatabaseName) -DifferenceObject (@($db7, $db8)) $comparison.Count | Should Be 0 } It "Works when piped from Get-DbaDatabase" { - $results = Get-DbaDatabase -SqlInstance $script:instance2 -Database $db7, $db8 | Set-DbaDbState -Online -MultiUser -Force + $results = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $db7, $db8 | Set-DbaDbState -Online -MultiUser -Force $results.Count | Should Be 2 $comparison = Compare-Object -ReferenceObject ($results.DatabaseName) -DifferenceObject (@($db7, $db8)) $comparison.Count | Should Be 0 } - $result = Set-DbaDbState -SqlInstance $script:instance2 -Database $db1 -Emergency -Force + $result = Set-DbaDbState -SqlInstance $TestConfig.instance2 -Database $db1 -Emergency -Force It "Has the correct properties" { $ExpectedProps = 'ComputerName,InstanceName,SqlInstance,DatabaseName,RW,Status,Access,Notes,Database'.Split(',') ($result.PsObject.Properties.Name | Sort-Object) | Should Be ($ExpectedProps | Sort-Object) @@ -183,4 +183,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } } } -} \ No newline at end of file +} diff --git a/tests/Set-DbaDefaultPath.Tests.ps1 b/tests/Set-DbaDefaultPath.Tests.ps1 index 0bff52431c..7fbfc5547d 100644 --- a/tests/Set-DbaDefaultPath.Tests.ps1 +++ b/tests/Set-DbaDefaultPath.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,7 +15,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Context "returns proper information" { - $results = Set-DbaDefaultPath -SqlInstance $script:instance1 -Type Backup -Path C:\temp + $results = Set-DbaDefaultPath -SqlInstance $TestConfig.instance1 -Type Backup -Path C:\temp It "Data returns a value that contains :\" { $results.Data -match "\:\\" } @@ -29,4 +29,4 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $results.ErrorLog -match "\:\\" } } -} \ No newline at end of file +} diff --git a/tests/Set-DbaEndpoint.Tests.ps1 b/tests/Set-DbaEndpoint.Tests.ps1 index a3f9ce1abd..b498aa5f84 100644 --- a/tests/Set-DbaEndpoint.Tests.ps1 +++ b/tests/Set-DbaEndpoint.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Set-DbaErrorLogConfig.Tests.ps1 b/tests/Set-DbaErrorLogConfig.Tests.ps1 index 46d668e9fc..a1e9e8aaeb 100644 --- a/tests/Set-DbaErrorLogConfig.Tests.ps1 +++ b/tests/Set-DbaErrorLogConfig.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag "UnitTests" { Context "Validate parameters" { @@ -15,7 +15,7 @@ Describe "$CommandName Unit Tests" -Tag "UnitTests" { Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $logfiles = $server.NumberOfLogFiles $logsize = $server.ErrorLogSizeKb @@ -23,7 +23,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $server.ErrorLogSizeKb = 1024 $server.Alter() - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance1 $logfiles2 = $server.NumberOfLogFiles $logsize2 = $server.ErrorLogSizeKb @@ -31,18 +31,18 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $server.Alter() } AfterAll { - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance1 $server.NumberOfLogFiles = $logfiles2 $server.Alter() - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $server.NumberOfLogFiles = $logfiles $server.ErrorLogSizeKb = $logsize $server.Alter() } Context "Apply LogCount to multiple instances" { - $results = Set-DbaErrorLogConfig -SqlInstance $script:instance2, $script:instance1 -LogCount 8 + $results = Set-DbaErrorLogConfig -SqlInstance $TestConfig.instance2, $TestConfig.instance1 -LogCount 8 foreach ($result in $results) { It 'Returns LogCount set to 8 for each instance' { $result.LogCount | Should Be 8 @@ -50,11 +50,11 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } } Context "Apply LogSize to multiple instances" { - $results = Set-DbaErrorLogConfig -SqlInstance $script:instance2, $script:instance1 -LogSize 100 -WarningAction SilentlyContinue -WarningVariable warn2 + $results = Set-DbaErrorLogConfig -SqlInstance $TestConfig.instance2, $TestConfig.instance1 -LogSize 100 -WarningAction SilentlyContinue -WarningVariable warn2 foreach ($result in $results) { It 'Returns LogSize set to 100 for each instance' { $result.LogSize.Kilobyte | Should Be 100 } } } -} \ No newline at end of file +} diff --git a/tests/Set-DbaExtendedProperty.Tests.ps1 b/tests/Set-DbaExtendedProperty.Tests.ps1 index 5aba4603ea..cf82a381d7 100644 --- a/tests/Set-DbaExtendedProperty.Tests.ps1 +++ b/tests/Set-DbaExtendedProperty.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,7 +16,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BeforeAll { $random = Get-Random - $instance2 = Connect-DbaInstance -SqlInstance $script:instance2 + $instance2 = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $null = Get-DbaProcess -SqlInstance $instance2 | Where-Object Program -match dbatools | Stop-DbaProcess -Confirm:$false $newDbName = "dbatoolsci_newdb_$random" $db = New-DbaDatabase -SqlInstance $instance2 -Name $newDbName @@ -35,4 +35,4 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $newep.Value | Should -Be "Test_Database_Value" } } -} \ No newline at end of file +} diff --git a/tests/Set-DbaExtendedProtection.Tests.ps1 b/tests/Set-DbaExtendedProtection.Tests.ps1 index d991feabdc..c9e177dc47 100644 --- a/tests/Set-DbaExtendedProtection.Tests.ps1 +++ b/tests/Set-DbaExtendedProtection.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,7 +16,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Command actually works" { It "Default set and returns '0 - Off'" { - $results = Set-DbaExtendedProtection -SqlInstance $script:instance1 -EnableException *>$null + $results = Set-DbaExtendedProtection -SqlInstance $TestConfig.instance1 -EnableException *>$null $results.ExtendedProtection -eq "0 - Off" } } @@ -30,7 +30,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $ScriptBlock, $EnableException ) - $server = [DbaInstanceParameter[]]$script:instance1 + $server = [DbaInstanceParameter[]]$TestConfig.instance1 @{ DisplayName = "SQL Server ($($instance.InstanceName))" AdvancedProperties = @( @@ -43,30 +43,31 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } -ModuleName dbatools } It "Set explicitly to '0 - Off' using text" { - $results = Set-DbaExtendedProtection -SqlInstance $script:instance1 -Value Off -EnableException -Verbose 4>&1 + $results = Set-DbaExtendedProtection -SqlInstance $TestConfig.instance1 -Value Off -EnableException -Verbose 4>&1 $results[-1] = 'Value: 0' } It "Set explicitly to '0 - Off' using number" { - $results = Set-DbaExtendedProtection -SqlInstance $script:instance1 -Value 0 -EnableException -Verbose 4>&1 + $results = Set-DbaExtendedProtection -SqlInstance $TestConfig.instance1 -Value 0 -EnableException -Verbose 4>&1 $results[-1] = 'Value: 0' } It "Set explicitly to '1 - Allowed' using text" { - $results = Set-DbaExtendedProtection -SqlInstance $script:instance1 -Value Allowed -EnableException -Verbose 4>&1 + $results = Set-DbaExtendedProtection -SqlInstance $TestConfig.instance1 -Value Allowed -EnableException -Verbose 4>&1 $results[-1] = 'Value: 1' } It "Set explicitly to '1 - Allowed' using number" { - $results = Set-DbaExtendedProtection -SqlInstance $script:instance1 -Value 1 -EnableException -Verbose 4>&1 + $results = Set-DbaExtendedProtection -SqlInstance $TestConfig.instance1 -Value 1 -EnableException -Verbose 4>&1 $results[-1] = 'Value: 1' } It "Set explicitly to '2 - Required' using text" { - $results = Set-DbaExtendedProtection -SqlInstance $script:instance1 -Value Required -EnableException -Verbose 4>&1 + $results = Set-DbaExtendedProtection -SqlInstance $TestConfig.instance1 -Value Required -EnableException -Verbose 4>&1 $results[-1] = 'Value: 2' } It "Set explicitly to '2 - Required' using number" { - $results = Set-DbaExtendedProtection -SqlInstance $script:instance1 -Value 2 -EnableException -Verbose 4>&1 + $results = Set-DbaExtendedProtection -SqlInstance $TestConfig.instance1 -Value 2 -EnableException -Verbose 4>&1 $results[-1] = 'Value: 2' } } } + diff --git a/tests/Set-DbaLogin.Tests.ps1 b/tests/Set-DbaLogin.Tests.ps1 index f120589ee1..e910f0a069 100644 --- a/tests/Set-DbaLogin.Tests.ps1 +++ b/tests/Set-DbaLogin.Tests.ps1 @@ -1,6 +1,6 @@ $commandname = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -36,23 +36,23 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { } It "Validates -Login and -NewName aren't the same" { - { Set-DbaLogin -SqlInstance $script:instance2 -Login testlogin -NewName testLogin -EnableException } | Should -Throw 'Login name is the same as the value in -NewName' + { Set-DbaLogin -SqlInstance $TestConfig.instance2 -Login testlogin -NewName testLogin -EnableException } | Should -Throw 'Login name is the same as the value in -NewName' } It "Validates -Enable and -Disable aren't used together" { - { Set-DbaLogin -SqlInstance $script:instance2 -Login testlogin -Enable -Disable -EnableException } | Should -Throw 'You cannot use both -Enable and -Disable together' + { Set-DbaLogin -SqlInstance $TestConfig.instance2 -Login testlogin -Enable -Disable -EnableException } | Should -Throw 'You cannot use both -Enable and -Disable together' } It "Validates -GrantLogin and -DenyLogin aren't used together" { - { Set-DbaLogin -SqlInstance $script:instance2 -Login testlogin -GrantLogin -DenyLogin -EnableException } | Should -Throw 'You cannot use both -GrantLogin and -DenyLogin together' + { Set-DbaLogin -SqlInstance $TestConfig.instance2 -Login testlogin -GrantLogin -DenyLogin -EnableException } | Should -Throw 'You cannot use both -GrantLogin and -DenyLogin together' } It "Validates -Login is required when using -SqlInstance" { - { Set-DbaLogin -SqlInstance $script:instance2 -EnableException } | Should -Throw 'You must specify a Login when using SqlInstance' + { Set-DbaLogin -SqlInstance $TestConfig.instance2 -EnableException } | Should -Throw 'You must specify a Login when using SqlInstance' } It "Validates -Password is a SecureString or PSCredential" { - { Set-DbaLogin -SqlInstance $script:instance2 -Login 'testLogin' -Password 'password' -EnableException } | Should -Throw 'Password must be a PSCredential or SecureString' + { Set-DbaLogin -SqlInstance $TestConfig.instance2 -Login 'testLogin' -Password 'password' -EnableException } | Should -Throw 'Password must be a PSCredential or SecureString' } } } @@ -68,118 +68,118 @@ Describe "$CommandName Integration Tests" -Tag 'IntegrationTests' { $password2 = ConvertTo-SecureString -String "password2A@" -AsPlainText -Force # Create the login - New-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random", "testlogin2_$random" -Password $password1 + New-DbaLogin -SqlInstance $TestConfig.instance2 -Login "testlogin1_$random", "testlogin2_$random" -Password $password1 - New-DbaDatabase -SqlInstance $script:instance2 -Name "testdb1_$random" -Confirm:$false + New-DbaDatabase -SqlInstance $TestConfig.instance2 -Name "testdb1_$random" -Confirm:$false } AfterAll { - Remove-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random", "testlogin2_$random" -Confirm:$false -Force - Remove-DbaDatabase -SqlInstance $script:instance2 -Database "testdb1_$random" -Confirm:$false + Remove-DbaLogin -SqlInstance $TestConfig.instance2 -Login "testlogin1_$random", "testlogin2_$random" -Confirm:$false -Force + Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database "testdb1_$random" -Confirm:$false } It "Does test login exist" { - $logins = Get-DbaLogin -SqlInstance $script:instance2 | Where-Object { $_.Name -eq "testlogin1_$random" } | Select-Object Name + $logins = Get-DbaLogin -SqlInstance $TestConfig.instance2 | Where-Object { $_.Name -eq "testlogin1_$random" } | Select-Object Name $logins.Name | Should -Be "testlogin1_$random" } It "Verifies -NewName doesn't already exist when renaming a login" { - $result = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" -NewName 'sa' -EnableException + $result = Set-DbaLogin -SqlInstance $TestConfig.instance2 -Login "testlogin1_$random" -NewName 'sa' -EnableException $result.Notes | Should -Be 'New login name already exists' } It 'Change the password from a SecureString' { - $result = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" -Password $password2 + $result = Set-DbaLogin -SqlInstance $TestConfig.instance2 -Login "testlogin1_$random" -Password $password2 $result.PasswordChanged | Should -Be $true } It 'Changes the password from a PSCredential' { $cred = New-Object System.Management.Automation.PSCredential ("testlogin1_$random", $password2) - $result = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" -Password $cred + $result = Set-DbaLogin -SqlInstance $TestConfig.instance2 -Login "testlogin1_$random" -Password $cred $result.PasswordChanged | Should -Be $true } It "Change the password from piped Login" { - $login = Get-DbaLogin -Sqlinstance $script:instance2 -Login "testlogin1_$random" + $login = Get-DbaLogin -Sqlinstance $TestConfig.instance2 -Login "testlogin1_$random" $result = $login | Set-DbaLogin -Password $password2 $result.PasswordChanged | Should -Be $true } It "Change the password from InputObject" { - $login = Get-DbaLogin -Sqlinstance $script:instance2 -Login "testlogin1_$random" + $login = Get-DbaLogin -Sqlinstance $TestConfig.instance2 -Login "testlogin1_$random" $result = Set-DbaLogin -InputObject $login -Password $password2 $result.PasswordChanged | Should -Be $true } It "Disable the login" { - $result = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" -Disable + $result = Set-DbaLogin -SqlInstance $TestConfig.instance2 -Login "testlogin1_$random" -Disable $result.IsDisabled | Should -Be $true } It "Enable the login" { - $result = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" -Enable + $result = Set-DbaLogin -SqlInstance $TestConfig.instance2 -Login "testlogin1_$random" -Enable $result.IsDisabled | Should -Be $false } It "Deny access to login" { - $result = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" -DenyLogin + $result = Set-DbaLogin -SqlInstance $TestConfig.instance2 -Login "testlogin1_$random" -DenyLogin $result.DenyLogin | Should -Be $true } It "Grant access to login" { - $result = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" -GrantLogin + $result = Set-DbaLogin -SqlInstance $TestConfig.instance2 -Login "testlogin1_$random" -GrantLogin $result.DenyLogin | Should -Be $false } It "Enforces password policy on login" { - $result = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" -PasswordPolicyEnforced + $result = Set-DbaLogin -SqlInstance $TestConfig.instance2 -Login "testlogin1_$random" -PasswordPolicyEnforced $result.PasswordPolicyEnforced | Should Be $true } It "Catches errors when password can't be changed" { # enforce password policy - $result = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" -PasswordPolicyEnforced -EnableException + $result = Set-DbaLogin -SqlInstance $TestConfig.instance2 -Login "testlogin1_$random" -PasswordPolicyEnforced -EnableException $result.PasswordPolicyEnforced | Should -Be $true # violate policy $invalidPassword = ConvertTo-SecureString -String "password1" -AsPlainText -Force - $result = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" -Password $invalidPassword -WarningAction 'SilentlyContinue' + $result = Set-DbaLogin -SqlInstance $TestConfig.instance2 -Login "testlogin1_$random" -Password $invalidPassword -WarningAction 'SilentlyContinue' $result | Should -Be $null - { Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" -Password $invalidPassword -EnableException } | Should -Throw + { Set-DbaLogin -SqlInstance $TestConfig.instance2 -Login "testlogin1_$random" -Password $invalidPassword -EnableException } | Should -Throw } It "Disables enforcing password policy on login" { - $result = Get-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" + $result = Get-DbaLogin -SqlInstance $TestConfig.instance2 -Login "testlogin1_$random" $result.PasswordPolicyEnforced | Should Be $true - $result = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" -PasswordPolicyEnforced:$false + $result = Set-DbaLogin -SqlInstance $TestConfig.instance2 -Login "testlogin1_$random" -PasswordPolicyEnforced:$false $result.PasswordPolicyEnforced | Should Be $false } It "Add roles to login" { - $result = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" -AddRole serveradmin, processadmin + $result = Set-DbaLogin -SqlInstance $TestConfig.instance2 -Login "testlogin1_$random" -AddRole serveradmin, processadmin $result.ServerRole | Should -Be "processadmin, serveradmin" } It "Remove roles from login" { - $result = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" -RemoveRole serveradmin + $result = Set-DbaLogin -SqlInstance $TestConfig.instance2 -Login "testlogin1_$random" -RemoveRole serveradmin $result.ServerRole | Should -Be "processadmin" } It "Results include multiple changed objects" { - $results = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random", "testlogin2_$random" -DenyLogin + $results = Set-DbaLogin -SqlInstance $TestConfig.instance2 -Login "testlogin1_$random", "testlogin2_$random" -DenyLogin $results.Count | Should -Be 2 foreach ($r in $results) { $r.DenyLogin | Should -Be $true @@ -187,43 +187,43 @@ Describe "$CommandName Integration Tests" -Tag 'IntegrationTests' { } It "DefaultDatabase" { - $results = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" -DefaultDatabase "testdb1_$random" + $results = Set-DbaLogin -SqlInstance $TestConfig.instance2 -Login "testlogin1_$random" -DefaultDatabase "testdb1_$random" $results.DefaultDatabase | Should -Be "testdb1_$random" } It "PasswordExpirationEnabled" { - $result = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin2_$random" -PasswordPolicyEnforced + $result = Set-DbaLogin -SqlInstance $TestConfig.instance2 -Login "testlogin2_$random" -PasswordPolicyEnforced $result.PasswordPolicyEnforced | Should Be $true # testlogin1_$random will get skipped since it does not have PasswordPolicyEnforced set to true (check_policy = ON) - $result = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random", "testlogin2_$random" -PasswordExpirationEnabled -ErrorVariable error + $result = Set-DbaLogin -SqlInstance $TestConfig.instance2 -Login "testlogin1_$random", "testlogin2_$random" -PasswordExpirationEnabled -ErrorVariable error $result.Count | Should -Be 1 $result.Name | Should -Be "testlogin2_$random" $result.PasswordExpirationEnabled | Should Be $true $error.Exception | Should -Match "Couldn't set check_expiration = ON because check_policy = OFF for \[testlogin1_$random\]" # set both params for this login - $result = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" -PasswordPolicyEnforced -PasswordExpirationEnabled + $result = Set-DbaLogin -SqlInstance $TestConfig.instance2 -Login "testlogin1_$random" -PasswordPolicyEnforced -PasswordExpirationEnabled $result.PasswordExpirationEnabled | Should -Be $true $result.PasswordPolicyEnforced | Should Be $true # disable the setting for this login - $result = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" -PasswordExpirationEnabled:$false + $result = Set-DbaLogin -SqlInstance $TestConfig.instance2 -Login "testlogin1_$random" -PasswordExpirationEnabled:$false $result.PasswordExpirationEnabled | Should -Be $false } It "Ensure both password policy settings can be disabled at the same time" { - $result = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" -PasswordPolicyEnforced -PasswordExpirationEnabled + $result = Set-DbaLogin -SqlInstance $TestConfig.instance2 -Login "testlogin1_$random" -PasswordPolicyEnforced -PasswordExpirationEnabled $result.PasswordExpirationEnabled | Should -Be $true $result.PasswordPolicyEnforced | Should Be $true - $result = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" -PasswordPolicyEnforced:$false -PasswordExpirationEnabled:$false + $result = Set-DbaLogin -SqlInstance $TestConfig.instance2 -Login "testlogin1_$random" -PasswordPolicyEnforced:$false -PasswordExpirationEnabled:$false $result.PasswordExpirationEnabled | Should -Be $false $result.PasswordPolicyEnforced | Should Be $false } It -Skip:$SkipLocalTest "Unlock" { - $results = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" -PasswordPolicyEnforced -EnableException + $results = Set-DbaLogin -SqlInstance $TestConfig.instance2 -Login "testlogin1_$random" -PasswordPolicyEnforced -EnableException $results.PasswordPolicyEnforced | Should -Be $true # simulate a lockout @@ -233,28 +233,28 @@ Describe "$CommandName Integration Tests" -Tag 'IntegrationTests' { # exceed the lockout count for (($i = 0); $i -le 4; $i++) { try { - Connect-DbaInstance -SqlInstance $script:instance2 -SqlCredential $invalidSqlCredential + Connect-DbaInstance -SqlInstance $TestConfig.instance2 -SqlCredential $invalidSqlCredential } catch { Write-Message -Level Warning -Message "invalid login credentials used on purpose to lock out account" Start-Sleep -s 5 } } - $results = Get-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" + $results = Get-DbaLogin -SqlInstance $TestConfig.instance2 -Login "testlogin1_$random" $results.IsLocked | Should -Be $true # this will generate a warning since neither the password or the -force param is specified - $results = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" -Unlock + $results = Set-DbaLogin -SqlInstance $TestConfig.instance2 -Login "testlogin1_$random" -Unlock $results | Should -BeNullOrEmpty # this will use the workaround solution to turn off/on the check_policy - $results = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" -Unlock -Force + $results = Set-DbaLogin -SqlInstance $TestConfig.instance2 -Login "testlogin1_$random" -Unlock -Force $results.IsLocked | Should -Be $false # exceed the lockout count again for (($i = 0); $i -le 4; $i++) { try { - Connect-DbaInstance -SqlInstance $script:instance2 -SqlCredential $invalidSqlCredential + Connect-DbaInstance -SqlInstance $TestConfig.instance2 -SqlCredential $invalidSqlCredential } catch { Write-Message -Level Warning -Message "invalid login credentials used on purpose to lock out account" Start-Sleep -s 5 @@ -262,47 +262,47 @@ Describe "$CommandName Integration Tests" -Tag 'IntegrationTests' { } # unlock by resetting the password - $results = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" -Unlock -SecurePassword $password1 + $results = Set-DbaLogin -SqlInstance $TestConfig.instance2 -Login "testlogin1_$random" -Unlock -SecurePassword $password1 $results.IsLocked | Should -Be $false } It "PasswordMustChange" { # password is required - $changeResult = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" -PasswordMustChange -ErrorVariable error + $changeResult = Set-DbaLogin -SqlInstance $TestConfig.instance2 -Login "testlogin1_$random" -PasswordMustChange -ErrorVariable error $changeResult | Should -BeNullOrEmpty $error.Exception | Should -Match "You must specify a password when using the -PasswordMustChange parameter" # ensure the policy settings are off - $result = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" -PasswordPolicyEnforced:$false -PasswordExpirationEnabled:$false + $result = Set-DbaLogin -SqlInstance $TestConfig.instance2 -Login "testlogin1_$random" -PasswordPolicyEnforced:$false -PasswordExpirationEnabled:$false $result.PasswordExpirationEnabled | Should -Be $false $result.PasswordPolicyEnforced | Should Be $false # set the policy options separately for testlogin2 - $changeResult = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin2_$random" -PasswordPolicyEnforced -PasswordExpirationEnabled + $changeResult = Set-DbaLogin -SqlInstance $TestConfig.instance2 -Login "testlogin2_$random" -PasswordPolicyEnforced -PasswordExpirationEnabled $changeResult.PasswordPolicyEnforced | Should Be $true $changeResult.PasswordExpirationEnabled | Should Be $true # check_policy and check_expiration must be set on the login - $changeResult = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random", "testlogin2_$random" -PasswordMustChange -Password $password1 -ErrorVariable error + $changeResult = Set-DbaLogin -SqlInstance $TestConfig.instance2 -Login "testlogin1_$random", "testlogin2_$random" -PasswordMustChange -Password $password1 -ErrorVariable error $changeResult.Count | Should -Be 1 $changeResult.Name | Should -Be "testlogin2_$random" $error.Exception | Should -Match "Unable to change the password and set the must_change option for \[testlogin1_$random\] because check_policy = False and check_expiration = False" - $changeResult = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin1_$random" -PasswordMustChange -Password $password1 -PasswordPolicyEnforced -PasswordExpirationEnabled + $changeResult = Set-DbaLogin -SqlInstance $TestConfig.instance2 -Login "testlogin1_$random" -PasswordMustChange -Password $password1 -PasswordPolicyEnforced -PasswordExpirationEnabled $changeResult.MustChangePassword | Should -Be $true $changeResult.PasswordChanged | Should -Be $true $changeResult.PasswordPolicyEnforced | Should Be $true $changeResult.PasswordExpirationEnabled | Should Be $true # now change the password and set the must_change - $changeResult = Set-DbaLogin -SqlInstance $script:instance2 -Login "testlogin2_$random" -PasswordMustChange -Password $password1 + $changeResult = Set-DbaLogin -SqlInstance $TestConfig.instance2 -Login "testlogin2_$random" -PasswordMustChange -Password $password1 $changeResult.MustChangePassword | Should -Be $true $changeResult.PasswordChanged | Should -Be $true # get a listing of the logins that must change their password - $result = Get-DbaLogin -SqlInstance $script:instance2 -MustChangePassword + $result = Get-DbaLogin -SqlInstance $TestConfig.instance2 -MustChangePassword $result.Name | Should -Contain "testlogin1_$random" $result.Name | Should -Contain "testlogin2_$random" } } -} \ No newline at end of file +} diff --git a/tests/Set-DbaMaxDop.Tests.ps1 b/tests/Set-DbaMaxDop.Tests.ps1 index ae689c4cb0..fce6e00870 100644 --- a/tests/Set-DbaMaxDop.Tests.ps1 +++ b/tests/Set-DbaMaxDop.Tests.ps1 @@ -1,6 +1,6 @@ $commandname = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$commandname Unit Tests" -Tag "UnitTests", Set-DbaMaxDop { Context "Validate parameters" { @@ -17,7 +17,7 @@ Describe "$commandname Unit Tests" -Tag "UnitTests", Set-DbaMaxDop { Mock Stop-Function { } -ModuleName dbatools } It "Should Call Stop-Function. -Database, -AllDatabases and -ExcludeDatabase are mutually exclusive." { - Set-DbaMaxDop -SqlInstance $script:instance1 -MaxDop 12 -Database $singledb -AllDatabases -ExcludeDatabase "master" | Should Be + Set-DbaMaxDop -SqlInstance $TestConfig.instance1 -MaxDop 12 -Database $singledb -AllDatabases -ExcludeDatabase "master" | Should Be } It "Validates that Stop Function Mock has been called" { $assertMockParams = @{ @@ -33,22 +33,22 @@ Describe "$commandname Unit Tests" -Tag "UnitTests", Set-DbaMaxDop { Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { - Get-DbaProcess -SqlInstance $script:instance1, $script:instance2 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue + Get-DbaProcess -SqlInstance $TestConfig.instance1, $TestConfig.instance2 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue $singledb = "dbatoolsci_singledb" $dbs = "dbatoolsci_lildb", "dbatoolsci_testMaxDop", $singledb - $null = Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbs | Remove-DbaDatabase -Confirm:$false + $null = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbs | Remove-DbaDatabase -Confirm:$false foreach ($db in $dbs) { - Invoke-DbaQuery -SqlInstance $script:instance1 -Query "CREATE DATABASE $db" - Invoke-DbaQuery -SqlInstance $script:instance2 -Query "CREATE DATABASE $db" + Invoke-DbaQuery -SqlInstance $TestConfig.instance1 -Query "CREATE DATABASE $db" + Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Query "CREATE DATABASE $db" } } AfterAll { - Get-DbaDatabase -SqlInstance $script:instance1 -Database $dbs | Remove-DbaDatabase -Confirm:$false - Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbs | Remove-DbaDatabase -Confirm:$false + Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $dbs | Remove-DbaDatabase -Confirm:$false + Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbs | Remove-DbaDatabase -Confirm:$false } Context "Apply to multiple instances" { - $results = Set-DbaMaxDop -SqlInstance $script:instance1, $script:instance2 -MaxDop 2 + $results = Set-DbaMaxDop -SqlInstance $TestConfig.instance1, $TestConfig.instance2 -MaxDop 2 foreach ($result in $results) { It 'Returns MaxDop 2 for each instance' { $result.CurrentInstanceMaxDop | Should Be 2 @@ -57,7 +57,7 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { } Context "Connects to 2016+ instance and apply configuration to single database" { - $results = Set-DbaMaxDop -SqlInstance $script:instance2 -MaxDop 4 -Database $singledb + $results = Set-DbaMaxDop -SqlInstance $TestConfig.instance2 -MaxDop 4 -Database $singledb foreach ($result in $results) { It 'Returns 4 for each database' { $result.DatabaseMaxDop | Should Be 4 @@ -66,7 +66,7 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { } Context "Connects to 2016+ instance and apply configuration to multiple databases" { - $results = Set-DbaMaxDop -SqlInstance $script:instance2 -MaxDop 8 -Database $dbs + $results = Set-DbaMaxDop -SqlInstance $TestConfig.instance2 -MaxDop 8 -Database $dbs foreach ($result in $results) { It 'Returns 8 for each database' { $result.DatabaseMaxDop | Should Be 8 @@ -75,8 +75,8 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { } Context "Piping from Test-DbaMaxDop works" { - $results = Test-DbaMaxDop -SqlInstance $script:instance2 | Set-DbaMaxDop -MaxDop 4 - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $results = Test-DbaMaxDop -SqlInstance $TestConfig.instance2 | Set-DbaMaxDop -MaxDop 4 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 It 'Command returns output' { $results.CurrentInstanceMaxDop | Should Not BeNullOrEmpty $results.CurrentInstanceMaxDop | Should Be 4 @@ -87,8 +87,8 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { } Context "Piping SqlInstance name works" { - $results = $script:instance2 | Set-DbaMaxDop -MaxDop 2 - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $results = $TestConfig.instance2 | Set-DbaMaxDop -MaxDop 2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 It 'Command returns output' { $results.CurrentInstanceMaxDop | Should Not BeNullOrEmpty $results.CurrentInstanceMaxDop | Should Be 2 @@ -97,4 +97,4 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { $server.Configuration.MaxDegreeOfParallelism.ConfigValue | Should Be 2 } } -} \ No newline at end of file +} diff --git a/tests/Set-DbaMaxMemory.Tests.ps1 b/tests/Set-DbaMaxMemory.Tests.ps1 index 1359232715..beb3f91d11 100644 --- a/tests/Set-DbaMaxMemory.Tests.ps1 +++ b/tests/Set-DbaMaxMemory.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Validate parameters" { @@ -15,19 +15,19 @@ Describe "$CommandName Unit Tests" -Tags "UnitTests" { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $inst1CurrentMaxValue = (Get-DbaMaxMemory -SqlInstance $script:instance1).MaxValue - $inst2CurrentMaxValue = (Get-DbaMaxMemory -SqlInstance $script:instance2).MaxValue + $inst1CurrentMaxValue = (Get-DbaMaxMemory -SqlInstance $TestConfig.instance1).MaxValue + $inst2CurrentMaxValue = (Get-DbaMaxMemory -SqlInstance $TestConfig.instance2).MaxValue } AfterAll { - $null = Set-DbaMaxMemory -SqlInstance $script:instance1 -Max $inst1CurrentMaxValue - $null = Set-DbaMaxMemory -SqlInstance $script:instance2 -Max $inst2CurrentMaxValue + $null = Set-DbaMaxMemory -SqlInstance $TestConfig.instance1 -Max $inst1CurrentMaxValue + $null = Set-DbaMaxMemory -SqlInstance $TestConfig.instance2 -Max $inst2CurrentMaxValue } Context "Connects to multiple instances" { - $results = Set-DbaMaxMemory -SqlInstance $script:instance1, $script:instance2 -Max 1024 + $results = Set-DbaMaxMemory -SqlInstance $TestConfig.instance1, $TestConfig.instance2 -Max 1024 foreach ($result in $results) { It 'Returns 1024 for each instance' { $result.MaxValue | Should Be 1024 } } } -} \ No newline at end of file +} diff --git a/tests/Set-DbaNetworkCertificate.Tests.ps1 b/tests/Set-DbaNetworkCertificate.Tests.ps1 index 12ef080cef..b39ed41eb7 100644 --- a/tests/Set-DbaNetworkCertificate.Tests.ps1 +++ b/tests/Set-DbaNetworkCertificate.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Set-DbaNetworkConfiguration.Tests.ps1 b/tests/Set-DbaNetworkConfiguration.Tests.ps1 index 4caf59563a..add4bebb3e 100644 --- a/tests/Set-DbaNetworkConfiguration.Tests.ps1 +++ b/tests/Set-DbaNetworkConfiguration.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -14,9 +14,9 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { } Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Command works with piped input" { - $netConf = Get-DbaNetworkConfiguration -SqlInstance $script:instance2 + $netConf = Get-DbaNetworkConfiguration -SqlInstance $TestConfig.instance2 $netConf.TcpIpProperties.KeepAlive = 60000 - $results = $netConf | Set-DbaNetworkConfiguration -Confirm:$false + $results = $netConf | Set-DbaNetworkConfiguration -Confirm:$false -WarningAction SilentlyContinue It "Should Return a Result" { $results.ComputerName | Should -Be $netConf.ComputerName @@ -25,14 +25,18 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { It "Should Return a Change" { $results.Changes | Should -Match "Changed TcpIpProperties.KeepAlive to 60000" } + + $netConf = Get-DbaNetworkConfiguration -SqlInstance $TestConfig.instance2 + $netConf.TcpIpProperties.KeepAlive = 30000 + $null = $netConf | Set-DbaNetworkConfiguration -Confirm:$false -WarningAction SilentlyContinue } Context "Command works with commandline input" { - $netConf = Get-DbaNetworkConfiguration -SqlInstance $script:instance2 + $netConf = Get-DbaNetworkConfiguration -SqlInstance $TestConfig.instance2 if ($netConf.NamedPipesEnabled) { - $results = Set-DbaNetworkConfiguration -SqlInstance $script:instance2 -DisableProtocol NamedPipes -Confirm:$false + $results = Set-DbaNetworkConfiguration -SqlInstance $TestConfig.instance2 -DisableProtocol NamedPipes -Confirm:$false -WarningAction SilentlyContinue } else { - $results = Set-DbaNetworkConfiguration -SqlInstance $script:instance2 -EnableProtocol NamedPipes -Confirm:$false + $results = Set-DbaNetworkConfiguration -SqlInstance $TestConfig.instance2 -EnableProtocol NamedPipes -Confirm:$false -WarningAction SilentlyContinue } It "Should Return a Result" { @@ -44,9 +48,9 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } if ($netConf.NamedPipesEnabled) { - $null = Set-DbaNetworkConfiguration -SqlInstance $script:instance2 -EnableProtocol NamedPipes -Confirm:$false + $null = Set-DbaNetworkConfiguration -SqlInstance $TestConfig.instance2 -EnableProtocol NamedPipes -Confirm:$false -WarningAction SilentlyContinue } else { - $null = Set-DbaNetworkConfiguration -SqlInstance $script:instance2 -DisableProtocol NamedPipes -Confirm:$false + $null = Set-DbaNetworkConfiguration -SqlInstance $TestConfig.instance2 -DisableProtocol NamedPipes -Confirm:$false -WarningAction SilentlyContinue } } -} \ No newline at end of file +} diff --git a/tests/Set-DbaPowerPlan.Tests.ps1 b/tests/Set-DbaPowerPlan.Tests.ps1 index c0c9967d0b..492607c800 100644 --- a/tests/Set-DbaPowerPlan.Tests.ps1 +++ b/tests/Set-DbaPowerPlan.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Set-DbaPrivilege.Tests.ps1 b/tests/Set-DbaPrivilege.Tests.ps1 index d9d16999d4..671bcc78d5 100644 --- a/tests/Set-DbaPrivilege.Tests.ps1 +++ b/tests/Set-DbaPrivilege.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Set-DbaResourceGovernor.Tests.ps1 b/tests/Set-DbaResourceGovernor.Tests.ps1 index f55513de91..a330503779 100644 --- a/tests/Set-DbaResourceGovernor.Tests.ps1 +++ b/tests/Set-DbaResourceGovernor.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag "UnitTests" { Context "Validate parameters" { @@ -25,32 +25,33 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BEGIN RETURN DB_NAME(); END;" - Invoke-DbaQuery -SqlInstance $script:instance2 -Query $createUDFQuery -Database "master" - Set-DbaResourceGovernor -SqlInstance $script:instance2 -Disabled -Confirm:$false + Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Query $createUDFQuery -Database "master" + Set-DbaResourceGovernor -SqlInstance $TestConfig.instance2 -Disabled -Confirm:$false } It "enables resource governor" { - $results = Set-DbaResourceGovernor -SqlInstance $script:instance2 -Enabled -Confirm:$false + $results = Set-DbaResourceGovernor -SqlInstance $TestConfig.instance2 -Enabled -Confirm:$false $results.Enabled | Should -Be $true } It "disables resource governor" { - $results = Set-DbaResourceGovernor -SqlInstance $script:instance2 -Disabled -Confirm:$false + $results = Set-DbaResourceGovernor -SqlInstance $TestConfig.instance2 -Disabled -Confirm:$false $results.Enabled | Should -Be $false } It "modifies resource governor classifier function" { $qualifiedClassifierFunction = "[dbo].[$classifierFunction]" - $results = Set-DbaResourceGovernor -SqlInstance $script:instance2 -ClassifierFunction $classifierFunction -Confirm:$false + $results = Set-DbaResourceGovernor -SqlInstance $TestConfig.instance2 -ClassifierFunction $classifierFunction -Confirm:$false $results.ClassifierFunction | Should -Be $qualifiedClassifierFunction } It "removes resource governor classifier function" { - $results = Set-DbaResourceGovernor -SqlInstance $script:instance2 -ClassifierFunction 'NULL' -Confirm:$false + $results = Set-DbaResourceGovernor -SqlInstance $TestConfig.instance2 -ClassifierFunction 'NULL' -Confirm:$false $results.ClassifierFunction | Should -Be '' } AfterAll { $dropUDFQuery = "DROP FUNCTION $qualifiedClassifierFunction;" - Invoke-DbaQuery -SqlInstance $script:instance2 -Query $dropUDFQuery -Database "master" + Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Query $dropUDFQuery -Database "master" } } } + diff --git a/tests/Set-DbaRgResourcePool.Tests.ps1 b/tests/Set-DbaRgResourcePool.Tests.ps1 index 0c37cb73d8..101de59178 100644 --- a/tests/Set-DbaRgResourcePool.Tests.ps1 +++ b/tests/Set-DbaRgResourcePool.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,12 +16,12 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Functionality" { BeforeAll { - $null = Set-DbaResourceGovernor -SqlInstance $script:instance2 -Enabled + $null = Set-DbaResourceGovernor -SqlInstance $TestConfig.instance2 -Enabled } It "Sets a resource pool" { $resourcePoolName = "dbatoolssci_poolTest" $splatNewResourcePool = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 ResourcePool = $resourcePoolName MaximumCpuPercentage = 100 MaximumMemoryPercentage = 100 @@ -29,14 +29,14 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { CapCpuPercent = 100 } $null = New-DbaRgResourcePool @splatNewResourcePool - $result2 = Set-DbaRgResourcePool -SqlInstance $script:instance2 -ResourcePool $resourcePoolName -MaximumCpuPercentage 99 + $result2 = Set-DbaRgResourcePool -SqlInstance $TestConfig.instance2 -ResourcePool $resourcePoolName -MaximumCpuPercentage 99 $result2.MaximumCpuPercentage | Should -Be 99 } It "Works using -Type Internal" { $resourcePoolName = "dbatoolssci_poolTest" $splatNewResourcePool = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 ResourcePool = $resourcePoolName MaximumCpuPercentage = 100 MaximumMemoryPercentage = 100 @@ -45,7 +45,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Type = "Internal" } $splatSetResourcePool = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 ResourcePool = $resourcePoolName MaximumCpuPercentage = 99 MaximumMemoryPercentage = 99 @@ -71,7 +71,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { It "Works using -Type External" { $resourcePoolName = "dbatoolssci_poolTest" $splatNewResourcePool = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 ResourcePool = $resourcePoolName MaximumCpuPercentage = 100 MaximumMemoryPercentage = 100 @@ -79,7 +79,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Type = "External" } $splatSetResourcePool = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 ResourcePool = $resourcePoolName MaximumCpuPercentage = 99 MaximumMemoryPercentage = 99 @@ -98,7 +98,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $resourcePoolName = "dbatoolssci_poolTest" $resourcePoolName2 = "dbatoolssci_poolTest2" $splatNewResourcePool = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 MaximumCpuPercentage = 100 MaximumMemoryPercentage = 100 MaximumIOPSPerVolume = 100 @@ -107,7 +107,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } $null = New-DbaRgResourcePool @splatNewResourcePool -ResourcePool $resourcePoolName $null = New-DbaRgResourcePool @splatNewResourcePool -ResourcePool $resourcePoolName2 - $result = Get-DbaRgResourcePool -SqlInstance $script:instance2 | Where-Object Name -in ($resourcePoolName, $resourcePoolName2) + $result = Get-DbaRgResourcePool -SqlInstance $TestConfig.instance2 | Where-Object Name -in ($resourcePoolName, $resourcePoolName2) ($result | Where-Object Name -eq $resourcePoolName).MaximumCpuPercentage = 99 ($result | Where-Object Name -eq $resourcePoolName2).MaximumCpuPercentage = 98 $result2 = $result | Set-DbaRgResourcePool @@ -118,7 +118,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { It "Skips Resource Governor reconfiguration" { $resourcePoolName = "dbatoolssci_poolTest" $splatNewResourcePool = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 ResourcePool = $resourcePoolName MaximumCpuPercentage = 100 MaximumMemoryPercentage = 100 @@ -127,16 +127,16 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } $null = New-DbaRgResourcePool @splatNewResourcePool - $null = Set-DbaRgResourcePool -SqlInstance $script:instance2 -ResourcePool $resourcePoolName -MaximumCpuPercentage 99 -SkipReconfigure - $result = Get-DbaResourceGovernor -SqlInstance $script:instance2 + $null = Set-DbaRgResourcePool -SqlInstance $TestConfig.instance2 -ResourcePool $resourcePoolName -MaximumCpuPercentage 99 -SkipReconfigure + $result = Get-DbaResourceGovernor -SqlInstance $TestConfig.instance2 $result.ReconfigurePending | Should -Be $true } AfterEach { $resourcePoolName = "dbatoolssci_poolTest" $resourcePoolName2 = "dbatoolssci_poolTest2" - $null = Remove-DbaRgResourcePool -SqlInstance $script:instance2 -ResourcePool $resourcePoolName, $resourcePoolName2 -Type Internal - $null = Remove-DbaRgResourcePool -SqlInstance $script:instance2 -ResourcePool $resourcePoolName, $resourcePoolName2 -Type External + $null = Remove-DbaRgResourcePool -SqlInstance $TestConfig.instance2 -ResourcePool $resourcePoolName, $resourcePoolName2 -Type Internal + $null = Remove-DbaRgResourcePool -SqlInstance $TestConfig.instance2 -ResourcePool $resourcePoolName, $resourcePoolName2 -Type External } } -} \ No newline at end of file +} diff --git a/tests/Set-DbaRgWorkloadGroup.Tests.ps1 b/tests/Set-DbaRgWorkloadGroup.Tests.ps1 index 9400013c59..c5d273d308 100644 --- a/tests/Set-DbaRgWorkloadGroup.Tests.ps1 +++ b/tests/Set-DbaRgWorkloadGroup.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,13 +16,13 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Functionality" { BeforeAll { - $null = Set-DbaResourceGovernor -SqlInstance $script:instance2 -Enabled + $null = Set-DbaResourceGovernor -SqlInstance $TestConfig.instance2 -Enabled } It "Sets a workload group in default resource pool" { $wklGroupName = "dbatoolssci_wklgroupTest" $resourcePoolType = "Internal" $splatNewWorkloadGroup = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 WorkloadGroup = $wklGroupName ResourcePool = "default" ResourcePoolType = $resourcePoolType @@ -35,7 +35,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Force = $true } $splatSetWorkloadGroup = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 WorkloadGroup = $wklGroupName ResourcePool = "default" ResourcePoolType = $resourcePoolType @@ -48,7 +48,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } $newWorkloadGroup = New-DbaRgWorkloadGroup @splatNewWorkloadGroup $result = Set-DbaRgWorkloadGroup @splatSetWorkloadGroup - $resGov = Get-DbaResourceGovernor -SqlInstance $script:instance2 + $resGov = Get-DbaResourceGovernor -SqlInstance $TestConfig.instance2 $newWorkloadGroup | Should -Not -Be $null $resGov.ReconfigurePending | Should -Be $false @@ -64,13 +64,13 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $resourcePoolName = "dbatoolssci_poolTest" $resourcePoolType = "Internal" $splatNewResourcePool = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 ResourcePool = $resourcePoolName Type = $resourcePoolType Force = $true } $splatNewWorkloadGroup = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 WorkloadGroup = $wklGroupName ResourcePool = $resourcePoolName ResourcePoolType = $resourcePoolType @@ -83,7 +83,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Force = $true } $splatSetWorkloadGroup = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 WorkloadGroup = $wklGroupName ResourcePool = $resourcePoolName ResourcePoolType = $resourcePoolType @@ -97,10 +97,10 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $null = New-DbaRgResourcePool @splatNewResourcePool $newWorkloadGroup = New-DbaRgWorkloadGroup @splatNewWorkloadGroup $result = Set-DbaRgWorkloadGroup @splatSetWorkloadGroup - $resGov = Get-DbaResourceGovernor -SqlInstance $script:instance2 + $resGov = Get-DbaResourceGovernor -SqlInstance $TestConfig.instance2 - $null = Remove-DbaRgWorkloadGroup -SqlInstance $script:instance2 -WorkloadGroup $wklGroupName -ResourcePool $resourcePoolName - $null = Remove-DbaRgResourcePool -SqlInstance $script:instance2 -ResourcePool $resourcePoolName -Type $resourcePoolType + $null = Remove-DbaRgWorkloadGroup -SqlInstance $TestConfig.instance2 -WorkloadGroup $wklGroupName -ResourcePool $resourcePoolName + $null = Remove-DbaRgResourcePool -SqlInstance $TestConfig.instance2 -ResourcePool $resourcePoolName -Type $resourcePoolType $newWorkloadGroup | Should -Not -Be $null $resGov.ReconfigurePending | Should -Be $false @@ -115,7 +115,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $wklGroupName = "dbatoolssci_wklgroupTest" $wklGroupName2 = "dbatoolssci_wklgroupTest" $splatNewWorkloadGroup = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 WorkloadGroup = @($wklGroupName, $wklGroupName2) Importance = "MEDIUM" RequestMaximumMemoryGrantPercentage = 25 @@ -126,7 +126,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Force = $true } $splatSetWorkloadGroup = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 WorkloadGroup = @($wklGroupName, $wklGroupName2) ResourcePool = "default" Importance = "HIGH" @@ -138,7 +138,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } $newWorkloadGroups = New-DbaRgWorkloadGroup @splatNewWorkloadGroup $result = Set-DbaRgWorkloadGroup @splatSetWorkloadGroup - $resGov = Get-DbaResourceGovernor -SqlInstance $script:instance2 + $resGov = Get-DbaResourceGovernor -SqlInstance $TestConfig.instance2 $newWorkloadGroups | Should -Not -Be $null $resGov.ReconfigurePending | Should -Be $false @@ -154,7 +154,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $oldGroupMaximumRequests = 10 $newGroupMaximumRequests = 10 $splatNewWorkloadGroup = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 WorkloadGroup = $wklGroupName ResourcePool = "default" GroupMaximumRequests = $oldGroupMaximumRequests @@ -169,13 +169,13 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { It "Skips Resource Governor reconfiguration" { $wklGroupName = "dbatoolssci_wklgroupTest" $splatNewWorkloadGroup = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 WorkloadGroup = $wklGroupName SkipReconfigure = $false Force = $true } $splatSetWorkloadGroup = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 WorkloadGroup = $wklGroupName ResourcePool = "default" ResourcePoolType = "Internal" @@ -184,17 +184,17 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } $null = New-DbaRgWorkloadGroup @splatNewWorkloadGroup - $result = Get-DbaResourceGovernor -SqlInstance $script:instance2 + $result = Get-DbaResourceGovernor -SqlInstance $TestConfig.instance2 $result.ReconfigurePending | Should -Be $false $null = Set-DbaRgWorkloadGroup @splatSetWorkloadGroup - $result2 = Get-DbaResourceGovernor -SqlInstance $script:instance2 + $result2 = Get-DbaResourceGovernor -SqlInstance $TestConfig.instance2 $result2.ReconfigurePending | Should -Be $true } AfterEach { $wklGroupName = "dbatoolssci_wklgroupTest" $wklGroupName2 = "dbatoolssci_wklgroupTest2" - $null = Remove-DbaRgWorkloadGroup -SqlInstance $script:instance2 -WorkloadGroup $wklGroupName, $wklGroupName2 + $null = Remove-DbaRgWorkloadGroup -SqlInstance $TestConfig.instance2 -WorkloadGroup $wklGroupName, $wklGroupName2 } } -} \ No newline at end of file +} diff --git a/tests/Set-DbaSpConfigure.Tests.ps1 b/tests/Set-DbaSpConfigure.Tests.ps1 index 1cfbc1cf28..0b42517d9d 100644 --- a/tests/Set-DbaSpConfigure.Tests.ps1 +++ b/tests/Set-DbaSpConfigure.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,7 +16,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Set configuration" { BeforeAll { - $remotequerytimeout = (Get-DbaSpConfigure -SqlInstance $script:instance1 -ConfigName RemoteQueryTimeout).ConfiguredValue + $remotequerytimeout = (Get-DbaSpConfigure -SqlInstance $TestConfig.instance1 -ConfigName RemoteQueryTimeout).ConfiguredValue $newtimeout = $remotequerytimeout + 1 } @@ -26,20 +26,20 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } It "changes the remote query timeout from $remotequerytimeout to $newtimeout" { - $results = Set-DbaSpConfigure -SqlInstance $script:instance1 -ConfigName RemoteQueryTimeout -Value $newtimeout + $results = Set-DbaSpConfigure -SqlInstance $TestConfig.instance1 -ConfigName RemoteQueryTimeout -Value $newtimeout $results.PreviousValue | Should Be $remotequerytimeout $results.NewValue | Should Be $newtimeout } It "changes the remote query timeout from $newtimeout to $remotequerytimeout" { - $results = Set-DbaSpConfigure -SqlInstance $script:instance1 -ConfigName RemoteQueryTimeout -Value $remotequerytimeout + $results = Set-DbaSpConfigure -SqlInstance $TestConfig.instance1 -ConfigName RemoteQueryTimeout -Value $remotequerytimeout $results.PreviousValue | Should Be $newtimeout $results.NewValue | Should Be $remotequerytimeout } - $results = Set-DbaSpConfigure -SqlInstance $script:instance1 -ConfigName RemoteQueryTimeout -Value $remotequerytimeout -WarningVariable warning -WarningAction SilentlyContinue + $results = Set-DbaSpConfigure -SqlInstance $TestConfig.instance1 -ConfigName RemoteQueryTimeout -Value $remotequerytimeout -WarningVariable warning -WarningAction SilentlyContinue It "returns a warning when if the new value is the same as the old" { $warning -match "existing" | Should be $true } } -} \ No newline at end of file +} diff --git a/tests/Set-DbaSpn.Tests.ps1 b/tests/Set-DbaSpn.Tests.ps1 index faafbeb2f8..3c535f32cb 100644 --- a/tests/Set-DbaSpn.Tests.ps1 +++ b/tests/Set-DbaSpn.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Set-DbaStartupParameter.Tests.ps1 b/tests/Set-DbaStartupParameter.Tests.ps1 index 3a81247602..4957aaa398 100644 --- a/tests/Set-DbaStartupParameter.Tests.ps1 +++ b/tests/Set-DbaStartupParameter.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,8 +15,8 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $defaultInstance = $script:instance1 - $namedInstance = $script:instance2 + $defaultInstance = $TestConfig.instance1 + $namedInstance = $TestConfig.instance2 $SkipLocalTest = $true # Change to $false to run the tests on a local instance. } @@ -49,4 +49,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $result.TraceFlags[0] | Should -Be 3226 } } -} \ No newline at end of file +} diff --git a/tests/Set-DbaTcpPort.Tests.ps1 b/tests/Set-DbaTcpPort.Tests.ps1 index 9dc9980f41..935f4b83fd 100644 --- a/tests/Set-DbaTcpPort.Tests.ps1 +++ b/tests/Set-DbaTcpPort.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -14,31 +14,32 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { } Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Command actually works" { - $oldPort = (Get-DbaTcpPort -SqlInstance $script:instance2).Port + $oldPort = (Get-DbaTcpPort -SqlInstance $TestConfig.instance2).Port $newPort = $oldPort + 1000 - $instance = [DbaInstance]$script:instance2 + $instance = [DbaInstance]$TestConfig.instance2 It "Should change the port" { - $result = Set-DbaTcpPort -SqlInstance $script:instance2 -Port $newPort -Confirm:$false + $result = Set-DbaTcpPort -SqlInstance $TestConfig.instance2 -Port $newPort -Confirm:$false $result.Changes | Should -Match 'Changed TcpPort' $result.RestartNeeded | Should -Be $true $result.Restarted | Should -Be $false $null = Restart-DbaService -ComputerName $instance.ComputerName -InstanceName $instance.InstanceName -Type Engine -Force - $setPort = (Get-DbaTcpPort -SqlInstance $script:instance2).Port + $setPort = (Get-DbaTcpPort -SqlInstance $TestConfig.instance2).Port $setPort | Should -Be $newPort } It "Should change the port back to the old value" { - $result = Set-DbaTcpPort -SqlInstance $script:instance2 -Port $oldPort -Confirm:$false + $result = Set-DbaTcpPort -SqlInstance $TestConfig.instance2 -Port $oldPort -Confirm:$false $result.Changes | Should -Match 'Changed TcpPort' $result.RestartNeeded | Should -Be $true $result.Restarted | Should -Be $false $null = Restart-DbaService -ComputerName $instance.ComputerName -InstanceName $instance.InstanceName -Type Engine -Force - $setPort = (Get-DbaTcpPort -SqlInstance $script:instance2).Port + $setPort = (Get-DbaTcpPort -SqlInstance $TestConfig.instance2).Port $setPort | Should -Be $oldPort } } } + diff --git a/tests/Set-DbaTempDbConfig.Tests.ps1 b/tests/Set-DbaTempDbConfig.Tests.ps1 index 0ba9becb7e..25b24af5c2 100644 --- a/tests/Set-DbaTempDbConfig.Tests.ps1 +++ b/tests/Set-DbaTempDbConfig.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,7 +16,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { BeforeAll { $random = Get-Random - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance1 $tempdbDataFilePhysicalName = $server.Databases['tempdb'].Query('SELECT physical_name as PhysicalName FROM sys.database_files WHERE file_id = 1').PhysicalName $tempdbDataFilePath = Split-Path $tempdbDataFilePhysicalName @@ -36,12 +36,12 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Command actually works" { It "test with an invalid data dir" { - $result = Set-DbaTempDbConfig -SqlInstance $script:instance1 -DataFileSize 1024 -DataPath "$tempdbDataFilePath\invalidDir_$random" -OutputScriptOnly + $result = Set-DbaTempDbConfig -SqlInstance $TestConfig.instance1 -DataFileSize 1024 -DataPath "$tempdbDataFilePath\invalidDir_$random" -OutputScriptOnly $result | Should -BeNullOrEmpty } It "valid sql is produced with nearly all options set and a single data directory" { - $result = Set-DbaTempDbConfig -SqlInstance $script:instance1 -DataFileCount 8 -DataFileSize 2048 -LogFileSize 512 -DataFileGrowth 1024 -LogFileGrowth 512 -DataPath "$tempdbDataFilePath\DataDir0_$random" -LogPath "$tempdbDataFilePath\Log_$random" -OutputScriptOnly + $result = Set-DbaTempDbConfig -SqlInstance $TestConfig.instance1 -DataFileCount 8 -DataFileSize 2048 -LogFileSize 512 -DataFileGrowth 1024 -LogFileGrowth 512 -DataPath "$tempdbDataFilePath\DataDir0_$random" -LogPath "$tempdbDataFilePath\Log_$random" -OutputScriptOnly $sqlStatements = $result -Split ";" | Where-Object { $_ -ne "" } $sqlStatements.Count | Should -Be 9 @@ -50,7 +50,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } It "valid sql is produced with -DisableGrowth" { - $result = Set-DbaTempDbConfig -SqlInstance $script:instance1 -DataFileCount 8 -DataFileSize 1024 -LogFileSize 512 -DisableGrowth -DataPath $tempdbDataFilePath -LogPath $tempdbDataFilePath -OutputScriptOnly + $result = Set-DbaTempDbConfig -SqlInstance $TestConfig.instance1 -DataFileCount 8 -DataFileSize 1024 -LogFileSize 512 -DisableGrowth -DataPath $tempdbDataFilePath -LogPath $tempdbDataFilePath -OutputScriptOnly $sqlStatements = $result -Split ";" | Where-Object { $_ -ne "" } $sqlStatements.Count | Should -Be 9 @@ -60,7 +60,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { It "multiple data directories are supported" { $dataDirLocations = "$tempdbDataFilePath\DataDir0_$random", "$tempdbDataFilePath\DataDir1_$random", "$tempdbDataFilePath\DataDir2_$random" - $result = Set-DbaTempDbConfig -SqlInstance $script:instance1 -DataFileCount 8 -DataFileSize 1024 -DataPath $dataDirLocations -OutputScriptOnly + $result = Set-DbaTempDbConfig -SqlInstance $TestConfig.instance1 -DataFileCount 8 -DataFileSize 1024 -DataPath $dataDirLocations -OutputScriptOnly $sqlStatements = $result -Split ";" | Where-Object { $_ -ne "" } # check the round robin assignment of files to data dir locations @@ -75,4 +75,4 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } } -} \ No newline at end of file +} diff --git a/tests/Set-DbatoolsConfig.Tests.ps1 b/tests/Set-DbatoolsConfig.Tests.ps1 index 9cd0915004..e97d932288 100644 --- a/tests/Set-DbatoolsConfig.Tests.ps1 +++ b/tests/Set-DbatoolsConfig.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Set-DbatoolsInsecureConnection.Tests.ps1 b/tests/Set-DbatoolsInsecureConnection.Tests.ps1 index 392b51f08a..155871874c 100644 --- a/tests/Set-DbatoolsInsecureConnection.Tests.ps1 +++ b/tests/Set-DbatoolsInsecureConnection.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Set-DbatoolsPath.Tests.ps1 b/tests/Set-DbatoolsPath.Tests.ps1 index 12adadd8e9..8c0f1535b0 100644 --- a/tests/Set-DbatoolsPath.Tests.ps1 +++ b/tests/Set-DbatoolsPath.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Show-DbaDbList.Tests.ps1 b/tests/Show-DbaDbList.Tests.ps1 index 0abc13e142..1b88bc9949 100644 --- a/tests/Show-DbaDbList.Tests.ps1 +++ b/tests/Show-DbaDbList.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Show-DbaInstanceFileSystem.Tests.ps1 b/tests/Show-DbaInstanceFileSystem.Tests.ps1 index 43b16dc2ce..9ffd814b48 100644 --- a/tests/Show-DbaInstanceFileSystem.Tests.ps1 +++ b/tests/Show-DbaInstanceFileSystem.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Start-DbaAgentJob.Tests.ps1 b/tests/Start-DbaAgentJob.Tests.ps1 index d0291b899a..7be791f88e 100644 --- a/tests/Start-DbaAgentJob.Tests.ps1 +++ b/tests/Start-DbaAgentJob.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -19,16 +19,16 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $jobs = "dbatoolsci_job_$(Get-Random)", "dbatoolsci_job_$(Get-Random)", "dbatoolsci_job_$(Get-Random)" $jobName1, $jobName2, $jobName3 = $jobs foreach ($job in $jobs) { - $null = New-DbaAgentJob -SqlInstance $script:instance2, $script:instance3 -Job $job - $null = New-DbaAgentJobStep -SqlInstance $script:instance2, $script:instance3 -Job $job -StepName "step1_$(Get-Random)" -Subsystem TransactSql -Command "WAITFOR DELAY '00:05:00'" - $null = New-DbaAgentJobStep -SqlInstance $script:instance2 -Job $job -StepName "step2" -StepId 2 -Subsystem TransactSql -Command "WAITFOR DELAY '00:00:01'" - $null = New-DbaAgentJobStep -SqlInstance $script:instance2 -Job $job -StepName "step3" -StepId 3 -Subsystem TransactSql -Command "SELECT 1" + $null = New-DbaAgentJob -SqlInstance $TestConfig.instance2, $TestConfig.instance3 -Job $job + $null = New-DbaAgentJobStep -SqlInstance $TestConfig.instance2, $TestConfig.instance3 -Job $job -StepName "step1_$(Get-Random)" -Subsystem TransactSql -Command "WAITFOR DELAY '00:05:00'" + $null = New-DbaAgentJobStep -SqlInstance $TestConfig.instance2 -Job $job -StepName "step2" -StepId 2 -Subsystem TransactSql -Command "WAITFOR DELAY '00:00:01'" + $null = New-DbaAgentJobStep -SqlInstance $TestConfig.instance2 -Job $job -StepName "step3" -StepId 3 -Subsystem TransactSql -Command "SELECT 1" } - $results = Get-DbaAgentJob -SqlInstance $script:instance2 -Job $jobName1 | Start-DbaAgentJob + $results = Get-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job $jobName1 | Start-DbaAgentJob } AfterAll { - $null = Remove-DbaAgentJob -SqlInstance $script:instance2, $script:instance3 -Job $jobs -Confirm:$false + $null = Remove-DbaAgentJob -SqlInstance $TestConfig.instance2, $TestConfig.instance3 -Job $jobs -Confirm:$false } It "returns a CurrentRunStatus of not Idle and supports pipe" { @@ -40,24 +40,24 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } It "does not run all jobs" { - $null = Start-DbaAgentJob -SqlInstance $script:instance2 -WarningAction SilentlyContinue -WarningVariable warn + $null = Start-DbaAgentJob -SqlInstance $TestConfig.instance2 -WarningAction SilentlyContinue -WarningVariable warn $warn -match 'use one of the job' | Should Be $true } It "returns on multiple server inputs" { - $results2 = Start-DbaAgentJob -SqlInstance $script:instance2, $script:instance3 -Job $jobName2 + $results2 = Start-DbaAgentJob -SqlInstance $TestConfig.instance2, $TestConfig.instance3 -Job $jobName2 ($results2.SqlInstance).Count | Should -Be 2 } It "starts job at specified step" { - $null = Start-DbaAgentJob -SqlInstance $script:instance2 -Job $jobName3 -StepName 'step3' - $results3 = Get-DbaAgentJobHistory -SqlInstance $script:instance2 -Job $jobName3 + $null = Start-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job $jobName3 -StepName 'step3' + $results3 = Get-DbaAgentJobHistory -SqlInstance $TestConfig.instance2 -Job $jobName3 ($results3.SqlInstance).Count | Should -Be 2 } It "do not start job if the step does not exist" { - $results4 = Start-DbaAgentJob -SqlInstance $script:instance2 -Job $jobName3 -StepName 'stepdoesnoteexist' + $results4 = Start-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job $jobName3 -StepName 'stepdoesnoteexist' ($results4.SqlInstance).Count | Should -Be 0 } } -} \ No newline at end of file +} diff --git a/tests/Start-DbaDbEncryption.Tests.ps1 b/tests/Start-DbaDbEncryption.Tests.ps1 index fe17b0d331..39ed491896 100644 --- a/tests/Start-DbaDbEncryption.Tests.ps1 +++ b/tests/Start-DbaDbEncryption.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Validate parameters" { @@ -18,7 +18,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { $PSDefaultParameterValues["*:Confirm"] = $false $alldbs = @() - 1..5 | ForEach-Object { $alldbs += New-DbaDatabase -SqlInstance $script:instance2 } + 1..5 | ForEach-Object { $alldbs += New-DbaDatabase -SqlInstance $TestConfig.instance2 } } AfterAll { @@ -31,7 +31,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { It "should mass enable encryption" { $passwd = ConvertTo-SecureString "dbatools.IO" -AsPlainText -Force $splat = @{ - SqlInstance = $script:instance2 + SqlInstance = $TestConfig.instance2 Database = $alldbs.Name MasterKeySecurePassword = $passwd BackupSecurePassword = $passwd @@ -44,4 +44,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $results | Select-Object -First 1 -ExpandProperty DatabaseName | Should -Match "random" } } -} \ No newline at end of file +} diff --git a/tests/Start-DbaEndpoint.Tests.ps1 b/tests/Start-DbaEndpoint.Tests.ps1 index 211352cb8e..16905c1757 100644 --- a/tests/Start-DbaEndpoint.Tests.ps1 +++ b/tests/Start-DbaEndpoint.Tests.ps1 @@ -1,6 +1,6 @@ $commandname = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Validate parameters" { @@ -15,15 +15,15 @@ Describe "$CommandName Unit Tests" -Tags "UnitTests" { Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { - Get-DbaEndpoint -SqlInstance $script:instance2 -Endpoint 'TSQL Default TCP' | Stop-DbaEndpoint -Confirm:$false + Get-DbaEndpoint -SqlInstance $TestConfig.instance2 -Endpoint 'TSQL Default TCP' | Stop-DbaEndpoint -Confirm:$false } AfterAll { - Get-DbaEndpoint -SqlInstance $script:instance2 -Endpoint 'TSQL Default TCP' | Start-DbaEndpoint -Confirm:$false + Get-DbaEndpoint -SqlInstance $TestConfig.instance2 -Endpoint 'TSQL Default TCP' | Start-DbaEndpoint -Confirm:$false } It "starts the endpoint" { - $endpoint = Get-DbaEndpoint -SqlInstance $script:instance2 -Endpoint 'TSQL Default TCP' + $endpoint = Get-DbaEndpoint -SqlInstance $TestConfig.instance2 -Endpoint 'TSQL Default TCP' $results = $endpoint | Start-DbaEndpoint -Confirm:$false $results.EndpointState | Should -Be 'Started' } -} \ No newline at end of file +} diff --git a/tests/Start-DbaMigration.Tests.ps1 b/tests/Start-DbaMigration.Tests.ps1 index c7d90c85f5..26dc630b15 100644 --- a/tests/Start-DbaMigration.Tests.ps1 +++ b/tests/Start-DbaMigration.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -27,23 +27,23 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { $startmigrationrestoredb = "dbatoolsci_startmigrationrestore$random" $startmigrationrestoredb2 = "dbatoolsci_startmigrationrestoreother$random" $detachattachdb = "dbatoolsci_detachattach$random" - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance2, $script:instance3 -Database $startmigrationrestoredb, $detachattachdb + Remove-DbaDatabase -Confirm:$false -SqlInstance $TestConfig.instance2, $TestConfig.instance3 -Database $startmigrationrestoredb, $detachattachdb - $server = Connect-DbaInstance -SqlInstance $script:instance3 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance3 Invoke-DbaQuery -SqlInstance $server -Query "CREATE DATABASE $startmigrationrestoredb2; ALTER DATABASE $startmigrationrestoredb2 SET AUTO_CLOSE OFF WITH ROLLBACK IMMEDIATE" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 Invoke-DbaQuery -SqlInstance $server -Query "CREATE DATABASE $startmigrationrestoredb; ALTER DATABASE $startmigrationrestoredb SET AUTO_CLOSE OFF WITH ROLLBACK IMMEDIATE" Invoke-DbaQuery -SqlInstance $server -Query "CREATE DATABASE $detachattachdb; ALTER DATABASE $detachattachdb SET AUTO_CLOSE OFF WITH ROLLBACK IMMEDIATE" Invoke-DbaQuery -SqlInstance $server -Query "CREATE DATABASE $startmigrationrestoredb2; ALTER DATABASE $startmigrationrestoredb2 SET AUTO_CLOSE OFF WITH ROLLBACK IMMEDIATE" - $null = Set-DbaDbOwner -SqlInstance $script:instance2 -Database $startmigrationrestoredb, $detachattachdb -TargetLogin sa + $null = Set-DbaDbOwner -SqlInstance $TestConfig.instance2 -Database $startmigrationrestoredb, $detachattachdb -TargetLogin sa } AfterAll { - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance2, $script:instance3 -Database $startmigrationrestoredb, $detachattachdb, $startmigrationrestoredb2 + Remove-DbaDatabase -Confirm:$false -SqlInstance $TestConfig.instance2, $TestConfig.instance3 -Database $startmigrationrestoredb, $detachattachdb, $startmigrationrestoredb2 } Context "Backup restore" { - $results = Start-DbaMigration -Force -Source $script:instance2 -Destination $script:instance3 -BackupRestore -SharedPath "C:\temp" -Exclude Logins, SpConfigure, SysDbUserObjects, AgentServer, CentralManagementServer, ExtendedEvents, PolicyManagement, ResourceGovernor, Endpoints, ServerAuditSpecifications, Audits, LinkedServers, SystemTriggers, DataCollector, DatabaseMail, BackupDevices, Credentials + $results = Start-DbaMigration -Force -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -BackupRestore -SharedPath "C:\temp" -Exclude Logins, SpConfigure, SysDbUserObjects, AgentServer, CentralManagementServer, ExtendedEvents, PolicyManagement, ResourceGovernor, Endpoints, ServerAuditSpecifications, Audits, LinkedServers, SystemTriggers, DataCollector, DatabaseMail, BackupDevices, Credentials It "returns at least one result" { $results | Should -Not -Be $null @@ -57,7 +57,7 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { } It "retains its name, recovery model, and status." { - $dbs = Get-DbaDatabase -SqlInstance $script:instance2, $script:instance3 -Database $startmigrationrestoredb2 + $dbs = Get-DbaDatabase -SqlInstance $TestConfig.instance2, $TestConfig.instance3 -Database $startmigrationrestoredb2 $dbs[0].Name -ne $null # Compare its variables $dbs[0].Name -eq $dbs[1].Name @@ -68,8 +68,8 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { } Context "Backup restore" { - $quickbackup = Get-DbaDatabase -SqlInstance $script:instance2 -ExcludeSystem | Backup-DbaDatabase -BackupDirectory C:\temp - $results = Start-DbaMigration -Force -Source $script:instance2 -Destination $script:instance3 -UseLastBackup -Exclude Logins, SpConfigure, SysDbUserObjects, AgentServer, CentralManagementServer, ExtendedEvents, PolicyManagement, ResourceGovernor, Endpoints, ServerAuditSpecifications, Audits, LinkedServers, SystemTriggers, DataCollector, DatabaseMail, BackupDevices, Credentials, StartupProcedures + $quickbackup = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -ExcludeSystem | Backup-DbaDatabase -BackupDirectory C:\temp + $results = Start-DbaMigration -Force -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -UseLastBackup -Exclude Logins, SpConfigure, SysDbUserObjects, AgentServer, CentralManagementServer, ExtendedEvents, PolicyManagement, ResourceGovernor, Endpoints, ServerAuditSpecifications, Audits, LinkedServers, SystemTriggers, DataCollector, DatabaseMail, BackupDevices, Credentials, StartupProcedures It "returns at least one result" { $results | Should -Not -Be $null @@ -83,7 +83,7 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { } It "retains its name, recovery model, and status." { - $dbs = Get-DbaDatabase -SqlInstance $script:instance2, $script:instance3 -Database $startmigrationrestoredb2 + $dbs = Get-DbaDatabase -SqlInstance $TestConfig.instance2, $TestConfig.instance3 -Database $startmigrationrestoredb2 $dbs[0].Name -ne $null # Compare its variables $dbs[0].Name -eq $dbs[1].Name @@ -92,4 +92,4 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { $dbs[0].Owner -eq $dbs[1].Owner } } -} \ No newline at end of file +} diff --git a/tests/Start-DbaPfDataCollectorSet.Tests.ps1 b/tests/Start-DbaPfDataCollectorSet.Tests.ps1 index 3b1b86ecdd..a957c93f73 100644 --- a/tests/Start-DbaPfDataCollectorSet.Tests.ps1 +++ b/tests/Start-DbaPfDataCollectorSet.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -31,4 +31,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } } } -} \ No newline at end of file +} diff --git a/tests/Start-DbaService.Tests.ps1 b/tests/Start-DbaService.Tests.ps1 index f3b990dec2..c0cc76f230 100644 --- a/tests/Start-DbaService.Tests.ps1 +++ b/tests/Start-DbaService.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,7 +16,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Command actually works" { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $instanceName = $server.ServiceName $computerName = $server.NetName @@ -30,7 +30,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Get-Service -ComputerName $computerName -Name $serviceName | Stop-Service -WarningAction SilentlyContinue | Out-Null It "starts the services back" { - $services = Start-DbaService -ComputerName $script:instance2 -Type Agent -InstanceName $instanceName + $services = Start-DbaService -ComputerName $TestConfig.instance2 -Type Agent -InstanceName $instanceName $services | Should Not Be $null foreach ($service in $services) { $service.State | Should Be 'Running' @@ -47,7 +47,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { foreach ($sn in $servicename) { Get-Service -ComputerName $computerName -Name $sn | Stop-Service -WarningAction SilentlyContinue | Out-Null } It "starts the services back through pipeline" { - $services = Get-DbaService -ComputerName $script:instance2 -InstanceName $instanceName -Type Agent, Engine | Start-DbaService + $services = Get-DbaService -ComputerName $TestConfig.instance2 -InstanceName $instanceName -Type Agent, Engine | Start-DbaService $services | Should Not Be $null foreach ($service in $services) { $service.State | Should Be 'Running' @@ -56,7 +56,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } It "errors when passing an invalid InstanceName" { - { Start-DbaService -ComputerName $script:instance2 -Type 'Agent' -InstanceName 'ThisIsInvalid' -EnableException } | Should Throw 'No SQL Server services found with current parameters.' + { Start-DbaService -ComputerName $TestConfig.instance2 -Type 'Agent' -InstanceName 'ThisIsInvalid' -EnableException } | Should Throw 'No SQL Server services found with current parameters.' } } -} \ No newline at end of file +} diff --git a/tests/Start-DbaTrace.Tests.ps1 b/tests/Start-DbaTrace.Tests.ps1 index bf10192e58..e92401c905 100644 --- a/tests/Start-DbaTrace.Tests.ps1 +++ b/tests/Start-DbaTrace.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -92,24 +92,24 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { -- display trace id for future references select TraceID=@TraceID" - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance1 $traceid = ($server.Query($sql)).TraceID - $null = Get-DbaTrace -SqlInstance $script:instance1 -Id $traceid | Stop-DbaTrace + $null = Get-DbaTrace -SqlInstance $TestConfig.instance1 -Id $traceid | Stop-DbaTrace } AfterAll { - $null = Remove-DbaTrace -SqlInstance $script:instance1 -Id $traceid + $null = Remove-DbaTrace -SqlInstance $TestConfig.instance1 -Id $traceid Remove-Item C:\windows\temp\temptrace.trc } Context "Test Starting Trace" { - $results = Get-DbaTrace -SqlInstance $script:instance1 -Id $traceid + $results = Get-DbaTrace -SqlInstance $TestConfig.instance1 -Id $traceid It "starts in a stopped state" { $results.Id | Should Be $traceid $results.IsRunning | Should Be $false } - $results = Get-DbaTrace -SqlInstance $script:instance1 -Id $traceid | Start-DbaTrace + $results = Get-DbaTrace -SqlInstance $TestConfig.instance1 -Id $traceid | Start-DbaTrace It "is now running" { $results.Id | Should Be $traceid $results.IsRunning | Should Be $true } } -} \ No newline at end of file +} diff --git a/tests/Start-DbaXESession.Tests.ps1 b/tests/Start-DbaXESession.Tests.ps1 index 1c2b80db49..5634930206 100644 --- a/tests/Start-DbaXESession.Tests.ps1 +++ b/tests/Start-DbaXESession.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,7 +15,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $conn = $server.ConnectionContext # Get the systemhealth session $systemhealth = Get-DbaXESession -SqlInstance $server -Session system_health @@ -52,6 +52,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { # Drop created objects $conn.ExecuteNonQuery("IF EXISTS(SELECT * FROM sys.server_event_sessions WHERE name = 'dbatoolsci_session_invalid') DROP EVENT SESSION [dbatoolsci_session_invalid] ON SERVER;") $conn.ExecuteNonQuery("IF EXISTS(SELECT * FROM sys.server_event_sessions WHERE name = 'dbatoolsci_session_valid') DROP EVENT SESSION [dbatoolsci_session_valid] ON SERVER;") + Get-DbaAgentSchedule -SqlInstance $TestConfig.instance2 -Schedule "XE Session START - dbatoolsci_session_valid", "XE Session STOP - dbatoolsci_session_valid" | Remove-DbaAgentSchedule -Force -Confirm:$false } Context "Verifying command works" { @@ -90,23 +91,35 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { It "works when -StopAt is passed" { $StopAt = (Get-Date).AddSeconds(10) Start-DbaXESession $server -Session $dbatoolsciValid.Name -StopAt $StopAt -WarningAction SilentlyContinue + $dbatoolsciValid.Refresh() $dbatoolsciValid.IsRunning | Should Be $true (Get-DbaAgentJob -SqlInstance $server -Job "XE Session STOP - dbatoolsci_session_valid").Count | Should -Be 1 $stopSchedule = Get-DbaAgentSchedule -SqlInstance $server -Schedule "XE Session STOP - dbatoolsci_session_valid" $stopSchedule.ActiveStartTimeOfDay.ToString('hhmmss') | Should -Be $StopAt.TimeOfDay.ToString('hhmmss') $stopSchedule.ActiveStartDate | Should -Be $StopAt.Date + Start-Sleep -Seconds 11 + $dbatoolsciValid.Refresh() + $dbatoolsciValid.IsRunning | Should Be $false + # Using $TestConfig.instance2 because the SMO $server is not updated after the job is removed + (Get-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job "XE Session STOP - dbatoolsci_session_valid").Count | Should -Be 0 } It "works when -StartAt is passed" { $null = Stop-DbaXESession -SqlInstance $server -Session $dbatoolsciValid.Name -WarningAction SilentlyContinue $StartAt = (Get-Date).AddSeconds(10) - $session = Start-DbaXESession $server -Session $dbatoolsciValid.Name -StartAt $StartAt - $session.IsRunning | Should Be $false + $null = Start-DbaXESession $server -Session $dbatoolsciValid.Name -StartAt $StartAt + $dbatoolsciValid.Refresh() + $dbatoolsciValid.IsRunning | Should Be $false (Get-DbaAgentJob -SqlInstance $server -Job "XE Session START - dbatoolsci_session_valid").Count | Should -Be 1 $startSchedule = Get-DbaAgentSchedule -SqlInstance $server -Schedule "XE Session START - dbatoolsci_session_valid" $startSchedule.ActiveStartTimeOfDay.ToString('hhmmss') | Should -Be $StartAt.TimeOfDay.ToString('hhmmss') $startSchedule.ActiveStartDate | Should -Be $StartAt.Date + Start-Sleep -Seconds 11 + $dbatoolsciValid.Refresh() + $dbatoolsciValid.IsRunning | Should Be $true + # Using $TestConfig.instance2 because the SMO $server is not updated after the job is removed + (Get-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job "XE Session STOP - dbatoolsci_session_valid").Count | Should -Be 0 } } -} \ No newline at end of file +} diff --git a/tests/Start-DbaXESmartTarget.Tests.ps1 b/tests/Start-DbaXESmartTarget.Tests.ps1 index 1863325a80..ac710830f9 100644 --- a/tests/Start-DbaXESmartTarget.Tests.ps1 +++ b/tests/Start-DbaXESmartTarget.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Stop-DbaAgentJob.Tests.ps1 b/tests/Stop-DbaAgentJob.Tests.ps1 index b4eef94224..e09cfbfca5 100644 --- a/tests/Stop-DbaAgentJob.Tests.ps1 +++ b/tests/Stop-DbaAgentJob.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,8 +16,8 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "executes and returns the accurate info" { It -Skip "returns a CurrentRunStatus of Idle" { - $agent = Get-DbaAgentJob -SqlInstance $script:instance2 -Job 'DatabaseBackup - SYSTEM_DATABASES - FULL' | Start-DbaAgentJob | Stop-DbaAgentJob + $agent = Get-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job 'DatabaseBackup - SYSTEM_DATABASES - FULL' | Start-DbaAgentJob | Stop-DbaAgentJob $results.CurrentRunStatus -eq 'Idle' | Should Be $true } } -} \ No newline at end of file +} diff --git a/tests/Stop-DbaDbEncryption.Tests.ps1 b/tests/Stop-DbaDbEncryption.Tests.ps1 index 64009cc8c4..e25b0fbb9d 100644 --- a/tests/Stop-DbaDbEncryption.Tests.ps1 +++ b/tests/Stop-DbaDbEncryption.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Validate parameters" { @@ -17,18 +17,18 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { $PSDefaultParameterValues["*:Confirm"] = $false $passwd = ConvertTo-SecureString "dbatools.IO" -AsPlainText -Force - $masterkey = Get-DbaDbMasterKey -SqlInstance $script:instance2 -Database master + $masterkey = Get-DbaDbMasterKey -SqlInstance $TestConfig.instance2 -Database master if (-not $masterkey) { $delmasterkey = $true - $masterkey = New-DbaServiceMasterKey -SqlInstance $script:instance2 -SecurePassword $passwd + $masterkey = New-DbaServiceMasterKey -SqlInstance $TestConfig.instance2 -SecurePassword $passwd } - $mastercert = Get-DbaDbCertificate -SqlInstance $script:instance2 -Database master | Where-Object Name -notmatch "##" | Select-Object -First 1 + $mastercert = Get-DbaDbCertificate -SqlInstance $TestConfig.instance2 -Database master | Where-Object Name -notmatch "##" | Select-Object -First 1 if (-not $mastercert) { $delmastercert = $true - $mastercert = New-DbaDbCertificate -SqlInstance $script:instance2 + $mastercert = New-DbaDbCertificate -SqlInstance $TestConfig.instance2 } - $db = New-DbaDatabase -SqlInstance $script:instance2 + $db = New-DbaDatabase -SqlInstance $TestConfig.instance2 $db | New-DbaDbMasterKey -SecurePassword $passwd $db | New-DbaDbCertificate $db | New-DbaDbEncryptionKey -Force @@ -51,11 +51,11 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { It "should disable encryption on a database with piping" { # Give it time to finish encrypting or it'll error Start-Sleep 10 - $results = Stop-DbaDbEncryption -SqlInstance $script:instance2 + $results = Stop-DbaDbEncryption -SqlInstance $TestConfig.instance2 $warn | Should -Be $null foreach ($result in $results) { $result.EncryptionEnabled | Should -Be $false } } } -} \ No newline at end of file +} diff --git a/tests/Stop-DbaEndpoint.Tests.ps1 b/tests/Stop-DbaEndpoint.Tests.ps1 index 38d9fd9089..325cce5469 100644 --- a/tests/Stop-DbaEndpoint.Tests.ps1 +++ b/tests/Stop-DbaEndpoint.Tests.ps1 @@ -1,6 +1,6 @@ $commandname = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Validate parameters" { @@ -15,15 +15,15 @@ Describe "$CommandName Unit Tests" -Tags "UnitTests" { Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { - Get-DbaEndpoint -SqlInstance $script:instance2 -Endpoint 'TSQL Default TCP' | Start-DbaEndpoint + Get-DbaEndpoint -SqlInstance $TestConfig.instance2 -Endpoint 'TSQL Default TCP' | Start-DbaEndpoint } AfterAll { - Get-DbaEndpoint -SqlInstance $script:instance2 -Endpoint 'TSQL Default TCP' | Start-DbaEndpoint + Get-DbaEndpoint -SqlInstance $TestConfig.instance2 -Endpoint 'TSQL Default TCP' | Start-DbaEndpoint } It "stops the endpoint" { - $endpoint = Get-DbaEndpoint -SqlInstance $script:instance2 -Endpoint 'TSQL Default TCP' + $endpoint = Get-DbaEndpoint -SqlInstance $TestConfig.instance2 -Endpoint 'TSQL Default TCP' $results = $endpoint | Stop-DbaEndpoint -Confirm:$false $results.EndpointState | Should -Be 'Stopped' } -} \ No newline at end of file +} diff --git a/tests/Stop-DbaExternalProcess.Tests.ps1 b/tests/Stop-DbaExternalProcess.Tests.ps1 index 7503363fd1..e729a88aef 100644 --- a/tests/Stop-DbaExternalProcess.Tests.ps1 +++ b/tests/Stop-DbaExternalProcess.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,7 +16,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Can stop an external process" { BeforeAll { - $null = Invoke-DbaQuery -SqlInstance $script:instance1 -Query " + $null = Invoke-DbaQuery -SqlInstance $TestConfig.instance1 -Query " -- To allow advanced options to be changed. EXECUTE sp_configure 'show advanced options', 1; GO @@ -33,7 +33,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $query = @" xp_cmdshell 'powershell -command ""sleep 20""' "@ - Start-Process -FilePath sqlcmd -ArgumentList "-S $script:instance1 -Q `"$query`"" -NoNewWindow -RedirectStandardOutput null + Start-Process -FilePath sqlcmd -ArgumentList "-S $($TestConfig.instance1) -Q `"$query`"" -NoNewWindow -RedirectStandardOutput null } It "returns results" { @@ -45,3 +45,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } } } + diff --git a/tests/Stop-DbaPfDataCollectorSet.Tests.ps1 b/tests/Stop-DbaPfDataCollectorSet.Tests.ps1 index 81f4d02bae..631c84e32b 100644 --- a/tests/Stop-DbaPfDataCollectorSet.Tests.ps1 +++ b/tests/Stop-DbaPfDataCollectorSet.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -31,4 +31,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } } } -} \ No newline at end of file +} diff --git a/tests/Stop-DbaProcess.Tests.ps1 b/tests/Stop-DbaProcess.Tests.ps1 index 5e24c0de4e..ba5f17cb01 100644 --- a/tests/Stop-DbaProcess.Tests.ps1 +++ b/tests/Stop-DbaProcess.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,19 +15,19 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Context "command works as expected" { - $fakeapp = Connect-DbaInstance -SqlInstance $script:instance1 -ClientName 'dbatoolsci test app' - $results = Stop-DbaProcess -SqlInstance $script:instance1 -Program 'dbatoolsci test app' + $fakeapp = Connect-DbaInstance -SqlInstance $TestConfig.instance1 -ClientName 'dbatoolsci test app' + $results = Stop-DbaProcess -SqlInstance $TestConfig.instance1 -Program 'dbatoolsci test app' It "kills only this specific process" { $results.Program.Count | Should -Be 1 $results.Program | Should -Be 'dbatoolsci test app' $results.Status | Should -Be 'Killed' } - $fakeapp = Connect-DbaInstance -SqlInstance $script:instance1 -ClientName 'dbatoolsci test app' - $results = Get-DbaProcess -SqlInstance $script:instance1 -Program 'dbatoolsci test app' | Stop-DbaProcess + $fakeapp = Connect-DbaInstance -SqlInstance $TestConfig.instance1 -ClientName 'dbatoolsci test app' + $results = Get-DbaProcess -SqlInstance $TestConfig.instance1 -Program 'dbatoolsci test app' | Stop-DbaProcess It "supports piping" { $results.Program.Count | Should -Be 1 $results.Program | Should -Be 'dbatoolsci test app' $results.Status | Should -Be 'Killed' } } -} \ No newline at end of file +} diff --git a/tests/Stop-DbaService.Tests.ps1 b/tests/Stop-DbaService.Tests.ps1 index ea0625ce5e..4c8849cd74 100644 --- a/tests/Stop-DbaService.Tests.ps1 +++ b/tests/Stop-DbaService.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -17,12 +17,12 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Command actually works" { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $instanceName = $server.ServiceName $computerName = $server.NetName It "stops some services" { - $services = Stop-DbaService -ComputerName $script:instance2 -InstanceName $instanceName -Type Agent + $services = Stop-DbaService -ComputerName $TestConfig.instance2 -InstanceName $instanceName -Type Agent $services | Should Not Be $null foreach ($service in $services) { $service.State | Should Be 'Stopped' @@ -39,7 +39,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Get-Service -ComputerName $computerName -Name $serviceName | Start-Service -WarningAction SilentlyContinue | Out-Null It "stops specific services based on instance name through pipeline" { - $services = Get-DbaService -ComputerName $script:instance2 -InstanceName $instanceName -Type Agent, Engine | Stop-DbaService + $services = Get-DbaService -ComputerName $TestConfig.instance2 -InstanceName $instanceName -Type Agent, Engine | Stop-DbaService $services | Should Not Be $null foreach ($service in $services) { $service.State | Should Be 'Stopped' @@ -56,4 +56,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { foreach ($sn in $servicename) { Get-Service -ComputerName $computerName -Name $sn | Start-Service -WarningAction SilentlyContinue | Out-Null } } -} \ No newline at end of file +} diff --git a/tests/Stop-DbaTrace.Tests.ps1 b/tests/Stop-DbaTrace.Tests.ps1 index 3b564a99f9..d06d8bc793 100644 --- a/tests/Stop-DbaTrace.Tests.ps1 +++ b/tests/Stop-DbaTrace.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -92,24 +92,24 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { -- display trace id for future references select TraceID=@TraceID" - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance1 $traceid = ($server.Query($sql)).TraceID - $null = Get-DbaTrace -SqlInstance $script:instance1 -Id $traceid | Start-DbaTrace + $null = Get-DbaTrace -SqlInstance $TestConfig.instance1 -Id $traceid | Start-DbaTrace } AfterAll { - $null = Remove-DbaTrace -SqlInstance $script:instance1 -Id $traceid + $null = Remove-DbaTrace -SqlInstance $TestConfig.instance1 -Id $traceid Remove-Item C:\windows\temp\temptrace.trc } Context "Test Stopping Trace" { - $results = Get-DbaTrace -SqlInstance $script:instance1 -Id $traceid + $results = Get-DbaTrace -SqlInstance $TestConfig.instance1 -Id $traceid It "starts in a running state" { $results.Id | Should Be $traceid $results.IsRunning | Should Be $true } - $results = Get-DbaTrace -SqlInstance $script:instance1 -Id $traceid | Stop-DbaTrace + $results = Get-DbaTrace -SqlInstance $TestConfig.instance1 -Id $traceid | Stop-DbaTrace It "is now in a stopped state" { $results.Id | Should Be $traceid $results.IsRunning | Should Be $false } } -} \ No newline at end of file +} diff --git a/tests/Stop-DbaXESession.Tests.ps1 b/tests/Stop-DbaXESession.Tests.ps1 index a04696ed58..97711aa462 100644 --- a/tests/Stop-DbaXESession.Tests.ps1 +++ b/tests/Stop-DbaXESession.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,13 +15,13 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 # Create a valid session and start it $server.Query("CREATE EVENT SESSION [dbatoolsci_session_valid] ON SERVER ADD EVENT sqlserver.lock_acquired;") - $dbatoolsciValid = Get-DbaXESession -SqlInstance $script:instance2 -Session dbatoolsci_session_valid + $dbatoolsciValid = Get-DbaXESession -SqlInstance $TestConfig.instance2 -Session dbatoolsci_session_valid $dbatoolsciValid.Start() # Record the Status of all sessions - $allSessions = Get-DbaXESession -SqlInstance $script:instance2 + $allSessions = Get-DbaXESession -SqlInstance $TestConfig.instance2 } BeforeEach { $dbatoolsciValid.Refresh() @@ -45,12 +45,12 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } # Drop created objects - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $server.Query("IF EXISTS(SELECT * FROM sys.server_event_sessions WHERE name = 'dbatoolsci_session_valid') DROP EVENT SESSION [dbatoolsci_session_valid] ON SERVER;") } Context "Verifying command works" { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 It "stops the system_health session" { $dbatoolsciValid | Stop-DbaXESession $dbatoolsciValid.Refresh() @@ -72,4 +72,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $dbatoolsciValid.IsRunning | Should Be $false } } -} \ No newline at end of file +} diff --git a/tests/Stop-DbaXESmartTarget.Tests.ps1 b/tests/Stop-DbaXESmartTarget.Tests.ps1 index ae062d8279..368df19f2f 100644 --- a/tests/Stop-DbaXESmartTarget.Tests.ps1 +++ b/tests/Stop-DbaXESmartTarget.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Stop-Function.Tests.ps1 b/tests/Stop-Function.Tests.ps1 index 0c668ad079..3987e112aa 100644 --- a/tests/Stop-Function.Tests.ps1 +++ b/tests/Stop-Function.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig . "$PSScriptRoot\..\private\functions\flowcontrol\Stop-Function.ps1" $PSDefaultParameterValues.Remove('*:WarningAction') diff --git a/tests/Suspend-DbaAgDbDataMovement.Tests.ps1 b/tests/Suspend-DbaAgDbDataMovement.Tests.ps1 index 6128fbe522..cfe25c2b55 100644 --- a/tests/Suspend-DbaAgDbDataMovement.Tests.ps1 +++ b/tests/Suspend-DbaAgDbDataMovement.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$commandname Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,15 +15,15 @@ Describe "$commandname Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $null = Get-DbaProcess -SqlInstance $script:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue - $server = Connect-DbaInstance -SqlInstance $script:instance3 + $null = Get-DbaProcess -SqlInstance $TestConfig.instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance3 $agname = "dbatoolsci_resumeagdb_agroup" $dbname = "dbatoolsci_resumeagdb_agroupdb" $server.Query("create database $dbname") - $null = Get-DbaDatabase -SqlInstance $script:instance3 -Database $dbname | Backup-DbaDatabase - $null = Get-DbaDatabase -SqlInstance $script:instance3 -Database $dbname | Backup-DbaDatabase -Type Log - $ag = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Database $dbname -Confirm:$false -Certificate dbatoolsci_AGCert -UseLastBackup - $null = Get-DbaAgDatabase -SqlInstance $script:instance3 -AvailabilityGroup $agname | Resume-DbaAgDbDataMovement -Confirm:$false + $null = Get-DbaDatabase -SqlInstance $TestConfig.instance3 -Database $dbname | Backup-DbaDatabase + $null = Get-DbaDatabase -SqlInstance $TestConfig.instance3 -Database $dbname | Backup-DbaDatabase -Type Log + $ag = New-DbaAvailabilityGroup -Primary $TestConfig.instance3 -Name $agname -ClusterType None -FailoverMode Manual -Database $dbname -Confirm:$false -Certificate dbatoolsci_AGCert -UseLastBackup + $null = Get-DbaAgDatabase -SqlInstance $TestConfig.instance3 -AvailabilityGroup $agname | Resume-DbaAgDbDataMovement -Confirm:$false } AfterAll { $null = Remove-DbaAvailabilityGroup -SqlInstance $server -AvailabilityGroup $agname -Confirm:$false @@ -31,10 +31,10 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { } Context "resumes data movement" { It "returns resumed results" { - $results = Suspend-DbaAgDbDataMovement -SqlInstance $script:instance3 -Database $dbname -Confirm:$false + $results = Suspend-DbaAgDbDataMovement -SqlInstance $TestConfig.instance3 -Database $dbname -Confirm:$false $results.AvailabilityGroup | Should -Be $agname $results.Name | Should -Be $dbname $results.SynchronizationState | Should -Be 'NotSynchronizing' } } -} #$script:instance2 for appveyor \ No newline at end of file +} #$TestConfig.instance2 for appveyor diff --git a/tests/Sync-DbaAvailabilityGroup.Tests.ps1 b/tests/Sync-DbaAvailabilityGroup.Tests.ps1 index 66c91301f3..d622ea0d2a 100644 --- a/tests/Sync-DbaAvailabilityGroup.Tests.ps1 +++ b/tests/Sync-DbaAvailabilityGroup.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Sync-DbaLoginPermission.Tests.ps1 b/tests/Sync-DbaLoginPermission.Tests.ps1 index 3e57eae00c..6ecef52a14 100644 --- a/tests/Sync-DbaLoginPermission.Tests.ps1 +++ b/tests/Sync-DbaLoginPermission.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -25,7 +25,7 @@ CREATE USER [$DBUserName] FOR LOGIN [$DBUserName] WITH DEFAULT_SCHEMA = dbo; GRANT VIEW ANY DEFINITION to [$DBUserName]; "@ - Invoke-DbaQuery -SqlInstance $script:instance2 -Query $CreateTestUser -Database master + Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Query $CreateTestUser -Database master #This is used later in the test $CreateTestLogin = @" @@ -35,27 +35,27 @@ CREATE LOGIN [$DBUserName] } AfterAll { $DropTestUser = "DROP LOGIN [$DBUserName]" - Invoke-DbaQuery -SqlInstance $script:instance2, $script:instance3 -Query $DropTestUser -Database master + Invoke-DbaQuery -SqlInstance $TestConfig.instance2, $TestConfig.instance3 -Query $DropTestUser -Database master } Context "Verifying command output" { It "Should not have the user permissions of $DBUserName" { - $permissionsBefore = Get-DbaUserPermission -SqlInstance $script:instance3 -Database master | Where-object {$_.member -eq $DBUserName} + $permissionsBefore = Get-DbaUserPermission -SqlInstance $TestConfig.instance3 -Database master | Where-object {$_.member -eq $DBUserName} $permissionsBefore | Should -be $null } It "Should execute against active nodes" { #Creates the user on - Invoke-DbaQuery -SqlInstance $script:instance3 -Query $CreateTestLogin - $results = Sync-DbaLoginPermission -Source $script:instance2 -Destination $script:instance3 -Login $DBUserName -ExcludeLogin 'NotaLogin' -Warningvariable $warn + Invoke-DbaQuery -SqlInstance $TestConfig.instance3 -Query $CreateTestLogin + $results = Sync-DbaLoginPermission -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -Login $DBUserName -ExcludeLogin 'NotaLogin' -Warningvariable $warn $results.Status | Should -Be 'Successful' $warn | Should -be $null } It "Should have coppied the user permissions of $DBUserName" { - $permissionsAfter = Get-DbaUserPermission -SqlInstance $script:instance3 -Database master | Where-object {$_.member -eq $DBUserName -and $_.permission -eq 'VIEW ANY DEFINITION' } + $permissionsAfter = Get-DbaUserPermission -SqlInstance $TestConfig.instance3 -Database master | Where-object {$_.member -eq $DBUserName -and $_.permission -eq 'VIEW ANY DEFINITION' } $permissionsAfter.member | Should -Be $DBUserName } } -} \ No newline at end of file +} diff --git a/tests/Test-DbaAgSpn.Tests.ps1 b/tests/Test-DbaAgSpn.Tests.ps1 index 24eb9e9108..24420724b8 100644 --- a/tests/Test-DbaAgSpn.Tests.ps1 +++ b/tests/Test-DbaAgSpn.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Test-DbaAgentJobOwner.Tests.ps1 b/tests/Test-DbaAgentJobOwner.Tests.ps1 index 81946e7168..1ef644b0c7 100644 --- a/tests/Test-DbaAgentJobOwner.Tests.ps1 +++ b/tests/Test-DbaAgentJobOwner.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -17,22 +17,22 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { $saJob = ("dbatoolsci_sa_{0}" -f $(Get-Random)) $notSaJob = ("dbatoolsci_nonsa_{0}" -f $(Get-Random)) - $null = New-DbaAgentJob -SqlInstance $script:instance2 -Job $saJob -OwnerLogin 'sa' - $null = New-DbaAgentJob -SqlInstance $script:instance2 -Job $notSaJob -OwnerLogin 'NT AUTHORITY\SYSTEM' + $null = New-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job $saJob -OwnerLogin 'sa' + $null = New-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job $notSaJob -OwnerLogin 'NT AUTHORITY\SYSTEM' } AfterAll { - $null = Remove-DbaAgentJob -SqlInstance $script:instance2 -Job $saJob, $notSaJob -Confirm:$false + $null = Remove-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job $saJob, $notSaJob -Confirm:$false } Context "Command actually works" { - $results = Test-DbaAgentJobOwner -SqlInstance $script:instance2 + $results = Test-DbaAgentJobOwner -SqlInstance $TestConfig.instance2 It "Should return $notSaJob" { $results | Where-Object {$_.Job -eq $notsajob} | Should Not Be Null } } Context "Command works for specific jobs" { - $results = Test-DbaAgentJobOwner -SqlInstance $script:instance2 -Job $saJob, $notSaJob + $results = Test-DbaAgentJobOwner -SqlInstance $TestConfig.instance2 -Job $saJob, $notSaJob It "Should find $sajob owner matches default sa" { $($results | Where-Object {$_.Job -eq $sajob}).OwnerMatch | Should Be $True } @@ -42,9 +42,9 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } Context "Exclusions work" { - $results = Test-DbaAgentJobOwner -SqlInstance $script:instance2 -ExcludeJob $notSaJob + $results = Test-DbaAgentJobOwner -SqlInstance $TestConfig.instance2 -ExcludeJob $notSaJob It "Should exclude $notsajob job" { $results.job | Should Not Match $notSaJob } } -} \ No newline at end of file +} diff --git a/tests/Test-DbaAvailabilityGroup.Tests.ps1 b/tests/Test-DbaAvailabilityGroup.Tests.ps1 index fe7054c0c2..05b560a3ab 100644 --- a/tests/Test-DbaAvailabilityGroup.Tests.ps1 +++ b/tests/Test-DbaAvailabilityGroup.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$commandname Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Test-DbaBackupEncrypted.Tests.ps1 b/tests/Test-DbaBackupEncrypted.Tests.ps1 index 47215d3168..a7c6cd45c2 100644 --- a/tests/Test-DbaBackupEncrypted.Tests.ps1 +++ b/tests/Test-DbaBackupEncrypted.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Validate parameters" { @@ -18,7 +18,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { $PSDefaultParameterValues["*:Confirm"] = $false $alldbs = @() - 1..2 | ForEach-Object { $alldbs += New-DbaDatabase -SqlInstance $script:instance2 } + 1..2 | ForEach-Object { $alldbs += New-DbaDatabase -SqlInstance $TestConfig.instance2 } } AfterAll { @@ -38,27 +38,27 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } $null = $alldbs | Start-DbaDbEncryption @splat $backups = $alldbs | Select-Object -First 1 | Backup-DbaDatabase -Path C:\temp - $results = $backups | Test-DbaBackupEncrypted -SqlInstance $script:instance2 + $results = $backups | Test-DbaBackupEncrypted -SqlInstance $TestConfig.instance2 $results.Encrypted | Should -Be $true } It "should detect encryption from piped file" { $backups = $alldbs | Select-Object -First 1 | Backup-DbaDatabase -Path C:\temp - $results = Test-DbaBackupEncrypted -SqlInstance $script:instance2 -FilePath $backups.BackupPath + $results = Test-DbaBackupEncrypted -SqlInstance $TestConfig.instance2 -FilePath $backups.BackupPath $results.Encrypted | Should -Be $true } It "should say a non-encryted file is not encrypted" { - $backups = New-DbaDatabase -SqlInstance $script:instance2 | Backup-DbaDatabase -Path C:\temp - $results = Test-DbaBackupEncrypted -SqlInstance $script:instance2 -FilePath $backups.BackupPath + $backups = New-DbaDatabase -SqlInstance $TestConfig.instance2 | Backup-DbaDatabase -Path C:\temp + $results = Test-DbaBackupEncrypted -SqlInstance $TestConfig.instance2 -FilePath $backups.BackupPath $results.Encrypted | Should -Be $false } It "should say a non-encryted file is not encrypted" { - $encryptor = (Get-DbaDbCertificate -SqlInstance $script:instance2 -Database master | Where-Object Name -notmatch "#" | Select-Object -First 1).Name - $db = New-DbaDatabase -SqlInstance $script:instance2 - $backup = Backup-DbaDatabase -SqlInstance $script:instance2 -Path C:\temp -EncryptionAlgorithm AES192 -EncryptionCertificate $encryptor -Database $db.Name - $results = Test-DbaBackupEncrypted -SqlInstance $script:instance2 -FilePath $backup.BackupPath + $encryptor = (Get-DbaDbCertificate -SqlInstance $TestConfig.instance2 -Database master | Where-Object Name -notmatch "#" | Select-Object -First 1).Name + $db = New-DbaDatabase -SqlInstance $TestConfig.instance2 + $backup = Backup-DbaDatabase -SqlInstance $TestConfig.instance2 -Path C:\temp -EncryptionAlgorithm AES192 -EncryptionCertificate $encryptor -Database $db.Name + $results = Test-DbaBackupEncrypted -SqlInstance $TestConfig.instance2 -FilePath $backup.BackupPath $results.Encrypted | Should -Be $true } } -} \ No newline at end of file +} diff --git a/tests/Test-DbaBackupInformation.Tests.ps1 b/tests/Test-DbaBackupInformation.Tests.ps1 index 93bbe07d5d..bfad94066c 100644 --- a/tests/Test-DbaBackupInformation.Tests.ps1 +++ b/tests/Test-DbaBackupInformation.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$commandname Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Test-DbaBuild.Tests.ps1 b/tests/Test-DbaBuild.Tests.ps1 index fd2152cd43..c54a1206c3 100644 --- a/tests/Test-DbaBuild.Tests.ps1 +++ b/tests/Test-DbaBuild.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -41,13 +41,13 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Command actually works" { It "Should return a result" { - $results = Test-DbaBuild -Build "12.00.4502" -MinimumBuild "12.0.4511" -SqlInstance $script:instance2 + $results = Test-DbaBuild -Build "12.00.4502" -MinimumBuild "12.0.4511" -SqlInstance $TestConfig.instance2 $results | Should -Not -Be $null } It "Should return a result" { - $results = Test-DbaBuild -Build "12.0.5540" -MaxBehind "1SP 1CU" -SqlInstance $script:instance2 + $results = Test-DbaBuild -Build "12.0.5540" -MaxBehind "1SP 1CU" -SqlInstance $TestConfig.instance2 $results | Should -Not -Be $null } } -} \ No newline at end of file +} diff --git a/tests/Test-DbaCmConnection.Tests.ps1 b/tests/Test-DbaCmConnection.Tests.ps1 index 5717ef5d2e..5c699d6506 100644 --- a/tests/Test-DbaCmConnection.Tests.ps1 +++ b/tests/Test-DbaCmConnection.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Test-DbaComputerCertificateExpiration.Tests.ps1 b/tests/Test-DbaComputerCertificateExpiration.Tests.ps1 index bd002ef317..19e3042302 100644 --- a/tests/Test-DbaComputerCertificateExpiration.Tests.ps1 +++ b/tests/Test-DbaComputerCertificateExpiration.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -20,11 +20,11 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } It "reports that the certificate is expired" { - $null = Add-DbaComputerCertificate -Path $script:appveyorlabrepo\certificates\localhost.crt -Confirm:$false + $null = Add-DbaComputerCertificate -Path "$($TestConfig.appveyorlabrepo)\certificates\localhost.crt" -Confirm:$false $thumbprint = "29C469578D6C6211076A09CEE5C5797EEA0C2713" $results = Test-DbaComputerCertificateExpiration -Thumbprint $thumbprint $results | Select-Object -ExpandProperty Note | Should -Be "This certificate has expired and is no longer valid" $results.Thumbprint | Should Be $thumbprint } } -} \ No newline at end of file +} diff --git a/tests/Test-DbaConnection.Tests.ps1 b/tests/Test-DbaConnection.Tests.ps1 index fe92077336..025567aaa0 100644 --- a/tests/Test-DbaConnection.Tests.ps1 +++ b/tests/Test-DbaConnection.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,7 +16,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Testing if command works" { - $results = Test-DbaConnection -SqlInstance $script:instance1 + $results = Test-DbaConnection -SqlInstance $TestConfig.instance1 $whoami = whoami It "returns the correct port" { $results.TcpPort | Should Be 1433 @@ -30,4 +30,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $results.ConnectingAsUser | Should Be $whoami } } -} \ No newline at end of file +} diff --git a/tests/Test-DbaConnectionAuthScheme.Tests.ps1 b/tests/Test-DbaConnectionAuthScheme.Tests.ps1 index aca40ef61f..da30a53e27 100644 --- a/tests/Test-DbaConnectionAuthScheme.Tests.ps1 +++ b/tests/Test-DbaConnectionAuthScheme.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,9 +15,9 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "returns the proper transport" { - $results = Test-DbaConnectionAuthScheme -SqlInstance $script:instance1 + $results = Test-DbaConnectionAuthScheme -SqlInstance $TestConfig.instance1 It "returns ntlm auth scheme" { $results.AuthScheme | Should Be 'ntlm' } } -} \ No newline at end of file +} diff --git a/tests/Test-DbaDbCollation.Tests.ps1 b/tests/Test-DbaDbCollation.Tests.ps1 index d725144cd7..b404abe211 100644 --- a/tests/Test-DbaDbCollation.Tests.ps1 +++ b/tests/Test-DbaDbCollation.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -17,7 +17,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "testing collation of a single database" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance1 $db1 = "dbatoolsci_collation" Get-DbaDatabase -SqlInstance $server -Database $db1 | Remove-DbaDatabase -Confirm:$false $server.Query("CREATE DATABASE $db1") @@ -27,8 +27,8 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } It "confirms the db is the same collation as the server" { - $result = Test-DbaDbCollation -SqlInstance $script:instance1 -Database $db1 + $result = Test-DbaDbCollation -SqlInstance $TestConfig.instance1 -Database $db1 $result.IsEqual } } -} \ No newline at end of file +} diff --git a/tests/Test-DbaDbCompatibility.Tests.ps1 b/tests/Test-DbaDbCompatibility.Tests.ps1 index 6a8504cbc9..110a3e2de1 100644 --- a/tests/Test-DbaDbCompatibility.Tests.ps1 +++ b/tests/Test-DbaDbCompatibility.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,18 +15,18 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Command actually works" { It "Should return a result" { - $results = Test-DbaDbCompatibility -SqlInstance $script:instance2 + $results = Test-DbaDbCompatibility -SqlInstance $TestConfig.instance2 $results | Should -Not -Be $null } It "Should return a result for a database" { - $results = Test-DbaDbCompatibility -Database Master -SqlInstance $script:instance2 + $results = Test-DbaDbCompatibility -Database Master -SqlInstance $TestConfig.instance2 $results | Should -Not -Be $null } It "Should return a result excluding one database" { - $results = Test-DbaDbCompatibility -ExcludeDatabase Master -SqlInstance $script:instance2 + $results = Test-DbaDbCompatibility -ExcludeDatabase Master -SqlInstance $TestConfig.instance2 $results | Should -Not -Be $null } } -} \ No newline at end of file +} diff --git a/tests/Test-DbaDbCompression.Tests.ps1 b/tests/Test-DbaDbCompression.Tests.ps1 index 9533bc9455..e37704e6cc 100644 --- a/tests/Test-DbaDbCompression.Tests.ps1 +++ b/tests/Test-DbaDbCompression.Tests.ps1 @@ -1,6 +1,6 @@ $commandname = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,9 +15,9 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { BeforeAll { - Get-DbaProcess -SqlInstance $script:instance2 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue + Get-DbaProcess -SqlInstance $TestConfig.instance2 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue $dbname = "dbatoolsci_test_$(get-random)" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $null = $server.Query("Create Database [$dbname]") $null = $server.Query("Create Schema test", $dbname) $null = $server.Query(" select * into syscols from sys.all_columns; @@ -29,11 +29,11 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { ", $dbname) } AfterAll { - Get-DbaProcess -SqlInstance $script:instance2 -Database $dbname | Stop-DbaProcess -WarningAction SilentlyContinue - Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbname -Confirm:$false + Get-DbaProcess -SqlInstance $TestConfig.instance2 -Database $dbname | Stop-DbaProcess -WarningAction SilentlyContinue + Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname -Confirm:$false } Context "Command gets suggestions" { - $results = Test-DbaDbCompression -SqlInstance $script:instance2 -Database $dbname + $results = Test-DbaDbCompression -SqlInstance $TestConfig.instance2 -Database $dbname It "Should get results for $dbname" { $results | Should Not Be $null } @@ -48,7 +48,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } Context "Command makes right suggestions" { - $results = Test-DbaDbCompression -SqlInstance $script:instance2 -Database $dbname + $results = Test-DbaDbCompression -SqlInstance $TestConfig.instance2 -Database $dbname It "Should suggest PAGE compression for a table with no updates or scans" { $($results | Where-Object { $_.TableName -eq "syscols" -and $_.IndexType -eq "HEAP"}).CompressionTypeRecommendation | Should Be "PAGE" } @@ -58,36 +58,36 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } Context "Command excludes results for specified database" { It "Shouldn't get any results for $dbname" { - $(Test-DbaDbCompression -SqlInstance $script:instance2 -Database $dbname -ExcludeDatabase $dbname).Database | Should not Match $dbname + $(Test-DbaDbCompression -SqlInstance $TestConfig.instance2 -Database $dbname -ExcludeDatabase $dbname).Database | Should not Match $dbname } } Context "Command gets Schema suggestions" { $schema = 'dbo' - $results = Test-DbaDbCompression -SqlInstance $script:instance2 -Database $dbname -Schema $schema + $results = Test-DbaDbCompression -SqlInstance $TestConfig.instance2 -Database $dbname -Schema $schema It "Should get results for Schema:$schema" { $results | Should Not Be $null } } Context "Command gets Table suggestions" { $table = 'syscols' - $results = Test-DbaDbCompression -SqlInstance $script:instance2 -Database $dbname -Table $table + $results = Test-DbaDbCompression -SqlInstance $TestConfig.instance2 -Database $dbname -Table $table It "Should get results for table:$table" { $results | Should Not Be $null } } Context "Command gets limited output" { $resultCount = 2 - $results = Test-DbaDbCompression -SqlInstance $script:instance2 -Database $dbname -ResultSize $resultCount -Rank TotalPages -FilterBy Partition + $results = Test-DbaDbCompression -SqlInstance $TestConfig.instance2 -Database $dbname -ResultSize $resultCount -Rank TotalPages -FilterBy Partition It "Should get only $resultCount results" { $results.Count | Should Be $resultCount } } Context "Returns result for empty table (see #9469)" { $table = 'testtable' - $results = Test-DbaDbCompression -SqlInstance $script:instance2 -Database $dbname -Table $table + $results = Test-DbaDbCompression -SqlInstance $TestConfig.instance2 -Database $dbname -Table $table It "Should get results for table:$table" { $results | Should Not Be $null $results[0].CompressionTypeRecommendation | Should Be '?' } } -} \ No newline at end of file +} diff --git a/tests/Test-DbaDbDataGeneratorConfig.Tests.ps1 b/tests/Test-DbaDbDataGeneratorConfig.Tests.ps1 index 04e95934c4..9180a174e4 100644 --- a/tests/Test-DbaDbDataGeneratorConfig.Tests.ps1 +++ b/tests/Test-DbaDbDataGeneratorConfig.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -18,7 +18,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $dbname = "dbatools_datagentest" $query = "CREATE DATABASE [$dbname]" - Invoke-DbaQuery -SqlInstance $script:instance1 -Database master -Query $query + Invoke-DbaQuery -SqlInstance $TestConfig.instance1 -Database master -Query $query $query = " CREATE TABLE [dbo].[Customer]( @@ -34,13 +34,13 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { ) ON [PRIMARY] " - Invoke-DbaQuery -SqlInstance $script:instance1 -Database $dbname -Query $query + Invoke-DbaQuery -SqlInstance $TestConfig.instance1 -Database $dbname -Query $query - $file = New-DbaDbDataGeneratorConfig -SqlInstance $script:instance1 -Database $dbname -Table Customer -Path "C:\temp\datageneration" + $file = New-DbaDbDataGeneratorConfig -SqlInstance $TestConfig.instance1 -Database $dbname -Table Customer -Path "C:\temp\datageneration" } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance1 -Database $dbname -Confirm:$false + Remove-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $dbname -Confirm:$false } It "gives no errors with a correct json file" { @@ -66,4 +66,4 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $findings.Count | Should -Be 1 } -} \ No newline at end of file +} diff --git a/tests/Test-DbaDbDataMaskingConfig.Tests.ps1 b/tests/Test-DbaDbDataMaskingConfig.Tests.ps1 index 02f0c3d9dc..362d93413a 100644 --- a/tests/Test-DbaDbDataMaskingConfig.Tests.ps1 +++ b/tests/Test-DbaDbDataMaskingConfig.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -84,7 +84,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $dbname = "dbatools_maskingtest" $query = "CREATE DATABASE [$dbname]" - Invoke-DbaQuery -SqlInstance $script:instance1 -Database master -Query $query + Invoke-DbaQuery -SqlInstance $TestConfig.instance1 -Database master -Query $query $query = " CREATE TABLE [dbo].[Customer]( @@ -100,13 +100,13 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { ) ON [PRIMARY] " - Invoke-DbaQuery -SqlInstance $script:instance1 -Database $dbname -Query $query + Invoke-DbaQuery -SqlInstance $TestConfig.instance1 -Database $dbname -Query $query - $file = New-DbaDbMaskingConfig -SqlInstance $script:instance1 -Database $dbname -Table Customer -Path "C:\temp\datamasking" + $file = New-DbaDbMaskingConfig -SqlInstance $TestConfig.instance1 -Database $dbname -Table Customer -Path "C:\temp\datamasking" } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance1 -Database $dbname -Confirm:$false + Remove-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $dbname -Confirm:$false } It "gives no errors with a correct json file" { @@ -132,4 +132,4 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $findings.Count | Should -Be 1 } -} \ No newline at end of file +} diff --git a/tests/Test-DbaDbLogShipStatus.Tests.ps1 b/tests/Test-DbaDbLogShipStatus.Tests.ps1 index 759be691e6..57a4c27f1b 100644 --- a/tests/Test-DbaDbLogShipStatus.Tests.ps1 +++ b/tests/Test-DbaDbLogShipStatus.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Validate parameters" { @@ -15,7 +15,7 @@ Describe "$CommandName Unit Tests" -Tags "UnitTests" { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance1 $skip = $false if ($server.Edition -notmatch 'Express') { $skip = $true @@ -23,12 +23,12 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } It -Skip:$skip "warns if SQL instance edition is not supported" { - $null = Test-DbaDbLogShipStatus -SqlInstance $script:instance1 -WarningAction SilentlyContinue -WarningVariable editionwarn + $null = Test-DbaDbLogShipStatus -SqlInstance $TestConfig.instance1 -WarningAction SilentlyContinue -WarningVariable editionwarn $editionwarn -match "Express" | Should Be $true } It "warns if no log shipping found" { - $null = Test-DbaDbLogShipStatus -SqlInstance $script:instance2 -Database 'master' -WarningAction SilentlyContinue -WarningVariable doesntexist + $null = Test-DbaDbLogShipStatus -SqlInstance $TestConfig.instance2 -Database 'master' -WarningAction SilentlyContinue -WarningVariable doesntexist $doesntexist -match "No information available" | Should Be $true } -} \ No newline at end of file +} diff --git a/tests/Test-DbaDbOwner.Tests.ps1 b/tests/Test-DbaDbOwner.Tests.ps1 index a368c18d4c..b6c63d9eaa 100644 --- a/tests/Test-DbaDbOwner.Tests.ps1 +++ b/tests/Test-DbaDbOwner.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag "UnitTests" { Context "Validate parameters" { @@ -271,20 +271,20 @@ Describe "$CommandName Unit Tests" -Tag "UnitTests" { Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { - Get-DbaProcess -SqlInstance $script:instance1 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue + Get-DbaProcess -SqlInstance $TestConfig.instance1 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue $dbname = "dbatoolsci_testdbowner" - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance1 $null = $server.Query("Create Database [$dbname]") } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance1 -Database $dbname -Confirm:$false + Remove-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $dbname -Confirm:$false } It "return the correct information including database, currentowner and targetowner" { $whoami = whoami - $results = Test-DbaDbOwner -SqlInstance $script:instance1 -Database $dbname + $results = Test-DbaDbOwner -SqlInstance $TestConfig.instance1 -Database $dbname $results.Database -eq $dbname $results.CurrentOwner -eq $whoami $results.TargetOwner -eq 'sa' } -} \ No newline at end of file +} diff --git a/tests/Test-DbaDbQueryStore.Tests.ps1 b/tests/Test-DbaDbQueryStore.Tests.ps1 index a7f9fac320..51827df090 100644 --- a/tests/Test-DbaDbQueryStore.Tests.ps1 +++ b/tests/Test-DbaDbQueryStore.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag "UnitTests" { Context "Validate parameters" { @@ -16,18 +16,18 @@ Describe "$CommandName Unit Tests" -Tag "UnitTests" { Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { $dbname = "JESSdbatoolsci_querystore_$(get-random)" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $db = New-DbaDatabase -SqlInstance $server -Name $dbname - $null = Set-DbaDbQueryStoreOption -SqlInstance $script:instance2 -Database $dbname -State ReadWrite - $null = Enable-DbaTraceFlag -SqlInstance $script:instance2 -TraceFlag 7745 + $null = Set-DbaDbQueryStoreOption -SqlInstance $TestConfig.instance2 -Database $dbname -State ReadWrite + $null = Enable-DbaTraceFlag -SqlInstance $TestConfig.instance2 -TraceFlag 7745 } AfterAll { - $null = Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbname -Confirm:$false - $null = Disable-DbaTraceFlag -SqlInstance $script:instance2 -TraceFlag 7745 + $null = Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname -Confirm:$false + $null = Disable-DbaTraceFlag -SqlInstance $TestConfig.instance2 -TraceFlag 7745 } Context 'Function works as expected' { - $svr = Connect-DbaInstance -SqlInstance $script:instance2 + $svr = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $results = Test-DbaDbQueryStore -SqlInstance $svr -Database $dbname It 'Should return results' { @@ -51,9 +51,9 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { } Context 'Exclude database works' { - $svr = Connect-DbaInstance -SqlInstance $script:instance2 + $svr = Connect-DbaInstance -SqlInstance $TestConfig.instance2 - $results = Test-DbaDbQueryStore -SqlInstance $script:instance2 -ExcludeDatabase $dbname + $results = Test-DbaDbQueryStore -SqlInstance $TestConfig.instance2 -ExcludeDatabase $dbname It 'Should return results' { $results | Should Not BeNullOrEmpty } @@ -63,7 +63,7 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { } Context 'Function works with piping smo server object' { - $svr = Connect-DbaInstance -SqlInstance $script:instance2 + $svr = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $results = $svr | Test-DbaDbQueryStore It 'Should return results' { @@ -76,4 +76,4 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { ($results | Where-Object { $_.Name -eq 'Trace Flag 7745 Enabled' }).IsBestPractice | Should Be $true } } -} \ No newline at end of file +} diff --git a/tests/Test-DbaDbRecoveryModel.Tests.ps1 b/tests/Test-DbaDbRecoveryModel.Tests.ps1 index 43aafc7344..013e61b75d 100644 --- a/tests/Test-DbaDbRecoveryModel.Tests.ps1 +++ b/tests/Test-DbaDbRecoveryModel.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -18,29 +18,29 @@ Describe "$CommandName Intigration Tests" -Tag "IntegrationTests" { $bulkLoggedRecovery = "dbatoolsci_RecoveryModelBulk" $simpleRecovery = "dbatoolsci_RecoveryModelSimple" $psudoSimpleRecovery = "dbatoolsci_RecoveryModelPsudoSimple" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 - Stop-DbaProcess -SqlInstance $script:instance2 -Database model + Stop-DbaProcess -SqlInstance $TestConfig.instance2 -Database model $server.Query("CREATE DATABASE $fullRecovery") - Stop-DbaProcess -SqlInstance $script:instance2 -Database model + Stop-DbaProcess -SqlInstance $TestConfig.instance2 -Database model $server.Query("CREATE DATABASE $bulkLoggedRecovery") - Stop-DbaProcess -SqlInstance $script:instance2 -Database model + Stop-DbaProcess -SqlInstance $TestConfig.instance2 -Database model $server.Query("CREATE DATABASE $simpleRecovery") - Stop-DbaProcess -SqlInstance $script:instance2 -Database model + Stop-DbaProcess -SqlInstance $TestConfig.instance2 -Database model $server.Query("CREATE DATABASE $psudoSimpleRecovery") - Set-DbaDbRecoveryModel -sqlInstance $script:instance2 -RecoveryModel BulkLogged -Database $bulkLoggedRecovery -Confirm:$false - Set-DbaDbRecoveryModel -SqlInstance $script:instance2 -RecoveryModel Simple -Database $simpleRecovery -Confirm:$false - Set-DbaDbRecoveryModel -SqlInstance $script:instance2 -RecoveryModel Simple -Database $psudoSimpleRecovery -Confirm:$false - Set-DbaDbRecoveryModel -SqlInstance $script:instance2 -RecoveryModel Full -Database $psudoSimpleRecovery -Confirm:$false + Set-DbaDbRecoveryModel -sqlInstance $TestConfig.instance2 -RecoveryModel BulkLogged -Database $bulkLoggedRecovery -Confirm:$false + Set-DbaDbRecoveryModel -SqlInstance $TestConfig.instance2 -RecoveryModel Simple -Database $simpleRecovery -Confirm:$false + Set-DbaDbRecoveryModel -SqlInstance $TestConfig.instance2 -RecoveryModel Simple -Database $psudoSimpleRecovery -Confirm:$false + Set-DbaDbRecoveryModel -SqlInstance $TestConfig.instance2 -RecoveryModel Full -Database $psudoSimpleRecovery -Confirm:$false } AfterAll { - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance2 -Database $fullRecovery, $bulkLoggedRecovery, $simpleRecovery, $psudoSimpleRecovery + Remove-DbaDatabase -Confirm:$false -SqlInstance $TestConfig.instance2 -Database $fullRecovery, $bulkLoggedRecovery, $simpleRecovery, $psudoSimpleRecovery } Context "Default Execution" { - $results = Test-DbaDbRecoveryModel -SqlInstance $script:instance2 -Database $fullRecovery, $psudoSimpleRecovery, 'Model' + $results = Test-DbaDbRecoveryModel -SqlInstance $TestConfig.instance2 -Database $fullRecovery, $psudoSimpleRecovery, 'Model' It "Should return $fullRecovery, $psudoSimpleRecovery, and Model" { $results.Database | should -BeIn ($fullRecovery, $psudoSimpleRecovery, 'Model') @@ -49,7 +49,7 @@ Describe "$CommandName Intigration Tests" -Tag "IntegrationTests" { } Context "Full Recovery" { - $results = Test-DbaDbRecoveryModel -SqlInstance $script:instance2 -RecoveryModel Full -Database $fullRecovery, $psudoSimpleRecovery -ExcludeDatabase 'Model' + $results = Test-DbaDbRecoveryModel -SqlInstance $TestConfig.instance2 -RecoveryModel Full -Database $fullRecovery, $psudoSimpleRecovery -ExcludeDatabase 'Model' It "Should return $fullRecovery and $psudoSimpleRecovery" { $results.Database | should -BeIn ($fullRecovery, $psudoSimpleRecovery) @@ -57,7 +57,7 @@ Describe "$CommandName Intigration Tests" -Tag "IntegrationTests" { } Context "Bulk Logged Recovery" { - $results = Test-DbaDbRecoveryModel -SqlInstance $script:instance2 -RecoveryModel Bulk_Logged -Database $bulkLoggedRecovery + $results = Test-DbaDbRecoveryModel -SqlInstance $TestConfig.instance2 -RecoveryModel Bulk_Logged -Database $bulkLoggedRecovery It "Should return $bulkLoggedRecovery" { $results.Database | should -Be "$bulkLoggedRecovery" @@ -66,7 +66,7 @@ Describe "$CommandName Intigration Tests" -Tag "IntegrationTests" { } Context "Simple Recovery" { - $results = Test-DbaDbRecoveryModel -SqlInstance $script:instance2 -RecoveryModel Simple -Database $simpleRecovery + $results = Test-DbaDbRecoveryModel -SqlInstance $TestConfig.instance2 -RecoveryModel Simple -Database $simpleRecovery It "Should return $simpleRecovery" { $results.Database | should -Be "$simpleRecovery" @@ -75,7 +75,7 @@ Describe "$CommandName Intigration Tests" -Tag "IntegrationTests" { } Context "Psudo Simple Recovery" { - $results = Test-DbaDbRecoveryModel -SqlInstance $script:instance2 -RecoveryModel Full | Where-Object {$_.database -eq "$psudoSimpleRecovery"} + $results = Test-DbaDbRecoveryModel -SqlInstance $TestConfig.instance2 -RecoveryModel Full | Where-Object {$_.database -eq "$psudoSimpleRecovery"} It "Should return $psudoSimpleRecovery" { $results.Database | should -Be "$psudoSimpleRecovery" @@ -86,20 +86,20 @@ Describe "$CommandName Intigration Tests" -Tag "IntegrationTests" { Context "Error Check" { It "Should Throw Error for Incorrect Recovery Model" { - {Test-DbaDbRecoveryModel -SqlInstance $script:instance2 -RecoveryModel Awesome -EnableException -Database 'dontexist' } | should -Throw + {Test-DbaDbRecoveryModel -SqlInstance $TestConfig.instance2 -RecoveryModel Awesome -EnableException -Database 'dontexist' } | should -Throw } Mock Connect-DbaInstance { Throw } -ModuleName dbatools It "Should Thow Error for a DB Connection Error" { - {Test-DbaDbRecoveryModel -SqlInstance $script:instance2 -EnableException | Should -Throw } + {Test-DbaDbRecoveryModel -SqlInstance $TestConfig.instance2 -EnableException | Should -Throw } } Mock Select-DefaultView { Throw } -ModuleName dbatools It "Should Thow Error for Output Error " { - {Test-DbaDbRecoveryModel -SqlInstance $script:instance2 -EnableException | Should -Throw } + {Test-DbaDbRecoveryModel -SqlInstance $TestConfig.instance2 -EnableException | Should -Throw } } } -} \ No newline at end of file +} diff --git a/tests/Test-DbaDeprecatedFeature.Tests.ps1 b/tests/Test-DbaDeprecatedFeature.Tests.ps1 index ab760718b1..6c696d7627 100644 --- a/tests/Test-DbaDeprecatedFeature.Tests.ps1 +++ b/tests/Test-DbaDeprecatedFeature.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig . "$PSScriptRoot\..\public\Test-DbaDeprecatedFeature.ps1" Describe "$CommandName Unit Tests" -Tag 'UnitTests' { @@ -16,13 +16,13 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Command actually works" { It "Should return a result" { - $results = Test-DbaDeprecatedFeature -SqlInstance $script:instance2 + $results = Test-DbaDeprecatedFeature -SqlInstance $TestConfig.instance2 $results | Should -Not -Be $null } It "Should return a result for a database" { - $results = Test-DbaDeprecatedFeature -SqlInstance $script:instance2 -Database Master + $results = Test-DbaDeprecatedFeature -SqlInstance $TestConfig.instance2 -Database Master $results | Should -Not -Be $null } } -} \ No newline at end of file +} diff --git a/tests/Test-DbaDiskAlignment.Tests.ps1 b/tests/Test-DbaDiskAlignment.Tests.ps1 index c25656c490..11f46e921c 100644 --- a/tests/Test-DbaDiskAlignment.Tests.ps1 +++ b/tests/Test-DbaDiskAlignment.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,13 +15,13 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Command actually works" { It "Should return a result" { - $results = Test-DbaDiskAlignment -ComputerName $script:dbatoolsci_computer + $results = Test-DbaDiskAlignment -ComputerName $TestConfig.dbatoolsci_computer $results | Should -Not -Be $null } It "Should return a result not using sql" { - $results = Test-DbaDiskAlignment -NoSqlCheck -ComputerName $script:dbatoolsci_computer + $results = Test-DbaDiskAlignment -NoSqlCheck -ComputerName $TestConfig.dbatoolsci_computer $results | Should -Not -Be $null } } -} \ No newline at end of file +} diff --git a/tests/Test-DbaDiskAllocation.Tests.ps1 b/tests/Test-DbaDiskAllocation.Tests.ps1 index 988d8a6668..8a7b1cc1a4 100644 --- a/tests/Test-DbaDiskAllocation.Tests.ps1 +++ b/tests/Test-DbaDiskAllocation.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,13 +15,13 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Command actually works" { It "Should return a result" { - $results = Test-DbaDiskAllocation -ComputerName $script:instance2 + $results = Test-DbaDiskAllocation -ComputerName $TestConfig.instance2 $results | Should -Not -Be $null } It "Should return a result not using sql" { - $results = Test-DbaDiskAllocation -NoSqlCheck -ComputerName $script:instance2 + $results = Test-DbaDiskAllocation -NoSqlCheck -ComputerName $TestConfig.instance2 $results | Should -Not -Be $null } } -} \ No newline at end of file +} diff --git a/tests/Test-DbaDiskSpeed.Tests.ps1 b/tests/Test-DbaDiskSpeed.Tests.ps1 index afbfd727aa..86c17e1f8d 100644 --- a/tests/Test-DbaDiskSpeed.Tests.ps1 +++ b/tests/Test-DbaDiskSpeed.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -16,11 +16,11 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Context "Command actually works" { It "should have info for model" { - $results = Test-DbaDiskSpeed -SqlInstance $script:instance1 + $results = Test-DbaDiskSpeed -SqlInstance $TestConfig.instance1 $results.FileName -contains 'modellog.ldf' | Should -Be $true } It "returns only for master" { - $results = Test-DbaDiskSpeed -SqlInstance $script:instance1 -Database master + $results = Test-DbaDiskSpeed -SqlInstance $TestConfig.instance1 -Database master $results.Count | Should -Be 2 (($results.FileName -contains 'master.mdf') -and ($results.FileName -contains 'mastlog.ldf')) | Should -Be $true @@ -31,30 +31,30 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { # note: if testing the Linux scenarios with instance2 this test should be skipped or change it to a different instance. It "sample pipeline" { - $results = @($script:instance1, $script:instance2) | Test-DbaDiskSpeed -Database master + $results = @($TestConfig.instance1, $TestConfig.instance2) | Test-DbaDiskSpeed -Database master $results.Count | Should -Be 4 - # for some reason this doesn't work on AppVeyor, perhaps due to the way the instances are started up the instance names do not match the values in constants.ps1 - #(($results.SqlInstance -contains $script:instance1) -and ($results.SqlInstance -contains $script:instance2)) | Should -Be $true + # for some reason this doesn't work on AppVeyor, perhaps due to the way the instances are started up the instance names do not match the values in Get-TestConfig + #(($results.SqlInstance -contains $TestConfig.instance1) -and ($results.SqlInstance -contains $TestConfig.instance2)) | Should -Be $true } It "multiple databases included" { $databases = @('master', 'model') - $results = Test-DbaDiskSpeed -SqlInstance $script:instance1 -Database $databases + $results = Test-DbaDiskSpeed -SqlInstance $TestConfig.instance1 -Database $databases $results.Count | Should -Be 4 (($results.Database -contains 'master') -and ($results.Database -contains 'model')) | Should -Be $true } It "multiple databases excluded" { $excludedDatabases = @('master', 'model') - $results = Test-DbaDiskSpeed -SqlInstance $script:instance1 -ExcludeDatabase $excludedDatabases + $results = Test-DbaDiskSpeed -SqlInstance $TestConfig.instance1 -ExcludeDatabase $excludedDatabases $results.Count | Should -BeGreaterOrEqual 1 (($results.Database -notcontains 'master') -and ($results.Database -notcontains 'model')) | Should -Be $true } It "default aggregate by file" { - $resultsWithParam = Test-DbaDiskSpeed -SqlInstance $script:instance1 -AggregateBy "File" - $resultsWithoutParam = Test-DbaDiskSpeed -SqlInstance $script:instance1 + $resultsWithParam = Test-DbaDiskSpeed -SqlInstance $TestConfig.instance1 -AggregateBy "File" + $resultsWithoutParam = Test-DbaDiskSpeed -SqlInstance $TestConfig.instance1 $resultsWithParam.count | Should -Be $resultsWithoutParam.count $resultsWithParam.FileName -contains 'modellog.ldf' | Should -Be $true @@ -62,17 +62,17 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } It "aggregate by database" { - $results = Test-DbaDiskSpeed -SqlInstance $script:instance1 -AggregateBy "Database" - #$databases = Get-DbaDatabase -SqlInstance $script:instance1 + $results = Test-DbaDiskSpeed -SqlInstance $TestConfig.instance1 -AggregateBy "Database" + #$databases = Get-DbaDatabase -SqlInstance $TestConfig.instance1 $results.Database -contains 'model' | Should -Be $true #$results.count | Should -Be $databases.count # not working on AppVeyor but works fine locally } It "aggregate by disk" { - $results = Test-DbaDiskSpeed -SqlInstance $script:instance1 -AggregateBy "Disk" + $results = Test-DbaDiskSpeed -SqlInstance $TestConfig.instance1 -AggregateBy "Disk" (($results -is [System.Data.DataRow]) -or ($results.count -ge 1)) | Should -Be $true - #($results.SqlInstance -contains $script:instance1) | Should -Be $true + #($results.SqlInstance -contains $TestConfig.instance1) | Should -Be $true } It "aggregate by file and check column names returned" { @@ -81,7 +81,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $validColumns = $false - $results = Test-DbaDiskSpeed -SqlInstance $script:instance1 # default usage of command with no params is equivalent to AggregateBy = "File" + $results = Test-DbaDiskSpeed -SqlInstance $TestConfig.instance1 # default usage of command with no params is equivalent to AggregateBy = "File" if ( ($null -ne $results) ) { $row = $null @@ -91,7 +91,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } elseif ($results -is [Object[]] -and $results.Count -gt 0) { $row = $results[0] } else { - Write-Message -Level Warning -Message "Unexpected results returned from $($script:instance1): $($results)" + Write-Message -Level Warning -Message "Unexpected results returned from $($TestConfig.instance1): $($results)" $validColumns = $false } @@ -99,10 +99,10 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { [object[]]$columnNamesReturned = @($row | Get-Member -MemberType Property | Select-Object -Property Name | ForEach-Object { $_.Name }) if ( @(Compare-Object -ReferenceObject $expectedColumnArray -DifferenceObject $columnNamesReturned).Count -eq 0 ) { - Write-Message -Level Debug -Message "Columns matched on $($script:instance1)" + Write-Message -Level Debug -Message "Columns matched on $($TestConfig.instance1)" $validColumns = $true } else { - Write-Message -Level Warning -Message "The columns specified in the expectedColumnArray variable do not match these returned columns from $($script:instance1): $($columnNamesReturned)" + Write-Message -Level Warning -Message "The columns specified in the expectedColumnArray variable do not match these returned columns from $($TestConfig.instance1): $($columnNamesReturned)" } } } @@ -116,7 +116,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $validColumns = $false - $results = Test-DbaDiskSpeed -SqlInstance $script:instance1 -AggregateBy "Database" + $results = Test-DbaDiskSpeed -SqlInstance $TestConfig.instance1 -AggregateBy "Database" if ( ($null -ne $results) ) { $row = $null @@ -126,7 +126,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } elseif ($results -is [Object[]] -and $results.Count -gt 0) { $row = $results[0] } else { - Write-Message -Level Warning -Message "Unexpected results returned from $($script:instance1): $($results)" + Write-Message -Level Warning -Message "Unexpected results returned from $($TestConfig.instance1): $($results)" $validColumns = $false } @@ -134,10 +134,10 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { [object[]]$columnNamesReturned = @($row | Get-Member -MemberType Property | Select-Object -Property Name | ForEach-Object { $_.Name }) if ( @(Compare-Object -ReferenceObject $expectedColumnArray -DifferenceObject $columnNamesReturned).Count -eq 0 ) { - Write-Message -Level Debug -Message "Columns matched on $($script:instance1)" + Write-Message -Level Debug -Message "Columns matched on $($TestConfig.instance1)" $validColumns = $true } else { - Write-Message -Level Warning -Message "The columns specified in the expectedColumnArray variable do not match these returned columns from $($script:instance1): $($columnNamesReturned)" + Write-Message -Level Warning -Message "The columns specified in the expectedColumnArray variable do not match these returned columns from $($TestConfig.instance1): $($columnNamesReturned)" } } } @@ -151,7 +151,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $validColumns = $false - $results = Test-DbaDiskSpeed -SqlInstance $script:instance1 -AggregateBy "Disk" + $results = Test-DbaDiskSpeed -SqlInstance $TestConfig.instance1 -AggregateBy "Disk" if ( ($null -ne $results) ) { $row = $null @@ -161,7 +161,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } elseif ($results -is [Object[]] -and $results.Count -gt 0) { $row = $results[0] } else { - Write-Message -Level Warning -Message "Unexpected results returned from $($script:instance1): $($results)" + Write-Message -Level Warning -Message "Unexpected results returned from $($TestConfig.instance1): $($results)" $validColumns = $false } @@ -169,10 +169,10 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { [object[]]$columnNamesReturned = @($row | Get-Member -MemberType Property | Select-Object -Property Name | ForEach-Object { $_.Name }) if ( @(Compare-Object -ReferenceObject $expectedColumnArray -DifferenceObject $columnNamesReturned).Count -eq 0 ) { - Write-Message -Level Debug -Message "Columns matched on $($script:instance1)" + Write-Message -Level Debug -Message "Columns matched on $($TestConfig.instance1)" $validColumns = $true } else { - Write-Message -Level Warning -Message "The columns specified in the expectedColumnArray variable do not match these returned columns from $($script:instance1): $($columnNamesReturned)" + Write-Message -Level Warning -Message "The columns specified in the expectedColumnArray variable do not match these returned columns from $($TestConfig.instance1): $($columnNamesReturned)" } } } @@ -181,25 +181,25 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } # Separate test to run against a Linux-hosted SQL instance. - # To run this test ensure you have specified the instance2 values for a Linux-hosted SQL instance in the constants.ps1 + # To run this test ensure you have specified the instance2 values for a Linux-hosted SQL instance in the Get-TestConfig It -Skip "test commands on a Linux instance" { # use instance with credential info and run through the 3 variations # -Skip to be added when checking in the code - $linuxSecurePassword = ConvertTo-SecureString -String $script:instance2SQLPassword -AsPlainText -Force - $linuxSqlCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $script:instance2SQLUserName, $linuxSecurePassword + $linuxSecurePassword = ConvertTo-SecureString -String $TestConfig.instance2SQLPassword -AsPlainText -Force + $linuxSqlCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $TestConfig.instance2SQLUserName, $linuxSecurePassword - $results = Test-DbaDiskSpeed -SqlInstance $script:instance2 -SqlCredential $linuxSqlCredential -AggregateBy "Database" - $databases = Get-DbaDatabase -SqlInstance $script:instance2 -SqlCredential $linuxSqlCredential + $results = Test-DbaDiskSpeed -SqlInstance $TestConfig.instance2 -SqlCredential $linuxSqlCredential -AggregateBy "Database" + $databases = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -SqlCredential $linuxSqlCredential $results.Database -contains 'model' | Should -Be $true $results.count | Should -Be $databases.count - $results = Test-DbaDiskSpeed -SqlInstance $script:instance2 -SqlCredential $linuxSqlCredential -AggregateBy "Disk" + $results = Test-DbaDiskSpeed -SqlInstance $TestConfig.instance2 -SqlCredential $linuxSqlCredential -AggregateBy "Disk" (($results -is [System.Data.DataRow]) -or ($results.count -ge 1)) | Should -Be $true - $resultsWithParam = Test-DbaDiskSpeed -SqlInstance $script:instance2 -SqlCredential $linuxSqlCredential -AggregateBy "File" - $resultsWithoutParam = Test-DbaDiskSpeed -SqlInstance $script:instance2 -SqlCredential $linuxSqlCredential + $resultsWithParam = Test-DbaDiskSpeed -SqlInstance $TestConfig.instance2 -SqlCredential $linuxSqlCredential -AggregateBy "File" + $resultsWithoutParam = Test-DbaDiskSpeed -SqlInstance $TestConfig.instance2 -SqlCredential $linuxSqlCredential $resultsWithParam.count | Should -Be $resultsWithoutParam.count $resultsWithParam.FileName -contains 'modellog.ldf' | Should -Be $true @@ -207,17 +207,17 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } # Separate test to run against a Linux-hosted SQL instance. - # To run this test ensure you have specified the instance2 values for a Linux-hosted SQL instance in the constants.ps1 + # To run this test ensure you have specified the instance2 values for a Linux-hosted SQL instance in the Get-TestConfig It -Skip "aggregate by file and check column names returned on a Linux instance" { # check returned columns [object[]]$expectedColumnArray = 'ComputerName', 'InstanceName', 'SqlInstance', 'Database', 'SizeGB', 'FileName', 'FileID', 'FileType', 'DiskLocation', 'Reads', 'AverageReadStall', 'ReadPerformance', 'Writes', 'AverageWriteStall', 'WritePerformance', 'Avg Overall Latency', 'Avg Bytes/Read', 'Avg Bytes/Write', 'Avg Bytes/Transfer' $validColumns = $false - $linuxSecurePassword = ConvertTo-SecureString -String $script:instance2SQLPassword -AsPlainText -Force - $linuxSqlCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $script:instance2SQLUserName, $linuxSecurePassword + $linuxSecurePassword = ConvertTo-SecureString -String $TestConfig.instance2SQLPassword -AsPlainText -Force + $linuxSqlCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $TestConfig.instance2SQLUserName, $linuxSecurePassword - $results = Test-DbaDiskSpeed -SqlInstance $script:instance2 -SqlCredential $linuxSqlCredential # default usage of command with no params is equivalent to AggregateBy = "File" + $results = Test-DbaDiskSpeed -SqlInstance $TestConfig.instance2 -SqlCredential $linuxSqlCredential # default usage of command with no params is equivalent to AggregateBy = "File" if ( ($null -ne $results) ) { $row = $null @@ -227,7 +227,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } elseif ($results -is [Object[]] -and $results.Count -gt 0) { $row = $results[0] } else { - Write-Message -Level Warning -Message "Unexpected results returned from $($script:instance1): $($results)" + Write-Message -Level Warning -Message "Unexpected results returned from $($TestConfig.instance1): $($results)" $validColumns = $false } @@ -235,10 +235,10 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { [object[]]$columnNamesReturned = @($row | Get-Member -MemberType Property | Select-Object -Property Name | ForEach-Object { $_.Name }) if ( @(Compare-Object -ReferenceObject $expectedColumnArray -DifferenceObject $columnNamesReturned).Count -eq 0 ) { - Write-Message -Level Debug -Message "Columns matched on $($script:instance1)" + Write-Message -Level Debug -Message "Columns matched on $($TestConfig.instance1)" $validColumns = $true } else { - Write-Message -Level Warning -Message "The columns specified in the expectedColumnArray variable do not match these returned columns from $($script:instance1): $($columnNamesReturned)" + Write-Message -Level Warning -Message "The columns specified in the expectedColumnArray variable do not match these returned columns from $($TestConfig.instance1): $($columnNamesReturned)" } } } @@ -247,17 +247,17 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } # Separate test to run against a Linux-hosted SQL instance. - # To run this test ensure you have specified the instance2 values for a Linux-hosted SQL instance in the constants.ps1 + # To run this test ensure you have specified the instance2 values for a Linux-hosted SQL instance in the Get-TestConfig It -Skip "aggregate by database and check column names returned on a Linux instance" { # check returned columns [object[]]$expectedColumnArray = 'ComputerName', 'InstanceName', 'SqlInstance', 'Database', 'DiskLocation', 'Reads', 'AverageReadStall', 'ReadPerformance', 'Writes', 'AverageWriteStall', 'WritePerformance', 'Avg Overall Latency', 'Avg Bytes/Read', 'Avg Bytes/Write', 'Avg Bytes/Transfer' $validColumns = $false - $linuxSecurePassword = ConvertTo-SecureString -String $script:instance2SQLPassword -AsPlainText -Force - $linuxSqlCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $script:instance2SQLUserName, $linuxSecurePassword + $linuxSecurePassword = ConvertTo-SecureString -String $TestConfig.instance2SQLPassword -AsPlainText -Force + $linuxSqlCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $TestConfig.instance2SQLUserName, $linuxSecurePassword - $results = Test-DbaDiskSpeed -SqlInstance $script:instance2 -SqlCredential $linuxSqlCredential -AggregateBy "Database" + $results = Test-DbaDiskSpeed -SqlInstance $TestConfig.instance2 -SqlCredential $linuxSqlCredential -AggregateBy "Database" if ( ($null -ne $results) ) { $row = $null @@ -267,7 +267,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } elseif ($results -is [Object[]] -and $results.Count -gt 0) { $row = $results[0] } else { - Write-Message -Level Warning -Message "Unexpected results returned from $($script:instance1): $($results)" + Write-Message -Level Warning -Message "Unexpected results returned from $($TestConfig.instance1): $($results)" $validColumns = $false } @@ -275,10 +275,10 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { [object[]]$columnNamesReturned = @($row | Get-Member -MemberType Property | Select-Object -Property Name | ForEach-Object { $_.Name }) if ( @(Compare-Object -ReferenceObject $expectedColumnArray -DifferenceObject $columnNamesReturned).Count -eq 0 ) { - Write-Message -Level Debug -Message "Columns matched on $($script:instance1)" + Write-Message -Level Debug -Message "Columns matched on $($TestConfig.instance1)" $validColumns = $true } else { - Write-Message -Level Warning -Message "The columns specified in the expectedColumnArray variable do not match these returned columns from $($script:instance1): $($columnNamesReturned)" + Write-Message -Level Warning -Message "The columns specified in the expectedColumnArray variable do not match these returned columns from $($TestConfig.instance1): $($columnNamesReturned)" } } } @@ -287,17 +287,17 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } # Separate test to run against a Linux-hosted SQL instance. - # To run this test ensure you have specified the instance2 values for a Linux-hosted SQL instance in the constants.ps1 + # To run this test ensure you have specified the instance2 values for a Linux-hosted SQL instance in the Get-TestConfig It -Skip "aggregate by disk and check column names returned on a Linux instance" { # check returned columns [object[]]$expectedColumnArray = 'ComputerName', 'InstanceName', 'SqlInstance', 'DiskLocation', 'Reads', 'AverageReadStall', 'ReadPerformance', 'Writes', 'AverageWriteStall', 'WritePerformance', 'Avg Overall Latency', 'Avg Bytes/Read', 'Avg Bytes/Write', 'Avg Bytes/Transfer' $validColumns = $false - $linuxSecurePassword = ConvertTo-SecureString -String $script:instance2SQLPassword -AsPlainText -Force - $linuxSqlCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $script:instance2SQLUserName, $linuxSecurePassword + $linuxSecurePassword = ConvertTo-SecureString -String $TestConfig.instance2SQLPassword -AsPlainText -Force + $linuxSqlCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $TestConfig.instance2SQLUserName, $linuxSecurePassword - $results = Test-DbaDiskSpeed -SqlInstance $script:instance2 -SqlCredential $linuxSqlCredential -AggregateBy "Disk" + $results = Test-DbaDiskSpeed -SqlInstance $TestConfig.instance2 -SqlCredential $linuxSqlCredential -AggregateBy "Disk" if ( ($null -ne $results) ) { $row = $null @@ -307,7 +307,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } elseif ($results -is [Object[]] -and $results.Count -gt 0) { $row = $results[0] } else { - Write-Message -Level Warning -Message "Unexpected results returned from $($script:instance1): $($results)" + Write-Message -Level Warning -Message "Unexpected results returned from $($TestConfig.instance1): $($results)" $validColumns = $false } @@ -315,10 +315,10 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { [object[]]$columnNamesReturned = @($row | Get-Member -MemberType Property | Select-Object -Property Name | ForEach-Object { $_.Name }) if ( @(Compare-Object -ReferenceObject $expectedColumnArray -DifferenceObject $columnNamesReturned).Count -eq 0 ) { - Write-Message -Level Debug -Message "Columns matched on $($script:instance1)" + Write-Message -Level Debug -Message "Columns matched on $($TestConfig.instance1)" $validColumns = $true } else { - Write-Message -Level Warning -Message "The columns specified in the expectedColumnArray variable do not match these returned columns from $($script:instance1): $($columnNamesReturned)" + Write-Message -Level Warning -Message "The columns specified in the expectedColumnArray variable do not match these returned columns from $($TestConfig.instance1): $($columnNamesReturned)" } } } @@ -326,4 +326,4 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $validColumns | Should -Be $true } } -} \ No newline at end of file +} diff --git a/tests/Test-DbaEndpoint.Tests.ps1 b/tests/Test-DbaEndpoint.Tests.ps1 index 9e79624e03..aa545d86b4 100644 --- a/tests/Test-DbaEndpoint.Tests.ps1 +++ b/tests/Test-DbaEndpoint.Tests.ps1 @@ -1,6 +1,6 @@ $commandname = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tags "UnitTests" { Context "Validate parameters" { @@ -15,7 +15,7 @@ Describe "$CommandName Unit Tests" -Tags "UnitTests" { Describe "$commandname Integration Tests" -Tag "IntegrationTests" { It -Skip "returns success" { - $results = Test-DbaEndpoint -SqlInstance $script:instance3 + $results = Test-DbaEndpoint -SqlInstance $TestConfig.instance3 $results | Select-Object -First 1 -ExpandProperty Connection | Should -Be 'Success' } -} #$script:instance2 for appveyor \ No newline at end of file +} #$TestConfig.instance2 for appveyor diff --git a/tests/Test-DbaIdentityUsage.Tests.ps1 b/tests/Test-DbaIdentityUsage.Tests.ps1 index fbcde1b861..5abddfb4ba 100644 --- a/tests/Test-DbaIdentityUsage.Tests.ps1 +++ b/tests/Test-DbaIdentityUsage.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -18,19 +18,19 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { $table = "TestTable_$(Get-random)" $tableDDL = "CREATE TABLE $table (testId TINYINT IDENTITY(1,1),testData DATETIME2 DEFAULT getdate() )" - Invoke-DbaQuery -SqlInstance $script:instance1 -Query $tableDDL -database TempDb + Invoke-DbaQuery -SqlInstance $TestConfig.instance1 -Query $tableDDL -database TempDb } AfterAll { $cleanup = "Drop table $table" - Invoke-DbaQuery -SqlInstance $script:instance1 -Query $cleanup -database TempDb + Invoke-DbaQuery -SqlInstance $TestConfig.instance1 -Query $cleanup -database TempDb } $insertSql = "INSERT INTO $table (testData) DEFAULT VALUES" for ($i = 1; $i -le 128; $i++) { - Invoke-DbaQuery -SqlInstance $script:instance1 -Query $insertSql -database TempDb + Invoke-DbaQuery -SqlInstance $TestConfig.instance1 -Query $insertSql -database TempDb } - $results = Test-DbaIdentityUsage -SqlInstance $script:instance1 -Database TempDb | Where-Object {$_.Table -eq $table} + $results = Test-DbaIdentityUsage -SqlInstance $TestConfig.instance1 -Database TempDb | Where-Object {$_.Table -eq $table} It "Identity column should have 128 uses" { $results.NumberOfUses | Should Be 128 @@ -41,9 +41,9 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $insertSql = "INSERT INTO $table (testData) DEFAULT VALUES" for ($i = 1; $i -le 127; $i++) { - Invoke-DbaQuery -SqlInstance $script:instance1 -Query $insertSql -database TempDb + Invoke-DbaQuery -SqlInstance $TestConfig.instance1 -Query $insertSql -database TempDb } - $results = Test-DbaIdentityUsage -SqlInstance $script:instance1 -Database TempDb | Where-Object {$_.Table -eq $table} + $results = Test-DbaIdentityUsage -SqlInstance $TestConfig.instance1 -Database TempDb | Where-Object {$_.Table -eq $table} It "Identity column should have 255 uses" { $results.NumberOfUses | Should Be 255 @@ -58,19 +58,19 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { $table = "TestTable_$(Get-random)" $tableDDL = "CREATE TABLE $table (testId tinyint IDENTITY(0,5),testData DATETIME2 DEFAULT getdate() )" - Invoke-DbaQuery -SqlInstance $script:instance1 -Query $tableDDL -database TempDb + Invoke-DbaQuery -SqlInstance $TestConfig.instance1 -Query $tableDDL -database TempDb } AfterAll { $cleanup = "Drop table $table" - Invoke-DbaQuery -SqlInstance $script:instance1 -Query $cleanup -database TempDb + Invoke-DbaQuery -SqlInstance $TestConfig.instance1 -Query $cleanup -database TempDb } $insertSql = "INSERT INTO $table (testData) DEFAULT VALUES" for ($i = 1; $i -le 25; $i++) { - Invoke-DbaQuery -SqlInstance $script:instance1 -Query $insertSql -database TempDb + Invoke-DbaQuery -SqlInstance $TestConfig.instance1 -Query $insertSql -database TempDb } - $results = Test-DbaIdentityUsage -SqlInstance $script:instance1 -Database TempDb | Where-Object {$_.Table -eq $table} + $results = Test-DbaIdentityUsage -SqlInstance $TestConfig.instance1 -Database TempDb | Where-Object {$_.Table -eq $table} It "Identity column should have 24 uses" { $results.NumberOfUses | Should Be 24 @@ -79,4 +79,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $results.PercentUsed | Should Be 47.06 } } -} \ No newline at end of file +} diff --git a/tests/Test-DbaInstanceName.Tests.ps1 b/tests/Test-DbaInstanceName.Tests.ps1 index a6c11bba10..a1c2afb22f 100644 --- a/tests/Test-DbaInstanceName.Tests.ps1 +++ b/tests/Test-DbaInstanceName.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { [object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object { $_ -notin ('whatif', 'confirm') } @@ -15,7 +15,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Command tests servername" { - $results = Test-DbaInstanceName -SqlInstance $script:instance2 + $results = Test-DbaInstanceName -SqlInstance $TestConfig.instance2 It "should say rename is not required" { $results.RenameRequired | Should -Be $false } @@ -25,4 +25,4 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { ($results.PsObject.Properties.Name | Sort-Object) | Should -Be ($ExpectedProps | Sort-Object) } } -} \ No newline at end of file +} diff --git a/tests/Test-DbaLastBackup.Tests.ps1 b/tests/Test-DbaLastBackup.Tests.ps1 index 9675e66805..aee7292831 100644 --- a/tests/Test-DbaLastBackup.Tests.ps1 +++ b/tests/Test-DbaLastBackup.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -19,7 +19,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $testlastbackup = "dbatoolsci_testlastbackup$random" $dbs = $testlastbackup, "dbatoolsci_lildb", "dbatoolsci_testrestore", "dbatoolsci_singlerestore" - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance1 foreach ($db in $dbs) { $server.Query("CREATE DATABASE $db") $server.Query("ALTER DATABASE $db SET RECOVERY FULL WITH NO_WAIT") @@ -31,27 +31,27 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { AfterAll { # these for sure $dbs += "bigtestrest", "smalltestrest" - Get-DbaDatabase -SqlInstance $script:instance1 -Database $dbs | Remove-DbaDatabase -Confirm:$false + Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $dbs | Remove-DbaDatabase -Confirm:$false # those just in case test-dbalastbackup didn't cooperate - Get-DbaDatabase -SqlInstance $script:instance1 | Where-Object Name -like 'dbatools-testrestore-dbatoolsci_*' | Remove-DbaDatabase -Confirm:$false + Get-DbaDatabase -SqlInstance $TestConfig.instance1 | Where-Object Name -like 'dbatools-testrestore-dbatoolsci_*' | Remove-DbaDatabase -Confirm:$false # see "Restores using a specific path" Get-ChildItem -Path C:\Temp\dbatools-testrestore-dbatoolsci_singlerestore* | Remove-Item } Context "Setup restores and backups on the local drive for Test-DbaLastBackup" { - Get-DbaDatabase -SqlInstance $script:instance1 -Database $dbs | Backup-DbaDatabase -Type Database - Invoke-DbaQuery -SqlInstance $script:instance1 -Query "INSERT INTO [$testlastbackup].[dbo].[Example] values ('sample')" - Get-DbaDatabase -SqlInstance $script:instance1 -Database $testlastbackup | Backup-DbaDatabase -Type Differential - Invoke-DbaQuery -SqlInstance $script:instance1 -Query "INSERT INTO [$testlastbackup].[dbo].[Example] values ('sample1')" - Get-DbaDatabase -SqlInstance $script:instance1 -Database $testlastbackup | Backup-DbaDatabase -Type Differential - Invoke-DbaQuery -SqlInstance $script:instance1 -Query "INSERT INTO [$testlastbackup].[dbo].[Example] values ('sample2')" - Get-DbaDatabase -SqlInstance $script:instance1 -Database $testlastbackup | Backup-DbaDatabase -Type Log - Invoke-DbaQuery -SqlInstance $script:instance1 -Query "INSERT INTO [$testlastbackup].[dbo].[Example] values ('sample3')" - Get-DbaDatabase -SqlInstance $script:instance1 -Database $testlastbackup | Backup-DbaDatabase -Type Log - Invoke-DbaQuery -SqlInstance $script:instance1 -Query "INSERT INTO [$testlastbackup].[dbo].[Example] values ('sample4')" + Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $dbs | Backup-DbaDatabase -Type Database + Invoke-DbaQuery -SqlInstance $TestConfig.instance1 -Query "INSERT INTO [$testlastbackup].[dbo].[Example] values ('sample')" + Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $testlastbackup | Backup-DbaDatabase -Type Differential + Invoke-DbaQuery -SqlInstance $TestConfig.instance1 -Query "INSERT INTO [$testlastbackup].[dbo].[Example] values ('sample1')" + Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $testlastbackup | Backup-DbaDatabase -Type Differential + Invoke-DbaQuery -SqlInstance $TestConfig.instance1 -Query "INSERT INTO [$testlastbackup].[dbo].[Example] values ('sample2')" + Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $testlastbackup | Backup-DbaDatabase -Type Log + Invoke-DbaQuery -SqlInstance $TestConfig.instance1 -Query "INSERT INTO [$testlastbackup].[dbo].[Example] values ('sample3')" + Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $testlastbackup | Backup-DbaDatabase -Type Log + Invoke-DbaQuery -SqlInstance $TestConfig.instance1 -Query "INSERT INTO [$testlastbackup].[dbo].[Example] values ('sample4')" } Context "Test a single database" { - $results = Test-DbaLastBackup -SqlInstance $script:instance1 -Database $testlastbackup + $results = Test-DbaLastBackup -SqlInstance $TestConfig.instance1 -Database $testlastbackup It "Should return success" { $results.RestoreResult | Should Be "Success" @@ -61,16 +61,16 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } Context "Testing the whole instance" { - $results = Test-DbaLastBackup -SqlInstance $script:instance1 -ExcludeDatabase tempdb + $results = Test-DbaLastBackup -SqlInstance $TestConfig.instance1 -ExcludeDatabase tempdb It "Should be more than 3 databases" { $results.count | Should BeGreaterThan 3 } } Context "Restores using a specific path" { - $null = Get-DbaDatabase -SqlInstance $script:instance1 -Database "dbatoolsci_singlerestore" | Backup-DbaDatabase - $null = Test-DbaLastBackup -SqlInstance $script:instance1 -Database "dbatoolsci_singlerestore" -DataDirectory C:\Temp -LogDirectory C:\Temp -NoDrop - $results = Get-DbaDbFile -SqlInstance $script:instance1 -Database "dbatools-testrestore-dbatoolsci_singlerestore" + $null = Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database "dbatoolsci_singlerestore" | Backup-DbaDatabase + $null = Test-DbaLastBackup -SqlInstance $TestConfig.instance1 -Database "dbatoolsci_singlerestore" -DataDirectory C:\Temp -LogDirectory C:\Temp -NoDrop + $results = Get-DbaDbFile -SqlInstance $TestConfig.instance1 -Database "dbatools-testrestore-dbatoolsci_singlerestore" It "Should match C:\Temp" { ('C:\Temp\dbatools-testrestore-dbatoolsci_singlerestore.mdf' -in $results.PhysicalName) | Should Be $true ('C:\Temp\dbatools-testrestore-dbatoolsci_singlerestore_log.ldf' -in $results.PhysicalName) | Should Be $true @@ -78,7 +78,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } Context "Test Ignoring Diff Backups" { - $results = Test-DbaLastBackup -SqlInstance $script:instance1 -Database $testlastbackup -IgnoreDiffBackup + $results = Test-DbaLastBackup -SqlInstance $TestConfig.instance1 -Database $testlastbackup -IgnoreDiffBackup It "Should return success" { $results.RestoreResult | Should Be "Success" @@ -90,12 +90,12 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } Context "Test dbsize skip and cleanup (Issue 3968)" { - $results1 = Restore-DbaDatabase -SqlInstance $script:instance1 -Database bigtestrest -Path $script:appveyorlabrepo\sql2008-backups\db1\FULL -ReplaceDbNameInFile - Backup-DbaDatabase -SqlInstance $script:instance1 -Database bigtestrest - $results1 = Restore-DbaDatabase -SqlInstance $script:instance1 -Database smalltestrest -Path $script:appveyorlabrepo\sql2008-backups\db2\FULL\SQL2008_db2_FULL_20170518_041738.bak -ReplaceDbNameInFile - Backup-DbaDatabase -SqlInstance $script:instance1 -Database smalltestrest + $results1 = Restore-DbaDatabase -SqlInstance $TestConfig.instance1 -Database bigtestrest -Path "$($TestConfig.appveyorlabrepo)\sql2008-backups\db1\FULL" -ReplaceDbNameInFile + Backup-DbaDatabase -SqlInstance $TestConfig.instance1 -Database bigtestrest + $results1 = Restore-DbaDatabase -SqlInstance $TestConfig.instance1 -Database smalltestrest -Path "$($TestConfig.appveyorlabrepo)\sql2008-backups\db2\FULL\SQL2008_db2_FULL_20170518_041738.bak" -ReplaceDbNameInFile + Backup-DbaDatabase -SqlInstance $TestConfig.instance1 -Database smalltestrest - $results = Test-DbaLastBackup -SqlInstance $script:instance1 -Database bigtestrest, smalltestrest -CopyFile -CopyPath c:\temp -MaxSize 3 -Prefix testlast + $results = Test-DbaLastBackup -SqlInstance $TestConfig.instance1 -Database bigtestrest, smalltestrest -CopyFile -CopyPath c:\temp -MaxSize 3 -Prefix testlast $fileresult = Get-ChildItem c:\temp | Where-Object { $_.name -like '*bigtestrest' } It "Should have skipped bigtestrest and tested smalltestrest" { $results[0].RestoreResult | Should -BeLike '*exceeds the specified maximum*' @@ -108,6 +108,6 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { ($null -eq $fileresult) | Should -Be $true } - Get-DbaDatabase -SqlInstance $script:instance1 -Database bigtestrest, smalltestrest | Remove-DbaDatabase -confirm:$false + Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database bigtestrest, smalltestrest | Remove-DbaDatabase -confirm:$false } -} \ No newline at end of file +} diff --git a/tests/Test-DbaLinkedServerConnection.Tests.ps1 b/tests/Test-DbaLinkedServerConnection.Tests.ps1 index 44e99de0eb..540447dcf4 100644 --- a/tests/Test-DbaLinkedServerConnection.Tests.ps1 +++ b/tests/Test-DbaLinkedServerConnection.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,17 +15,17 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { - Get-DbaProcess -SqlInstance $script:instance1 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue - $server = Connect-DbaInstance -SqlInstance $script:instance1 -Database master + Get-DbaProcess -SqlInstance $TestConfig.instance1 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance1 -Database master $server.Query("EXEC master.dbo.sp_addlinkedserver @server = N'localhost', @srvproduct=N'SQL Server'") } AfterAll { - Get-DbaProcess -SqlInstance $script:instance1 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue - $server = Connect-DbaInstance -SqlInstance $script:instance1 -Database master + Get-DbaProcess -SqlInstance $TestConfig.instance1 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance1 -Database master $server.Query("EXEC master.dbo.sp_dropserver @server=N'localhost', @droplogins='droplogins'") } Context "Function works" { - $results = Test-DbaLinkedServerConnection -SqlInstance $script:instance1 | Where-Object LinkedServerName -eq 'localhost' + $results = Test-DbaLinkedServerConnection -SqlInstance $TestConfig.instance1 | Where-Object LinkedServerName -eq 'localhost' It "function returns results" { $results | Should Not BeNullOrEmpty } @@ -38,7 +38,7 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { } Context "Piping to function works" { - $pipeResults = Get-DbaLinkedServer -SqlInstance $script:instance1 | Test-DbaLinkedServerConnection + $pipeResults = Get-DbaLinkedServer -SqlInstance $TestConfig.instance1 | Test-DbaLinkedServerConnection It "piping from Get-DbaLinkedServerConnection returns results" { $pipeResults | Should Not BeNullOrEmpty } @@ -49,4 +49,4 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { $pipeResults.Connectivity | Should BeTrue } } -} \ No newline at end of file +} diff --git a/tests/Test-DbaLoginPassword.Tests.ps1 b/tests/Test-DbaLoginPassword.Tests.ps1 index 12769f6703..01d8b7247e 100644 --- a/tests/Test-DbaLoginPassword.Tests.ps1 +++ b/tests/Test-DbaLoginPassword.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig . "$PSScriptRoot\..\private\functions\Get-PasswordHash.ps1" Describe "$CommandName Unit Tests" -Tag UnitTests, Get-DbaLogin { @@ -16,10 +16,10 @@ Describe "$CommandName Unit Tests" -Tag UnitTests, Get-DbaLogin { Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance1 $weaksauce = "dbatoolsci_testweak" $weakpass = ConvertTo-SecureString $weaksauce -AsPlainText -Force - $newlogin = New-DbaLogin -SqlInstance $script:instance1 -Login $weaksauce -HashedPassword (Get-PasswordHash $weakpass $server.VersionMajor) -Force + $newlogin = New-DbaLogin -SqlInstance $TestConfig.instance1 -Login $weaksauce -HashedPassword (Get-PasswordHash $weakpass $server.VersionMajor) -Force } AfterAll { try { @@ -31,16 +31,16 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { Context "making sure command works" { It "finds the new weak password and supports piping" { - $results = Get-DbaLogin -SqlInstance $script:instance1 | Test-DbaLoginPassword + $results = Get-DbaLogin -SqlInstance $TestConfig.instance1 | Test-DbaLoginPassword $results.SqlLogin | Should -Contain $weaksauce } It "returns just one login" { - $results = Test-DbaLoginPassword -SqlInstance $script:instance1 -Login $weaksauce + $results = Test-DbaLoginPassword -SqlInstance $TestConfig.instance1 -Login $weaksauce $results.SqlLogin | Should -Be $weaksauce } It "handles passwords with quotes, see #9095" { - $results = Test-DbaLoginPassword -SqlInstance $script:instance1 -Login $weaksauce -Dictionary "&é`"'(-", "hello" + $results = Test-DbaLoginPassword -SqlInstance $TestConfig.instance1 -Login $weaksauce -Dictionary "&é`"'(-", "hello" $results.SqlLogin | Should -Be $weaksauce } } -} \ No newline at end of file +} diff --git a/tests/Test-DbaLsnChain.Tests.ps1 b/tests/Test-DbaLsnChain.Tests.ps1 index cbead55f62..e93ce1393f 100644 --- a/tests/Test-DbaLsnChain.Tests.ps1 +++ b/tests/Test-DbaLsnChain.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig . "$PSScriptRoot\..\private\functions\Test-DbaLsnChain.ps1" Describe "$commandname Unit Tests" -Tag 'UnitTests' { diff --git a/tests/Test-DbaManagementObject.Tests.ps1 b/tests/Test-DbaManagementObject.Tests.ps1 index cc21b3a156..e2c37b2adf 100644 --- a/tests/Test-DbaManagementObject.Tests.ps1 +++ b/tests/Test-DbaManagementObject.Tests.ps1 @@ -3,7 +3,7 @@ #> $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig <# Unit test is required for any command added @@ -20,10 +20,10 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { } Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $versionMajor = (Connect-DbaInstance -SqlInstance $script:instance2).VersionMajor + $versionMajor = (Connect-DbaInstance -SqlInstance $TestConfig.instance2).VersionMajor } Context "Command actually works" { - $trueResults = Test-DbaManagementObject -ComputerName $script:instance2 -VersionNumber $versionMajor + $trueResults = Test-DbaManagementObject -ComputerName $TestConfig.instance2 -VersionNumber $versionMajor It "Should have correct properties" { $ExpectedProps = 'ComputerName,Version,Exists'.Split(',') ($trueResults[0].PsObject.Properties.Name | Sort-Object) | Should Be ($ExpectedProps | Sort-Object) @@ -33,9 +33,9 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $trueResults.Exists | Should Be $true } - $falseResults = Test-DbaManagementObject -ComputerName $script:instance2 -VersionNumber -1 + $falseResults = Test-DbaManagementObject -ComputerName $TestConfig.instance2 -VersionNumber -1 It "Should return false for VersionNumber -1" { $falseResults.Exists | Should Be $false } } -} \ No newline at end of file +} diff --git a/tests/Test-DbaMaxDop.Tests.ps1 b/tests/Test-DbaMaxDop.Tests.ps1 index 483e87b7c6..e58895c3ff 100644 --- a/tests/Test-DbaMaxDop.Tests.ps1 +++ b/tests/Test-DbaMaxDop.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,24 +15,24 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BeforeAll { - Get-DbaProcess -SqlInstance $script:instance2 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue - $server = Connect-DbaInstance -SqlInstance $script:instance2 + Get-DbaProcess -SqlInstance $TestConfig.instance2 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $db1 = "dbatoolsci_testMaxDop" $server.Query("CREATE DATABASE dbatoolsci_testMaxDop") - $needed = Get-DbaDatabase -SqlInstance $script:instance2 -Database $db1 + $needed = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $db1 $setupright = $true if (-not $needed) { $setupright = $false } } AfterAll { - Get-DbaDatabase -SqlInstance $script:instance2 -Database $db1 | Remove-DbaDatabase -Confirm:$false + Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $db1 | Remove-DbaDatabase -Confirm:$false } # Just not messin with this in appveyor if ($setupright) { Context "Command works on SQL Server 2016 or higher instances" { - $results = Test-DbaMaxDop -SqlInstance $script:instance2 + $results = Test-DbaMaxDop -SqlInstance $TestConfig.instance2 It "Should have correct properties" { $ExpectedProps = 'ComputerName,InstanceName,SqlInstance,Database,DatabaseMaxDop,CurrentInstanceMaxDop,RecommendedMaxDop,Notes'.Split(',') @@ -46,4 +46,4 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } } } -} \ No newline at end of file +} diff --git a/tests/Test-DbaMaxMemory.Tests.ps1 b/tests/Test-DbaMaxMemory.Tests.ps1 index 42ccd86d58..fb9506b81d 100644 --- a/tests/Test-DbaMaxMemory.Tests.ps1 +++ b/tests/Test-DbaMaxMemory.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Validate parameters" { diff --git a/tests/Test-DbaMigrationConstraint.Tests.ps1 b/tests/Test-DbaMigrationConstraint.Tests.ps1 index 62164d3e94..54bcdccd3d 100644 --- a/tests/Test-DbaMigrationConstraint.Tests.ps1 +++ b/tests/Test-DbaMigrationConstraint.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,12 +15,12 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tag 'IntegrationTests' { BeforeAll { - Get-DbaProcess -SqlInstance $script:instance1 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue + Get-DbaProcess -SqlInstance $TestConfig.instance1 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue $db1 = "dbatoolsci_testMigrationConstraint" $db2 = "dbatoolsci_testMigrationConstraint_2" - Invoke-DbaQuery -SqlInstance $script:instance1 -Query "CREATE DATABASE $db1" - Invoke-DbaQuery -SqlInstance $script:instance1 -Query "CREATE DATABASE $db2" - $needed = Get-DbaDatabase -SqlInstance $script:instance1 -Database $db1, $db2 + Invoke-DbaQuery -SqlInstance $TestConfig.instance1 -Query "CREATE DATABASE $db1" + Invoke-DbaQuery -SqlInstance $TestConfig.instance1 -Query "CREATE DATABASE $db2" + $needed = Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $db1, $db2 $setupright = $true if ($needed.Count -ne 2) { $setupright = $false @@ -31,12 +31,12 @@ Describe "$CommandName Integration Tests" -Tag 'IntegrationTests' { } AfterAll { if (-not $appveyor) { - Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance1 -Database $db1, $db2 -ErrorAction SilentlyContinue + Remove-DbaDatabase -Confirm:$false -SqlInstance $TestConfig.instance1 -Database $db1, $db2 -ErrorAction SilentlyContinue } } Context "Validate multiple databases" { It 'Both databases are migratable' { - $results = Test-DbaMigrationConstraint -Source $script:instance1 -Destination $script:instance2 + $results = Test-DbaMigrationConstraint -Source $TestConfig.instance1 -Destination $TestConfig.instance2 foreach ($result in $results) { $result.IsMigratable | Should Be $true } @@ -44,7 +44,7 @@ Describe "$CommandName Integration Tests" -Tag 'IntegrationTests' { } Context "Validate single database" { It 'Databases are migratable' { - (Test-DbaMigrationConstraint -Source $script:instance1 -Destination $script:instance2 -Database $db1).IsMigratable | Should Be $true + (Test-DbaMigrationConstraint -Source $TestConfig.instance1 -Destination $TestConfig.instance2 -Database $db1).IsMigratable | Should Be $true } } -} \ No newline at end of file +} diff --git a/tests/Test-DbaNetworkLatency.Tests.ps1 b/tests/Test-DbaNetworkLatency.Tests.ps1 index 87cb9181f5..eae726ce58 100644 --- a/tests/Test-DbaNetworkLatency.Tests.ps1 +++ b/tests/Test-DbaNetworkLatency.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,13 +15,13 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Command returns proper info" { - $results = $instances | Test-DbaNetworkLatency + $results = $TestConfig.instances | Test-DbaNetworkLatency It "returns two objects" { $results.Count | Should Be 2 } - $results = Test-DbaNetworkLatency -SqlInstance $instances + $results = Test-DbaNetworkLatency -SqlInstance $TestConfig.instances It "executes 3 times by default" { $results.ExecutionCount | Should Be 3, 3 diff --git a/tests/Test-DbaOptimizeForAdHoc.Tests.ps1 b/tests/Test-DbaOptimizeForAdHoc.Tests.ps1 index fb88a27eda..eeda5ddb63 100644 --- a/tests/Test-DbaOptimizeForAdHoc.Tests.ps1 +++ b/tests/Test-DbaOptimizeForAdHoc.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,7 +15,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Command actually works" { - $results = Test-DbaOptimizeForAdHoc -SqlInstance $script:instance2 + $results = Test-DbaOptimizeForAdHoc -SqlInstance $TestConfig.instance2 It "Should return result for the server" { $results | Should Not Be Null } @@ -26,4 +26,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $results.RecommendedOptimizeAdHoc | Should BeOfType System.Int32 } } -} \ No newline at end of file +} diff --git a/tests/Test-DbaPath.Tests.ps1 b/tests/Test-DbaPath.Tests.ps1 index d5495a0bde..ce608cf69a 100644 --- a/tests/Test-DbaPath.Tests.ps1 +++ b/tests/Test-DbaPath.Tests.ps1 @@ -3,7 +3,7 @@ #> $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig <# Unit test is required for any command added @@ -21,7 +21,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $trueTest = (Get-DbaDbFile -SqlInstance $script:instance2 -Database master)[0].PhysicalName + $trueTest = (Get-DbaDbFile -SqlInstance $TestConfig.instance2 -Database master)[0].PhysicalName if ($trueTest.Length -eq 0) { It "has failed setup" { Set-TestInconclusive -message "Setup failed" @@ -31,32 +31,32 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $trueTestPath = [System.IO.Path]::GetDirectoryName($trueTest) } Context "Command actually works" { - $result = Test-DbaPath -SqlInstance $script:instance2 -Path $trueTest + $result = Test-DbaPath -SqlInstance $TestConfig.instance2 -Path $trueTest It "Should only return true if the path IS accessible to the instance" { $result | Should Be $true } - $result = Test-DbaPath -SqlInstance $script:instance2 -Path $falseTest + $result = Test-DbaPath -SqlInstance $TestConfig.instance2 -Path $falseTest It "Should only return false if the path IS NOT accessible to the instance" { $result | Should Be $false } - $results = Test-DbaPath -SqlInstance $script:instance2 -Path $trueTest, $falseTest + $results = Test-DbaPath -SqlInstance $TestConfig.instance2 -Path $trueTest, $falseTest It "Should return multiple results when passed multiple paths" { ($results | Where-Object FilePath -eq $trueTest).FileExists | Should Be $true ($results | Where-Object FilePath -eq $falseTest).FileExists | Should Be $false } - $results = Test-DbaPath -SqlInstance $script:instance2, $script:instance1 -Path $falseTest + $results = Test-DbaPath -SqlInstance $TestConfig.instance2, $TestConfig.instance1 -Path $falseTest It "Should return multiple results when passed multiple instances" { foreach ($result in $results) { $result.FileExists | Should Be $false } ($results.SqlInstance | Sort-Object -Unique).Count | Should Be 2 } - $results = Test-DbaPath -SqlInstance $script:instance2 -Path @($trueTest) + $results = Test-DbaPath -SqlInstance $TestConfig.instance2 -Path @($trueTest) It "Should return pscustomobject results when passed an array (even with one path)" { ($results | Where-Object FilePath -eq $trueTest).FileExists | Should Be $true } - $results = Test-DbaPath -SqlInstance $script:instance2 -Path @($trueTest, $trueTestPath) + $results = Test-DbaPath -SqlInstance $TestConfig.instance2 -Path @($trueTest, $trueTestPath) It "Should return pscustomobject results indicating if the path is a file or a directory" { ($results | Where-Object FilePath -eq $trueTest).FileExists | Should Be $true ($results | Where-Object FilePath -eq $trueTestPath).FileExists | Should Be $true @@ -64,4 +64,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { ($results | Where-Object FilePath -eq $trueTestPath).IsContainer | Should Be $true } } -} \ No newline at end of file +} diff --git a/tests/Test-DbaPowerPlan.Tests.ps1 b/tests/Test-DbaPowerPlan.Tests.ps1 index abbddba28a..0f51e95ebc 100644 --- a/tests/Test-DbaPowerPlan.Tests.ps1 +++ b/tests/Test-DbaPowerPlan.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,11 +15,11 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $null = Set-DbaPowerPlan -ComputerName $script:instance2 -PowerPlan 'Balanced' + $null = Set-DbaPowerPlan -ComputerName $TestConfig.instance2 -PowerPlan 'Balanced' } Context "Command actually works" { It "Should return result for the server" { - $results = Test-DbaPowerPlan -ComputerName $script:instance2 + $results = Test-DbaPowerPlan -ComputerName $TestConfig.instance2 $results | Should Not Be Null $results.ActivePowerPlan | Should Be 'Balanced' $results.RecommendedPowerPlan | Should Be 'High performance' @@ -27,8 +27,8 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $results.IsBestPractice | Should Be $false } It "Use 'Balanced' plan as best practice" { - $results = Test-DbaPowerPlan -ComputerName $script:instance2 -PowerPlan 'Balanced' + $results = Test-DbaPowerPlan -ComputerName $TestConfig.instance2 -PowerPlan 'Balanced' $results.IsBestPractice | Should Be $true } } -} \ No newline at end of file +} diff --git a/tests/Test-DbaReplLatency.Tests.ps1 b/tests/Test-DbaReplLatency.Tests.ps1 index de02df1513..ae78526ba1 100644 --- a/tests/Test-DbaReplLatency.Tests.ps1 +++ b/tests/Test-DbaReplLatency.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$commandname Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Test-DbaSpn.Tests.ps1 b/tests/Test-DbaSpn.Tests.ps1 index b6b2997477..abb10c9e69 100644 --- a/tests/Test-DbaSpn.Tests.ps1 +++ b/tests/Test-DbaSpn.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Test-DbaTempDbConfig.Tests.ps1 b/tests/Test-DbaTempDbConfig.Tests.ps1 index fb18f273dd..7ef060516b 100644 --- a/tests/Test-DbaTempDbConfig.Tests.ps1 +++ b/tests/Test-DbaTempDbConfig.Tests.ps1 @@ -3,7 +3,7 @@ #> $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig <# Unit test is required for any command added @@ -20,8 +20,8 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { } Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { - Context "Command actually works on $script:instance2" { - $server = Connect-DbaInstance -SqlInstance $script:instance2 + Context "Command actually works on $($TestConfig.instance2)" { + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $results = Test-DbaTempdbConfig -SqlInstance $server It "Should have correct properties" { $ExpectedProps = 'ComputerName,InstanceName,SqlInstance,Rule,Recommended,CurrentSetting,IsBestPractice,Notes'.Split(',') @@ -51,4 +51,4 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { ($results | Where-Object Rule -match $rule).Recommended | Should Be $recommended } } -} \ No newline at end of file +} diff --git a/tests/Test-DbaWindowsLogin.Tests.ps1 b/tests/Test-DbaWindowsLogin.Tests.ps1 index 312629e0b0..5a5a59dda6 100644 --- a/tests/Test-DbaWindowsLogin.Tests.ps1 +++ b/tests/Test-DbaWindowsLogin.Tests.ps1 @@ -3,7 +3,7 @@ #> $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig <# Unit test is required for any command added @@ -22,7 +22,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Did not include these tests yet as I was unsure if AppVeyor was capable of testing domain logins. Included these for future use. Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Command actually works" { - $results = Test-DbaWindowsLogin -SqlInstance $script:instance2 + $results = Test-DbaWindowsLogin -SqlInstance $TestConfig.instance2 It "Should return correct properties" { $ExpectedProps = 'AccountNotDelegated,AllowReversiblePasswordEncryption,CannotChangePassword,DisabledInSQLServer,Domain,Enabled,Found,LockedOut,Login,PasswordExpired,PasswordNeverExpires,PasswordNotRequired,Server,SmartcardLogonRequired,TrustedForDelegation,Type,UserAccountControl'.Split(',') ($results[0].PsObject.Properties.Name | Sort-Object) | Should Be ($ExpectedProps | Sort-Object) @@ -36,4 +36,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { ($results | Where-Object Found).Found | Should Be $true } } -}#> \ No newline at end of file +}#> diff --git a/tests/Test-PSRemoting.Tests.ps1 b/tests/Test-PSRemoting.Tests.ps1 index 2c9242a54a..b4856f2cc0 100644 --- a/tests/Test-PSRemoting.Tests.ps1 +++ b/tests/Test-PSRemoting.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig . "$PSScriptRoot\..\private\functions\Test-PSRemoting.ps1" @@ -27,9 +27,9 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } Context "handles an instance, using just the computername" { - $result = Test-PSRemoting -ComputerName $script:instance1 + $result = Test-PSRemoting -ComputerName $TestConfig.instance1 It "returns $true when succeeding" { $result | Should Be $true } } -} \ No newline at end of file +} diff --git a/tests/Uninstall-DbaSqlWatch.Tests.ps1 b/tests/Uninstall-DbaSqlWatch.Tests.ps1 index c3acdcb9b8..344f300d54 100644 --- a/tests/Uninstall-DbaSqlWatch.Tests.ps1 +++ b/tests/Uninstall-DbaSqlWatch.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -17,31 +17,31 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Testing SqlWatch uninstaller" { BeforeAll { $database = "dbatoolsci_sqlwatch_$(Get-Random)" - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $server.Query("CREATE DATABASE $database") - Install-DbaSqlWatch -SqlInstance $script:instance2 -Database $database - Uninstall-DbaSqlWatch -SqlInstance $script:instance2 -Database $database + Install-DbaSqlWatch -SqlInstance $TestConfig.instance2 -Database $database + Uninstall-DbaSqlWatch -SqlInstance $TestConfig.instance2 -Database $database } AfterAll { - Remove-DbaDatabase -SqlInstance $script:instance2 -Database $database -Confirm:$false + Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $database -Confirm:$false } It "Removed all tables" { - $tableCount = (Get-DbaDbTable -SqlInstance $script:instance2 -Database $Database | Where-Object {($PSItem.Name -like "sql_perf_mon_*") -or ($PSItem.Name -like "logger_*")}).Count + $tableCount = (Get-DbaDbTable -SqlInstance $TestConfig.instance2 -Database $Database | Where-Object {($PSItem.Name -like "sql_perf_mon_*") -or ($PSItem.Name -like "logger_*")}).Count $tableCount | Should -Be 0 } It "Removed all views" { - $viewCount = (Get-DbaDbView -SqlInstance $script:instance2 -Database $Database | Where-Object {$PSItem.Name -like "vw_sql_perf_mon_*" }).Count + $viewCount = (Get-DbaDbView -SqlInstance $TestConfig.instance2 -Database $Database | Where-Object {$PSItem.Name -like "vw_sql_perf_mon_*" }).Count $viewCount | Should -Be 0 } It "Removed all stored procedures" { - $sprocCount = (Get-DbaDbStoredProcedure -SqlInstance $script:instance2 -Database $Database | Where-Object {($PSItem.Name -like "sp_sql_perf_mon_*") -or ($PSItem.Name -like "usp_logger_*")}).Count + $sprocCount = (Get-DbaDbStoredProcedure -SqlInstance $TestConfig.instance2 -Database $Database | Where-Object {($PSItem.Name -like "sp_sql_perf_mon_*") -or ($PSItem.Name -like "usp_logger_*")}).Count $sprocCount | Should -Be 0 } It "Removed all SQL Agent jobs" { - $agentCount = (Get-DbaAgentJob -SqlInstance $script:instance2 | Where-Object {($PSItem.Name -like "SqlWatch-*") -or ($PSItem.Name -like "DBA-PERF-*")}).Count + $agentCount = (Get-DbaAgentJob -SqlInstance $TestConfig.instance2 | Where-Object {($PSItem.Name -like "SqlWatch-*") -or ($PSItem.Name -like "DBA-PERF-*")}).Count $agentCount | Should -Be 0 } } -} \ No newline at end of file +} diff --git a/tests/Unregister-DbatoolsConfig.Tests.ps1 b/tests/Unregister-DbatoolsConfig.Tests.ps1 index 30ea3b069b..b04a026752 100644 --- a/tests/Unregister-DbatoolsConfig.Tests.ps1 +++ b/tests/Unregister-DbatoolsConfig.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Update-DbaBuildReference.Tests.ps1 b/tests/Update-DbaBuildReference.Tests.ps1 index ef2227e6b5..5f20195cad 100644 --- a/tests/Update-DbaBuildReference.Tests.ps1 +++ b/tests/Update-DbaBuildReference.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Update-DbaInstance.Tests.ps1 b/tests/Update-DbaInstance.Tests.ps1 index c290c3eac7..2721a9e7c2 100644 --- a/tests/Update-DbaInstance.Tests.ps1 +++ b/tests/Update-DbaInstance.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig $exeDir = "C:\Temp\dbatools_$CommandName" @@ -841,9 +841,9 @@ Describe "$CommandName Integration Tests" -Tag 'IntegrationTests' { } Context "WhatIf upgrade target instance to latest SPCU" { It "Should whatif-upgrade to latest SPCU" { - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance1 $instance = $server.ServiceName - $null = Update-DbaInstance -ComputerName $script:instance1 -Path $exeDir -Restart -EnableException -WhatIf -InstanceName $instance 3>$null + $null = Update-DbaInstance -ComputerName $TestConfig.instance1 -Path $exeDir -Restart -EnableException -WhatIf -InstanceName $instance 3>$null $testBuild = Test-DbaBuild -SqlInstance $server -MaxBehind 0CU Assert-MockCalled -CommandName Test-PendingReboot -Scope It -ModuleName dbatools Assert-MockCalled -CommandName Test-ElevationRequirement -Scope It -ModuleName dbatools @@ -852,4 +852,4 @@ Describe "$CommandName Integration Tests" -Tag 'IntegrationTests' { } } } -} \ No newline at end of file +} diff --git a/tests/Update-DbaMaintenanceSolution.Tests.ps1 b/tests/Update-DbaMaintenanceSolution.Tests.ps1 index c58ab011b4..d4a4bee685 100644 --- a/tests/Update-DbaMaintenanceSolution.Tests.ps1 +++ b/tests/Update-DbaMaintenanceSolution.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Update-DbaServiceAccount.Tests.ps1 b/tests/Update-DbaServiceAccount.Tests.ps1 index 6133429b3b..e8b2e1af9f 100644 --- a/tests/Update-DbaServiceAccount.Tests.ps1 +++ b/tests/Update-DbaServiceAccount.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -21,7 +21,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $securePassword = ConvertTo-SecureString $password -AsPlainText -Force $newPassword = 'Myxtr33mly$ecur3P@ssw0rd' $newSecurePassword = ConvertTo-SecureString $newPassword -AsPlainText -Force - $server = Connect-DbaInstance -SqlInstance $script:instance2 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $computerName = $server.NetName $instanceName = $server.ServiceName $winLogin = "$computerName\$login" @@ -35,7 +35,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } } catch { <#User does not exist#> } - if ($l = Get-DbaLogin -SqlInstance $script:instance2 -Login $winLogin) { + if ($l = Get-DbaLogin -SqlInstance $TestConfig.instance2 -Login $winLogin) { $results = $server.Query("IF EXISTS (SELECT * FROM sys.server_principals WHERE name = '$winLogin') EXEC sp_who '$winLogin'") foreach ($spid in $results.spid) { $null = $server.Query("kill $spid") @@ -51,7 +51,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $user.SetInfo() #Get current service users - $services = Get-DbaService -ComputerName $script:instance2 -Type Engine, Agent -Instance $instanceName + $services = Get-DbaService -ComputerName $TestConfig.instance2 -Type Engine, Agent -Instance $instanceName $currentAgentUser = ($services | Where-Object { $_.ServiceType -eq 'Agent' }).StartName $currentEngineUser = ($services | Where-Object { $_.ServiceType -eq 'Engine' }).StartName @@ -205,4 +205,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } -} \ No newline at end of file +} diff --git a/tests/Update-dbatools.Tests.ps1 b/tests/Update-dbatools.Tests.ps1 index ffce1850d9..cd45e353f3 100644 --- a/tests/Update-dbatools.Tests.ps1 +++ b/tests/Update-dbatools.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { diff --git a/tests/Watch-DbaDbLogin.Tests.ps1 b/tests/Watch-DbaDbLogin.Tests.ps1 index b00f74aa8a..a1707fc30b 100644 --- a/tests/Watch-DbaDbLogin.Tests.ps1 +++ b/tests/Watch-DbaDbLogin.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -20,47 +20,47 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $tableName2 = 'dbatoolsciwatchdblogin2' $tableName3 = 'dbatoolsciwatchdblogin3' $databaseName = "dbatoolsci_$random" - $newDb = New-DbaDatabase -SqlInstance $script:instance1 -Name $databaseName + $newDb = New-DbaDatabase -SqlInstance $TestConfig.instance1 -Name $databaseName $testFile = 'C:\temp\Servers_$random.txt' if (Test-Path $testFile) { Remove-Item $testFile -Force } - $script:instance1, $script:instance2 | Out-File $testFile + $TestConfig.instance1, $TestConfig.instance2 | Out-File $testFile - $server1 = Connect-DbaInstance -SqlInstance $script:instance1 - $server2 = Connect-DbaInstance -SqlInstance $script:instance2 + $server1 = Connect-DbaInstance -SqlInstance $TestConfig.instance1 + $server2 = Connect-DbaInstance -SqlInstance $TestConfig.instance2 - $regServer1 = Add-DbaRegServer -SqlInstance $script:instance1 -ServerName $script:instance1 -Name "dbatoolsci_instance1_$random" - $regServer2 = Add-DbaRegServer -SqlInstance $script:instance1 -ServerName $script:instance2 -Name "dbatoolsci_instance2_$random" + $regServer1 = Add-DbaRegServer -SqlInstance $TestConfig.instance1 -ServerName $TestConfig.instance1 -Name "dbatoolsci_instance1_$random" + $regServer2 = Add-DbaRegServer -SqlInstance $TestConfig.instance1 -ServerName $TestConfig.instance2 -Name "dbatoolsci_instance2_$random" } AfterAll { $null = $newDb | Remove-DbaDatabase -Confirm:$false - Get-DbaRegServer -SqlInstance $script:instance1 | Where-Object Name -match dbatoolsci | Remove-DbaRegServer -Confirm:$false + Get-DbaRegServer -SqlInstance $TestConfig.instance1 | Where-Object Name -match dbatoolsci | Remove-DbaRegServer -Confirm:$false } Context "Command actually works" { It "ServersFromFile" { - Watch-DbaDbLogin -SqlInstance $script:instance1 -Database $databaseName -Table $tableName1 -ServersFromFile $testFile -EnableException - $result = Get-DbaDbTable -SqlInstance $script:instance1 -Database $databaseName -Table $tableName1 -IncludeSystemDBs + Watch-DbaDbLogin -SqlInstance $TestConfig.instance1 -Database $databaseName -Table $tableName1 -ServersFromFile $testFile -EnableException + $result = Get-DbaDbTable -SqlInstance $TestConfig.instance1 -Database $databaseName -Table $tableName1 -IncludeSystemDBs $result.Name | Should Be $tableName1 $result.Count | Should BeGreaterThan 0 } It "Pipeline of instances" { - $server1, $server2 | Watch-DbaDbLogin -SqlInstance $script:instance1 -Database $databaseName -Table $tableName2 -EnableException - $result = Get-DbaDbTable -SqlInstance $script:instance1 -Database $databaseName -Table $tableName2 -IncludeSystemDBs + $server1, $server2 | Watch-DbaDbLogin -SqlInstance $TestConfig.instance1 -Database $databaseName -Table $tableName2 -EnableException + $result = Get-DbaDbTable -SqlInstance $TestConfig.instance1 -Database $databaseName -Table $tableName2 -IncludeSystemDBs $result.Name | Should Be $tableName2 $result.Count | Should BeGreaterThan 0 } It "ServersFromCMS" { - Watch-DbaDbLogin -SqlInstance $script:instance1 -Database $databaseName -Table $tableName3 -SqlCms $script:instance1 -EnableException - $result = Get-DbaDbTable -SqlInstance $script:instance1 -Database $databaseName -Table $tableName3 -IncludeSystemDBs + Watch-DbaDbLogin -SqlInstance $TestConfig.instance1 -Database $databaseName -Table $tableName3 -SqlCms $TestConfig.instance1 -EnableException + $result = Get-DbaDbTable -SqlInstance $TestConfig.instance1 -Database $databaseName -Table $tableName3 -IncludeSystemDBs $result.Name | Should Be $tableName3 $result.Count | Should BeGreaterThan 0 } } -} \ No newline at end of file +} diff --git a/tests/Watch-DbaXESession.Tests.ps1 b/tests/Watch-DbaXESession.Tests.ps1 index d6580ca56f..658d180bf2 100644 --- a/tests/Watch-DbaXESession.Tests.ps1 +++ b/tests/Watch-DbaXESession.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -17,8 +17,8 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Command functions as expected" { It "warns if SQL instance version is not supported" { - $results = Watch-DbaXESession -SqlInstance $script:instance1 -Session system_health -WarningAction SilentlyContinue -WarningVariable versionwarn + $results = Watch-DbaXESession -SqlInstance $TestConfig.instance1 -Session system_health -WarningAction SilentlyContinue -WarningVariable versionwarn $versionwarn -join '' -match "SQL Server version 11 required" | Should Be $true } } -} \ No newline at end of file +} diff --git a/tests/Write-DbaDbTableData.Tests.ps1 b/tests/Write-DbaDbTableData.Tests.ps1 index 80b9049dba..ca45261b60 100644 --- a/tests/Write-DbaDbTableData.Tests.ps1 +++ b/tests/Write-DbaDbTableData.Tests.ps1 @@ -1,6 +1,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" +$global:TestConfig = Get-TestConfig Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { @@ -15,7 +15,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance1 + $server = Connect-DbaInstance -SqlInstance $TestConfig.instance1 $random = Get-Random $db = "dbatoolsci_writedbadaatable$random" $server.Query("CREATE DATABASE $db") @@ -27,8 +27,8 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { # calling random function to throw data into a table It "defaults to dbo if no schema is specified" { $results = Get-ChildItem | ConvertTo-DbaDataTable - $results | Write-DbaDbTableData -SqlInstance $script:instance1 -Database $db -Table 'childitem' -AutoCreateTable + $results | Write-DbaDbTableData -SqlInstance $TestConfig.instance1 -Database $db -Table 'childitem' -AutoCreateTable ($server.Databases[$db].Tables | Where-Object { $_.Schema -eq 'dbo' -and $_.Name -eq 'childitem' }).Count | Should Be 1 } -} \ No newline at end of file +} diff --git a/tests/appveyor.pester.ps1 b/tests/appveyor.pester.ps1 index b1ced2ba5b..038cd00a01 100644 --- a/tests/appveyor.pester.ps1 +++ b/tests/appveyor.pester.ps1 @@ -3,7 +3,7 @@ This script will invoke Pester tests, then serialize XML results and pull them in appveyor.yml .DESCRIPTION -Internal function that creates SMO server object. +Internal function that runs pester tests .PARAMETER Finalize If Finalize is specified, we collect XML output, upload tests, and indicate build errors @@ -45,10 +45,11 @@ Set-Location $ModuleBase # required to calculate coverage $global:dbatools_dotsourcemodule = $true $dbatools_serialimport = $true -#imports the psm1 to be able to use internal functions in tests -Import-Module "$ModuleBase\dbatools.psm1" -Force + #imports the module making sure DLL is loaded ok Import-Module "$ModuleBase\dbatools.psd1" +#imports the psm1 to be able to use internal functions in tests +Import-Module "$ModuleBase\dbatools.psm1" -Force Update-TypeData -AppendPath "$ModuleBase\xml\dbatools.types.ps1xml" -ErrorAction SilentlyContinue # ( this should already be loaded by dbatools.psd1 ) Start-Sleep 5 @@ -159,23 +160,13 @@ function Get-CodecovReport($Results, $ModuleBase) { $newreport } -function Send-CodecovReport($CodecovReport) { - $params = @{ } - $params['branch'] = $env:APPVEYOR_REPO_BRANCH - $params['service'] = "appveyor" - $params['job'] = $env:APPVEYOR_ACCOUNT_NAME - if ($params['job']) { $params['job'] += '/' + $env:APPVEYOR_PROJECT_SLUG } - if ($params['job']) { $params['job'] += '/' + $env:APPVEYOR_BUILD_VERSION } - $params['build'] = $env:APPVEYOR_JOB_ID - $params['pr'] = $env:APPVEYOR_PULL_REQUEST_NUMBER - $params['slug'] = $env:APPVEYOR_REPO_NAME - $params['commit'] = $env:APPVEYOR_REPO_COMMIT - Add-Type -AssemblyName System.Web - $CodeCovParams = [System.Web.HttpUtility]::ParseQueryString([String]::Empty) - $params.GetEnumerator() | Where-Object Value | ForEach-Object { $CodeCovParams.Add($_.Name, $_.Value) } - $Request = [System.UriBuilder]('https://codecov.io/upload/v2') - $Request.Query = $CodeCovParams.ToString() - Invoke-RestMethod -Uri $Request.Uri -Method Post -InFile $CodecovReport -ContentType 'multipart/form-data' +function Get-PesterTestVersion($testFilePath) { + $testFileContent = Get-Content -Path $testFilePath -Raw + if ($testFileContent -match 'HaveParameter') + { + return '5' + } + return '4' } @@ -188,15 +179,19 @@ if (-not $Finalize) { #Run a test with the current version of PowerShell #Make things faster by removing most output if (-not $Finalize) { - Import-Module Pester - Write-Host -Object "appveyor.pester: Running with Pester Version $((Get-Command Invoke-Pester -ErrorAction SilentlyContinue).Version)" -ForegroundColor DarkGreen Set-Variable ProgressPreference -Value SilentlyContinue if ($AllScenarioTests.Count -eq 0) { Write-Host -ForegroundColor DarkGreen "Nothing to do in this scenario" return } + # Remove any previously loaded pester module + Remove-Module -Name pester -ErrorAction SilentlyContinue + # Import pester 4 + Import-Module pester -RequiredVersion 4.4.2 + Write-Host -Object "appveyor.pester: Running with Pester Version $((Get-Command Invoke-Pester -ErrorAction SilentlyContinue).Version)" -ForegroundColor DarkGreen # invoking a single invoke-pester consumes too much memory, let's go file by file $AllTestsWithinScenario = Get-ChildItem -File -Path $AllScenarioTests + #start the round for pester 4 tests $Counter = 0 foreach ($f in $AllTestsWithinScenario) { $Counter += 1 @@ -205,6 +200,13 @@ if (-not $Finalize) { 'Show' = 'None' 'PassThru' = $true } + #get if this test should run on pester 4 or pester 5 + $pesterVersionToUse = Get-PesterTestVersion -testFilePath $f.FullName + if ($pesterVersionToUse -eq '5') { + # we're in the "region" of pester 4, so skip + continue + } + #opt-in if ($IncludeCoverage) { $CoverFiles = Get-CoverageIndications -Path $f -ModuleBase $ModuleBase @@ -218,7 +220,7 @@ if (-not $Finalize) { if ($trialNo -eq 1) { $appvTestName = $f.Name } else { - $appvTestName = "$f.Name, attempt #$trialNo" + $appvTestName = "$($f.Name), attempt #$trialNo" } Add-AppveyorTest -Name $appvTestName -Framework NUnit -FileName $f.FullName -Outcome Running $PesterRun = Invoke-Pester @PesterSplat @@ -233,6 +235,56 @@ if (-not $Finalize) { } } } + + #start the round for pester 5 tests + # Remove any previously loaded pester module + Remove-Module -Name pester -ErrorAction SilentlyContinue + # Import pester 4 + Import-Module pester -RequiredVersion 5.6.1 + Write-Host -Object "appveyor.pester: Running with Pester Version $((Get-Command Invoke-Pester -ErrorAction SilentlyContinue).Version)" -ForegroundColor DarkGreen + $Counter = 0 + foreach ($f in $AllTestsWithinScenario) { + $Counter += 1 + + #get if this test should run on pester 4 or pester 5 + $pesterVersionToUse = Get-PesterTestVersion -testFilePath $f.FullName + if ($pesterVersionToUse -eq '4') { + # we're in the "region" of pester 5, so skip + continue + } + $pester5Config = New-PesterConfiguration + $pester5Config.Run.Path = $f.FullName + $pester5config.Run.PassThru = $true + #opt-in + if ($IncludeCoverage) { + $CoverFiles = Get-CoverageIndications -Path $f -ModuleBase $ModuleBase + $pester5Config.CodeCoverage.Enabled = $true + $pester5Config.CodeCoverage.Path = $CoverFiles + $pester5Config.CodeCoverage.OutputFormat = 'JaCoCo' + $pester5Config.CodeCoverage.OutputPath = "$ModuleBase\Pester5Coverage$PSVersion$Counter.xml" + } + + $trialNo = 1 + while ($trialNo -le 3) { + if ($trialNo -eq 1) { + $appvTestName = $f.Name + } else { + $appvTestName = "$($f.Name), attempt #$trialNo" + } + Add-AppveyorTest -Name $appvTestName -Framework NUnit -FileName $f.FullName -Outcome Running + $PesterRun = Invoke-Pester -Configuration $pester5config + $PesterRun | Export-Clixml -Path "$ModuleBase\Pester5Results$PSVersion$Counter.xml" + $outcome = "Passed" + if ($PesterRun.FailedCount -gt 0) { + $trialno += 1 + Update-AppveyorTest -Name $appvTestName -Framework NUnit -FileName $f.FullName -Outcome "Failed" -Duration $PesterRun.Duration.TotalMilliseconds + } else { + Update-AppveyorTest -Name $appvTestName -Framework NUnit -FileName $f.FullName -Outcome "Passed" -Duration $PesterRun.Duration.TotalMilliseconds + break + } + } + } + # Gather support package as an artifact # New-DbatoolsSupportPackage -Path $ModuleBase - turns out to be too heavy try { @@ -279,11 +331,13 @@ if (-not $Finalize) { Get-ChildItem $ModuleBase\dbatools_messages_and_errors.xml.zip | ForEach-Object { Push-AppveyorArtifact $_.FullName -FileName $_.Name } } #$totalcount = $results | Select-Object -ExpandProperty TotalCount | Measure-Object -Sum | Select-Object -ExpandProperty Sum - $failedcount = $results | Select-Object -ExpandProperty FailedCount | Measure-Object -Sum | Select-Object -ExpandProperty Sum + $failedcount = 0 + $failedcount += $results | Select-Object -ExpandProperty FailedCount | Measure-Object -Sum | Select-Object -ExpandProperty Sum if ($failedcount -gt 0) { + # pester 4 output $faileditems = $results | Select-Object -ExpandProperty TestResult | Where-Object { $_.Passed -notlike $True } if ($faileditems) { - Write-Warning "Failed tests summary:" + Write-Warning "Failed tests summary (pester 4):" $faileditems | ForEach-Object { $name = $_.Name [pscustomobject]@{ @@ -297,8 +351,31 @@ if (-not $Finalize) { throw "$failedcount tests failed." } } + + + $results5 = @(Get-ChildItem -Path "$ModuleBase\Pester5Results*.xml" | Import-Clixml) + $failedcount += $results | Select-Object -ExpandProperty FailedCount | Measure-Object -Sum | Select-Object -ExpandProperty Sum + # pester 5 output + $faileditems = $results5 | Select-Object -ExpandProperty Tests | Where-Object { $_.Passed -notlike $True } + if ($faileditems) { + Write-Warning "Failed tests summary (pester 5):" + $faileditems | ForEach-Object { + $name = $_.Name + [pscustomobject]@{ + Path = $_.Path -Join '/' + Name = "It $name" + Result = $_.Result + Message = $_.ErrorRecord -Join "" + } + } | Sort-Object Path, Name, Result, Message | Format-List + throw "$failedcount tests failed." + } + #opt-in if ($IncludeCoverage) { + # for now, this manages recreating a codecov-ingestable format for pester 4. Pester 5 uses JaCoCo natively, which + # codecov accepts ... there's only the small matter that we generate one coverage per run, and there's a run per test file + # and there's no native-powershelly-way to merge JaCoCo reports. Let's start small, and complicate our lives farther down the line. $CodecovReport = Get-CodecovReport -Results $results -ModuleBase $ModuleBase $CodecovReport | ConvertTo-Json -Depth 4 -Compress | Out-File -FilePath "$ModuleBase\PesterResultsCoverage.json" -Encoding utf8 } diff --git a/tests/appveyor.post.ps1 b/tests/appveyor.post.ps1 index a25051f33c..688d7fe675 100644 --- a/tests/appveyor.post.ps1 +++ b/tests/appveyor.post.ps1 @@ -1,7 +1,19 @@ Add-AppveyorTest -Name "appveyor.post" -Framework NUnit -FileName "appveyor.post.ps1" -Outcome Running $sw = [system.diagnostics.stopwatch]::startNew() -Write-Host -Object "appveyor.post: Sending coverage data" -ForeGroundColor DarkGreen +Write-Host -Object "appveyor.post: Sending coverage data (pester 4)" -ForeGroundColor DarkGreen Push-AppveyorArtifact PesterResultsCoverage.json -FileName "PesterResultsCoverage" -codecov -f PesterResultsCoverage.json --flag "ps,$($env:SCENARIO.ToLowerInvariant())" | Out-Null +codecov -f PesterResultsCoverage.json --flag "pester4_$($env:SCENARIO.ToLowerInvariant())" | Out-Null + +Write-Host -Object "appveyor.post: Sending coverage data (pester 5)" -ForeGroundColor DarkGreen +$ProjectRoot = $env:APPVEYOR_BUILD_FOLDER +$ModuleBase = $ProjectRoot +$pester5CoverageFiles = Get-ChildItem -Path "$ModuleBase\Pester5Coverage*.xml" +foreach($coverageFile in $pester5CoverageFiles) +{ + Write-Host -Object "appveyor.post: Sending $($coverageFile.FullName)" -ForeGroundColor DarkGreen + Push-AppveyorArtifact $coverageFile.FullName -FileName $coverageFile.Name + codecov -f $coverageFile.FullName --flag "pester5_$($env:SCENARIO.ToLowerInvariant())" | Out-Null +} + $sw.Stop() Update-AppveyorTest -Name "appveyor.post" -Framework NUnit -FileName "appveyor.post.ps1" -Outcome Passed -Duration $sw.ElapsedMilliseconds \ No newline at end of file diff --git a/tests/appveyor.prep.ps1 b/tests/appveyor.prep.ps1 index 9363d20e3b..bd00f2e055 100644 --- a/tests/appveyor.prep.ps1 +++ b/tests/appveyor.prep.ps1 @@ -19,6 +19,7 @@ git clone -q --branch=master --depth=1 https://github.com/dataplat/appveyor-lab. #Get codecov (to upload coverage results) Write-Host -Object "appveyor.prep: Install codecov" -ForegroundColor DarkGreen choco install codecov | Out-Null +#FIXME : read about the new uploader https://docs.codecov.com/docs/codecov-uploader#using-the-uploader #Get PSScriptAnalyzer (to check warnings) Write-Host -Object "appveyor.prep: Install PSScriptAnalyzer" -ForegroundColor DarkGreen @@ -33,10 +34,14 @@ if (-not(Test-Path 'C:\Program Files\WindowsPowerShell\Modules\dbatools.library' } #Get Pester (to run tests) - choco isn't working onall scenarios, weird -Write-Host -Object "appveyor.prep: Install Pester" -ForegroundColor DarkGreen +Write-Host -Object "appveyor.prep: Install Pester4" -ForegroundColor DarkGreen if (-not(Test-Path 'C:\Program Files\WindowsPowerShell\Modules\Pester\4.4.2')) { Install-Module -Name Pester -Force -SkipPublisherCheck -MaximumVersion 4.4.2 | Out-Null } +Write-Host -Object "appveyor.prep: Install Pester5" -ForegroundColor DarkGreen +if (-not(Test-Path 'C:\Program Files\WindowsPowerShell\Modules\Pester\5.6.1')) { + Install-Module -Name Pester -Force -SkipPublisherCheck -RequiredVersion 5.6.1 | Out-Null +} #Setup DbatoolsConfig Path.DbatoolsExport path Write-Host -Object "appveyor.prep: Create Path.DbatoolsExport" -ForegroundColor DarkGreen @@ -45,10 +50,6 @@ if (-not(Test-Path 'C:\Users\appveyor\Documents\DbatoolsExport')) { } -#Get opencover.portable (to run DLL tests) -Write-Host -Object "appveyor.prep: Install opencover.portable" -ForegroundColor DarkGreen -choco install opencover.portable | Out-Null - Write-Host -Object "appveyor.prep: Trust SQL Server Cert (now required)" -ForegroundColor DarkGreen Import-Module dbatools.library Import-Module C:\github\dbatools\dbatools.psd1 diff --git a/tests/constants.local.ps1.example b/tests/constants.local.ps1.example new file mode 100644 index 0000000000..ad19576648 --- /dev/null +++ b/tests/constants.local.ps1.example @@ -0,0 +1,59 @@ +# constants.local.ps1.example +# Copy this file to constants.local.ps1 and customize the values as needed. + +# Modify the $config hashtable to include your custom configurations. + +# Define your local SQL Server instances +$config['instance1'] = "localhost\SQLInstance1" # Replace with your first SQL Server instance +$config['instance2'] = "localhost\SQLInstance2" # Replace with your second SQL Server instance +$config['instance3'] = "localhost\SQLInstance3" # Replace with your third SQL Server instance + +# Array of SQL Server instances +$config['instances'] = @($config['instance1'], $config['instance2']) + +# SQL Server credentials +# Replace 'YourPassword' with your actual password and 'sa' with your username if different +$securePassword = ConvertTo-SecureString "YourPassword" -AsPlainText -Force +$config['SqlCred'] = New-Object System.Management.Automation.PSCredential ("sa", $securePassword) + +# Default parameter values for the tests +$config['PSDefaultParameterValues'] = @{ + "*:SqlCredential" = $config['SqlCred'] +} + +# Additional configurations +$config['dbatoolsci_computer'] = "localhost" # Replace if your CI computer is different + +# If using SQL authentication for Instance2, specify the username and password +$config['instance2SQLUserName'] = $null # Replace with username if applicable +$config['instance2SQLPassword'] = $null # Replace with password if applicable + +# Detailed instance name for Instance2 (if needed) +$config['instance2_detailed'] = "localhost,1433\SQLInstance2" # Adjust port and instance name as necessary + +# Path to your local AppVeyor lab repository (if applicable) +$config['appveyorlabrepo'] = "C:\path\to\appveyor-lab" # Replace with the correct path + +# SSIS Server instance +$config['ssisserver'] = "localhost\SQLInstance2" # Replace if using a different SSIS server + +# Azure Blob storage configurations (if applicable) +$config['azureblob'] = "https://yourstorageaccount.blob.core.windows.net/sql" +$config['azureblobaccount'] = "yourstorageaccount" # Replace with your Azure Storage account name + +# Azure SQL Server configurations (if applicable) +$config['azureserver'] = "yourazureserver.database.windows.net" # Replace with your Azure SQL Server name +$config['azuresqldblogin'] = "yourusername@yourdomain.com" # Replace with your Azure SQL DB login + +# Path to a large database backup file (if needed for tests) +$config['bigDatabaseBackup'] = "C:\path\to\yourdatabase.bak" # Replace with the path to your .bak file + +# URL to download the large database backup file +$config['bigDatabaseBackupSourceUrl'] = "https://yoururl.com/yourdatabase.bak" # Replace with the actual URL + +# Handle appveyor environment if needed +if ($env:appveyor) { + $config['PSDefaultParameterValues'] = @{ + '*:WarningAction' = 'SilentlyContinue' + } +} diff --git a/tests/constants.ps1 b/tests/constants.ps1 deleted file mode 100644 index c926fa203e..0000000000 --- a/tests/constants.ps1 +++ /dev/null @@ -1,49 +0,0 @@ -# constants -if (Test-Path "$PSScriptRoot\constants.local.ps1") { - Write-Host "Tests will use local constants file: tests\constants.local.ps1." -ForegroundColor Cyan - . "$PSScriptRoot\constants.local.ps1" -} elseif ($env:CODESPACES -and ($env:TERM_PROGRAM -eq 'vscode' -and $env:REMOTE_CONTAINERS)) { - $script:instance1 = "dbatools1" - $script:instance2 = "dbatools2" - $script:instance3 = "dbatools3" - $script:instances = @($script:instance1, $script:instance2) - - $SqlCred = [PSCredential]::new('sa', (ConvertTo-SecureString $env:SA_PASSWORD -AsPlainText -Force)) - $PSDefaultParameterValues = @{ - "*:SqlCredential" = $sqlCred - } -} elseif ($env:GITHUB_WORKSPACE) { - $script:dbatoolsci_computer = "localhost" - $script:instance1 = "localhost" - $script:instance2 = "localhost:14333" - $script:instance2SQLUserName = $null # placeholders for -SqlCredential testing - $script:instance2SQLPassword = $null - $script:instance3 = "localhost" - $script:instance2_detailed = "localhost,14333" #Just to make sure things parse a port properly - $script:appveyorlabrepo = "/tmp/appveyor-lab" - $instances = @($script:instance1, $script:instance2) - $ssisserver = "localhost\sql2016" - $script:azureblob = "https://dbatools.blob.core.windows.net/sql" - $script:azureblobaccount = "dbatools" - $script:azureserver = 'psdbatools.database.windows.net' - $script:azuresqldblogin = "appveyor@clemairegmail.onmicrosoft.com" -} else { - $script:dbatoolsci_computer = "localhost" - $script:instance1 = "localhost\sql2008r2sp2" - $script:instance2 = "localhost\sql2016" - $script:instance2SQLUserName = $null # placeholders for -SqlCredential testing - $script:instance2SQLPassword = $null - $script:instance3 = "localhost\sql2017" - $script:instance2_detailed = "localhost,14333\sql2016" #Just to make sure things parse a port properly - $script:appveyorlabrepo = "C:\github\appveyor-lab" - $instances = @($script:instance1, $script:instance2) - $ssisserver = "localhost\sql2016" - $script:azureblob = "https://dbatools.blob.core.windows.net/sql" - $script:azureblobaccount = "dbatools" - $script:azureserver = 'psdbatools.database.windows.net' - $script:azuresqldblogin = "appveyor@clemairegmail.onmicrosoft.com" -} - -if ($env:appveyor) { - $PSDefaultParameterValues['*:WarningAction'] = 'SilentlyContinue' -} diff --git a/tests/dbatools.Tests.ps1 b/tests/dbatools.Tests.ps1 index b68b6adaff..d1b40df797 100644 --- a/tests/dbatools.Tests.ps1 +++ b/tests/dbatools.Tests.ps1 @@ -233,17 +233,17 @@ Describe "Manifest" { { - $Script:Manifest = Test-ModuleManifest -Path $ManifestPath -ErrorAction Stop -WarningAction SilentlyContinue + $script:Manifest = Test-ModuleManifest -Path $ManifestPath -ErrorAction Stop -WarningAction SilentlyContinue } | Should Not Throw } ## Should -Be fixed now - Until the issue with requiring full paths for required assemblies is resolved need to keep this commented out RMS 01112016 -$Script:Manifest = Test-ModuleManifest -Path $ManifestPath -ErrorAction SilentlyContinue +$script:Manifest = Test-ModuleManifest -Path $ManifestPath -ErrorAction SilentlyContinue It "has a valid name" { - $Script:Manifest.Name | Should -Be $ModuleName + $script:Manifest.Name | Should -Be $ModuleName } @@ -251,7 +251,7 @@ $Script:Manifest = Test-ModuleManifest -Path $ManifestPath -ErrorAction Silently It "has a valid root module" { - $Script:Manifest.RootModule | Should -Be "$ModuleName.psm1" + $script:Manifest.RootModule | Should -Be "$ModuleName.psm1" } @@ -259,33 +259,33 @@ $Script:Manifest = Test-ModuleManifest -Path $ManifestPath -ErrorAction Silently It "has a valid Description" { - $Script:Manifest.Description | Should -Be 'Provides extra functionality for SQL Server Database admins and enables SQL Server instance migrations.' + $script:Manifest.Description | Should -Be 'Provides extra functionality for SQL Server Database admins and enables SQL Server instance migrations.' } It "has a valid Author" { - $Script:Manifest.Author | Should -Be 'Chrissy LeMaire' + $script:Manifest.Author | Should -Be 'Chrissy LeMaire' } It "has a valid Company Name" { - $Script:Manifest.CompanyName | Should -Be 'dbatools.io' + $script:Manifest.CompanyName | Should -Be 'dbatools.io' } It "has a valid guid" { - $Script:Manifest.Guid | Should -Be '9d139310-ce45-41ce-8e8b-d76335aa1789' + $script:Manifest.Guid | Should -Be '9d139310-ce45-41ce-8e8b-d76335aa1789' } It "has valid PowerShell version" { - $Script:Manifest.PowerShellVersion | Should -Be '3.0' + $script:Manifest.PowerShellVersion | Should -Be '3.0' } It "has valid required assemblies" { - {$Script:Manifest.RequiredAssemblies -eq @()} | Should -Be $true + {$script:Manifest.RequiredAssemblies -eq @()} | Should -Be $true } It "has a valid copyright" { - $Script:Manifest.CopyRight | Should BeLike '* Chrissy LeMaire' + $script:Manifest.CopyRight | Should BeLike '* Chrissy LeMaire' } @@ -299,7 +299,7 @@ $Script:Manifest = Test-ModuleManifest -Path $ManifestPath -ErrorAction Silently $FunctionNames = $FunctionFiles - $ExFunctions = $Script:Manifest.ExportedFunctions.Values.Name + $ExFunctions = $script:Manifest.ExportedFunctions.Values.Name $ExFunctions foreach ($FunctionName in $FunctionNames) @@ -311,4 +311,4 @@ $Script:Manifest = Test-ModuleManifest -Path $ManifestPath -ErrorAction Silently } } -#> \ No newline at end of file +#> diff --git a/tests/manual.pester.ps1 b/tests/manual.pester.ps1 deleted file mode 100644 index a9c006ade6..0000000000 --- a/tests/manual.pester.ps1 +++ /dev/null @@ -1,260 +0,0 @@ -<# - .SYNOPSIS - Runs dbatools tests. - - .DESCRIPTION - This is an helper to automate running tests locally - - .PARAMETER Path - The Path to the test files to run. It accepts multiple test file paths passed in (e.g. .\Find-DbaOrphanedFile.Tests.ps1) as well - as simple strings (e.g. "orphaned" will run all files matching .\*orphaned*.Tests.ps1) - - .PARAMETER Show - Gets passed down to Pester's -Show parameter (useful if you want to reduce verbosity) - - .PARAMETER PassThru - Gets passed down to Pester's -PassThru parameter (useful if you want to return an object to analyze) - - .PARAMETER TestIntegration - dbatools's suite has unittests and integrationtests. This switch enables IntegrationTests, which need live instances - see constants.ps1 for customizations - - .PARAMETER Coverage - Enables measuring code coverage on the tested function - - .PARAMETER DependencyCoverage - Enables measuring code coverage also of "lower level" (i.e. called) functions - - .PARAMETER ScriptAnalyzer - Enables checking the called function's code with Invoke-ScriptAnalyzer, with dbatools's profile - - .EXAMPLE - .\manual.pester.ps1 -Path Find-DbaOrphanedFile.Tests.ps1 -TestIntegration -Coverage -DependencyCoverage -ScriptAnalyzer - - The most complete number of checks: - - Runs both unittests and integrationtests - - Gathers and shows code coverage measurement for Find-DbaOrphanedFile and all its dependencies - - Checks Find-DbaOrphanedFile with Invoke-ScriptAnalyzer - - .EXAMPLE - .\manual.pester.ps1 -Path Find-DbaOrphanedFile.Tests.ps1 - - Runs unittests stored in Find-DbaOrphanedFile.Tests.ps1 - - .EXAMPLE - .\manual.pester.ps1 -Path Find-DbaOrphanedFile.Tests.ps1 -PassThru - - Runs unittests stored in Find-DbaOrphanedFile.Tests.ps1 and returns an object that can be analyzed - - .EXAMPLE - .\manual.pester.ps1 -Path orphan - - Runs unittests for all tests matching in `*orphan*.Tests.ps1 - - .EXAMPLE - .\manual.pester.ps1 -Path Find-DbaOrphanedFile.Tests.ps1 -Show Default - - Runs unittests stored in Find-DbaOrphanedFile.Tests.ps1, with reduced verbosity - - .EXAMPLE - .\manual.pester.ps1 -Path Find-DbaOrphanedFile.Tests.ps1 -TestIntegration - - Runs both unittests and integrationtests stored in Find-DbaOrphanedFile.Tests.ps1 - - .EXAMPLE - .\manual.pester.ps1 -Path Find-DbaOrphanedFile.Tests.ps1 -TestIntegration -Coverage - - Gathers and shows code coverage measurement for Find-DbaOrphanedFile - - .EXAMPLE - .\manual.pester.ps1 -Path Find-DbaOrphanedFile.Tests.ps1 -TestIntegration -Coverage -DependencyCoverage - - Gathers and shows code coverage measurement for Find-DbaOrphanedFile and all its dependencies - -#> - -[CmdletBinding()] -param ( - [string[]] - $Path, - - [ValidateSet('None', 'Default', 'Passed', 'Failed', 'Pending', 'Skipped', 'Inconclusive', 'Describe', 'Context', 'Summary', 'Header', 'All', 'Fails')] - [string] - $Show = "All", - - [switch] - $PassThru, - - [switch] - $TestIntegration, - - [switch] - $Coverage, - - [switch] - $DependencyCoverage, - - [switch] - $ScriptAnalyzer -) - -<# -Remove-Module -Name Pester -Import-Module -name Pester -MaximumVersion 4.* -#> - -$invokeFormatterVersion = (Get-Command Invoke-Formatter -ErrorAction SilentlyContinue).Version -$HasScriptAnalyzer = $null -ne $invokeFormatterVersion -$MinimumPesterVersion = [Version] '3.4.5.0' # Because this is when -Show was introduced -$MaximumPesterVersion = [Version] '5.0.0.0' # Because our tests (and runners) are only compatible with 4.* -$PesterVersion = (Get-Command Invoke-Pester -ErrorAction SilentlyContinue).Version -$HasPester = $null -ne $PesterVersion -$ScriptAnalyzerCorrectVersion = '1.18.2' - -if (!($HasScriptAnalyzer)) { - Write-Warning "Please install PSScriptAnalyzer" - Write-Warning " Install-Module -Name PSScriptAnalyzer -RequiredVersion '$ScriptAnalyzerCorrectVersion'" - Write-Warning " or go to https://github.com/PowerShell/PSScriptAnalyzer" -} else { - if ($invokeFormatterVersion -ne $ScriptAnalyzerCorrectVersion) { - Remove-Module PSScriptAnalyzer - try { - Import-Module PSScriptAnalyzer -RequiredVersion $ScriptAnalyzerCorrectVersion -ErrorAction Stop - } catch { - Write-Warning "Please install PSScriptAnalyzer $ScriptAnalyzerCorrectVersion" - Write-Warning " Install-Module -Name PSScriptAnalyzer -RequiredVersion '$ScriptAnalyzerCorrectVersion'" - } - } -} -if (!($HasPester)) { - Write-Warning "Please install Pester" - Write-Warning " Install-Module -Name Pester -Force -SkipPublisherCheck" - Write-Warning " or go to https://github.com/pester/Pester" -} -if ($PesterVersion -lt $MinimumPesterVersion) { - Write-Warning "Please update Pester to at least 3.4.5" - Write-Warning " Install-Module -Name Pester -MaximumVersion '4.10' -Force -SkipPublisherCheck" - Write-Warning " or go to https://github.com/pester/Pester" -} -if ($PesterVersion -gt $MaximumPesterVersion) { - Write-Warning "Please get Pester to the 4.* release" - Write-Warning " Install-Module -Name Pester -MaximumVersion '4.10' -Force -SkipPublisherCheck" - Write-Warning " or go to https://github.com/pester/Pester" -} - -if (($HasPester -and $HasScriptAnalyzer -and ($PesterVersion -ge $MinimumPesterVersion) -and ($PesterVersion -lt $MaximumPesterVersion) -and ($invokeFormatterVersion -eq $ScriptAnalyzerCorrectVersion)) -eq $false) { - Write-Warning "Exiting..." - return -} - -$ModuleBase = Split-Path -Path $PSScriptRoot -Parent - -if (-not(Test-Path "$ModuleBase\.git" -Type Container)) { - New-Item -Type Container -Path "$ModuleBase\.git" -Force -} - -#removes previously imported dbatools, if any -Remove-Module dbatools -ErrorAction Ignore -#imports the module making sure DLL is loaded ok -Import-Module "$ModuleBase\dbatools.psd1" -DisableNameChecking -#imports the psm1 to be able to use internal functions in tests -Import-Module "$ModuleBase\dbatools.psm1" -DisableNameChecking -Force - -$ScriptAnalyzerRulesExclude = @('PSUseOutputTypeCorrectly', 'PSAvoidUsingPlainTextForPassword', 'PSUseBOMForUnicodeEncodedFile') - -$testInt = $false -if ($config_TestIntegration) { - $testInt = $true -} -if ($TestIntegration) { - $testInt = $true -} - -function Get-CoverageIndications($Path, $ModuleBase) { - # takes a test file path and figures out what to analyze for coverage (i.e. dependencies) - $CBHRex = [regex]'(?smi)<#(.*)#>' - $everything = (Get-Module dbatools).ExportedCommands.Values - $everyfunction = $everything.Name - $funcs = @() - $leaf = Split-Path $path -Leaf - # assuming Get-DbaFoo.Tests.ps1 wants coverage for "Get-DbaFoo" - # but allowing also Get-DbaFoo.one.Tests.ps1 and Get-DbaFoo.two.Tests.ps1 - $func_name += ($leaf -replace '^([^.]+)(.+)?.Tests.ps1', '$1') - if ($func_name -in $everyfunction) { - $funcs += $func_name - $f = $everything | Where-Object Name -eq $func_name - $source = $f.Definition - $CBH = $CBHRex.match($source).Value - $cmdonly = $source.Replace($CBH, '') - foreach ($e in $everyfunction) { - # hacky, I know, but every occurrence of any function plus a space kinda denotes usage !? - $searchme = "$e " - if ($cmdonly.contains($searchme)) { - $funcs += $e - } - } - } - $testpaths = @() - $allfiles = Get-ChildItem -File -Path "$ModuleBase\private\functions", "$ModuleBase\public" -Filter '*.ps1' - foreach ($f in $funcs) { - # exclude always used functions ?! - if ($f -in ('Connect-DbaInstance', 'Select-DefaultView', 'Stop-Function', 'Write-Message')) { continue } - # can I find a correspondence to a physical file (again, on the convenience of having Get-DbaFoo.ps1 actually defining Get-DbaFoo)? - $res = $allfiles | Where-Object { $_.Name.Replace('.ps1', '') -eq $f } - if ($res.count -gt 0) { - $testpaths += $res.FullName - } - } - return @() + ($testpaths | Select-Object -Unique) -} - -$files = @() - -if ($Path) { - foreach ($item in $path) { - if (Test-Path $item) { - $files += Get-ChildItem -Path $item - } else { - $files += Get-ChildItem -Path "$ModuleBase\tests\*$item*.Tests.ps1" - } - } -} - -if ($files.Length -eq 0) { - Write-Warning "No tests to be run" -} - -$AllTestsWithinScenario = $files - -foreach ($f in $AllTestsWithinScenario) { - $PesterSplat = @{ - 'Script' = $f.FullName - 'Show' = $show - 'PassThru' = $passThru - } - #opt-in - $HeadFunctionPath = $f.FullName - - if ($Coverage -or $ScriptAnalyzer) { - $CoverFiles = Get-CoverageIndications -Path $f -ModuleBase $ModuleBase - $HeadFunctionPath = $CoverFiles | Select-Object -First 1 - } - if ($Coverage) { - if ($DependencyCoverage) { - $CoverFilesPester = $CoverFiles - } else { - $CoverFilesPester = $HeadFunctionPath - } - $PesterSplat['CodeCoverage'] = $CoverFilesPester - } - if (!($testInt)) { - $PesterSplat['ExcludeTag'] = "IntegrationTests" - } - Invoke-Pester @PesterSplat - if ($ScriptAnalyzer) { - if ($Show -ne "None") { - Write-Host -ForegroundColor green -Object "ScriptAnalyzer check for $HeadFunctionPath" - } - Invoke-ScriptAnalyzer -Path $HeadFunctionPath -ExcludeRule $ScriptAnalyzerRulesExclude - } -} \ No newline at end of file diff --git a/tests/pester.groups.ps1 b/tests/pester.groups.ps1 index db2fa34755..b50102d51b 100644 --- a/tests/pester.groups.ps1 +++ b/tests/pester.groups.ps1 @@ -2,11 +2,11 @@ $TestsRunGroups = @{ # run on scenario 2008R2 - "2008R2" = 'autodetect_$script:instance1' + "2008R2" = 'autodetect_$TestConfig.instance1' # run on scenario 2016 - "2016" = 'autodetect_$script:instance2' + "2016" = 'autodetect_$TestConfig.instance2' # run on scenario 2016_2017 - tests that need developer license - "2016_2017" = 'autodetect_$script:instance2,$script:instance3' + "2016_2017" = 'autodetect_$TestConfig.instance2,$TestConfig.instance3' #run on scenario service_restarts - SQL Server service tests that might disrupt other tests "service_restarts" = @( 'Start-DbaService', @@ -22,49 +22,38 @@ $TestsRunGroups = @{ ) # do not run on appveyor "appveyor_disabled" = @( - # takes too long - 'Install-DbaSqlWatch', - 'Uninstall-DbaSqlWatch', - 'Get-DbaExecutionPlan', - # Non-useful info from newly started sql servers - 'Get-DbaCpuRingBuffer', - 'Get-DbaLatchStatistic', - # fails on newer version of SMO + # tests that work locally against SQL Server 2022 instances without problems but fail on AppVeyor + 'ConvertTo-DbaXESession', + 'Export-DbaUser', + 'Get-DbaPermission', 'Get-DbaUserPermission', - 'Invoke-DbaBalanceDataFiles', - 'Invoke-DbaWhoisActive', # Works locally aganint a SQL Server 2022 instance without problems. 'Install-DbaDarlingData', - # previous tests that were failing on older versions too + 'Invoke-DbaWhoisActive', 'Remove-DbaAvailabilityGroup', - 'Read-DbaAuditFile', + 'Remove-DbaDatabaseSafely', 'Sync-DbaLoginPermission', - 'Read-DbaXEFile', - 'Stop-DbaXESession', - 'Test-DbaTempDbConfig', - #'New-DbaDbUser', - 'Stop-DbaXESession', + # tests that fail locally against SQL Server 2022 instances and fail on AppVeyor + 'Set-DbaAgentJobStep', 'New-DbaLogin', 'Watch-DbaDbLogin', - 'ConvertTo-DbaXESession', - 'Test-DbaInstanceName', - 'Test-DbaDeprecatedFeature', - 'Remove-DbaDatabaseSafely', - 'Get-DbaDbMasterKey', - 'Get-DbaPermission', - 'Test-DbaManagementObject', + # tests that fail because the command does not work + 'Copy-DbaDbCertificate', 'Export-DbaDacPackage', - 'New-DbaDbTransfer', - 'Get-DbaDbSynonym', - 'Get-DbaDbVirtualLogFile', - 'Get-DbaFile', - 'Get-DbaHelpIndex', - 'Get-DbaExternalProcess', - # just fails too often - 'Remove-DbaDbTableData', - 'Test-DbaMaxDop', - 'Test-DbaOptimizeForAdHoc', - 'New-DbaDbSnapshot' + 'Read-DbaAuditFile', + 'Read-DbaXEFile', + # takes too long + 'Install-DbaSqlWatch', + 'Uninstall-DbaSqlWatch', + 'Get-DbaExecutionPlan', + # Non-useful info from newly started sql servers + 'Get-DbaCpuRingBuffer', + 'Get-DbaLatchStatistic', + # uses a backup that only works on SQL Server 2022 + 'Get-DbaEstimatedCompletionTime', + # fix shortly, broke once we moved to Get-TestConfig + 'Remove-DbaLinkedServer' ) # do not run everywhere "disabled" = @() } +