Skip to content

Commit 99cb741

Browse files
authored
Merge pull request #6 from cloudyspells/feature/testoutput
Feature/testoutput
2 parents df99c5b + 53a5d53 commit 99cb741

4 files changed

Lines changed: 100 additions & 9 deletions

File tree

.github/workflows/qa.yml

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,42 @@ jobs:
3939
Set-PSRepository PSGallery -InstallationPolicy Trusted
4040
Install-Module Az.Resources
4141
Import-Module Az.Resources
42-
Invoke-Pester ./tests/PSWattTime.Tests/PSWattTime.Tests.ps1 `
43-
-PassThru `
44-
-CodeCoverage ./src/PSWattTime/PSWattTime.psm1 `
45-
-CodeCoverageOutputFile ./tests/coverage.xml `
46-
-CodeCoverageOutputFileFormat JaCoCo `
47-
-OutputFile ./tests/junit.xml `
48-
-OutputFormat JUnitXml `
49-
-EnableExit
42+
Import-Module Pester
43+
$pConfig = New-PesterConfiguration
44+
$pConfig.Run.Path = './tests/PSWattTime.Tests/PSWattTime.Tests.ps1'
45+
$pConfig.Run.PassThru = $true
46+
$pConfig.Output.CIFormat = 'GithubActions'
47+
$pConfig.Output.Verbosity = 'Detailed'
48+
$pConfig.TestResult.OutputFormat = 'JunitXml'
49+
$pConfig.TestResult.OutputPath ='./tests/junit.xml'
50+
$pConfig.TestResult.Enabled = $true
51+
$pConfig.CodeCoverage.Enabled = $true
52+
$pConfig.CodeCoverage.OutputFormat = 'JaCoCo'
53+
$pConfig.CodeCoverage.OutputPath = './tests/coverage.xml'
54+
$pConfig.CodeCoverage.Path = './src/PSWattTime/PSWattTime.psm1'
55+
$p = Invoke-Pester -Configuration $pConfig
56+
Write-Output "## Pester Test Results" >> $env:GITHUB_STEP_SUMMARY
57+
Write-Output "" >> $env:GITHUB_STEP_SUMMARY
58+
Write-Output "- Code coverage: **$($p.CodeCoverage.CoveragePercent)**" >> $env:GITHUB_STEP_SUMMARY
59+
Write-Output "- Commands Executed: **$($p.CodeCoverage.CommandsExecutedCount)**" >> $env:GITHUB_STEP_SUMMARY
60+
Write-Output "- Commands Missed: **$($p.CodeCoverage.CommandsMissedCount)**" >> $env:GITHUB_STEP_SUMMARY
61+
Write-Output "" >> $env:GITHUB_STEP_SUMMARY
62+
Write-Output "|Block|Test|Duration|Result|" >> $env:GITHUB_STEP_SUMMARY
63+
Write-Output "|---|---|---|---|" >> $env:GITHUB_STEP_SUMMARY
64+
$p.Tests | ForEach-Object {
65+
$mdTestResult = ""
66+
If($_.Result -eq 'Failed') {
67+
$mdTestResult = ":boom: Failed"
68+
}
69+
ElseIf($_.Result -eq 'Passed') {
70+
$mdTestResult = ":green_heart: Passed"
71+
}
72+
Else {
73+
$mdTestResult = ":nerd_face: $($_.Result)"
74+
}
75+
Write-Output "|$($_.Block)|$($_.Name)|$($_.Duration)|$($mdTestResult)|"
76+
} >> $env:GITHUB_STEP_SUMMARY
77+
Write-Output "" >> $env:GITHUB_STEP_SUMMARY
5078
5179
- name: Test the Module Manifest
5280
shell: pwsh
@@ -70,4 +98,4 @@ jobs:
7098
with:
7199
name: unit-tests
72100
path: ./tests/*.xml
73-
if: ${{ always() }}
101+
if: ${{ always() }}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
**/coverage.xml
2+
**/junit.xml
3+
**/coverage.xml

PSScriptAnalyzerSettings.psd1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@{
2+
ExcludeRules = @('PSAvoidUsingPlainTextForPassword')
3+
}

tests/PSWattTime.Tests/PSWattTime.Tests.ps1

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,45 @@ Describe "PSWattTimeTests" {
55
$env:WATTTIMEUSERNAME | Should -Not -BeNullOrEmpty
66
$env:WATTTIMEPASSWORD | Should -Not -BeNullOrEmpty
77
}
8+
9+
Context "When we have imported the module" {
10+
It "Should have a ConvertFrom-AzureRegion command" {
11+
$test = Get-Command -Module PSWattTime -Name 'ConvertFrom-AzureRegion'
12+
$test | Should -Not -BeNullOrEmpty
13+
$test.CommandType | Should -Be 'Function'
14+
}
15+
16+
It "Should have a Get-AzureRegionWithLowestWattTime command" {
17+
$test = Get-Command -Module PSWattTime -Name 'Get-AzureRegionWithLowestWattTime'
18+
$test | Should -Not -BeNullOrEmpty
19+
$test.CommandType | Should -Be 'Function'
20+
}
21+
22+
It "Should have a Get-WattTime command" {
23+
$test = Get-Command -Module PSWattTime -Name 'Get-WattTime'
24+
$test | Should -Not -BeNullOrEmpty
25+
$test.CommandType | Should -Be 'Function'
26+
}
27+
28+
It "Should have a Get-WattTimeAuthToken command" {
29+
$test = Get-Command -Module PSWattTime -Name 'Get-WattTimeAuthToken'
30+
$test | Should -Not -BeNullOrEmpty
31+
$test.CommandType | Should -Be 'Function'
32+
}
33+
34+
It "Should have a Get-WattTimeForAzureRegion command" {
35+
$test = Get-Command -Module PSWattTime -Name 'Get-WattTimeForAzureRegion'
36+
$test | Should -Not -BeNullOrEmpty
37+
$test.CommandType | Should -Be 'Function'
38+
}
39+
40+
It "Should have a New-WattTimeAccount command" {
41+
$test = Get-Command -Module PSWattTime -Name 'New-WattTimeAccount'
42+
$test | Should -Not -BeNullOrEmpty
43+
$test.CommandType | Should -Be 'Function'
44+
}
45+
46+
}
847

948
Context "When we login" {
1049
It "Should return a token" {
@@ -105,4 +144,22 @@ Describe "PSWattTimeTests" {
105144
$wattTime.percent | Should -BeOfType 'string'
106145
}
107146
}
147+
Context "When we register an account" {
148+
BeforeAll {
149+
Mock -ModuleName PSWattTime -CommandName Invoke-RestMethod { return (New-Object PSObject -Property @{'user' = 'freddo';'ok' = 'User created'})}
150+
$newAccount = New-WattTimeAccount `
151+
-Username 'freddo' `
152+
-Password 'P@ssvvordsAr3St00p1d' `
153+
-Organization 'CloudySpells' `
154+
-Email 'freddo@example.com'
155+
}
156+
157+
It "Should return a PSObject" {
158+
$newAccount | Should -BeOfType 'PSObject'
159+
}
160+
161+
It "Should return an ok field with a user created value" {
162+
$newAccount.ok | Should -Be 'User created'
163+
}
164+
}
108165
}

0 commit comments

Comments
 (0)