Skip to content

Commit

Permalink
Merge pull request #1247 from PowerShell/dev
Browse files Browse the repository at this point in the history
Release of version 12.1.0.0 of SqlServerDsc
  • Loading branch information
kwirkykat authored Oct 25, 2018
2 parents cf6383a + 457082c commit 5cf11f7
Show file tree
Hide file tree
Showing 63 changed files with 3,044 additions and 294 deletions.
4 changes: 3 additions & 1 deletion .MetaTestOptIn.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@
"Common Tests - Validate Example Files",
"Common Tests - Required Script Analyzer Rules",
"Common Tests - New Error-Level Script Analyzer Rules",
"Common Tests - Custom Script Analyzer Rules"
"Common Tests - Custom Script Analyzer Rules",
"Common Tests - Validate Markdown Links",
"Common Tests - Relative Path Length"
]
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
DSCResource.Tests
DscResource.Tests
DSCResource.Tests
.vs
.vscode
node_modules
53 changes: 53 additions & 0 deletions .vscode/analyzersettings.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
@{
<#
For the custom rules to work, the DscResource.Tests repo must be
cloned. It is automatically clone as soon as any unit or
integration tests are run.
#>
CustomRulePath = '.\DSCResource.Tests\DscResource.AnalyzerRules'

IncludeRules = @(
# DSC Resource Kit style guideline rules.
'PSAvoidDefaultValueForMandatoryParameter',
'PSAvoidDefaultValueSwitchParameter',
'PSAvoidInvokingEmptyMembers',
'PSAvoidNullOrEmptyHelpMessageAttribute',
'PSAvoidUsingCmdletAliases',
'PSAvoidUsingComputerNameHardcoded',
'PSAvoidUsingDeprecatedManifestFields',
'PSAvoidUsingEmptyCatchBlock',
'PSAvoidUsingInvokeExpression',
'PSAvoidUsingPositionalParameters',
'PSAvoidShouldContinueWithoutForce',
'PSAvoidUsingWMICmdlet',
'PSAvoidUsingWriteHost',
'PSDSCReturnCorrectTypesForDSCFunctions',
'PSDSCStandardDSCFunctionsInResource',
'PSDSCUseIdenticalMandatoryParametersForDSC',
'PSDSCUseIdenticalParametersForDSC',
'PSMisleadingBacktick',
'PSMissingModuleManifestField',
'PSPossibleIncorrectComparisonWithNull',
'PSProvideCommentHelp',
'PSReservedCmdletChar',
'PSReservedParams',
'PSUseApprovedVerbs',
'PSUseCmdletCorrectly',
'PSUseOutputTypeCorrectly',
'PSAvoidGlobalVars',
'PSAvoidUsingConvertToSecureStringWithPlainText',
'PSAvoidUsingPlainTextForPassword',
'PSAvoidUsingUsernameAndPasswordParams',
'PSDSCUseVerboseMessageInDSCResource',
'PSShouldProcess',
'PSUseDeclaredVarsMoreThanAssignments',
'PSUsePSCredentialType',

<#
This is to test all the DSC Resource Kit custom rules.
The name of the function-blocks of each custom rule start
with 'Measure*'.
#>
'Measure-*'
)
}
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
"powershell.codeFormatting.ignoreOneLineBlock": false,
"powershell.codeFormatting.preset": "Custom",
"files.trimTrailingWhitespace": true,
"files.insertFinalNewline": true
"files.insertFinalNewline": true,
"powershell.scriptAnalysis.settingsPath": ".vscode\\analyzersettings.psd1"
}
103 changes: 103 additions & 0 deletions Assert-TestEnvironment.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<#
.SYNOPSIS
Assert that the test environment is properly setup and loaded into the
PowerShell session.
.DESCRIPTION
Assert that the test environment is properly setup and loaded into the
PowerShell session.
.EXAMPLE
.\Assert-testEnvironment.ps1
Will assert that the current PowerShell session is ready to run tests.
#>

[CmdletBinding(SupportsShouldProcess = $true)]
param
(
)

#region Verify prerequisites Pester
$pesterModuleName = 'Pester'

# This is the minimum version that can be used with the tests in this repo.
$pesterModuleMinimumVersion = '4.0.2'

