Skip to content

Commit

Permalink
Merge pull request #214 from PlagueHO/Issue-188
Browse files Browse the repository at this point in the history
Refactor Module to Remove Harness - Fixes #188
  • Loading branch information
PlagueHO authored Apr 13, 2019
2 parents 2f890b2 + d6ae914 commit 91eba65
Show file tree
Hide file tree
Showing 95 changed files with 326 additions and 391 deletions.
12 changes: 0 additions & 12 deletions .vscode/RunAllTests.ps1

This file was deleted.

19 changes: 0 additions & 19 deletions .vscode/launch.json

This file was deleted.

8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
- IdleWaitTimeout returned from Get-TargetResource always null - Fixes [Issue #186](https://github.com/PowerShell/ComputerManagementDsc/issues/186).
- Added BuiltInAccount Property to allow running task as one of the build in
service accounts - Fixes [Issue #130](https://github.com/PowerShell/ComputerManagementDsc/issues/130).
- Refactored module folder structure to move resource to root folder of
repository and remove test harness - fixes [Issue #188](https://github.com/PowerShell/ComputerManagementDsc/issues/188).
- Added a CODE\_OF\_CONDUCT.md with the same content as in the README.md and
linked to it from README.MD instead.
- Updated test header for all unit tests to version 1.2.4.
- Updated test header for all imtegration to version 1.3.3.
- Enabled example publish to PowerShell Gallery by adding `gallery_api`
environment variable to `AppVeyor.yml`.

## 6.3.0.0

Expand Down
6 changes: 6 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Code of conduct

This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)
or contact [[email protected]](mailto:[email protected]) with any additional
questions or comments.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ The **ComputerManagementDsc** module contains the following resources:
- **WindowsEventLog**: This resource allows configuration of a specified
Windows Event Log.

This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)
or contact [[email protected]](mailto:[email protected]) with any
additional questions or comments.
This project has adopted [this code of conduct](CODE_OF_CONDUCT.md).

## Documentation and Examples

Expand Down
10 changes: 5 additions & 5 deletions Tests/Integration/ComputerManagementDsc.Common.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#region HEADER
$script:ModuleName = 'ComputerManagementDsc.Common'

Import-Module -Name (Join-Path -Path (Join-Path -Path (Split-Path $PSScriptRoot -Parent) -ChildPath 'TestHelpers') -ChildPath 'CommonTestHelper.psm1') -Global

#region HEADER
# Unit Test Template Version: 1.1.0
$script:moduleRoot = Join-Path -Path $(Split-Path -Parent (Split-Path -Parent (Split-Path -Parent $Script:MyInvocation.MyCommand.Path))) -ChildPath 'Modules\ComputerManagementDsc'
# Unit Test Template Version: 1.2.4
$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot)
if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or `
(-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) )
{
& git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\'))
& git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath 'DscResource.Tests'))
}

Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force
Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force
Import-Module (Join-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'Modules' -ChildPath $script:ModuleName)) -ChildPath "$script:ModuleName.psm1") -Force
#endregion HEADER

Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
$script:DSCModuleName = 'ComputerManagementDsc'
$script:DSCResourceName = 'MSFT_PowerShellExecutionPolicy'

#region HEADER
# Integration Test Template Version: 1.1.1
$script:moduleRoot = Join-Path -Path $(Split-Path -Parent (Split-Path -Parent (Split-Path -Parent $Script:MyInvocation.MyCommand.Path))) -ChildPath 'Modules\ComputerManagementDsc'
$script:dscModuleName = 'ComputerManagementDsc'
$script:dscResourceName = 'MSFT_PowerShellExecutionPolicy'

# Integration Test Template Version: 1.3.3
$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot)
if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or `
(-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) )
{
& git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\'))
& git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath 'DscResource.Tests'))
}

Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force
$TestEnvironment = Initialize-TestEnvironment `
-DSCModuleName $script:DSCModuleName `
-DSCResourceName $script:DSCResourceName `
-DSCModuleName $script:dscModuleName `
-DSCResourceName $script:dscResourceName `
-TestType Integration

#endregion

try
{
#region Integration Tests
$configFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:DSCResourceName).config.ps1"
$configFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:dscResourceName).config.ps1"
. $configFile

Describe "$($script:DSCResourceName)_Integration" {
Describe "$($script:dscResourceName)_Integration" {
#region DEFAULT TESTS
It 'Should compile and apply the MOF without throwing' {
{
& "$($script:DSCResourceName)_Config" -OutputPath $TestDrive
& "$($script:dscResourceName)_Config" -OutputPath $TestDrive

$startDscConfigurationParameters = @{
Path = $TestDrive
Expand All @@ -52,7 +51,7 @@ try

It 'Should have set the resource and all the parameters should match' {
$current = Get-DscConfiguration | Where-Object -FilterScript {
$_.ConfigurationName -eq "$($script:DSCResourceName)_Config"
$_.ConfigurationName -eq "$($script:dscResourceName)_Config"
}
$current.ExecutionPolicy | Should Be 'RemoteSigned'
$current.ExecutionPolicyScope | Should Be 'LocalMachine'
Expand Down
22 changes: 13 additions & 9 deletions Tests/Integration/MSFT_ScheduledTask.Integration.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
#Requires -Version 5.0
$Script:DSCModuleName = 'ComputerManagementDsc'
$Script:DSCResourceName = 'MSFT_ScheduledTask'
#region HEADER
# Integration Test Template Version: 1.1.1
$script:moduleRoot = Join-Path -Path $(Split-Path -Parent (Split-Path -Parent (Split-Path -Parent $Script:MyInvocation.MyCommand.Path))) -ChildPath 'Modules\ComputerManagementDsc'
$script:dscModuleName = 'ComputerManagementDsc'
$script:dscResourceName = 'MSFT_ScheduledTask'

# Integration Test Template Version: 1.3.3
$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot)
if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or `
(-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) )
{
& git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\'))
& git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath 'DscResource.Tests'))
}

Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force
$TestEnvironment = Initialize-TestEnvironment `
-DSCModuleName $Script:DSCModuleName `
-DSCResourceName $Script:DSCResourceName `
-DSCModuleName $script:dscModuleName `
-DSCResourceName $script:dscResourceName `
-TestType Integration
#endregion

Import-Module -Name (Join-Path -Path (Join-Path -Path (Split-Path $PSScriptRoot -Parent) -ChildPath 'TestHelpers') -ChildPath 'CommonTestHelper.psm1') -Global

# Load the ComputerManagementDsc.Common module to use Set-TimezoneId function
Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'Modules' -ChildPath 'ComputerManagementDsc.Common')) -Force

# Begin Testing
try
{
$ConfigFile = Join-Path -Path $PSScriptRoot -ChildPath "$($Script:DSCResourceName).config.ps1"
$ConfigFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:dscResourceName).config.ps1"
. $ConfigFile

#region Pester Tests
Describe $Script:DSCResourceName {
Describe $script:dscResourceName {

$contexts = @{
Once = 'ScheduledTaskOnce'
Expand Down
27 changes: 14 additions & 13 deletions Tests/Integration/MSFT_TimeZone.Integration.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
$script:DSCModuleName = 'ComputerManagementDsc'
$script:DSCResourceName = 'MSFT_TimeZone'

#region HEADER
# Integration Test Template Version: 1.1.1
$script:moduleRoot = Join-Path -Path $(Split-Path -Parent (Split-Path -Parent (Split-Path -Parent $Script:MyInvocation.MyCommand.Path))) -ChildPath 'Modules\ComputerManagementDsc'
$script:dscModuleName = 'ComputerManagementDsc'
$script:dscResourceName = 'MSFT_TimeZone'

# Integration Test Template Version: 1.3.3
$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot)
if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or `
(-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) )
(-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) )
{
& git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\'))
& git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath 'DscResource.Tests'))
}

Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force
$TestEnvironment = Initialize-TestEnvironment `
-DSCModuleName $script:DSCModuleName `
-DSCResourceName $script:DSCResourceName `
-DSCModuleName $script:dscModuleName `
-DSCResourceName $script:dscResourceName `
-TestType Integration
#endregion

# Store the test machine timezone
$currentTimeZone = & tzutil.exe /g
Expand All @@ -26,10 +27,10 @@ tzutil.exe /s 'Eastern Standard Time'
try
{
#region Integration Tests
$configFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:DSCResourceName).config.ps1"
$configFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:dscResourceName).config.ps1"
. $configFile -Verbose -ErrorAction Stop

Describe "$($script:DSCResourceName)_Integration" {
Describe "$($script:dscResourceName)_Integration" {
$configData = @{
AllNodes = @(
@{
Expand All @@ -42,7 +43,7 @@ try

It 'Should compile and apply the MOF without throwing' {
{
& "$($script:DSCResourceName)_Config" `
& "$($script:dscResourceName)_Config" `
-OutputPath $TestDrive `
-ConfigurationData $configData

