Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion InstallModuleFromGit.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'InstallModuleFromGit.psm1'

# Version number of this module.
ModuleVersion = '1.0.0'
ModuleVersion = '1.0.1'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
Empty file removed Tests/Get-GitModule.Tests.ps1
Empty file.
26 changes: 26 additions & 0 deletions Tests/functions/Get-GitModule.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#
# This is a PowerShell Unit Test file.
# You need a unit test framework such as Pester to run PowerShell Unit tests.
# You can download Pester from http://go.microsoft.com/fwlink/?LinkID=534084
#

$CommandName = 'Get-GitModule'

Describe "$CommandName basic testing" -Tag 'Functionality' {

$moduleName = 'FIFA2018'
$moduleURL = 'https://github.com/iricigor/' + $moduleName

It "$CommandName does not throw an exception" {
{Get-GitModule $moduleURL} | Should -Not -Throw
}

It "$CommandName returns some value" {
Get-GitModule $moduleURL | Should -Not -Be $null
}

It "$CommandName returns proper value" {
(Get-GitModule $moduleURL).Name | Should -Be $moduleName
}

}
29 changes: 29 additions & 0 deletions Tests/functions/Install-GitModule.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#
# This is a PowerShell Unit Test file.
# You need a unit test framework such as Pester to run PowerShell Unit tests.
# You can download Pester from http://go.microsoft.com/fwlink/?LinkID=534084
#

$CommandName = 'Install-GitModule'

Describe "$CommandName basic testing" -Tag 'Functionality' {

$moduleName = 'psaptgetupdate'
$moduleURL = 'https://github.com/iricigor/' + $moduleName

It "$CommandName does not throw an exception" {
{Install-GitModule $moduleURL -Force} | Should -Not -Throw
}

It "$CommandName returns some value" {
Install-GitModule $moduleURL -Force | Should -Not -Be $null
}

It "$CommandName returns proper value" {
(Install-GitModule $moduleURL -Force).Name | Should -Be $moduleName
}

It "$CommandName really installs module" {
Get-Module $moduleName -ListAvailable | Should -Not -Be $null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,81 +9,62 @@
#

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


#
# Fake test
#

Describe "Fake-Test" {
Describe "Fake-Test" -Tag 'Other' {
It "Should be fixed by developer" {
$true | Should -Be $true
}
}


#
# Module should import two functions
# Module manifest should have proper format
#

Describe 'Proper Module Declaration' -Tag 'Documentation' {

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

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

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


#
# Basic tests, this should be added to individual files
# Module should import two functions
#

Describe 'Basic testing' {

$moduleName = 'FIFA2018'
$moduleURL = 'https://github.com/iricigor/' + $moduleName
It 'Get-GitModule does not throw an exception' {
{Get-GitModule $moduleURL} | Should -Not -Throw
}

It 'Get-GitModule returns some value' {
Get-GitModule $moduleURL | Should -Not -Be $null
}

It 'Get-GitModule returns proper value' {
(Get-GitModule $moduleURL).Name | Should -Be $moduleName
}

$moduleName = 'psaptgetupdate'
$moduleURL = 'https://github.com/iricigor/' + $moduleName
It 'Install-GitModule does not throw an exception' {
{Install-GitModule $moduleURL -Force} | Should -Not -Throw
}

It 'Install-GitModule returns some value' {
Install-GitModule $moduleURL -Force | Should -Not -Be $null
}

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

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


Describe 'Proper Documentation' {
Describe 'Proper Documentation' -Tag 'Documentation' {

It 'Updates documentation and does git diff' {

Expand All @@ -105,7 +86,7 @@ Describe 'Proper Documentation' {
}


Describe 'ScriptAnalyzer Tests' {
Describe 'ScriptAnalyzer Tests' -Tag 'Documentation' {
it 'Checks cmdlets and finds no errors' {
# Install PSScriptAnalyzer
if (!(Get-Module PSScriptAnalyzer -List -ea 0)) {Install-Module PSScriptAnalyzer -Force -Scope CurrentUser}
Expand Down

This file was deleted.

Binary file not shown.
Binary file not shown.
18 changes: 17 additions & 1 deletion InvokeTests.ps1 → tools/InvokeTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
# Script which invokes tests inside of Azure DevOps Pipelines
#

param (
# Describes what type of tests to run
[ValidateSet('FunctionalityOnly','DocumentationOnly','All')]
[string]$TestsToRun
)

function InstallModule ([string]$Name,[version]$Version){
if (!(Get-Module $Name -List | where Version -ge $Version)) {
Write-Host "Installing $Name"
Expand Down Expand Up @@ -34,6 +40,16 @@ InstallModule PSScriptAnalyzer '1.17.0'
# Run Pester Tests
#

$here = Split-Path -Parent $MyInvocation.MyCommand.Path # tools folder
$root = (get-item $here).Parent.FullName # module root folder
$tests = Join-Path $root 'Tests' # tests folder

switch ($TestsToRun) {
'FunctionalityOnly' { $Tags = @('Functionality','Other') }
'DocumentationOnly' { $Tags = @('Documentation','Other') }
'All' { $Tags = @('Documentation','Functionality','Other') }
}

Write-Host "Run Pester tests"
$Result = Invoke-Pester -PassThru -OutputFile PesterTestResults.xml
$Result = Invoke-Pester -Path "$tests/module", "$tests/functions" -Tag $Tags -PassThru -OutputFile PesterTestResults.xml
if ($Result.failedCount -ne 0) {Write-Error "Pester returned errors"}