Skip to content

Commit

Permalink
Added stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
adbertram committed May 12, 2017
1 parent 98b81f7 commit 1e78a8f
Show file tree
Hide file tree
Showing 3 changed files with 277 additions and 169 deletions.
207 changes: 133 additions & 74 deletions PowerShell Gallery/Publish-PowerShellGalleryModule.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,115 +1,174 @@
. .\Publish-PowerShellGalleryModule.ps1
. "$PSScriptRoot\Publish-PowerShellGalleryModule.ps1"

$commandName = 'Publish-PowerShellGalleryModule'

#region Mocks
mock 'Test-Path' {
$true
}

mock 'ShowMenu'

mock 'PromptChoice'

mock 'GetRequiredManifestKeyParams' {
@{
Version = 'ver'
Description = 'desc'
Author = 'authorhere'
ProjectUri = 'urihere'
describe 'Publish-PowerShellGalleryModule' {
#region Mocks
mock 'Test-Path' {
$true
}
}

mock 'New-ModuleManifest'
mock 'ShowMenu'

mock 'Test-ModuleManifest' {
$true
}

mock 'Add-Content'
mock 'PromptChoice'

mock 'Get-Module' {
@{
Path = 'manifestpath'
Description = 'deschere'
Author = 'authhere'
Version = 'verhere'
LicenseUri = 'licurihere'
mock 'GetRequiredManifestKeyParams' {
@{
Version = 'ver'
Description = 'desc'
Author = 'authorhere'
ProjectUri = 'urihere'
}
}
}

mock 'Update-ModuleManifest'
mock 'New-ModuleManifest'

mock 'Publish-Module'
mock 'Test-ModuleManifest' {
$true
}

mock 'Invoke-Test'
#endregion
mock 'Add-Content'

it 'should run all optional tests if chosen' {
& $commandName -ModuleFilePath 'C:\module.psm1' -RunOptionalTests
mock 'Update-ModuleManifest'

mock 'Publish-Module'

}
mock 'Invoke-Test'

it 'should run all mandatory tests' {
function Get-Module {
@{
Path = 'manifestpath'
Description = 'deschere'
Author = 'authhere'
Version = 'verhere'
LicenseUri = 'licurihere'
ModuleBase = 'modulebase'
Name = 'modulename'
}
}
#endregion

}
$parameterSets = @(
@{
ModuleFilePath = 'C:\module.psm1'
TestName = 'Mandatory params'
}
@{
ModuleFilePath = 'C:\module.psm1'
RunOptionalTests = $true
NuGetApiKey = 'xxxx'
PublishToGallery = $true
TestName = 'All tests / Publish to Gallery'
}
@{
ModuleFilePath = 'C:\module.psm1'
RunOptionalTests = $true
NuGetApiKey = 'xxxx'
TestName = 'All tests'
}
@{
ModuleFilePath = 'C:\module.psm1'
NuGetApiKey = 'xxxx'
PublishToGallery = $true
TestName = 'Publish to Gallery'
}
)

$testCases = @{
All = $parameterSets
AllTests = $parameterSets.where({$_.ContainsKey('RunOptionalTests')})
PublishToGallery = $parameterSets.where({$_.ContainsKey('PublishToGallery')})
NoApi = $parameterSets.where({-not $_.ContainsKey('NuGetApiKey')})
NugetApi = $parameterSets.where({$_.ContainsKey('NuGetApiKey')})
}

it 'should call Publish-Module with the expected parameters' {

}
it 'should run all mandatory tests: <TestName>' -TestCases $testCases.NugetApi {
param($ModuleFilePath,$RunOptionalTests,$NuGetApiKey,$PublishGallery)

$result = & $commandName @PSBoundParameters

$testNames = 'Module manifest exists','Manifest has all required keys','Manifest passes Test-Modulemanifest validation'
foreach ($name in $testNames) {
$assMParams = @{
CommandName = 'Invoke-Test'
Times = 1
Exactly = $true
Scope = 'It'
ParameterFilter = { $PSBoundParameters.TestName -eq $name }
}
Assert-MockCalled @assMParams
}

context 'When immediately publishing to the PowerShell Gallery' {
}

it 'should call Publish-Module with the expected parameters' {
# context 'When RunOptionalTests is chosen' {

}
}
# it 'should run all optional tests: <TestName>' -TestCases $testCases.AllTests {
# param($ModuleFilePath,$RunOptionalTests,$NuGetApiKey,$PublishGallery)

# $result = & $commandName @PSBoundParameters
# }

context 'When no NuGet API key is passed' {
# }

it 'throws an exception' {
s
}
}
# context 'when PublishToGallery is chosen' {

context 'When no module manifest exists' {
# it 'should call Publish-Module with the expected parameters: <TestName>' -TestCases $testCases.PublishToGallery {
# param($ModuleFilePath,$RunOptionalTests,$NuGetApiKey,$PublishGallery)

# $result = & $commandName @PSBoundParameters
# }

it 'should run the fix action' {

}
}
# }

context 'When a module manifest exists but does not have required keys' {
# context 'When no NuGet API key is passed' {

it 'should run the fix action' {
# it 'return a non-terminating error: <TestName>' -TestCases $testCases.NoApi {
# param($ModuleFilePath,$RunOptionalTests,$NuGetApiKey,$PublishGallery)

# $result = & $commandName @PSBoundParameters -ErrorVariable err -ErrorAction SilentlyContinue
# $err.Exception.Message | should match 'The NuGet API key was not found'
# }
# }

}
}
# context 'When no module manifest exists' {

context 'When no Pester tests are found' {
# it 'should run the fix action' {
# param($ModuleFilePath,$RunOptionalTests,$NuGetApiKey,$PublishGallery)
# }
# }

it 'should run the fix action' {
# context 'When a module manifest exists but does not have required keys' {

}
# it 'should run the fix action' {
# param($ModuleFilePath,$RunOptionalTests,$NuGetApiKey,$PublishGallery)
# }
# }

it 'should create a describe block for each exported module function' {
# context 'When no Pester tests are found' {

}
}
# it 'should run the fix action' {
# param($ModuleFilePath,$RunOptionalTests,$NuGetApiKey,$PublishGallery)
# }

context 'When it does not pass Test-ModuleManifest' {
# it 'should create a describe block for each exported module function' {
# param($ModuleFilePath,$RunOptionalTests,$NuGetApiKey,$PublishGallery)
# }
# }

it 'should run the fix action' {
# context 'When it does not pass Test-ModuleManifest' {

}
}
# it 'should run the fix action' {
# param($ModuleFilePath,$RunOptionalTests,$NuGetApiKey,$PublishGallery)
# }
# }

context 'When the module is not found' {
# context 'When the module is not found' {

it 'should throw an exception' {
# it 'should throw an exception' {

}
# }
# }
}


Loading

0 comments on commit 1e78a8f

Please sign in to comment.