Skip to content

Commit c4b6175

Browse files
authored
split tests, add switches, remove obsolete cabs (#23)
* split tests, add switches, remove obsolete cabs * module tests
1 parent aef55a1 commit c4b6175

9 files changed

Lines changed: 98 additions & 56 deletions

InstallModuleFromGit.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
RootModule = 'InstallModuleFromGit.psm1'
1313

1414
# Version number of this module.
15-
ModuleVersion = '1.0.0'
15+
ModuleVersion = '1.0.1'
1616

1717
# Supported PSEditions
1818
# CompatiblePSEditions = @()

Tests/Get-GitModule.Tests.ps1

Whitespace-only changes.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#
2+
# This is a PowerShell Unit Test file.
3+
# You need a unit test framework such as Pester to run PowerShell Unit tests.
4+
# You can download Pester from http://go.microsoft.com/fwlink/?LinkID=534084
5+
#
6+
7+
$CommandName = 'Get-GitModule'
8+
9+
Describe "$CommandName basic testing" -Tag 'Functionality' {
10+
11+
$moduleName = 'FIFA2018'
12+
$moduleURL = 'https://github.com/iricigor/' + $moduleName
13+
14+
It "$CommandName does not throw an exception" {
15+
{Get-GitModule $moduleURL} | Should -Not -Throw
16+
}
17+
18+
It "$CommandName returns some value" {
19+
Get-GitModule $moduleURL | Should -Not -Be $null
20+
}
21+
22+
It "$CommandName returns proper value" {
23+
(Get-GitModule $moduleURL).Name | Should -Be $moduleName
24+
}
25+
26+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#
2+
# This is a PowerShell Unit Test file.
3+
# You need a unit test framework such as Pester to run PowerShell Unit tests.
4+
# You can download Pester from http://go.microsoft.com/fwlink/?LinkID=534084
5+
#
6+
7+
$CommandName = 'Install-GitModule'
8+
9+
Describe "$CommandName basic testing" -Tag 'Functionality' {
10+
11+
$moduleName = 'psaptgetupdate'
12+
$moduleURL = 'https://github.com/iricigor/' + $moduleName
13+
14+
It "$CommandName does not throw an exception" {
15+
{Install-GitModule $moduleURL -Force} | Should -Not -Throw
16+
}
17+
18+
It "$CommandName returns some value" {
19+
Install-GitModule $moduleURL -Force | Should -Not -Be $null
20+
}
21+
22+
It "$CommandName returns proper value" {
23+
(Install-GitModule $moduleURL -Force).Name | Should -Be $moduleName
24+
}
25+
26+
It "$CommandName really installs module" {
27+
Get-Module $moduleName -ListAvailable | Should -Not -Be $null
28+
}
29+
}

Tests/Module.Tests.ps1 renamed to Tests/module/InstallModuleFromGit.Tests.ps1

Lines changed: 25 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -9,81 +9,62 @@
99
#
1010

1111
$ModuleName = 'InstallModuleFromGit'
12-
$here = Split-Path -Parent $MyInvocation.MyCommand.Path # test folder
13-
$root = (get-item $here).Parent.FullName # module root folder
12+
$here = Split-Path -Parent $MyInvocation.MyCommand.Path # Tests/Module folder
13+
$root = (get-item $here).Parent.Parent.FullName # module root folder
1414
Import-Module (Join-Path $root "$ModuleName.psm1") -Force
1515

1616

1717
#
1818
# Fake test
1919
#
2020

21-
Describe "Fake-Test" {
21+
Describe "Fake-Test" -Tag 'Other' {
2222
It "Should be fixed by developer" {
2323
$true | Should -Be $true
2424
}
2525
}
2626

2727

2828
#
29-
# Module should import two functions
29+
# Module manifest should have proper format
3030
#
3131

32+
Describe 'Proper Module Declaration' -Tag 'Documentation' {
3233

33-
Describe 'Proper Declarations' {
34+
$ModuleManifestFile = "$root/$ModuleName.psd1"
35+
It 'Module manifest can be parsed' {
36+
{Test-ModuleManifest $ModuleManifestFile} | Should -Not -Throw
37+
}
3438

35-
It 'Checks for existence of functions' {
36-
@(Get-Command -Module $ModuleName -CommandType Function).Count | Should -Be 2 -Because 'We should have two functions defined'
37-
Get-Command NonExistingCommand -ea 0 | Should -Be $Null
38-
# cache management
39-
Get-Command Get-GitModule -ea 0 | Should -Not -Be $Null
40-
Get-Command Install-GitModule -ea 0 | Should -Not -Be $Null
39+
$ModuleManifest = Test-ModuleManifest $ModuleManifestFile
40+
$ModuleVersion = $ModuleManifest.Version
41+
It 'Module version must be x.y.z' {
42+
($ModuleVersion.ToString() -split '\.').Count -ge 3 | Should -Be $true -Because "Module with version $ModuleVersion cannot exist online"
4143
}
4244

45+
It "Checks online for module version $ModuleVersion" {
46+
Find-Module $ModuleName -Repository PSGallery -RequiredVersion $ModuleVersion -ea 0 | Should -Be $null
47+
}
4348
}
4449

4550

4651
#
47-
# Basic tests, this should be added to individual files
52+
# Module should import two functions
4853
#
4954

50-
Describe 'Basic testing' {
51-
52-
$moduleName = 'FIFA2018'
53-
$moduleURL = 'https://github.com/iricigor/' + $moduleName
54-
It 'Get-GitModule does not throw an exception' {
55-
{Get-GitModule $moduleURL} | Should -Not -Throw
56-
}
57-
58-
It 'Get-GitModule returns some value' {
59-
Get-GitModule $moduleURL | Should -Not -Be $null
60-
}
61-
62-
It 'Get-GitModule returns proper value' {
63-
(Get-GitModule $moduleURL).Name | Should -Be $moduleName
64-
}
65-
66-
$moduleName = 'psaptgetupdate'
67-
$moduleURL = 'https://github.com/iricigor/' + $moduleName
68-
It 'Install-GitModule does not throw an exception' {
69-
{Install-GitModule $moduleURL -Force} | Should -Not -Throw
70-
}
71-
72-
It 'Install-GitModule returns some value' {
73-
Install-GitModule $moduleURL -Force | Should -Not -Be $null
74-
}
7555

76-
It 'Install-GitModule returns proper value' {
77-
(Install-GitModule $moduleURL -Force).Name | Should -Be $moduleName
78-
}
56+
Describe 'Proper Functions Declaration' -Tag 'Other' {
7957

80-
It 'Install-GitModule really installs module' {
81-
Get-Module $moduleName -ListAvailable | Should -Not -Be $null
58+
It 'Checks for existence of functions' {
59+
@(Get-Command -Module $ModuleName -CommandType Function).Count | Should -Be 2 -Because 'We should have two functions defined'
60+
Get-Command NonExistingCommand -ea 0 | Should -Be $Null
61+
Get-Command Get-GitModule -ea 0 | Should -Not -Be $Null
62+
Get-Command Install-GitModule -ea 0 | Should -Not -Be $Null
8263
}
8364
}
8465

8566

86-
Describe 'Proper Documentation' {
67+
Describe 'Proper Documentation' -Tag 'Documentation' {
8768

8869
It 'Updates documentation and does git diff' {
8970

@@ -105,7 +86,7 @@ Describe 'Proper Documentation' {
10586
}
10687

10788

108-
Describe 'ScriptAnalyzer Tests' {
89+
Describe 'ScriptAnalyzer Tests' -Tag 'Documentation' {
10990
it 'Checks cmdlets and finds no errors' {
11091
# Install PSScriptAnalyzer
11192
if (!(Get-Module PSScriptAnalyzer -List -ea 0)) {Install-Module PSScriptAnalyzer -Force -Scope CurrentUser}

cab/InstallGitModule_d6a1577c-e3b5-48f2-a698-f08ab4865a58_HelpInfo.xml

Lines changed: 0 additions & 10 deletions
This file was deleted.
Binary file not shown.
Binary file not shown.

InvokeTests.ps1 renamed to tools/InvokeTests.ps1

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
# Script which invokes tests inside of Azure DevOps Pipelines
33
#
44

5+
param (
6+
# Describes what type of tests to run
7+
[ValidateSet('FunctionalityOnly','DocumentationOnly','All')]
8+
[string]$TestsToRun
9+
)
10+
511
function InstallModule ([string]$Name,[version]$Version){
612
if (!(Get-Module $Name -List | where Version -ge $Version)) {
713
Write-Host "Installing $Name"
@@ -34,6 +40,16 @@ InstallModule PSScriptAnalyzer '1.17.0'
3440
# Run Pester Tests
3541
#
3642

43+
$here = Split-Path -Parent $MyInvocation.MyCommand.Path # tools folder
44+
$root = (get-item $here).Parent.FullName # module root folder
45+
$tests = Join-Path $root 'Tests' # tests folder
46+
47+
switch ($TestsToRun) {
48+
'FunctionalityOnly' { $Tags = @('Functionality','Other') }
49+
'DocumentationOnly' { $Tags = @('Documentation','Other') }
50+
'All' { $Tags = @('Documentation','Functionality','Other') }
51+
}
52+
3753
Write-Host "Run Pester tests"
38-
$Result = Invoke-Pester -PassThru -OutputFile PesterTestResults.xml
54+
$Result = Invoke-Pester -Path "$tests/module", "$tests/functions" -Tag $Tags -PassThru -OutputFile PesterTestResults.xml
3955
if ($Result.failedCount -ne 0) {Write-Error "Pester returned errors"}

0 commit comments

Comments
 (0)