<#
Pester v4.4.0 has a fix for '-Not -Throw' so it shows the actual error
message if an unexpected exception does occur. It will help when debugging
tests.
If no Pester module exist, then use this as the minimum version.
#>
$pesterModuleRecommendedMinimumVersion = '4.4.0'

$pesterModule = Get-Module $pesterModuleName -ListAvailable -Verbose:$false |
Where-Object -Property 'Version' -GE -Value $pesterModuleMinimumVersion |
Sort-Object -Property 'Version' -Descending |
Select-Object -First 1

if (-not $pesterModule)
{
<#
Not installing the module here because it's not known what scope the
user want (can) to install the module in.
#>
$message = 'Missing a compatible version of the {0} module. Minimum version of {0} module can be ''{2}'', but the recommended minimum version is ''{1}''.' -f $pesterModuleName, $pesterModuleRecommendedMinimumVersion, $pesterModuleMinimumVersion
Write-Warning -Message $message
$dependencyMissing = $true
}
else
{
Write-Verbose -Message ('A compatible {0} module is already installed (v{1}). If you want to use a newer version of {0} module, please install it manually.' -f $pesterModule.Name, $pesterModule.Version)
}
#endregion Verify prerequisites Pester

#region Verify prerequisites PSDepend
$psDependModuleName = 'PSDepend'

# This is the minimum version that can be used with the tests in this repo.
$psDependModuleMinimumVersion = '0.3.0'
$psDependModuleRecommendedMinimumVersion = 'latest'

$psDependModule = Get-Module $psDependModuleName -ListAvailable -Verbose:$false |
Where-Object -Property 'Version' -GE -Value $psDependModuleMinimumVersion |
Sort-Object -Property 'Version' -Descending |
Select-Object -First 1

if (-not $psDependModule)
{
<#
Not installing the module here because it's not known what scope the
user want (can) to install the module in.
#>
$message = 'Missing a compatible version of the {0} module. Minimum version of {0} module can be ''{2}'', but the recommended minimum version is ''{1}''. Please install {0} module manually, then run this script again.' -f $psDependModuleName, $psDependModuleRecommendedMinimumVersion, $psDependModuleMinimumVersion
Write-Warning -Message $message
$dependencyMissing = $true
}
else
{
Write-Verbose -Message ('A compatible {0} module is already installed (v{1}). If you want to use a newer version of {0} module, please install it manually.' -f $psDependModule.Name, $psDependModule.Version)
}
#endregion Verify prerequisites PSDepend

if ($dependencyMissing)
{
Write-Output -InputObject 'Please install the necessary dependencies manually, then run this script again.'
return
}

$dependenciesPath = Join-Path $PSScriptRoot -ChildPath 'Tests'

Write-Verbose -Message ('Running Invoke-PSDepend using dependencies found under the path ''{0}''.' -f $dependenciesPath)

if ($PSBoundParameters.ContainsKey('Confirm'))
{
$invokePSDependConfirmation = $ConfirmPreference
}
else
{
$invokePSDependConfirmation = $false
}

Invoke-PSDepend -Path $dependenciesPath -Confirm:$invokePSDependConfirmation
55 changes: 55 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,61 @@

## Unreleased

## 12.1.0.0

