Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lipkau committed Oct 20, 2018
1 parent 765d97b commit 5108885
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 28 deletions.
7 changes: 5 additions & 2 deletions JiraPS.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ task PrepareTests Init, {

# Synopsis: Compile all functions into the .psm1 file
task CompileModule Init, {
$regionsToKeep = @('Dependencies', 'ModuleConfig')
$regionsToKeep = @('Dependencies', 'Configuration')

$targetFile = "$env:BHBuildOutput/$env:BHProjectName/$env:BHProjectName.psm1"
$content = Get-Content -Encoding UTF8 -LiteralPath $targetFile
Expand Down Expand Up @@ -225,7 +225,9 @@ task UpdateManifest GetNextVersion, {
}

# Synopsis: Create a ZIP file with this build
task Package GenerateRelease, {
task Package Init, {
Assert-True { Test-Path "$env:BHBuildOutput\$env:BHProjectName" } "Missing files to package"

Remove-Item "$env:BHBuildOutput\$env:BHProjectName.zip" -ErrorAction SilentlyContinue
$null = Compress-Archive -Path "$env:BHBuildOutput\$env:BHProjectName" -DestinationPath "$env:BHBuildOutput\$env:BHProjectName.zip"
}
Expand All @@ -246,6 +248,7 @@ task Test Init, {
$codeCoverageFiles = Get-ChildItem @params #>

try {
$ExcludeTag | Out-String | Write-Host
$parameter = @{
Script = "$env:BHBuildOutput/Tests/*"
Tag = $Tag
Expand Down
43 changes: 23 additions & 20 deletions Tests/Functions/Invoke-JiraMethod.Unit.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,13 @@ Describe "Invoke-JiraMethod" -Tag 'Unit' {
Mock Invoke-WebRequest -ModuleName $env:BHProjectName {
ShowMockInfo 'Invoke-WebRequest' -Params 'Uri', 'Method', 'Body', 'Headers', 'ContentType', 'SessionVariable', 'WebSession'
$InvokeWebRequestSplat = @{
Uri = $Uri
Method = $Method
Body = $Body
Headers = $Headers
WebSession = $WebSession
ContentType = $ContentType
Uri = $Uri
Method = $Method
Body = $Body
Headers = $Headers
WebSession = $WebSession
ContentType = $ContentType
UseBasicParsing = $true
}
if ($SessionVariable) {
$InvokeWebRequestSplat["SessionVariable"] = $SessionVariable
Expand Down Expand Up @@ -221,7 +222,7 @@ Describe "Invoke-JiraMethod" -Tag 'Unit' {
ParameterFilter = {
$Body -is [Byte[]] -and
(($Body -join " ") -eq "76 111 114 101 109 32 195 153 226 128 166 195 152 194 177 195 152 194 173 195 152 194 168 195 152 194 167 32 195 144 226 128 148 195 144 194 180 195 145 226 130 172 195 144 194 176 195 144 194 178 195 145 194 129 195 145 226 128 154 195 144 194 178 195 145 198 146 195 144 194 185 195 145 226 128 154 195 144 194 181 32 195 176 197 184 203 156 194 129" -or
($Body -join " ") -eq "76 111 114 101 109 32 217 133 216 177 216 173 216 168 216 167 32 208 151 208 180 209 128 208 176 208 178 209 129 209 130 208 178 209 131 208 185 209 130 208 181 32 240 159 152 129")
($Body -join " ") -eq "76 111 114 101 109 32 217 133 216 177 216 173 216 168 216 167 32 208 151 208 180 209 128 208 176 208 178 209 129 209 130 208 178 209 131 208 185 209 130 208 181 32 240 159 152 129")
}
Exactly = $true
Times = 1
Expand Down Expand Up @@ -329,12 +330,12 @@ Describe "Invoke-JiraMethod" -Tag 'Unit' {
Invoke-JiraMethod -Method get -URI "https://postman-echo.com/get" -OutputType $type -Paging -ErrorAction Stop

$assertMockCalledSplat = @{
CommandName = "Convert-Result"
ModuleName = $env:BHProjectName
CommandName = "Convert-Result"
ModuleName = $env:BHProjectName
ParameterFilter = { $OutputType -eq $type}
Exactly = $true
Times = 1
Scope = 'It'
Exactly = $true
Times = 1
Scope = 'It'
}
Assert-MockCalled @assertMockCalledSplat
}
Expand All @@ -343,12 +344,12 @@ Describe "Invoke-JiraMethod" -Tag 'Unit' {
Invoke-JiraMethod -Method get -URI "https://postman-echo.com/get" -OutputType $type -ErrorAction Stop

$assertMockCalledSplat = @{
CommandName = "Convert-Result"
ModuleName = $env:BHProjectName
CommandName = "Convert-Result"
ModuleName = $env:BHProjectName
ParameterFilter = { $OutputType -eq $type}
Exactly = $true
Times = 0
Scope = 'It'
Exactly = $true
Times = 0
Scope = 'It'
}
Assert-MockCalled @assertMockCalledSplat
}
Expand Down Expand Up @@ -546,9 +547,11 @@ Describe "Invoke-JiraMethod" -Tag 'Unit' {
}

$InvokeWebRequestSplat = @{
Uri = "https://postman-echo.com/post"
Method = "Post"
Body = $response
Uri = "https://postman-echo.com/post"
Method = "Post"
Body = $response
UseBasicParsing = $true

}
$result = Microsoft.PowerShell.Utility\Invoke-WebRequest @InvokeWebRequestSplat

Expand Down
7 changes: 5 additions & 2 deletions Tests/Project.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,13 @@ Describe "General project validation" -Tag Unit {
}

It "has all the public functions as a file in '$env:BHProjectName/Public'" {
$publicFunctions = (Get-Module -Name $env:BHProjectName).ExportedCommands.Keys
$module = (Get-Module -Name $env:BHProjectName)
$publicFunctions = $module.ExportedFunctions.Keys

foreach ($function in $publicFunctions) {
# $function = $function.Replace((Get-Module -Name $env:BHProjectName).Prefix, '')
if ($module.Prefix) {
$function = $function.Replace($module.Prefix, '')
}

(Get-ChildItem "$env:BHModulePath/Public").BaseName | Should -Contain $function
}
Expand Down
8 changes: 4 additions & 4 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ phases:
Invoke-Build -Task ShowInfo
displayName: Setup
- powershell: 'Invoke-Build -Task Test -ExcludeTag "Integration"'
- powershell: 'Invoke-Build -Task Test -ExcludeTag "Documentation", "Integration"'
displayName: Test

- task: PublishTestResults@2
Expand Down Expand Up @@ -87,7 +87,7 @@ phases:
Invoke-Build -Task ShowInfo
displayName: Setup
- powershell: 'Invoke-Build -Task Test -ExcludeTag "Integration"'
- powershell: 'Invoke-Build -Task Test -ExcludeTag "Documentation", "Integration"'
displayName: Test

- task: PublishTestResults@2
Expand Down Expand Up @@ -118,7 +118,7 @@ phases:
Invoke-Build -Task ShowInfo
displayName: Setup
- powershell: 'Invoke-Build -Task Test -ExcludeTag "Integration"'
- powershell: 'Invoke-Build -Task Test -ExcludeTag "Documentation", "Integration"'
displayName: Test

- task: PublishTestResults@2
Expand Down Expand Up @@ -154,7 +154,7 @@ phases:
- powershell: |
$Env:Path = [Environment]::GetEnvironmentVariable('Path',[EnvironmentVariableTarget]::Machine)
pwsh -command "Invoke-Build -Task Test -ExcludeTag "Integration""
pwsh -command "Invoke-Build -Task Test -ExcludeTag "Documentation", "Integration""
displayName: Test
- task: PublishTestResults@2
Expand Down

0 comments on commit 5108885

Please sign in to comment.