Expand All @@ -62,7 +63,7 @@ try

It 'Should have set the configuration and all the parameters should match' {
$current = Get-DscConfiguration | Where-Object -FilterScript {
$_.ConfigurationName -eq "$($script:DSCResourceName)_Config"
$_.ConfigurationName -eq "$($script:dscResourceName)_Config"
}
$current.TimeZone | Should -Be $configData.AllNodes[0].TimeZone
$current.IsSingleInstance | Should -Be $configData.AllNodes[0].IsSingleInstance
Expand Down
23 changes: 11 additions & 12 deletions Tests/Integration/MSFT_VirtualMemory.Integration.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
$script:DSCModuleName = 'ComputerManagementDsc'
$script:DSCResourceName = 'MSFT_VirtualMemory'

#region HEADER
# Integration Test Template Version: 1.1.1
$script:moduleRoot = Join-Path -Path $(Split-Path -Parent (Split-Path -Parent (Split-Path -Parent $Script:MyInvocation.MyCommand.Path))) -ChildPath 'Modules\ComputerManagementDsc'
$script:dscModuleName = 'ComputerManagementDsc'
$script:dscResourceName = 'MSFT_VirtualMemory'

# Integration Test Template Version: 1.3.3
$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot)
if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or `
(-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) )
(-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) )
{
& git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\'))
& git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath 'DscResource.Tests'))
}

Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force
$TestEnvironment = Initialize-TestEnvironment `
-DSCModuleName $script:DSCModuleName `
-DSCResourceName $script:DSCResourceName `
-DSCModuleName $script:dscModuleName `
-DSCResourceName $script:dscResourceName `
-TestType Integration

