Skip to content

Commit

Permalink
SqlServiceAccount: Added integration tests (plus other changes) (#987)
Browse files Browse the repository at this point in the history
- Changes to SqlServerDsc
  - Added a README.md under Tests\Integration to help contributors to write
   integration tests.
  - Added 'Integration tests' section in the CONTRIBUTING.md.
- Changes to SqlServiceAccount
  - Added a read-only parameter ServiceAccountName so that the service account
    name is correctly returned as a string (issue #982).
  - Added integration tests (issue #980).
- Changes to SqlSetup
  - Cleaned up integration tests.
  - Added integration tests for installing a default instance of Database Engine.
  • Loading branch information
johlju authored Jan 4, 2018
1 parent 1f5a166 commit 2631d70
Show file tree
Hide file tree
Showing 12 changed files with 1,396 additions and 312 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
done to follow the style guideline.
- Updated manifest and license to reflect the new year
([issue #965](https://github.com/PowerShell/SqlServerDsc/issues/965)).
- Added a README.md under Tests\Integration to help contributors to write
integration tests.
- Added 'Integration tests' section in the CONTRIBUTING.md.
- Changes to SqlAlias
- Fixed issue where exception was thrown if reg keys did not exist
([issue #949](https://github.com/PowerShell/SqlServerDsc/issues/949)).
Expand All @@ -25,12 +28,17 @@
([issue #930](https://github.com/PowerShell/SqlServerDsc/issues/930)).
- Made the description of parameter RestartService more descriptive
([issue #960](https://github.com/PowerShell/SqlServerDsc/issues/960)).
- Added a read-only parameter ServiceAccountName so that the service account
name is correctly returned as a string ([issue #982](https://github.com/PowerShell/SqlServerDsc/issues/982)).
- Added integration tests ([issue #980](https://github.com/PowerShell/SqlServerDsc/issues/980)).
- Changes to SqlSetup
- Added parameter `ASServerMode` to support installing Analysis Services in
Multidimensional mode, Tabular mode and PowerPivot mode
([issue #388](https://github.com/PowerShell/SqlServerDsc/issues/388)).
- Added integration tests for testing Analysis Services Multidimensional mode
and Tabular mode.
- Cleaned up integration tests.
- Added integration tests for installing a default instance of Database Engine.

## 10.0.0.0

Expand Down
17 changes: 14 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ one resource, then the functions can also be placed in the common
[SqlServerDscHelper.psm1](https://github.com/PowerShell/SqlServerDsc/blob/dev/SqlServerDscHelper.psm1)
module file.

### Tests
### Unit tests

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
Expand All @@ -386,7 +386,7 @@ cd '<path to cloned repository>\Tests'
Invoke-Pester
```

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

When sending in a Pull Request (PR) a style check will be performed on all Markdown
files, and if the tests find any error the build will fail.
Expand All @@ -398,7 +398,7 @@ To have npm available you need to install [node.js](https://nodejs.org/en/downlo
If 'npm' is not available, a warning text will print and the rest of the tests
will continue run.

#### Tests for examples files
#### Unit tests for examples files

When sending in a Pull Request (PR) all example files will be tested so they can
be compiled to a .mof file. If the tests find any errors the build will fail.
Expand All @@ -408,6 +408,17 @@ To run this test locally, make sure you have the SqlServerDsc module
deployed to a path where it can be used.
See `$env:PSModulePath` to view the existing paths.

### Integration tests

Integration tests should be written for resources so they can be validated by
the automated test framework which is run in AppVeyor when commits are pushed
to a Pull Request (PR).
Please see the [Testing Guidelines](https://github.com/PowerShell/DscResources/blob/master/TestsGuidelines.md)
for common DSC Resource Kit testing guidelines.
There are also configuration made by existing integration tests that can be reused
to write integration tests for other resources. This is documented in
[Integration tests for SqlServerDsc](https://github.com/PowerShell/SqlServerDsc/blob/dev/Tests/Integration/README.md).

#### Using SMO stub classes

There are [stub classes](https://github.com/PowerShell/SqlServerDsc/blob/dev/Tests/Unit/Stubs/SMO.cs)
Expand Down
18 changes: 9 additions & 9 deletions DSCResources/MSFT_SqlServiceAccount/MSFT_SqlServiceAccount.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ function Get-TargetResource
# Replace a domain of '.' with the value for $ServerName
$serviceAccountName = $serviceObject.ServiceAccount -ireplace '^([\.])\\(.*)$', "$ServerName\`$2"

# Return a hashtable with the service information
# Return a hash table with the service information
return @{
ServerName = $ServerName
InstanceName = $InstanceName
ServiceType = $serviceObject.Type
ServiceAccount = $serviceAccountName
ServerName = $ServerName
InstanceName = $InstanceName
ServiceType = $serviceObject.Type
ServiceAccountName = $serviceAccountName
}
}

Expand Down Expand Up @@ -99,7 +99,7 @@ function Get-TargetResource
Forces the service account to be updated.
.EXAMPLE
Test-TargetResource -ServerName $env:COMPUTERNAME -SQLInstaneName MSSQLSERVER -ServiceType DatabaseEngine -ServiceAccount $account
Test-TargetResource -ServerName $env:COMPUTERNAME -InstanceName MSSQLSERVER -ServiceType DatabaseEngine -ServiceAccount $account
#>
function Test-TargetResource
Expand Down Expand Up @@ -142,9 +142,9 @@ function Test-TargetResource

# Get the current state
$currentState = Get-TargetResource -ServerName $ServerName -InstanceName $InstanceName -ServiceType $ServiceType -ServiceAccount $ServiceAccount
New-VerboseMessage -Message ($script:localizedData.CurrentServiceAccount -f $currentState.ServiceAccount, $ServerName, $InstanceName)
New-VerboseMessage -Message ($script:localizedData.CurrentServiceAccount -f $currentState.ServiceAccountName, $ServerName, $InstanceName)

return ($currentState.ServiceAccount -ieq $ServiceAccount.UserName)
return ($currentState.ServiceAccountName -ieq $ServiceAccount.UserName)
}

<#
Expand Down Expand Up @@ -172,7 +172,7 @@ function Test-TargetResource
Forces the service account to be updated.
.EXAMPLE
Set-TargetResource -ServerName $env:COMPUTERNAME -SQLInstaneName MSSQLSERVER -ServiceType DatabaseEngine -ServiceAccount $account
Set-TargetResource -ServerName $env:COMPUTERNAME -InstanceName MSSQLSERVER -ServiceType DatabaseEngine -ServiceAccount $account
#>
function Set-TargetResource
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ class MSFT_SqlServiceAccount : OMI_BaseResource
[Required, EmbeddedInstance("MSFT_Credential"), Description("The service account that should be used when running the service.")] String ServiceAccount;
[Write, Description("Determines whether the service is automatically restarted when a change to the configuration was needed.")] Boolean RestartService;
[Write, Description("Forces the service account to be updated. Useful for password changes.")] Boolean Force;
[Read, Description("Returns the service account username for the service.")] String ServiceAccountName;
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

ConvertFrom-StringData @'
ForceServiceAccountUpdate = Force specified, skipping tests. With this configuration, Test-TargetResource will always return 'False'.
CurrentServiceAccount = Current service account is '{0}' for {1}\{2}.
CurrentServiceAccount = Current service account is '{0}' for {1}\\{2}.
ConnectingToWmi = Connecting to WMI on '{0}'.
UpdatingServiceAccount = Setting service account to '{0}' for service {1}.
RestartingService = Restarting '{0}' and any dependent services.
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1276,6 +1276,11 @@ Manage the service account for SQL Server services.
Useful for password changes. This will cause `Set-TargetResource` to be run on
each consecutive run.

#### Read-Only Properties from Get-TargetResource

* **`[String]` ServiceAccountName** _(Read)_: Returns the service account username
for the service.

#### Examples

* [Run service under a user account](/Examples/Resources/SqlServiceAccount/1-ConfigureServiceAccount-UserAccount.ps1)
Expand Down
Loading

0 comments on commit 2631d70

Please sign in to comment.