Skip to content

Commit

Permalink
Adding test and release Utilities (#84)
Browse files Browse the repository at this point in the history
* added test module

* added tools

* Moved files

* updated paths

* updated paths

* added test data

* fixed paths

* rem old tests

* added ps 6 return

* fixed root path

* rem local file

* rem old files

* fixed path

* added PS core check
  • Loading branch information
athaynes authored Aug 22, 2018
1 parent ef79f64 commit 14b7ab2
Show file tree
Hide file tree
Showing 22 changed files with 3,466 additions and 229 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Cloned modules
DSCResource.Tests
PowerStig.Tests

# Editors
.vscode/
.vs/

# local preference scripts/utilities
.local/
12 changes: 2 additions & 10 deletions Tests/Integration/.tests.header.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@ $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot)
$script:moduleName = 'PowerStig.Convert'
$script:modulePath = "$($script:moduleRoot)\$($script:moduleName).psm1"

if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'PowerStig.Tests'))) -or `
(-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'PowerStig.Tests\TestHelper.psm1'))) )
{
& git @('clone', 'https://github.com/Microsoft/PowerStig.Tests', (Join-Path -Path $script:moduleRoot -ChildPath 'PowerStig.Tests'))
}

Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (
Join-Path -Path 'PowerStig.Tests' -ChildPath 'TestHelper.psm1')
) -Force

$helperModulePath = Join-Path -Path $script:moduleRoot -ChildPath 'Tools\TestHelper\TestHelper.psm1'
Import-Module $helperModulePath -Force
Import-Module $modulePath -Force
2 changes: 1 addition & 1 deletion Tests/Integration/DSCResources/.tests.header.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCR
& 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 'Tests\helper.psm1' ) -Force
Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'Tools\TestHelper\TestHelper.psm1' ) -Force
Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force
$TestEnvironment = Initialize-TestEnvironment `
-DSCModuleName $script:DSCModuleName `
Expand Down
8 changes: 1 addition & 7 deletions Tests/Integration/PowerStig.Integration.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@ $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot)
$script:moduleName = 'PowerStig'
$script:modulePath = "$($script:moduleRoot)\$($script:moduleName).psd1"

if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'PowerStig.Tests'))) -or `
(-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'PowerStig.Tests\TestHelper.psm1'))) )
{
& git @('clone', 'https://github.com/Microsoft/PowerStig.Tests', (Join-Path -Path $script:moduleRoot -ChildPath 'PowerStig.Tests'))
}

Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'PowerStig.Tests' -ChildPath 'TestHelper.psm1')) -Force
Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath 'Tools\TestHelper\TestHelper.psm1') -Force
Import-Module $modulePath -Force
#endregion

Expand Down
13 changes: 13 additions & 0 deletions Tests/Unit/.tests.header.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Unit Test Header
$script:moduleSection = Split-Path -Path (Split-Path -Path (Get-PSCallStack)[1].ScriptName -Parent ) -Leaf
$script:projectRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot)
$script:toolsRoot = Join-Path -Path $script:projectRoot -ChildPath 'Tools'
$script:moduleName = (Get-PSCallStack)[1].Command -replace '\.tests\.ps1', ''

$script:modulePath = "$($script:projectRoot)\$($script:moduleSection)\$script:moduleName\$($script:moduleName).psm1"

$helperModulePath = Join-Path -Path $script:toolsRoot -ChildPath (
Join-Path -Path 'TestHelper' -ChildPath 'TestHelper.psm1')

Import-Module -Name $helperModulePath -Force -Global
Import-Module -Name $script:modulePath -Force
2 changes: 1 addition & 1 deletion Tests/Unit/DSCResources/.tests.header.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Unit Test Header
$script:moduleRoot = Split-Path -Parent (Split-Path -Parent ( Split-Path -Parent $PSScriptRoot ) )
Import-Module (Join-Path -Path $moduleRoot -ChildPath 'Tests\helper.psm1') -Force
Import-Module (Join-Path -Path $moduleRoot -ChildPath 'Tools\TestHelper\TestHelper.psm1') -Force
2 changes: 1 addition & 1 deletion Tests/Unit/DSCResources/Composite.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ $script:DSCModuleName = 'PowerStig'
# Header

$script:moduleRoot = Split-Path -Parent (Split-Path -Parent (Split-Path -Parent $PSScriptRoot))
Import-Module (Join-Path -Path $moduleRoot -ChildPath 'Tests\helper.psm1') -Force
Import-Module (Join-Path -Path $moduleRoot -ChildPath 'Tools\TestHelper\TestHelper.psm1') -Force

Describe 'Common Tests - Configuration Module Requirements' {

Expand Down
10 changes: 1 addition & 9 deletions Tests/Unit/Module/.tests.header.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,7 @@ $script:moduleRoot = Split-Path -Parent (Split-Path -Parent (Split-Path -Parent
$script:moduleName = (Get-PSCallStack)[1].Command -replace '\.tests\.ps1', ''
$script:modulePath = "$($script:moduleRoot)$(($PSScriptRoot -split 'Unit')[1])\$script:moduleName\$($script:moduleName).psm1"

if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'PowerStig.Tests'))) -or `
(-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'PowerStig.Tests\TestHelper.psm1'))) )
{
& git @('clone', 'https://github.com/Microsoft/PowerStig.Tests', (Join-Path -Path $script:moduleRoot -ChildPath 'PowerStig.Tests'))
}

Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (
Join-Path -Path 'PowerStig.Tests' -ChildPath 'TestHelper.psm1')
) -Force -Global
Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath 'Tools\TestHelper\TestHelper.psm1') -Force -Global

<#
Several classes check for duplicate rules against a global variable stigSettings.
Expand Down
Loading

0 comments on commit 14b7ab2

Please sign in to comment.