- Changes to SqlServerDsc
- Add support for validating the code with the DSC ResourceKit
Script Analyzer rules, both in Visual Studio Code and directly using
`Invoke-ScriptAnalyzer`.
- Opt-in for common test "Common Tests - Validate Markdown Links".
- Updated broken links in `\README.md` and in `\Examples\README.md`
- Opt-in for common test 'Common Tests - Relative Path Length'.
- Updated the Installation section in the README.md.
- Updated the Contributing section in the README.md after
[Style Guideline and Best Practices guidelines](https://github.com/PowerShell/DscResources/blob/master/StyleGuidelines.md)
has merged into one document.
- To speed up testing in AppVeyor, unit tests are now run in two containers.
- Adding the PowerShell script `Assert-TestEnvironment.ps1` which
must be run prior to running any unit tests locally with
`Invoke-Pester`.
Read more in the specific contributing guidelines, under the section
[Unit Tests](https://github.com/PowerShell/SqlServerDsc/blob/dev/CONTRIBUTING.md#unit-tests).
- Changes to SqlServerDscHelper
- Fix style guideline lint errors.
- Changes to Connect-SQL
- Adding verbose message in Connect-SQL so it
now shows the username that is connecting.
- Changes to Import-SQLPS
- Fixed so that when importing SQLPS it imports
using the path (and not the .psd1 file).
- Fixed so that the verbose message correctly
shows the name, version and path when importing
the module SQLPS (it did show correctly for the
SqlServer module).
- Changes to SqlAg, SqlAGDatabase, and SqlAGReplica examples
- Included configuration for SqlAlwaysOnService to enable
HADR on each node to avoid confusion
([issue #1182](https://github.com/PowerShell/SqlServerDsc/issues/1182)).
- Changes to SqlServerDatabaseMail
- Minor update to Ensure parameter description in the README.md.
- Changes to Write-ModuleStubFile.ps1
- Create aliases for cmdlets in the stubbed module which have aliases
([issue #1224](https://github.com/PowerShell/SqlServerDsc/issues/1224)).
[Dan Reist (@randomnote1)](https://github.com/randomnote1)
- Use a string builder to build the function stubs.
- Fixed formatting issues for the function to work with modules other
than SqlServer.
- New DSC resource SqlServerSecureConnection
- New resource to configure a SQL Server instance for encrypted SQL
connections.
- Changes to SqlAlwaysOnService
- Updated integration tests to use NetworkingDsc
([issue #1129](https://github.com/PowerShell/SqlServerDsc/issues/1129)).
- Changes to SqlServiceAccount
- Fix unit tests that didn't mock some of the calls. It no longer fail
when a SQL Server installation is not present on the node running the
unit test ([issue #983](https://github.com/PowerShell/SqlServerDsc/issues/983)).

## 12.0.0.0

- Changes to SqlServerDatabaseMail
Expand Down
41 changes: 38 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -378,14 +378,23 @@ For a review of a Pull Request (PR) to start, all tests must pass without error.
If you need help to figure why some test don't pass, just write a comment in the
Pull Request (PR), or submit an issue, and somebody will come along and assist.

To run all tests manually run the following.
To run all unit tests manually run the following.

```powershell
Install-Module Pester
cd '<path to cloned repository>\Tests'
cd '<path to cloned repository>'
.\Assert-TestEnvironment.ps1 -Confirm -Verbose
cd '<path to cloned repository>\Tests\Unit'
Invoke-Pester
```

The script `Assert-TestEnvironment.ps1` will clone the test framework
from GitHub, and load some necessary types which is needed to run some
of the tests. Read more about the bootstrap script in the section
[Bootstrap script Assert-TestEnvironment](#bootstrap-script-assert-testenvironment).

The cmdlet `Invoke-Pester` looks for all the '*.Tests.ps1' PowerShell
script files recursively and executes the tests.

#### Unit tests for style check of Markdown files

When sending in a Pull Request (PR) a style check will be performed on all Markdown
Expand Down Expand Up @@ -439,3 +448,29 @@ If using Visual Studio Code to edit Markdown files it can be a good idea to inst
the markdownlint extension. It will help to do style checking.
The file [.markdownlint.json](/.markdownlint.json) is prepared with a default set
of rules which will automatically be used by the extension.

## Bootstrap script Assert-TestEnvironment

The bootstrap script [`Assert-TestEnvironment.ps1`](Assert-TestEnvironment.ps1)
was needed when tests were updated to run in containers.
There are some custom types (`Microsoft.DscResourceKit.*`) that are needed
to be able to parse the test script files. Those types must be loaded
into the session prior to running any unit tests with `Invoke-Pester`.

The script works without any parameters and will do the following.

>**Note:** If you want to confirm each step, then add the `-Confirm`
>parameter.
- Check if a compatible *Pester* version is available.
- Check if a compatible *PSDepend* version is available.
- Invoke PSDepend (using `Tests/Tests.depend.psd1`).
- Remove local cloned repository *DscResource.Tests* if it is present
(always assumes it's an older version).
- Clone *DscResource.Tests* from GitHub into the local repository
folder, and check out the branch `dev` to always be on the latest
commit available.
- Load the necessary types from the test framework *DscResource.Tests*.

If there are no compatible Pester or PSDepend version available, you will be asked
to install it manually, and then run the script again.
Loading

0 comments on commit 5cf11f7

Please sign in to comment.