#endregion

# Using try/finally to always cleanup.
try
{
#region Integration Tests
$configFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:DSCResourceName).config.ps1"
$configFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:dscResourceName).config.ps1"
. $configFile

Describe "$($script:DSCResourceName)_Integration" {
Describe "$($script:dscResourceName)_Integration" {

Context 'Set page file to automatically managed' {
$CurrentConfig = 'setToAuto'
Expand Down
23 changes: 11 additions & 12 deletions Tests/Integration/MSFT_WindowsEventLog.Integration.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
$script:DSCModuleName = 'ComputerManagementDsc'
$script:DSCResourceName = 'MSFT_WindowsEventLog'

#region HEADER
# Integration Test Template Version: 1.1.1
$script:moduleRoot = Join-Path -Path $(Split-Path -Parent (Split-Path -Parent (Split-Path -Parent $Script:MyInvocation.MyCommand.Path))) -ChildPath 'Modules\ComputerManagementDsc'
$script:dscModuleName = 'ComputerManagementDsc'
$script:dscResourceName = 'MSFT_WindowsEventLog'

# Integration Test Template Version: 1.3.3
$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot)
if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or `
(-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) )
(-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) )
{
& git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\'))
& git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath 'DscResource.Tests'))
}

Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force
$TestEnvironment = Initialize-TestEnvironment `
-DSCModuleName $script:DSCModuleName `
-DSCResourceName $script:DSCResourceName `
-DSCModuleName $script:dscModuleName `
-DSCResourceName $script:dscResourceName `
-TestType Integration

#endregion

# Using try/finally to always cleanup.
try
{
#region Integration Tests
$configFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:DSCResourceName).config.ps1"
$configFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:dscResourceName).config.ps1"
. $configFile
Describe "$($script:DSCResourceName)_Integration" {
Describe "$($script:dscResourceName)_Integration" {

Context 'Set Windows Event Log to Logmode Retain' {
$CurrentConfig = 'MSFT_WindowsEventLog_RetainSize'
Expand Down
Loading

0 comments on commit 91eba65

Please sign in to comment.