Skip to content

Commit 0b69b3f

Browse files
committed
Using ModuleTools
1 parent 33a85bd commit 0b69b3f

File tree

5 files changed

+41
-11
lines changed

5 files changed

+41
-11
lines changed

.github/workflows/Tests.yml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Run Tests
2+
3+
# Controls when the workflow will run
4+
on:
5+
push:
6+
branches:
7+
- main
8+
pull_request:
9+
branches:
10+
- main
11+
workflow_dispatch:
12+
13+
jobs:
14+
build:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Install ModuleTools module form PSGallery
20+
run: |
21+
Install-PSResource -Repository PSGallery -Name ModuleTools -TrustRepository
22+
shell: pwsh
23+
24+
- name: Install ModuleTools module form PSGallery
25+
run: |
26+
Invoke-MTTest
27+
shell: pwsh

project.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
"LicenseUri": "https://github.com/belibug/SecretBackup/blob/main/LICENSE"
2020
},
2121
"Pester": {
22-
"TestResult": false,
22+
"TestResult": {
23+
"Enabled": true,
24+
"OutputFormat": "NUnitXml"
25+
},
2326
"Output": {
2427
"Verbosity": "Detailed"
2528
}
@@ -35,4 +38,4 @@
3538
"PSAvoidUsingConvertToSecureStringWithPlainText"
3639
]
3740
}
38-
}
41+
}

tests/integration/Module.Tests.ps1 tests/Module.Tests.ps1

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
BeforeAll {
2-
Import-Module -Name .\PSPacker
3-
$data = Import-ProjectData
2+
$data = Get-MTProjectInfo
43
}
54

65
Describe 'General Module Control' {

tests/integration/OutputFiles.Tests.ps1 tests/OutputFiles.Tests.ps1

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
BeforeAll {
2-
Import-Module -Name .\PSPacker
3-
$data = Import-ProjectData
2+
$data = Get-MTProjectInfo
43
$files = Get-ChildItem $data.OutputModuleDir
54
}
65

@@ -19,8 +18,7 @@ Describe 'Module and Manifest testing' {
1918
$status = (Get-AuthenticodeSignature -FilePath $_).Status
2019
if ($status -eq 'NotSigned') {
2120
Set-TestInconclusive -Message 'Not yet signed'
22-
}
23-
else {
21+
} else {
2422
$status | Should -Be 'Valid'
2523
}
2624
}

tests/meta/ScriptAnalyzer.Tests.ps1 tests/ScriptAnalyzer.Tests.ps1

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ BeforeDiscovery {
22
$files = Get-ChildItem -Path .\src -Filter '*.ps1' -Recurse
33
}
44
BeforeAll {
5-
Import-Module -Name .\PSPacker -Force
6-
$data = Import-ProjectData
5+
$ScriptAnalyzerSettings = @{
6+
IncludeDefaultRules = $true
7+
Severity = @('Warning', 'Error')
8+
ExcludeRules = @('PSAvoidUsingWriteHost', 'PSAvoidUsingConvertToSecureStringWithPlainText')
9+
}
710
}
811
Describe 'File: <_.basename>' -ForEach $files {
912
Context 'Code Quality Check' {
@@ -14,7 +17,7 @@ Describe 'File: <_.basename>' -ForEach $files {
1417
$errors.Count | Should -Be 0
1518
}
1619
It 'passess ScriptAnalyzer' {
17-
$saResults = Invoke-ScriptAnalyzer -Path $_ -Settings $data.PSScriptAnalyzer
20+
$saResults = Invoke-ScriptAnalyzer -Path $_ -Settings $ScriptAnalyzerSettings
1821
$saResults | Should -BeNullOrEmpty -Because $($saResults.Message -join ';')
1922
}
2023
}

0 commit comments

Comments
 (0)