Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing tasks module #78

Merged
merged 4 commits into from
Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- DscResource.Common
- Update pipeline files to the latest in Sampler.
- Fix missing tasks module.
- Update unit tests to import and remove the module being tested.

### Fixed

Expand Down
1 change: 1 addition & 0 deletions RequiredModules.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@
'DscResource.AnalyzerRules' = 'latest'
xDscResourceDesigner = 'latest'
'DscResource.Test' = 'latest'
'DscResource.DocGenerator' = 'latest'
}
3 changes: 3 additions & 0 deletions build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ BuildWorkflow:
- Build_Module_ModuleBuilder
- Build_NestedModules_ModuleBuilder
- Create_changelog_release_output
- Generate_Wiki_Content

pack:
- build
Expand Down Expand Up @@ -107,6 +108,8 @@ ModuleBuildTasks:
- '*.build.Sampler.ib.tasks'
Sampler.GitHubTasks:
- '*.ib.tasks'
DscResource.DocGenerator:
- 'Task.*'
DscResource.Test:
- 'Task.*'

Expand Down
52 changes: 28 additions & 24 deletions tests/QA/module.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,35 +32,39 @@ BeforeAll {
).Directory.FullName
}

Describe 'Changelog Management' -Tag 'Changelog' {
It 'Changelog has been updated' -skip:(
!([bool](Get-Command git -EA SilentlyContinue) -and
[bool](&(Get-Process -id $PID).Path -NoProfile -Command 'git rev-parse --is-inside-work-tree 2>$null'))
) {
# Get the list of changed files compared with branch main
$HeadCommit = &git rev-parse HEAD
$defaultBranchCommit = &git rev-parse origin/main
$filesChanged = &git @('diff', "$defaultBranchCommit...$HeadCommit", '--name-only')
$filesStagedAndUnstaged = &git @('diff', "HEAD", '--name-only')

$filesChanged += $filesStagedAndUnstaged

# Only check if there are any changed files.
if ($filesChanged)
{
$filesChanged | Should -Contain 'CHANGELOG.md' -Because 'the CHANGELOG.md must be updated with at least one entry in the Unreleased section for each PR'
}
}
AfterAll {
Get-Module -Name 'DscResource.Common' -All | Remove-Module -Force
}

It 'Changelog format compliant with keepachangelog format' -skip:(![bool](Get-Command git -EA SilentlyContinue)) {
{ Get-ChangelogData (Join-Path $ProjectPath 'CHANGELOG.md') -ErrorAction Stop } | Should -Not -Throw
Describe 'Changelog Management' -Tag 'Changelog' {
It 'Changelog has been updated' -skip:(
!([bool](Get-Command git -EA SilentlyContinue) -and
[bool](&(Get-Process -id $PID).Path -NoProfile -Command 'git rev-parse --is-inside-work-tree 2>$null'))
) {
# Get the list of changed files compared with branch main
$HeadCommit = &git rev-parse HEAD
$defaultBranchCommit = &git rev-parse origin/main
$filesChanged = &git @('diff', "$defaultBranchCommit...$HeadCommit", '--name-only')
$filesStagedAndUnstaged = &git @('diff', "HEAD", '--name-only')

$filesChanged += $filesStagedAndUnstaged

# Only check if there are any changed files.
if ($filesChanged)
{
$filesChanged | Should -Contain 'CHANGELOG.md' -Because 'the CHANGELOG.md must be updated with at least one entry in the Unreleased section for each PR'
}
}

It 'Changelog should have an Unreleased header' -Skip:$skipTest {
(Get-ChangelogData -Path (Join-Path -Path $ProjectPath -ChildPath 'CHANGELOG.md') -ErrorAction 'Stop').Unreleased.RawData | Should -Not -BeNullOrEmpty
}
It 'Changelog format compliant with keepachangelog format' -skip:(![bool](Get-Command git -EA SilentlyContinue)) {
{ Get-ChangelogData (Join-Path $ProjectPath 'CHANGELOG.md') -ErrorAction Stop } | Should -Not -Throw
}

It 'Changelog should have an Unreleased header' -Skip:$skipTest {
(Get-ChangelogData -Path (Join-Path -Path $ProjectPath -ChildPath 'CHANGELOG.md') -ErrorAction 'Stop').Unreleased.RawData | Should -Not -BeNullOrEmpty
}
}

Describe 'General module control' -Tags 'FunctionalQuality' {
It 'Should import without errors' {
{ Import-Module -Name $script:moduleName -Force -ErrorAction Stop } | Should -Not -Throw
Expand Down
18 changes: 14 additions & 4 deletions tests/Unit/Private/Test-DscObjectHasProperty.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
BeforeAll {
$script:moduleName = 'DscResource.Common'

Remove-Module -Name $script:moduleName -Force -ErrorAction 'SilentlyContinue'
# If the module is not found, run the build task 'noop'.
if (-not (Get-Module -Name $script:moduleName -ListAvailable))
{
# Redirect all streams to $null, except the error stream (stream 2)
& "$PSScriptRoot/../../build.ps1" -Tasks 'noop' 2>&1 4>&1 5>&1 6>&1 > $null
}

Get-Module -Name $script:moduleName -ListAvailable |
Select-Object -First 1 |
Import-Module -Force -ErrorAction 'Stop'
# Re-import the module using force to get any code changes between runs.
Import-Module -Name $script:moduleName -Force -ErrorAction 'Stop'

$PSDefaultParameterValues['InModuleScope:ModuleName'] = $script:moduleName
$PSDefaultParameterValues['Mock:ModuleName'] = $script:moduleName
$PSDefaultParameterValues['Should:ModuleName'] = $script:moduleName
}

AfterAll {
$PSDefaultParameterValues.Remove('Mock:ModuleName')
$PSDefaultParameterValues.Remove('InModuleScope:ModuleName')
$PSDefaultParameterValues.Remove('Should:ModuleName')

Remove-Module -Name $script:moduleName
}

Describe 'Test-DscObjectHasProperty' {
Expand Down
18 changes: 14 additions & 4 deletions tests/Unit/Private/Test-DscPropertyState.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
BeforeAll {
$script:moduleName = 'DscResource.Common'

Remove-Module -Name $script:moduleName -Force -ErrorAction 'SilentlyContinue'
# If the module is not found, run the build task 'noop'.
if (-not (Get-Module -Name $script:moduleName -ListAvailable))
{
# Redirect all streams to $null, except the error stream (stream 2)
& "$PSScriptRoot/../../build.ps1" -Tasks 'noop' 2>&1 4>&1 5>&1 6>&1 > $null
}

Get-Module -Name $script:moduleName -ListAvailable |
Select-Object -First 1 |
Import-Module -Force -ErrorAction 'Stop'
# Re-import the module using force to get any code changes between runs.
Import-Module -Name $script:moduleName -Force -ErrorAction 'Stop'

$PSDefaultParameterValues['InModuleScope:ModuleName'] = $script:moduleName
$PSDefaultParameterValues['Mock:ModuleName'] = $script:moduleName
$PSDefaultParameterValues['Should:ModuleName'] = $script:moduleName
}

AfterAll {
$PSDefaultParameterValues.Remove('Mock:ModuleName')
$PSDefaultParameterValues.Remove('InModuleScope:ModuleName')
$PSDefaultParameterValues.Remove('Should:ModuleName')

Remove-Module -Name $script:moduleName
}

Describe 'Test-DscPropertyState' -Tag 'TestDscPropertyState' {
Expand Down
18 changes: 14 additions & 4 deletions tests/Unit/Public/Assert-BoundParameter.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
BeforeAll {
$script:moduleName = 'DscResource.Common'

Remove-Module -Name $script:moduleName -Force -ErrorAction 'SilentlyContinue'
# If the module is not found, run the build task 'noop'.
if (-not (Get-Module -Name $script:moduleName -ListAvailable))
{
# Redirect all streams to $null, except the error stream (stream 2)
& "$PSScriptRoot/../../build.ps1" -Tasks 'noop' 2>&1 4>&1 5>&1 6>&1 > $null
}

Get-Module -Name $script:moduleName -ListAvailable |
Select-Object -First 1 |
Import-Module -Force -ErrorAction 'Stop'
# Re-import the module using force to get any code changes between runs.
Import-Module -Name $script:moduleName -Force -ErrorAction 'Stop'

$PSDefaultParameterValues['InModuleScope:ModuleName'] = $script:moduleName
$PSDefaultParameterValues['Mock:ModuleName'] = $script:moduleName
$PSDefaultParameterValues['Should:ModuleName'] = $script:moduleName
}

AfterAll {
$PSDefaultParameterValues.Remove('Mock:ModuleName')
$PSDefaultParameterValues.Remove('InModuleScope:ModuleName')
$PSDefaultParameterValues.Remove('Should:ModuleName')

Remove-Module -Name $script:moduleName
}

Describe 'Assert-BoundParameter' -Tag 'AssertBoundParameter' {
Expand Down
19 changes: 14 additions & 5 deletions tests/Unit/Public/Assert-IPAddress.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
BeforeAll {
$script:moduleName = 'DscResource.Common'

Remove-Module -Name $script:moduleName -Force -ErrorAction 'SilentlyContinue'
# If the module is not found, run the build task 'noop'.
if (-not (Get-Module -Name $script:moduleName -ListAvailable))
{
# Redirect all streams to $null, except the error stream (stream 2)
& "$PSScriptRoot/../../build.ps1" -Tasks 'noop' 2>&1 4>&1 5>&1 6>&1 > $null
}

Get-Module -Name $script:moduleName -ListAvailable |
Select-Object -First 1 |
Import-Module -Force -ErrorAction 'Stop'
# Re-import the module using force to get any code changes between runs.
Import-Module -Name $script:moduleName -Force -ErrorAction 'Stop'

$PSDefaultParameterValues['InModuleScope:ModuleName'] = $script:moduleName
$PSDefaultParameterValues['Mock:ModuleName'] = $script:moduleName
$PSDefaultParameterValues['Should:ModuleName'] = $script:moduleName
}

AfterAll {
$PSDefaultParameterValues.Remove('Mock:ModuleName')
$PSDefaultParameterValues.Remove('InModuleScope:ModuleName')
}
$PSDefaultParameterValues.Remove('Should:ModuleName')

Remove-Module -Name $script:moduleName
}

Describe 'Assert-IPAddress' -Tag 'AssertIPAddress' {
Context 'When invoking with valid IPv4 Address' {
Expand Down
16 changes: 11 additions & 5 deletions tests/Unit/Public/Assert-Module.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
BeforeAll {
$script:moduleName = 'DscResource.Common'

Remove-Module -Name $script:moduleName -Force -ErrorAction 'SilentlyContinue'
# If the module is not found, run the build task 'noop'.
if (-not (Get-Module -Name $script:moduleName -ListAvailable))
{
# Redirect all streams to $null, except the error stream (stream 2)
& "$PSScriptRoot/../../build.ps1" -Tasks 'noop' 2>&1 4>&1 5>&1 6>&1 > $null
}

Get-Module -Name $script:moduleName -ListAvailable |
Select-Object -First 1 |
Import-Module -Force -ErrorAction 'Stop'
# Re-import the module using force to get any code changes between runs.
Import-Module -Name $script:moduleName -Force -ErrorAction 'Stop'

$PSDefaultParameterValues['InModuleScope:ModuleName'] = $script:moduleName
$PSDefaultParameterValues['Mock:ModuleName'] = $script:moduleName
$PSDefaultParameterValues['Should:ModuleName'] = $script:moduleName
}

AfterAll {
$PSDefaultParameterValues.Remove('InModuleScope:ModuleName')
$PSDefaultParameterValues.Remove('Mock:ModuleName')
$PSDefaultParameterValues.Remove('InModuleScope:ModuleName')
$PSDefaultParameterValues.Remove('Should:ModuleName')

Remove-Module -Name $script:moduleName
}

Describe 'Assert-Module' {
Expand Down
24 changes: 20 additions & 4 deletions tests/Unit/Public/Compare-DscParameterState.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
BeforeAll {
$script:moduleName = 'DscResource.Common'

Remove-Module -Name $script:moduleName -Force -ErrorAction 'SilentlyContinue'
# If the module is not found, run the build task 'noop'.
if (-not (Get-Module -Name $script:moduleName -ListAvailable))
{
# Redirect all streams to $null, except the error stream (stream 2)
& "$PSScriptRoot/../../build.ps1" -Tasks 'noop' 2>&1 4>&1 5>&1 6>&1 > $null
}

# Re-import the module using force to get any code changes between runs.
Import-Module -Name $script:moduleName -Force -ErrorAction 'Stop'

$PSDefaultParameterValues['InModuleScope:ModuleName'] = $script:moduleName
$PSDefaultParameterValues['Mock:ModuleName'] = $script:moduleName
$PSDefaultParameterValues['Should:ModuleName'] = $script:moduleName
}

AfterAll {
$PSDefaultParameterValues.Remove('Mock:ModuleName')
$PSDefaultParameterValues.Remove('InModuleScope:ModuleName')
$PSDefaultParameterValues.Remove('Should:ModuleName')

Get-Module -Name $script:moduleName -ListAvailable |
Select-Object -First 1 |
Import-Module -Force -ErrorAction 'Stop'
Remove-Module -Name $script:moduleName
}

Describe 'ComputerManagementDsc.Common\Compare-DscParameterState' {
Expand Down
24 changes: 20 additions & 4 deletions tests/Unit/Public/Compare-ResourcePropertyState.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
BeforeAll {
$script:moduleName = 'DscResource.Common'

Remove-Module -Name $script:moduleName -Force -ErrorAction 'SilentlyContinue'
# If the module is not found, run the build task 'noop'.
if (-not (Get-Module -Name $script:moduleName -ListAvailable))
{
# Redirect all streams to $null, except the error stream (stream 2)
& "$PSScriptRoot/../../build.ps1" -Tasks 'noop' 2>&1 4>&1 5>&1 6>&1 > $null
}

# Re-import the module using force to get any code changes between runs.
Import-Module -Name $script:moduleName -Force -ErrorAction 'Stop'

$PSDefaultParameterValues['InModuleScope:ModuleName'] = $script:moduleName
$PSDefaultParameterValues['Mock:ModuleName'] = $script:moduleName
$PSDefaultParameterValues['Should:ModuleName'] = $script:moduleName
}

AfterAll {
$PSDefaultParameterValues.Remove('Mock:ModuleName')
$PSDefaultParameterValues.Remove('InModuleScope:ModuleName')
$PSDefaultParameterValues.Remove('Should:ModuleName')

Get-Module -Name $script:moduleName -ListAvailable |
Select-Object -First 1 |
Import-Module -Force -ErrorAction 'Stop'
Remove-Module -Name $script:moduleName
}

Describe 'Compare-ResourcePropertyState' -Tag 'CompareResourcePropertyState' {
Expand Down
24 changes: 20 additions & 4 deletions tests/Unit/Public/ConvertFrom-DscResourceInstance.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
BeforeAll {
$script:moduleName = 'DscResource.Common'

Remove-Module -Name $script:moduleName -Force -ErrorAction 'SilentlyContinue'
# If the module is not found, run the build task 'noop'.
if (-not (Get-Module -Name $script:moduleName -ListAvailable))
{
# Redirect all streams to $null, except the error stream (stream 2)
& "$PSScriptRoot/../../build.ps1" -Tasks 'noop' 2>&1 4>&1 5>&1 6>&1 > $null
}

# Re-import the module using force to get any code changes between runs.
Import-Module -Name $script:moduleName -Force -ErrorAction 'Stop'

$PSDefaultParameterValues['InModuleScope:ModuleName'] = $script:moduleName
$PSDefaultParameterValues['Mock:ModuleName'] = $script:moduleName
$PSDefaultParameterValues['Should:ModuleName'] = $script:moduleName
}

AfterAll {
$PSDefaultParameterValues.Remove('Mock:ModuleName')
$PSDefaultParameterValues.Remove('InModuleScope:ModuleName')
$PSDefaultParameterValues.Remove('Should:ModuleName')

Get-Module -Name $script:moduleName -ListAvailable |
Select-Object -First 1 |
Import-Module -Force -ErrorAction 'Stop'
Remove-Module -Name $script:moduleName
}

Describe 'ConvertFrom-DscResourceInstance' {
Expand Down
24 changes: 20 additions & 4 deletions tests/Unit/Public/ConvertTo-CimInstance.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
BeforeAll {
$script:moduleName = 'DscResource.Common'

Remove-Module -Name $script:moduleName -Force -ErrorAction 'SilentlyContinue'
# If the module is not found, run the build task 'noop'.
if (-not (Get-Module -Name $script:moduleName -ListAvailable))
{
# Redirect all streams to $null, except the error stream (stream 2)
& "$PSScriptRoot/../../build.ps1" -Tasks 'noop' 2>&1 4>&1 5>&1 6>&1 > $null
}

# Re-import the module using force to get any code changes between runs.
Import-Module -Name $script:moduleName -Force -ErrorAction 'Stop'

$PSDefaultParameterValues['InModuleScope:ModuleName'] = $script:moduleName
$PSDefaultParameterValues['Mock:ModuleName'] = $script:moduleName
$PSDefaultParameterValues['Should:ModuleName'] = $script:moduleName
}

AfterAll {
$PSDefaultParameterValues.Remove('Mock:ModuleName')
$PSDefaultParameterValues.Remove('InModuleScope:ModuleName')
$PSDefaultParameterValues.Remove('Should:ModuleName')

Get-Module -Name $script:moduleName -ListAvailable |
Select-Object -First 1 |
Import-Module -Force -ErrorAction 'Stop'
Remove-Module -Name $script:moduleName
}

# macOS and Linux does not support CimInstance.
Expand Down
Loading