Skip to content

Commit

Permalink
Adding pester test
Browse files Browse the repository at this point in the history
  • Loading branch information
rumart committed Apr 17, 2019
1 parent 620135a commit c69ea7f
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 1 deletion.
Binary file modified GlobalDashboardPS/GlobalDashboardPS.psd1
Binary file not shown.
7 changes: 6 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Pester tests
- Scriptanalyzer test
- Function for adding members to a group
- Function for removing members from a group
Expand Down Expand Up @@ -37,6 +36,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Output format

## [version 0.4.0] - 2019-04-17

### Added

- Pester tests

## [version 0.3.0] - 2019-03-28

### Changed
Expand Down
25 changes: 25 additions & 0 deletions tests/Project.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
$projectRoot = Resolve-Path "$PSScriptRoot\.."
$moduleName = Split-Path $projectRoot -Leaf
$moduleRoot = Split-Path (Resolve-Path "$projectRoot\$moduleName\*.psm1")

Describe "General project validation: $moduleName" {

$scripts = Get-ChildItem $projectRoot -Include *.ps1,*.psm1,*.psd1 -Recurse

# TestCases are splatted to the script so we need hashtables
$testCase = $scripts | Foreach-Object{@{file=$_}}
It "Script <file> should be valid powershell" -TestCases $testCase {
param($file)

$file.fullname | Should Exist

$contents = Get-Content -Path $file.fullname -ErrorAction Stop
$errors = $null
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
$errors.Count | Should Be 0
}

It "Module '$moduleName' can import cleanly" {
{Import-Module (Join-Path $moduleRoot "$moduleName.psd1") -force } | Should Not Throw
}
}
25 changes: 25 additions & 0 deletions tests/ScriptAnalyzer.tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
$projectRoot = Resolve-Path "$PSScriptRoot\.."
$scripts = Get-ChildItem $projectRoot -Include *.ps1,*.psm1,*.psd1 -Recurse
Describe 'Testing against PSSA rules' {

Context "Checking all files against Powershell ScriptAnalyzer"{
It "Checking files exists" {
$script.count | Should Not Be 0
}
It "Checking if Invoke-ScriptAnalyzer exists" {
{ Get-Command Invoke-ScriptAnalyzer -ErrorAction Stop } | Should Not Throw
}
}

$scriptAnalyzerRules = Get-ScriptAnalyzerRule | Where-Object {$_.RuleName -ne "PSAvoidGlobalVars" -and $_.RuleName -ne "PSAvoidDefaultValueSwitchParameter"}

foreach($script in $scripts){
Context "PSSA Standard Rules - $($script.name)" {
forEach ($rule in $scriptAnalyzerRules) {
It "$script Should pass $($rule.RuleName)" {
(Invoke-ScriptAnalyzer -Path $script -IncludeRule $rule).Count | Should Be 0
}
}
}
}
}

0 comments on commit c69ea7f

Please sign in to comment.